What are the differences between Apollo Client and

2019-05-16 15:08发布

问题:

I have just been introduced to GraphQL and am deciding between the two frameworks (Apollo and Relay) for implementing my front end React web app.

I'm aware that Relay is built by Facebook, while Apollo is by Meteor. Has anyone tried both and how has your experience been? I'm wondering what are the differences between them and which kind of GraphQL apps would benefit more from using Relay as compared to Apollo.

回答1:

TL;DR: The answer to this question boils down to "it depends". I encourage you to try both GraphQL clients and come up with your own conclusion. Learn Apollo and Learn Relay are great resources to get started with this, or you could try example apps for Relay and Apollo.

Have a look at this in-depth comparions of Apollo vs. Relay. Here's a quick overview:

Frameworks

Relay only works on React and RN while Apollo is framework agnostic. As you want to build a React app, that's not an issue for you, but it's still worth mentioning.

GraphQL API

Relay requires a custom schema further described in the Relay specification. Apollo works with any GraphQL schema.

Flexibility

Relay imposes a strict, fixed structure that you absolutely need to follow. Apollo on the other hand gives you a lot of different approaches and choices for handling a particular topic.

Productivity

Relay offers great developer experience, but comes with a high entry barrier. Apollo requires more manual work to get things done.

Difficulty

Relay introduces a lot of new concepts and to reiterate, comes with a high entry barrier. Apollo is extremely easy to get started with in constrast to that.

Subscriptions

Aside from some community efforts to make subscriptions work with Relay, there's not really a consensus about subscriptions in Relay. On the other hand, Apollo integrates nicely with subscriptions-transport-ws that already finds great adoption in the community. Here's a worldchat app using GraphQL subscriptions for example.

Schema Check

Relay requires a schema check using Babel on build-time. Apollo offers optional tools for this instead.