首页 > 解决方案 > 如果获得超过 1 个模式,Graphql 工具 mergeSchemas 会抛出错误

问题描述

我正在尝试使用 graphql 工具来执行模式拼接。但是,如果我传递多个模式,则会引发 2 个错误。

有时它会抛出

 Object.keys(source).forEach(key => {
                                        ^
RangeError: Maximum call stack size exceeded

或者

\'use strict';
^

RangeError: Maximum call stack size exceeded

我的架构设置非常简单。我只有 2 个模式国家和城市。那些也有 UUID、JSON 标量类型。

import {
  makeExecutableSchema,
  mergeSchemas,
} from 'graphql-tools'
import GraphQLUUID from 'graphql-type-uuid'
import GraphQLJSON from 'graphql-type-json'

const countrySchema = makeExecutableSchema({
  typeDefs:`
    scalar UUID
    type Country {
      id: UUID!
      name: String
    }
    type Query {
      country: Country
    }
  `,
  resolvers: {
    UUID: GraphQLUUID,
  }
})


const citySchema = makeExecutableSchema({
  typeDefs:`
    scalar UUID
    scalar JSON
    type City {
      id: UUID!
      name: String
      coordinates: JSON
    }
    type Query {
      city: City
    }
  `,
  resolvers: {
    UUID: GraphQLUUID,
    JSON: GraphQLJSON,
  }
})


const resolvers = {
  Query: {
    country: () => ({ id: '2ij29fij390f3j', name: 'Toronto'}),
    city: () => ({id: '2ij29fij390f3j11', name: 'Toronto', coordinates: "[]"})
  }
}

export const schema = mergeSchemas({
  schemas: [ countrySchema, citySchema],
  resolvers: resolvers

});

有趣的是,如果我将 countrySchema 或 citySchema 传递给 schemas 数组。有用。但他们都抛出了我上面提到的错误。

请分享你的想法。

标签: graphql-jsapollo-servergraphql-tools

解决方案


这似乎是 6.0.0 版本引入的回归graphql-tools。通过运行将您的版本降低到 5.0.0 npm install graphql-tools@5.0.0。如果一个 issue 还没有被打开,你可以在 Github 上为这个 bug 打开一个。


推荐阅读