【问题标题】:apollo client, query with filterapollo 客户端,带过滤器的查询
【发布时间】:2018-05-12 21:34:00
【问题描述】:

实际上,我所有的查询都没有过滤器,只需从表中检索所有记录

我已阅读此链接: https://github.com/graphql/graphql-js/issues/640

这是关于构建手动过滤器,但讨论并没有以明确的解决方案结束。

有一种方法可以在 apollo 客户端中向查询发送参数吗?

在我使用的突变中,但我对使用查询有疑问

一个查询是一个例子:

query TourList {

    tours {
      id
      name
      price
      country
      seatsmax
      seatsmin
      datestart
      dateend
      organizer_id
   }
}

如何按 Organizer_id 过滤?我正在使用续集...

【问题讨论】:

    标签: graphql apollo-client apollo-server


    【解决方案1】:

    您通过参数将organizer_id 提供给解析器,并在那里进行过滤。像这样的:

    query TourList {
        tours(oid: 1) {
          id
          name
          price
          ...
       }
    }
    
    // type definitions:
    Query {
       tours(oid: Int): [Tour!]!
    }
    
    
    // tours resolver:
    tours: (obj, args, ctx, info) => {
      // logic to get and return the filtered tours 
    }
    

    您可以像处理突变一样使用变量

    【讨论】:

    • 谢谢,oid 可能是 null 吗?所以如果它是空的,我会做任何过滤吗?
    • 当然,如果不标记为必填,就不用发了
    猜你喜欢
    • 2021-06-01
    • 2020-02-15
    • 2020-11-07
    • 2016-08-31
    • 2021-04-13
    • 2018-04-19
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多