Представьте, что у нас есть схема 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'.
}
}
}
})
Как получить доступ к этим полям внутри других равных полей?