0

I am working with Apollo GraphQL and have to call nested query .But while call the Query in .graphql file it showing

Syntax error : Expected Name, found {

Let me know how to call Nested query of GraphQL. enter image description here

I have to call getAllproduct{....} query with the specified parameters.Here the FilterInput having the parameter as location with another pattern of query , so I don't know how to call this nested query.Anyone please help me to find out the solution.Thanks...

1 Answer 1

2

If an argument is an Input Object Type (as opposed to a Scalar), you can include the fields of the Input Object Type by using curly brackets.

query MyProductsQuery {
  allProducts(
    pageNumber: "someString"
    filter: {
      title: "someOtherString"
      yearFrom: 1900
      location: {
        city: "yetAnotherString"
        state: "FL"
      }
    }
  ) {
    id
    # other product fields
  }
}

Of course, hardcoding those values in a .graphql file is not very helpful. You probably want to be able to swap those values out programatically. So here's what that same query looks like with variables:

query MyProductsQuery($pageNumber: String, $filter: FilterInput) {
  allProducts(pageNumber: $pageNumber, filter: $filter) {
    id
    # other product fields
  }
}

Your variables are passed in separately from your query and unlike your query, are not a GraphQL document. They are just JSON:

{
  "pageNumber": "someString",
  "filter": {
    "title": "someOtherString",
    "yearFrom": 1900,
    "location": {
      "city": "yetAnotherString",
      "state": "FL"
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.