A Supergraph
is the singuar representation of a stitched graph. Supergraph
is composed from many locations, and provides a combined GraphQL schema and delegation maps used to route incoming requests.
A Supergraph is designed to be composed, cached, and restored. Calling to_definition
will return an SDL (Schema Definition Language) print of the combined graph schema with delegation mapping directives. This pre-composed schema can be persisted in any raw format that suits your stack:
supergraph_sdl = supergraph.to_definition
# write the composed schema as a file into your repo...
File.write("supergraph/schema.graphql", supergraph_sdl)
# or, stash this composed schema in a cache...
$cache.set("cached_supergraph_sdl", supergraph_sdl)
To restore a Supergraph, call from_definition
providing the cached SDL string and a hash of executables keyed by their location names:
supergraph_sdl = File.read("supergraph/schema.graphql")
supergraph = GraphQL::Stitching::Supergraph.from_definition(
supergraph_sdl,
executables: {
my_remote: GraphQL::Stitching::HttpExecutable.new(url: "http://localhost:3000"),
my_local: MyLocalSchema,
}
)