Saturday, December 2, 2017

What is GraphQL query language? Give an example

Characteristics of Query Language:

1. It behaves like a structured language which is used for accessing data from API
2. It looks like JSON (but isn't)
3. It can request fields from (nested) objects
4. Fields can have parameters that are similar to function parameters we use in a programming language.

Example of Query Language:

   query {
     employee(id: 1) {
       firstName
       lastName
       age
       salary
       dob
     }
   }

Output:

{
  "data": {
    "employee": {
      "firstName": "Mark",
      "lastName": "Zuckerberg",
      "age": "33",
      "salary": "200K",
      "dob": "May 14, 1984"
    }
  }
}

What is Query? 
Query: A read request

What is Mutation?
Mutation: Request for modifying data

No comments:

Post a Comment