Can two GraphQLSchema instances be merged?

merge-graphql-schemas
merge graphql queries

I'm looking to write a function like Object.assign or _.merge, but that operates on GraphQLSchema objects.

Suppose I have two instances of GraphQLSchema, call them Base and Other, and I would like to merge Other into Base to produce a new instance Result such that

  • Fields present in exactly one of Base or Other are defined in Result by their original GraphQLFieldConfig
  • Fields present in both are reduced to the GraphQLFieldConfig in Other.

It looks as though there is no documented means to do this. Is that correct? If I went the (considerably more dangerous) undocumented route, I've noticed that I could exploit internal properties of the object:

, but I'd prefer not to do that.

Any advice would be appreciated. Thanks in advance!

Please check the library merge-graphql-schemas. I think this may help you

GraphQL schema stitching, There are tons of examples out there, including the Apollo GitHunt Schema stitching is the idea that you can take two or more GraphQL schemas, and merge them into one endpoint that can pull data from all of them. There are two ways you can use this package: manually import each type; import everything from a specified folder; Manually import each type. If you decide to have manual control of each file that gets merged, all you need is the mergeTypes(types) function. Ability to merge a GQL Type defined multiple times in separate files.

Here is my solution:

const { mergeTypes } = require('merge-graphql-schemas');
const { printSchema, parse } = require('graphql');

const typeArray = graphqlSchemas.map(printSchema);
const schema = mergeTypes(typeArray, { all: true });

  try {
    parse(schema);
  } catch (err) {
    console.log(err);
  }

graphqlSchemas is GraphQLSchema type. For my case, it's array.

printSchema convert GraphQLSchema to string template schema.

mergeTypes merge all string template schemas into one.

And, for safety, use try/catch to validate the schema is valid or not.

Schema stitching - Apollo Server, To do this, we first need to make a GraphQL schema object for each remote API we want to stitch together. Apollo Link brings with it a large feature set for common use cases. In this example we'll stitch together two very simple schemas. resolvers on a merged schema can define a fragment property that specifies the  Having one large schema file is not always viable. You can modularise you schema using two techniques. The first technique is to merge multiple Schema SDL files into one logic unit. In the case below the schema has been split into multiple files and merged all together just before schema generation.

Using mergeSchemas from 'graphql-tools', you can merge GraphQLSchema objects

https://www.apollographql.com/docs/graphql-tools/schema-stitching.html#mergeSchemas

import { mergeSchemas } from 'graphql-tools';

const schema = mergeSchemas({
  schemas: [
    chirpSchema,
    authorSchema,
  ],
});

The Guild is taking over maintenance of merge-graphql-schemas, so , merge-graphql-schemas will be added to the existing Schema management of merge-graphql-schemas, so let's talk about GraphQL Schema management GraphQL Tools and Frameworks; Structuring multiple servers instances into a  GraphQL error: Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory. 👍 7

The ultimate guide to Schema Stitching in GraphQL, with custom typedefs & resolvers you can define, to create a newly combined GraphQL schema We will use Hasura GraphQL Engine API for all our examples. 2. Create executable schemas from the remote GraphQL APIs using the view raw merge-github-bazookaand.js hosted with ❤ by GitHub. 4. Merges another GraphQLObjectType or GraphQLInterfaceType with this one by taking the union of all fields in both types, overwriting this type's fields with the other's if there are conflicts. For GraphQLObjectTypes, implemented interfaces are also merged.

Merging GraphQL schema files and more from the CLI, new GraphQL transform feature for orchestrating multiple AI/ML use cases For example, you may want to break down your GraphQL schema based You can merge your schema files across different modules and directories. A glob is a string of both literal and wildcard characters that you can use to  This is a WIP take on schema-stiching and schema merging. This will be published to a pre-release tag. See src/test/testingSchemas.js for examples.. API makeRemoteExecutableSchema({ schema: GraphQLSchema, fetcher: Fetcher }): GraphQLSchema Given a GraphQL schema (can be a non-executable client schema made by buildClientSchema) and a Fetcher, produce a GraphQL Schema that routes all requests to

Combining APIs using GraphQL schema stitching: Part 2, This can make it easier to access data that is split across multiple APIs In this sequel, we will delve into a working example of GraphQL schema stitching to the executable schemas for both these APIs and merging them together in in this instance) holds (such as which team maintains the repository). A new instance of GraphQLSchema will be created and stored on the instance but the pre-existing resolvers will be deeply merged with the supplied resolvers on the schema to be merged and all will be applied and bound to the newly generated schema.

Comments
  • This library seems do not support merge GraphQLSchema objects. It only supports merge graphql string schema.