Skip to content

Latest commit

 

History

History
31 lines (22 loc) · 1.21 KB

supergraph.md

File metadata and controls

31 lines (22 loc) · 1.21 KB

GraphQL::Stitching::Supergraph

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.

Export and caching

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

# stash this composed schema in a cache...
$cache.set("cached_supergraph_sdl", supergraph_sdl)

# or, write the composed schema as a file into your repo...
File.write("supergraph/schema.graphql", 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 = $cache.get("cached_supergraph_sdl")

supergraph = GraphQL::Stitching::Supergraph.from_definition(
  supergraph_sdl,
  executables: {
    my_remote: GraphQL::Stitching::HttpExecutable.new(url: "http://localhost:3000"),
    my_local: MyLocalSchema,
  }
)