With pizza eaten and beers in hand the Facebook auditorium was once again rammed for this months React.js meetup. We were incredibly excited and honoured to welcome Nick Schrock, Facebook Engineer & GraphQL co-creator, to give an extended talk on his creation – GraphQL. GraphQL is server side query language which is designed for client side applications to interact with trees of data and takes a markedly fresh approach to client-server communications.
Nick started by giving us some background about how GraphQL came to be. It was essentially Facebook's solution to the problem of having potentially hundreds of different app versions all needing different data. Traditional RESTful APIs aren't really ideal for a great mobile experience due to the ping-pong nature of how data is requested when drilling down into an app. Facebook have been using GraphQL to power several of its applications including the iOS & Android Feed applications as well as Messenger and Ads Manager for some time. GraphQL is able to support multiple versions of all these applications without having to support multiple versions of their API. The beauty is that the client application decides what it needs and the server responds with the data in one single response. If a new version of an application requires data that isn't yet supported by GraphQL schema then it can be added without fear of polluting older versions as they won't be asking for it. Sticking with an additive attitude means that backwards compatibility is much easier to handle.
How can I use this now?
A large portion of Nick's talk was devoted to how a developer might be able to start using GraphQL or at least selling it into an existing project. Obviously for GraphQL to be most efficient it makes the most sense that it would entirely replace any API that currently exists but this is not always possible and is more than likely too big an ask. The best way would to introduce GraphQL into a project would be to build a thin layer over existing APIs, most likely a subset to start off with, and rather than speaking directly to a database GraphQL is used to glue your API endpoints together. He coined this approach 'REST Polyfill Structure'. This approach means you can have the marked improvement of a single request and also you can demonstrate how GraphQL can be used in your application. To really show of you can use GraphiQL to demonstrate the power of introspection.
To get a more detailed look into how you might start using GraphQL on your project take a look at swapi-graphql - a GraphQL wrapper around the Star Wars API.
Although there were no official announcements about future features there was mention of subscriptions which will mean an end to polling; a very welcome addition to the GraphQL feature set.
The next React.js will be on Tuesday 17th November this time at Bloomberg. Check out the Meetup page for more info about the event and how to get your free ticket.
Want to be using GraphQL in production now?
Red Badger has already started using implementations of GraphQL in production as well as loads of cutting edge tech including React.js. If you fancy working for a company which thrives on innovative new tech get in touch.