r/graphql • Apollo Team • Jul 14 '20

Apollo Client 3 is finally here! 🎉

After eleven months of feedback and several release candidates, we're excited to announce that Apollo Client 3 is finally here.

Here's a little bit of what's new:
- Single entry point, set up client with a single package
- New cache features, cache policies / garbage collection
- Expanded and refined UI reactivity
- An extensive internal refactoring

Read the blog post to learn more about the latest release
https://www.apollographql.com/blog/announcing-the-release-of-apollo-client-3-0/

Or check out the migration guide
https://www.apollographql.com/docs/react/migrating/apollo-client-3-migration/

And spend some time with the newly refreshed docs!
https://www.apollographql.com/docs/react/

Cheers!

87 Upvotes

10 comments sorted by

5

u/YungSparkNote Jul 14 '20

If you had a working graphql backend and were writing a frontend tomorrow, would you go with AC3 over urql? What are some drawbacks to each? Is the urql cache solution intuitive and/or somewhat straightforward to set up?

5

u/stemmlerjs Apollo Team Jul 14 '20

tl;dr - they're both very similar, but Apollo Client aims to provide solutions to a lot of the problems you're likely to run into in production projects (local state management, pagination, complex updates, etc). urql is lightweight, minimal, and is probably a great choice if you're primarily using it to fetch data.

---

At face value, they are pretty similar. I haven't spent nearly enough time with urql yet so definitely take what I say with a grain of salt. But from my limited time looking at it, here's what I'm learning.

Philosophy: urql is minimal and lightweight. That means you'll only get a subset of the utilities/features currently in Apollo Client (pagination helpers, local state management story, reactive variables, etc). The philosophy of urql is to give you the basics you'll need to design and build your own data-fetching infrastructure. It's kind of like Express.js. Everyone uses it in a slightly different way. Apollo Client aims to provide solutions to those problems like pagination, local state management, persisted queries, etc -- out of the box. If you know you're going to invest in implementing solutions to these common problems your own way, you might have an easier time using urql.

Packaging: Previously, Apollo used to be split across several packages. That made urql a lot more ideal in this category. With this release, you can grab everything you need from `@apollo/client`. urql is the same.

Setup: They both look really similar in terms of setup.

Size: urql is smaller than Apollo Client. Given the minimal methodology, that makes a ton of sense.

Caching: Today, both urql and Apollo Client have normalized caching. Previously, urql used to only cache against queries where Apollo Client cached against individual items.

Local state management: AC3 recently moved away from local resolvers to a cleaner way to combine `remote` state and client-side only `local` state. This is one of the most notable features of the 3.0 release. With this, if you wanted to replace a tool like Context or Redux entirely and decorate your `remote` GraphQL data with some local state, it's possible now. Not sure where urql is on local state management atm. I found an open issue here though!

5

u/_philpl urql team Jul 15 '20

urql core contributor here :) I'd just like to add on to this as our approaches differ a lot to the Apollo Client to reflect on this.

Ultimately Apollo Client and urql are similar in how you'd use them. Both are GraphQL clients that make no assumptions on your schema and allow you to query any GraphQL API. Given that Relay puts some restrictions on this that's an important thing to note.

urql's philosophy however is to be customisable and flexible and to grow with your requirements: https://formidable.com/open-source/urql/docs/concepts/philosophy/ So in terms of its size and typical use one could say it's minimal, but you'd add on officially maintained packages to expand it depending on what you need.

You'll get very similar solutions to the same problems. In fact I wouldn't liken it to the Express.js way at all, but our extensibility simply goes further than Apollo's. In fact, there are solutions for pagination, persisted queries, etc. It's true that you're encouraged to implement "exchanges" for your own requirements, but the only moment you're forced to implement one is for instance if you're implementing a more complex auth system. This is similar to Apollo. Other than that all the pieces are there, like file upload support, persisted fetch support, etc. For a lot of edge cases Apollo does lean on community packages, whereas we aim to provide solid officially maintained packages.

Local State Management via the normalized cache is something we definitely do not want to implement. This is where philosophies between the client split a lot, but our normalized cache leans on reflecting server state and behaviour accurately. Its configuration is meant to even reflect that behaviour accurately. Ultimately we believe that local state will make this harder to track for no gained benefit, since state can also be maintained outside of GraphQL for no added cost. We're looking into a separate local state solution, but it's lower on our priority list.

Regarding Packaging: We have a very different split than Apollo. I believe a common complaint has been that Apollo had an unintuitive way of splitting things, which is different from urql where the "exchanges" are the only extensibility model, hence it doesn't become as confusing. In urql we provide the basics in the main package and the bindings to your framework of choice (React / Preact / Svelte currently), apart from that exchanges are always separate, even normalised caching.

For Size I'd like to add that urql is currently smaller and that includes even our normalized caching. We do spend the time to optimise for performance and bundle size a lot and it's something we take pride in. Depending on whether you care about that or not this may be interesting for you.

Caching: Just a thing to summarise here from above. We know the pain points of normalised caching very well and are approaching it actually quite differently. While there won't be much difference as to how normalised caching works between different implementations, our focus is on: correctness / ease of use, performance, and extra features. Our normalised cache has an extensive set of guarantees and warnings, resolvers can be made to resolve complex data that matches the schema, schema awareness allows for partial results to be safe, and we added Offline support recently :)

That's all!

1

u/stemmlerjs Apollo Team Jul 17 '20

Thanks for taking the time to share your approach! Great work by the way. I love your docs.

14

u/[deleted] Jul 14 '20 edited Jul 15 '20

This release gives how Apollo as company changed over the years.100% swag and low quality code, good code copied from community projects. Release is forced and unfinished. It took 1 year to do simple features. URQL is miles ahead in terms of features and community support.

2

u/stemmlerjs Apollo Team Jul 14 '20

It's gotten a lot better!

8

u/YodaLoL Jul 14 '20

Agreed. However let's not downplay Apollo's role as a pioneer in GraphQL adaptation

6

u/gsvclass GraphJin Jul 14 '20

I'm loving Apollo Client 3 I use it with Super Graph to build https://abtcode.com the cache stuff is so much better.

https://github.com/dosco/super-graph

2

u/[deleted] Jul 15 '20

What is the estimated size of the the react verson of Apollo?
Consider I have a websocket server too that runs on subsciptions.
Bundle size is very important now-a-days for libraries. Its not just Apollo that I will be using.

2

u/dbbk Jul 14 '20

Any support for Ember?