GraphQL

Sashko Stubailo, core team member of the Apollo/GraphQL project gave a state of GraphQL at This.JavaScript. In this update, Sashko talks about the resources available in the GraphQL ecosystem and shares what you need to know to get started.

#History and Introduction to GraphQL GraphQL was introduced in 2015 and is maintained by Facebook and other open source community members. It is a query language for APIs which help define the data in your application. It has features which allow for self-documentation and elimination of both over fetching and request waterfalls. GraphQL also provides an extensive community of clients, servers, and developer tools.

GraphQL is neither a library nor a product, but rather a specification and a community — one that provides a schema for your entire set of data and a query language for retrieving it. One of the benefits of GraphQL is that it is incrementally adoptable in virtually any architecture.

#Using GraphQL Subscriptions vs Live Query GraphQL Subscriptions was originally released with queries for fetching data and mutations to update that data. It allows you to retrieve real-time streams of data.

The way subscriptions work is that a server-side pop-up system (or something similar) is used to push specific messages to clients. Subscriptions are different from live query because live queries implement a method that is similar to optimized polling, whereas subscriptions follow a more finite approach that is easier to manage.

#Open Source Tooling Servers are one of the most important parts of the GraphQL architecture. There are currently a number of them in the works as open source projects. If you are looking for different server libraries, they are available in every popular server-side technology and framework and can be found at graphql.org/code.

One of the most recent GraphQL implementations was made by Walmart Labs. It is a server called Lacinia and serves both samsclub.com and Walmart Grocery.

#Clients By using basic HTTP caching that operates on a per request basis, individuals can fetch all kinds of queries with varying shapes and results. However, greater benefits can be obtained if more sophisticated clients are used to help with caching. Presently, there are two major GraphQL client libraries (for javascript) with 1.0 releases. The first is Apollo, which released on March 30 and works with all javascript technologies, and the second being Relay, a more opinionated architecture announced by facebook.

On a side note, with Native Mobile clients, it is important to make sure that API technology can be accessed from the clients. Therefore, libraries that allow you to fetch GraphQL queries easily from Swift on iOS and Java on Android, are made available. These libraries are also capable of code generation which foster numerous benefits.

Developers are currently trying to integrate similar properties to Javascript clients. They are working with New York Times, Shopify, and Airbnb, to find out ways of implementing the sharing of data between separate parts of an app. As developers are aware, this is due to the case of creating an application using different types of code.

#Developer Tools Since there is a strongly typed API with a query language to go along with it, a whole new space of developer tools becomes accessible. With these tools, APIs and data fetching can be explored in more depth.

The autocompleting query editor called Graphical was one of the first dev tools to be made. This is a tool that the majority of individuals use to interact with their API. Other tools have also been created such as persisted queries and chrome dev tools, as well as a couple others made responsible for query validation as well as extraction of those queries from code.

#GraphQL Language Service Another new project developed by Facebook is the GraphQL language service which gives a similar experience to graphical tool. It contains a standalone web IDE that can be found in one’s normal code editor IDE. This enables individuals to open up source code editors such as Visual Studio Code, and type GraphQL queries right in their code. Validation and autocompletion would then take place, so that API docs don’t have to be referred to.

To find out more about GraphQL, follow them on twitter @GraphQL. By Trinh Kien

Need JavaScript consulting, mentoring, or training help? Check out our list of services at This Dot Labs.

Share