Apollo Client vs Relay vs GraphQL-Request vs Nanographql
I encourage you to read the full article but if you need the quickest answer. I recommend Apollo Client because of its popularity and full feature set. However, if you do not need caching or package size is a concern GraphQL-Request is my second choice.
Do I need a GraphQL client?
GraphQL clients provide a layer of abstraction. Clients let you focus on what is important to you: getting the data & displaying that data in the UI. Under the hood, most GraphQL requests are making a POST request over HTTP to your endpoint, but can include many more helpful features along the way.
The top GraphQL Clients
- Apollo Client
Let us dive into and look at the details of each of these GraphQL clients.
- Fully featured works with React, Next.js, Angular, Vue and more
- Enhanced tooling for Typescript, in browser, & VS Code
- Zero-config caching feature
- Larger package size 57.7kB, but not too big
Apollo GraphQL is one of the most popular GraphQL clients available. It is owned and maintained by Apollo Graph Inc, and has a significant community supporting it. The large community means there are many tutorials and examples built showing how to use Apollo Client. I highly recommend using Apollo Client.
- Created and maintained by Facebook (the original creators of GraphQL)
- Small package size 8.4kB
- Includes caching feature
- Less popular than you would expect
- Only built for React or React frameworks (Next.js)
- Infrequent releases (As of writing the last release was over a year ago)
Even though Relay was created by Facebook, it is hard to recommend because of the lack of adoption by the community. It is fully featured, but you may not find the same level of support as other GraphQL clients.
- Lightweight GraphQL client
- Written in TypeScript
- Smaller package size 15.9kB
- Does not have built in caching feature
Created and maintained by Prisma Labs, GraphQL-Request is a popular lightweight GraphQL client. It is built to be simple and flexible, adding no unnecessary features. It is a great client to pick if all you want to do is make GraphQL requests and do not need advanced features like caching.
- Truly a nano sized GraphQL client
- Tiny package size at 413 bytes
- No thrills, no added features
If the tiniest of tiny package sizes is important to you, Nanographql may be your choice. It has no additional features to maintain that tiny package size.
In conclusion, my choice would be Apollo Client. It is fully featured, and a heavily adopted GraphQL client. You will easily find examples, tutorials, and community support when using Apollo Client.
However, if you do not want or need caching GraphQL-Request would be my choice. It is smaller package size, simplicity, and flexibility to make it an excellent choice as a lightweight GraphQL client.