Graphql工具mergeSchemas如果获得多个模式,则会引发错误

问题描述 投票:1回答:1

我正在尝试使用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-js apollo-server graphql-tools
1个回答
0
投票

这似乎是graphql-tools版本6.0.0引入的回归。通过运行npm install [email protected]将您的版本降低到5.0.0。如果尚未打开问题,则可以在Github上打开此错误。

© www.soinside.com 2019 - 2024. All rights reserved.