1
想象一下,我们有GraphQL方案,其中某些字段依赖于未在父类型中解析的对等字段。 foo
和bar
在下面的代码片段中。如何获取GraphQL中的对等字段?
const MyType = new GraphQLObjectType({
name 'MyType'
fields {
id: {
type: GraphQLString // Resolved from parent type
},
foo: {
type: GraphQLString,
description: 'Foo',
resolve: function({id}, args, {rootValue:{logger, datasources:{pool}}}) {
// Making some queries to database
}
},
bar: {
type: GraphQLString,
description: 'Bar',
resolve: function({id}, args, {rootValue:{logger, datasources:{pool}}}) {
// Making some queries to database
}
},
baz: {
type: GraphQLString,
description: 'Baz',
resolve: function({id}, args, {rootValue:{logger, datasources:{pool}}}) {
// This field actually depends from 'foo' and 'bar' peers.
// How to obtain peer fields 'foo' and 'bar to resolve this field?
// We have access to 'id' here, but this field resolved from parent type
// and we can't access to 'foo' and 'bar' like we do it for 'id'.
}
}
}
})
如何访问其他对等字段内的这些字段?