There has been a lot of buzzes about GraphQL recently. GraphQL's name rings a bell in most conferences around the world. There were a number of GraphQL sessions in the recent ReactEurope tour. This post throws insights into why GraphQL is the future for APIs.
GraphQL is a query language for your API, and a server-side runtime for executing queries by using a type system you define for your data. GraphQL isn’t tied to any specific database or storage engine and is instead backed by your existing code and data.
GraphQL is internally developed by Facebook in 2012 before being publicly released in 2015. GraphQL is a new way to think about building and querying APIs. Rather than construct several REST requests to fetch data that you’re interested in, you can often make a single call to fetch the information you need.
Why GraphQL?
There are a number of reasons you might use GraphQL in your product or project.
- You are planning to serve APIs to your customers and becomes a little complicated after scaling.
- You have to serve a large number of clients like Web, Mobile, Tablet, Watch, TV, etc.
- Your client requests only what information it wants, nothing more nothing less.
- Your client requests data in one request even in slow mobile network connections.
- You want to leverage your existing data and code.
- You are moving to Microservices architecture.
GraphQL’s query has exactly the same shape as the response.
Graphs are powerful tools for modeling many real-world phenomena because they resemble our natural mental models and verbal descriptions of the underlying process.
GraphQL suggests modeling your business domain as a graph by defining a schema and within that schema defining your nodes and the relationship between them.
GraphQL Design Principles
- Hierarchical: A GraphQL query itself is structured hierarchically.
- Product centric: GraphQL is driven by the requirements of views and the front-end engineers that write them.
- Strongly typed: Every GraphQL server defines an application-specific type system.
- Introspective: A GraphQL server is queryable by the GraphQL language.
- Version free: GraphQL removes the need for an incrementing version number.
Who is using GraphQL?
GraphQL is used by big companies and teams of all sizes.
- Github
- Intuit
- Shopify
- Coursera
Learn GraphQL properly
There are various resources out on the Web to learn GraphQL. Start learning from the official GraphQL website. Learn GraphQL by Arunoda Susiripala is an excellent 10-part tutorial that teaches you the basics of GraphQL.
Looking for documentation on how to build a GraphQL service? There are libraries to help you implement GraphQL in many different languages. GraphQL makes it easy to build powerful tools like GraphiQL by leveraging your API’s type system.
Graph-based solutions are great opportunities to think about redesigning your API. We think though GraphQL is backed by big companies, thinking in Graphs seems to be a good fit for your data and kind of topology. We need to start thinking about REST APIs to solve our business problems.
That’s it for now. Let us know what you think about GraphQL. If you have already tried it out or plan to use it in the next project?
Contact Ideas2IT - a Custom Software Development Company to learn more about the services we offer.