node.jsgraphqlapollographql-tools

graphql mergeSchemas from GraphQLObjectType schemas


I'm new to graphql so i'm facing some problems. Server based on nodeJS with express package. I'm writing my schemas for Apollo Graphql in GraphQLObjectType notation. When i want to merge two schemas in one i use mergeSchemas method from graphql-tools npm package and got some errors with merging. Can anyone point me what i'm doing incorrect?

const { mergeSchemas } = require('graphql-tools');
const { GraphQLSchema } = require('graphql');

const queryType = require('./queryType');
const eventMutations = require('./eventMutations');
const userMutations = require('./userMutations');

const mutationType = mergeSchemas({
  schemas: [eventMutations, userMutations],
});

module.exports = new GraphQLSchema({
  query: queryType,
  mutation: mutationType,
});

each of eventMutations, userMutations is GraphQLObjectType

The error is:

Invalid schema passed

at

mergeSchemas({...

Any ideas?


Solution

  • The problem was I wanted to merge GraphQLObjectType but not really GraphQLSchema. So the solution was to create GraphQLSchema for user and event and then perfectly merge them together.