In the past 2 months I’ve been working on a storefront iOS app for a client’s store that’s build on the Shopify platform. Since Shopify uses GraphQL — a query language and runtime system — for accessing its API, I thought that would be a good time to dive into learning GraphQL. I have previous experience with REST and working with GraphQL has been nothing less than love at first sight. Being a huge fan of TypeScript I just love how everything is fully typed and part of a schema and also reachable through a single endpoint unlike REST where you’d have a different url for each part of data.

My client of choice has been Apollo Client v3 which integrates with React Native very smooth and provides easy hooks for operations as well as a global state management system through its cache and reactive variables or local only fields using the @client tag .

On the previous project I have worked on I’ve used Redux as the local state management and I really like the control flow and the logistics of Redux. Apollo has been a bit difficult to wrap my head around at start but after a while I started to enjoy using Apollo Client quite a bit more than Redux to be honest and that’s because of how Apollo stores data in the cache and only tries to get the data that it actually needs from the server when that data is not available in the memory cache — all of these can be configured using the cache policies. I also find reactivity and subscriptions to data in my components to be much more intuitive and easier to implement using Apollo with reactive variables.

#graphql #apollo #typescript

Typescript, Apollo Client and GraphQL Code Generator  -  A Love Triangle.
3.00 GEEK