graphql-gateway-tools
A set of tools to help you build a GraphQL Gateway using remote schemas and schema stitching.
SchemaGenerator
A higher order helper for creating a merged schema. It makes it easy to compose a schema, by providing methods to add remote schema endpoints, local GraphQL schemas, partial type definitions, and multiple resolver functions.
// Create a remoteExecutableSchema by specifying the endpoint addressawait schemaGenerator.registerEndpoint // Create a remoteExecutableSchema by specifying endpoint adddress and introspection schema:await schemaGenerator.registerEndpoint // Create a remoteExecutableSchema by passing in an ApolloLink instanceawait schemaGenerator.registerEndpoint // Create a remoteExecutableSchema that uses an Authorization bearer tokenawait schemaGenerator.registerEndpoint // Add a schema schemaGenerator.registerSchemaschema: myGraphQLSchema // Add a type definitionschemaGenerator.registerTypeDefinitiontypeDefs: myTypeDefinitionString // Add a resolver functionschemaGenerator.registerResolverresolverFunction: myResolverFunction // Generate the merged schema
See the examples folder for a complete example (coming soon).
addTypeNameField
If you add an Interface Types to your merged schema, you have to manually add the __typeName
field to your resolvers. This helper function makes it easy to do so.
// Assuming you have created a remote schema mySchema with types Car and Boat
addFields(mergeInfo: MergeInfo, fields: Array<FieldNode | string>)
A generic helper for adding fields to the resolveInfo, by passing in a fieldName, or a complete FieldNode.
addFieldsmergeInfo,