BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage Articles GraphQL Reference Guide: Building Flexible and Understandable APIs

GraphQL Reference Guide: Building Flexible and Understandable APIs

This item in japanese

Lire ce contenu en français

Bookmarks

Key Takeaways

  • GraphQL is both an open source query language for an API and a server-side runtime for executing queries. It enables the use of a type system that developers define for their data. 
  • GraphQL is rapidly becoming a popular alternative to REST and gRPC, particularly for exposing data at the edge of systems
  • Clients can define the structure of the data required with GraphQL, which can be implemented to provide a common abstraction (schema) between the frontend and backend
  • GraphQL has clearly crossed the diffusion of innovation chasm, with the only debate in the InfoQ 2020 Architecture and Design trend report being how widely it is adopted within organisations that have large existing SOAP and REST API deployments. 
  • There is still innovation occurring within this space, specifically in relation to scaling and federating GraphQL schema, and making it ubiquitous and general-purpose for large enterprises.

Introduction

GraphQL is both an open source query language for an API and a server-side runtime for executing queries. It enables the use of a type system that developers define for their data.

GraphQL supports reading, writing, and subscribing to changes to data, and SDKs and servers are available for multiple languages, including JavaScript, Python, Ruby, Java, C#, Go, Rust, PHP, and more.

GraphQL is rapidly becoming a popular alternative to REST and gRPC, particularly for exposing data at the edge of systems. According to the GraphQL homepage, "GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools."

 
GraphQL query and type system (Image courtesy of Goodbye REST APIs. Hello GraphQL!)

GraphQL was developed internally by Facebook in 2012 before being publicly released in 2015 Similar projects also coevolved at the time, such as Netflix’s Falcor, but did not see as much adoption, particularly outside of Netflix.

On 7 November 2018, the GraphQL project was moved from Facebook to the newly-established GraphQL Foundation, hosted by the non-profit Linux Foundation.

Why Would You Use GraphQL?

GraphQL provides an approach to developing web APIs and is often compared with REST, and to a lesser extent gRPC-web and other web service architectures.

GraphQL allows clients to define the structure of the data required, which can be implemented to provide a common abstraction (schema) between the frontend and backend, and also to reduce the size of payloads sent from the server. According to the Wikipedia entry for GraphQL, "the flexibility and richness of the query language also adds complexity that may not be worthwhile for simple APIs."

As with all architectural considerations, there are inherent benefits and tradeoffs with using GraphQL.

Why Should You Pay Attention to GraphQL Now?

GraphQL has clearly crossed the diffusion of innovation chasm, with the only debate in the InfoQ 2020 Architecture and Design trend report being how widely it is adopted within organisations that have large existing SOAP and REST API deployments.

There is still innovation occurring within this space, specifically in relation to scaling and federating GraphQL schema, and making it ubiquitous and general-purpose for large enterprises.

GraphQL on the InfoQ Architecture and Design Trends Report 2020 graph.

Getting Started with GraphQL

For architects and developers researching and exploring GraphQL, we recommend the following content:

Introducing GraphQL into Your Tech Stack

For engineerings teams that are exploring the introduction and integration of GraphQL into their tech stack, we recommend the following:

Data Modelling in the Enterprise: How GraphQL Can Help

Data modelling is a perennially difficult change, particularly at scale. GraphQL provides different options and implementations than REST or traditional SOA approaches, with a focus on modularity. The early approach of "schema stitching" has now evolved into "federation".

This content is a good primer to the benefits and challenges of data modelling with GraphQL:

GraphQL Case Studies

The following GraphQL case studies provide best practices and warning of "gotchas" that early adopters discovered:

Advanced Use Case: Netflix’s GraphQL Federation

Netflix have been early adopters of GraphQL and have recently begun to publicly discuss how they have scaled their implementation of this. The following content provides deeper insight into their approach and also the lessons learned:

About the Author

Daniel Bryant is leading change within organisations and technology. His current technical expertise focuses on ‘DevOps’ tooling, cloud/container platforms and microservice implementations. Daniel is a leader within the London Java Community (LJC), contributes to several open source projects, writes for well-known technical websites such as InfoQ, DZone and Voxxed, and regularly presents at international conferences such as QCon, JavaOne and Devoxx.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT