我遵循了官方的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'
]
文档是过时的还是缺少什么?
谢谢
答案 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],
})
在这里,foo
和bar
的解析器将无法访问mergeInfo
,但是foobar
的解析器将具有访问权限。