Menu

Showing posts with label GraphQL query. Show all posts
Showing posts with label GraphQL query. Show all posts

GraphQL query with filter

We Could apply filter or filters in graphQL query to get the filtered result. Below is an example of filter query. You could also run or play this query here<https://lucasconstantino.github.io/graphiql-online> and understand how this query is working with actual results.

1. Using filter keyword

query getCountries {
countries(filter: { code: { eq: "IN" } }) {
name
phone
code
languages @include(if: true) {
name
native
rtl
}
}
}


Result: The result of above graphQL query you will see as below.

{

  "data": {

    "countries": [

      {

        "name": "India",

        "phone": "91",

        "code": "IN",

        "languages": [

          {

            "name": "Hindi",

            "native": "हिन्दी",

            "rtl": false

          },

          {

            "name": "English",

            "native": "English",

            "rtl": false

          }

        ]

      }

    ]

  }

}


2. Using unique property of the object

Other way to filter is use the unique property of country and add that as a parameter. Here is an example.

query getCountries2 {

country(code: "IN") {

name

phone

code

languages @include(if: true) {

name

native

rtl

}

}

}

This query will also return the same as above query.

Screenshot for reference:



How to write GraphQL query with filter
How to write GraphQL query with filter