DEV Community

Cover image for What GraphQL Is and Isn't?
Mahibul Haque
Mahibul Haque

Posted on

What GraphQL Is and Isn't?

Definition :

Graphql is a query language. But it does not mean it is a language that interacts with the database like popular SQL languages (e.g. MySQL, PostgresSQL).

So what does GraphQL do?
Queries an API, not a database.


Distinction between Query and Mutation in GraphQL

GraphQL doesn't require http requests method such as GET, POST, PUT, DELETE.

In GraphQL your most likely going to GET data by using Query. The other data update methods POST, PUT, DELETE will be handled by Mutations.

A query to fetch all the pets from the app might look like this:

query GetAllPets {
  pets {
    name
    petType
  }
}
Enter fullscreen mode Exit fullscreen mode

And then a mutation that adds a new pet might look a little something like this:

mutation AddNewPet ($name: String!, $petType: PetType) {
  addPet(name: $name, petType: $petType) {
    id
    name
    petType
  }
}
Enter fullscreen mode Exit fullscreen mode

GraphQL Vs REST

GraphQL REST
GraphQL is an application layer server-side technology which is developed by Facebook for executing queries with existing data. REST is a software architectural style that defines a set of constraints for creating Web services.
It follows client-driven architecture. It follows server-driven architecture.
GraphQL can be organized in terms of a schema. REST can be arranged in terms of endpoints.
GraphQL is a growing community. REST is a large community.
The development speed in GraphQL is fast. The development speed in REST is Slow.
The learning curve in GraphQL is difficult. The learning curve in REST is moderate.
The identity is separated from how you fetch it. The endpoint you call in REST is the identity of an object.
In GraphQL, the server determines available resources. The shape and size of the resource are determined by the server in REST.
GraphQL provides high consistency across all platforms. It is hard to get consistency across all platforms.
The message format for GraphQL mutations should be a string. The message format for REST mutations can be anything.
It is strongly typed. It is weakly typed.
GraphQL API endpoints are single. REST API endpoints are multiple.
It uses metadata for
query validation.
It does not have machine-readable metadata cacheable.
Provides consistent and high-quality UX across all operating systems. It is difficult to get consistency across all operating systems.
Partners of GraphQL require API customization. It offers flexible public API that can easily enable new applications.

Top comments (0)