21. FAQ 2 - GraphQL - API for beginners

21. FAQ 2 - GraphQL - API for beginners

Graph Querry Language GraphQL

What is GraphQL?

GraphQL is an open-source query language. GraphQL is an answer to problems that REST API has:

  • a lot of endpoints;

  • it is harder for developers to learn and understand your API;

  • there is over- and under-fetching of information.

Who created GraphQL?

To solve above mention problems Facebook created GraphQL.

How GraphQL works?

What are queries and mutations?

A GraphQL operation can either be:

  • Read operation, known as Query, is used to read or fetch values

  • Write operation, known as Mutation, is used to write or delete values.

What is a schema?

A schema is a key concept and collection of GraphQL types. ISchema defines how the client can request the data.

What are resolvers?

Resolver is a function that generates responses for GraphQL queries & mutations. Then, the resolver returns the results wrapped by a callable function.

What is the role of the developer?

  1. Create a schema for allowed document fields and field types

  2. Create and implement a resolver to return corresponding data.

Advantages

  • A GraphQL schema sets a single source of truth in a GraphQL application.

  • GraphQL calls are handled in a single round trip.

  • Miscommunication between the client and the server is reduced.

  • GraphQL is introspective. This is ideal for auto-generating documentation.

  • GraphQL extensions offer features not available with REST APIs.

  • GraphQL can be introduced on top of an existing REST API.

Disadvantages

  • GraphQL presents a learning curve for developers familiar with REST APIs.

  • GraphQL shifts much of the work of a data query to the server side, which adds complexity for server developers.

  • Depending on how it is implemented, GraphQL might require different API management strategies than REST APIs, particularly when considering rate limits and pricing.

  • Caching is more complex than REST.

  • API maintainers have the additional task of writing maintainable GraphQL schema.

Resources

https://graphql.org/learn/

https://www.freecodecamp.org/news/a-beginners-guide-to-graphql-86f849ce1bec/

https://welearncode.com/beginners-guide-graphql/

https://medium.com/techtalkers/a-beginners-guide-to-graphql-12d60d3fba03

https://blog.postman.com/the-future-of-graphql/

https://blog.postman.com/what-is-a-graphql-api-how-does-it-work/

https://blog.postman.com/the-future-of-graphql/

https://scandiweb.com/blog/what-is-graphql-api-how-does-it-work/