1

我是graphql的新手,所以我遇到了一些问题。基于 nodeJS 的服务器,带有 express 包。我正在用 GraphQLObjectType 表示法为 Apollo Graphql 编写模式。当我想将两个模式合并为一个时,我使用 graphql-tools npm 包中的 mergeSchemas 方法,并在合并时遇到了一些错误。谁能指出我做错了什么?

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,
});

每个 eventMutations, userMutations 都是 GraphQLObjectType

错误是:

Invalid schema passed

mergeSchemas({...

有任何想法吗?

4

1 回答 1

1

问题是我想合并 GraphQLObjectType 但不是真正的 GraphQLSchema。因此解决方案是为用户和事件创建 GraphQLSchema,然后将它们完美地合并在一起。

于 2019-04-01T06:43:40.853 回答