GraphQL Engine
What is GraphQL Engine?
- GraphQL is a specification (query language) of how to talk to an API. Itβs typically used over HTTP where the key idea is to POST a βqueryβ to an HTTP endpoint, instead of hitting different HTTP endpoints for different resources.
- GraphQL is designed for developers of web/mobile apps to be able to make API calls to fetch exactly the data they need from their backend APIs.
- GraphQL defines a standard grammar for a query language to read/write data
Why to use GraphQL Engine?
- Developers love using GraphQL because itβs the most convenient API for JSON data.
- GraphQL is easy to read and debug, and has a rich ecosystem of community tooling.
- GraphQL is database agnostic and can be used with any language or framework.
- GraphQL Schema and Type System contract enables frontend and backend developers to collaborate and work independently.
- GraphQL is designed to make APIs fast, flexible, and developer-friendly. It can even be deployed within an integrated development environment (IDE) known as GraphiQL.
History of GraphQL
π GraphQL was developed internally by Facebook in 2012 before being publicly released in 2015.
π On 7 November 2018, the GraphQL project was moved from Facebook to the newly-established GraphQL Foundation, hosted by the non-profit Linux Foundation.
π Since 2012, GraphQL's rise has followed the adoption timeline as set out by Lee Byron, GraphQL's creator, with accuracy. Byron's goal is to make GraphQL omnipresent across web platforms.
Advantage of GraphQL Engine
- A GraphQL schema sets a single source of truth in a GraphQL application. It offers an organization a way to federate its entire API.
- GraphQL calls are handled in a single round trip. Clients get what they request with no overfetching.
- Strongly defined data types reduce miscommunication between the client and the server.
- GraphQL is introspective. A client can request a list of data types available. This is ideal for auto-generating documentation.
- GraphQL allows an application API to evolve without breaking existing queries.
- Many open source GraphQL extensions are available to offer features not available with REST APIs.
- GraphQL does not dictate a specific application architecture. It can be introduced on top of an existing REST API and can work with existing API management tools.
Disadvantage of GraphQL Engine
- 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 with REST.
- API maintainers have the additional task of writing maintainable GraphQL schema.
Example of GraphQL Query
This will ask an API to return specific fields in a shape youβve specified.
{
me {
name
}
}
This is the result in JSON Format
{
"me": {
"name": "EDWARD"
}
}
Passing argument in Query
{
human(id: "1000") {
name
height
}
}
It will give result as : π
{
"data": {
"human": {
"name": "David",
"height": 1.72
}
}
}
Some GraphQL IDE'S With Reference
- GraphQL Playground is an IDE by Prisma built off of GraphiQL. It takes the best parts of GraphiQL and adds features and improvements, like a better query history display and more ergonomic exploration and debugging.
- π―GraphQL Playgroud
- GraphiQL Made by the GraphQL Foundation, GraphiQL is an interactive in-browser IDE built on React. It is probably the most popular and lightweight GraphQL IDE out there.The GraphiQL IDE supports the full GraphQL Language Spec, ranging from Queries and Mutations to Fragments and Unions.
- π―GraphiQL