我正在尝试使用 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 数组。有用。但他们都抛出了我上面提到的错误。
请分享你的想法。