How to use distinct in GraphQL query?

后端 未结 2 1459
野趣味
野趣味 2021-01-17 19:32

Here is query where I try to use distinct in graphQl query:

query{
    contacts(take: 10, distinct: true) {
        firstName
        lastName
        title
         


        
相关标签:
2条回答
  • 2021-01-17 20:10

    GraphQL has no built-in sorting/filtering. It is up to the server to implement features like that, so if you're relying on a third party API and it doesn't support it then you will have to filter the response yourself.

    0 讨论(0)
  • 2021-01-17 20:24

    Here is a example of distinct query.

    query {
      contacts {
        distinct(field: title)
      }
    }
    

    Result will be.

    {
      "data": {
        "contacts": {
          "distinct": [
            "This is my test post",
            "This is my test post1",
            "This is my test post2"
          ]
        }
      }
    }
    

    This query binds all titles and deduplicates.

    0 讨论(0)
提交回复
热议问题