GraphQL Apollo模式委托:info.mergeInfo未定义

时间:2019-05-19 11:47:45

标签: graphql apollo

我遵循了官方的doc to delegate a graphql schema,这表明要这样做,必须使用在参数{{1}的属性delegateSchema上可以找到的方法mergeInfo }传递给解析器:

info

但是resolver: (parent, args, ctx, info) => { return info.mergeInfo.delegateSchema({ // Schema delegation options... }) } 参数上没有属性mergeInfo!因此,我收到以下错误消息:info,这是正常的,考虑到这些是GraphQL Error GraphQL error: Cannot read property 'delegateToSchema' of undefined的顶级属性:

info
console.log(Object.keys(info))

type definition of the GraphQLResolveInfo object

中甚至没有提到[ 'fieldName', 'fieldNodes', 'returnType', 'parentType', 'path', 'schema', 'fragments', 'rootValue', 'operation', 'variableValues', 'cacheControl' ]

文档是过时的还是缺少什​​么?

谢谢

1 个答案:

答案 0 :(得分:2)

mergeInfo仅在使用mergeSchemas将两个或多个模式缝合在一起时才注入到信息对象中。此外,它只会 注入到您在模式拼接过程中添加的字段的解析器中-架构的解析器不会受到影响( delegate并没有什么意义转换为现有模式之一上下文中的另一个模式)。

这是一个简单的例子:

const { makeExecutableSchema, mergeSchemas } = require('graphql-tools')

const schemaA = makeExecutableSchema({
  typeDefs: `
    type Query {
      foo: String
    }
  `,
})
const schemaB = makeExecutableSchema({
  typeDefs: `
    type Query {
      bar: String
    }
  `,
})
const typeDefs = `
extend type Query {
  foobar: String
}
`
const schema = mergeSchemas({
  schemas: [schemaA, schemaB, typeDefs],
})

在这里,foobar的解析器将无法访问mergeInfo,但是foobar的解析器将具有访问权限。