Apollo Client 和 Relay 有什么区别? [英] What are the differences between Apollo Client and Relay?

查看:22
本文介绍了Apollo Client 和 Relay 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚接触了 GraphQL,正在决定在两个框架(ApolloRelay) 用于实现我的前端 React Web 应用程序.

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.

我知道 Relay 是由 Facebook 构建的,而 Apollo 是由 Meteor 构建的.有没有人尝试过这两种方法,您的体验如何?我想知道它们之间有什么区别,与 Apollo 相比,哪种 GraphQL 应用程序会从使用 Relay 中受益更多.

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.

推荐答案

TL;DR: 这个问题的答案归结为视情况而定".我鼓励你尝试两个 GraphQL 客户端并得出你自己的结论.学习 ApolloLearn Relay 是入门的绝佳资源.

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.

请注意,以下是关于中继 1,而不是中继 2.

Note that the following speaks about Relay 1, not Relay 2.

Relay 仅适用于 React 和 RN,而 Apollo 与框架无关.当你想构建一个 React 应用程序时,这对你来说不是问题,但仍然值得一提.

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.

中继需要在中继规范中进一步描述的自定义架构.Apollo 适用于任何 GraphQL 架构.

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

Relay 强加了一个您绝对需要遵循的严格、固定的结构.另一方面,Apollo 为您提供了许多不同的方法和选择来处理特定主题.

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.

Relay 提供了出色的开发者体验,但也有很高的进入门槛.Apollo 需要更多的手动工作才能完成任务.

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

Relay 引入了很多新概念,如节点、边和连接,重申一下,它具有很高的进入门槛.相比之下,Apollo 非常容易上手.

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

除了一些社区努力使订阅与 Relay 一起工作之外,关于 Relay 中的订阅并没有真正达成共识.另一方面,Apollo 与 subscriptions-transport-ws 已经在社区中得到广泛采用.例如,这是一个使用 GraphQL 订阅的世界聊天应用.

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.

Relay 需要在构建时使用 Babel 进行模式检查.Apollo 为此提供了可选工具.

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

这篇关于Apollo Client 和 Relay 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆