小编Jon*_*dle的帖子

基于嵌套字段的过滤器从 apollo-server 返回数据

是否可以为 apollo 中基于嵌套字段过滤器的查询返回数据?例如:

询问:

Users($filter: String!) {
  user(filter: $filter) { 
    id, 
    name, 
    address(filter: $filter) { 
       street, 
       city, 
       country
    } 
  } 
}
Run Code Online (Sandbox Code Playgroud)

类型定义:

Query: {
   users(filter: String): [User]!
}

User: {
    id: ID!,
    name: String!,
    address: Address
}

Address: {
    street: String!,
    city: String!,
    country: String!
}
Run Code Online (Sandbox Code Playgroud)

阿波罗解析器:

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 …
Run Code Online (Sandbox Code Playgroud)

apollo reactjs graphql apollo-server

7
推荐指数
1
解决办法
780
查看次数

标签 统计

apollo ×1

apollo-server ×1

graphql ×1

reactjs ×1