是否可以为基于嵌套字段过滤器的阿波罗查询返回数据?例如:
查询:
Users($filter: String!) {
user(filter: $filter) {
id,
name,
address(filter: $filter) {
street,
city,
country
}
}
}
TypeDefs:
Query: {
users(filter: String): [User]!
}
User: {
id: ID!,
name: String!,
address: Address
}
Address: {
street: String!,
city: String!,
country: String!
}
阿波罗解析器:
const resolverMap = {
Query: {
User(obj, args, context, info) {
// query api for User info (not including address)
// the final results of the query should only return users with the
// specific address (for example if the filter is country: England, only
// return users that live in England.
},
},
Address: {
address: (obj, args, context, info) {
// query another api for address based on parent (User) Id
},
},
}
使用该查询,我只希望返回居住在特定国家(例如英国)的用户的结果。由于此过滤器用于嵌套的[address]类型,是否有可能使用此查询而不必查询address的第一个?