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

GraphQL Apollo schema delegation: info.mergeInfo is undefined

我按照官方的doc to delegate a graphql schema说明,要做到这一点,必须使用方法delegateSchema,可以在属性 mergeInfo传递给解析器的参数 info

resolver: (parent, args, ctx, info) => {
  return info.mergeInfo.delegateSchema({
    // Schema delegation options...
  })
}

但是 info 参数上没有 属性 mergeInfo !所以我收到此错误消息:GraphQL Error GraphQL error: Cannot read property 'delegateToSchema' of undefined 考虑到这些是 info:

的顶级属性,这是正常的
console.log(Object.keys(info))
[
  'fieldName',
  'fieldNodes',
  'returnType',
  'parentType',
  'path',
  'schema',
  'fragments',
  'rootValue',
  'operation',
  'variableValues',
  'cacheControl'
]

甚至 type definition of the GraphQLResolveInfo object

中似乎都没有提到 mergeInfo

文档是否过时或者我遗漏了什么?

谢谢

mergeInfo 仅在您使用 mergeSchemas 将两个或多个模式拼接在一起时才注入到信息对象中。此外,它将 注入到您作为模式拼接的一部分添加的字段的解析器中——模式的解析器不会受到影响(对 委托给现有模式之一上下文中的另一个模式。

这是一个简单的例子:

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 的解析器可以。