GraphQL is a query language for APIs that has been powering Facebook mobile apps since 2012. Its spec became open sourced in 2015 and is now available in various environments. Thanks to a revolutionary way of accessing data, GraphQL is very often used for building mobile applications. In the REST model you would send two separate requests to download the entire user data and then display the necessary parts of it. It takes a certain amount of time and time is something that really matters in mobile applications, where we’d like to get the data as quick as possible. With GraphQL, instead of working with fixed servers-defined endpoints, you can define the amount of data you need for the moment and send queries to get these files in one request.
Why you should consider using GraphQL for mobile applications?
As mentioned before, GraphQL queries sent to your API always return predictable results. The amount of data to be downloaded is defined by the app developer himself, not by the server. You get the exact data you asked for – not more, not less. And this makes your application stable and run much faster.
Another reason that speaks for using GraphQL for mobile applications to boost performance is a possibility to limit to a single request. GraphQL APIs can get all the data in only one request instead of loading from multiple URLs. All you need is just one defined endpoint.
GraphQL’s API schemes provide the possibility of constant improvement. In most APIs, adding a feature or changing the data structure is a massive change that recquires preparing a new version. This makes the apps maintenance more difficult. Since GraphQL returns only the data that were specifically requested, new features can be added with new types and fields so there’s no need to spend much time on developing a new version.
GraphQL itself is database independent – it is a specification for queries and responses between the client and server. Your GraphQL server connects with any database of your choice – either MySQL, NoSQL, Mongo, text files etc. – which creates a great number of possibilities.
To sum up, a big reason for using GraphQL for mobile applications is the app’s increased performance, which creates a major business value. If your project involves many applications and channels that would use one database you should really consider building a GraphQL API.