Interview: What is Graph QL

What ?

GraphQL is a query language. Fetch What You Want!

In the case of data retrieval from the server: REST API ends up making requests to multiple endpoints, whereas, GraphQL, only has a single endpoint with which one has to access at the time data fetching on a server.

Why ?

  • Frontend apps, using GraphQL are fast because they control the data they get, not the server.
  • GraphQL only supports the POST method while REST support GET, POST, DELETE, PATCH, etc.
  • In GraphQL One can make changes to the existing API to help it evolve without versioning.
  • Unlike REST, by allowing you to define a schema, GraphQL gives you a lot of benefits, like automatic validation and introspection.

Popular client library : Apollo

If your REST API is following good practices, like allowing careful evolution instead of global versioning, serializing data instead of returning directly from data store, implementing sparse fieldsets to allow slimming down response sizes, GZiping contents, outlining data structures with JSON Schema, offering binary alternatives to JSON like Protobuff or BSON, etc., then the advertised advantages of GraphQL seem to fall a bit short.

If you need a highly query-able API, expect an array of clients that need small and different data, and can restructure your data to be inexpensive to query, then GraphQL is likely to fit your needs.