Book Update. What is GraphQL?
GraphQL is the main alternative to REST. But do you know its downsides?
Today I started updating the networking chapter of The iOS Interview Guide 2nd edition.
One of the changes in the iOS world since 2017 was a seeming proliferation and popularity of GraphQL over REST as the API solution of choice.
This is often an interview question nowadays and I am now adding it to the book.
One of the interesting interview red flags not every iOS developer is aware of is what makes GraphQL a poor choice in some instances. Here’s what I have added to the 2nd edition of the book on that:
Red flag: Probably the biggest red flag would be to claim that GraphQL is the only or best way of implementing client side APIs.
Despite its seeming popularity it's still in the minority when it comes to API implementation choices.
Another big down side of GraphQL lies in its flexibility - it's far too easy to have a poorly optimized API for a given business problem because you can't predict upfront and control all the permutations of data querying and mutation the client side applications will make.
With REST, the contract between client side and backend is "set in stone" so to speak and there are clearly defined use cases for each endpoint. With GraphQL, you never know if a client will request just one field or a hundred. Plus, you don't know what depth and combination of data would be needed. All of that makes it hard to optimize for each use case.
Use case optimization is very important, especially for mobile applications, as it is paramount to optimize mobile backend APIs and only send and receive the minimum possible amount of data to satisfy the constraints and requirements such as battery life, network reception, etc.
Where GraphQL shines, though, is a publicly available API for multiple different client applications, mobile or web. Because, as an API provider, you cannot predict how your API will be used in this case and what data the client apps will need, so it is much easier to just give them a "pallet" to choose from.
What are your thoughts on GraphQL? What interview questions around GraphQL have you encountered?
Subscribe to The Mobile Engineer newsletter to follow along my book writing journey and to receive more updates and snippets like this from the upcoming second edition of the book.