0
votes

I am using REST API GET with payload ( passing input params ) and it returns with JSON response. I need to convert it into GraphQL, I have the schema and types defined, but how to merge GET request payload along with GraphQL query JSON and process it to get the desired response back?

Example GET: http://localhost/myproject/getAllCustomers

payload :

{
    "name":"Harish"
    "passion":"reading"
}

GraphQL query :

{
  customer {
    name
    age
    city
  }
}
1
Can you add an example? - Rcordoval
For example : if I have an endpoint as localhost/getUser/id I can write graphql query as below - type Query { users: [User] user(id: ID): User } BUT what if I have id as part of json in request body as payload and not as part of url How should I pass those params into graphql query ? is it the same way as above ? - Deepak S

1 Answers

0
votes

You pass variable to GraphQL query arguments

Query:

query getCustomer($name: String, $passion: String) {
  customer(name: $name, passion: $passion) {
    name
    age
    city
  }
}

Variable:

{
  "name": "Harish",
  "passion": "reading"
}