使用 GraphQL 和 React-Native 的 Relay vs Redux vs Apollo [英] Relay vs Redux vs Apollo with GraphQL and React-Native

查看:26
本文介绍了使用 GraphQL 和 React-Native 的 Relay vs Redux vs Apollo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从头开始一个新的(网络 + 原生)项目(中型应用).由于有过多的 JS 框架和实现,尤其是在过去几年中,我对我常用的堆栈产生了第二个疑问.

I have to start a new (web + native) project (mid-size app) from scratch. Due to the plethora of JS frameworks and implementation out there especially in the last couple of years, I have been having a second doubt on my usual stack.

我一直在前端使用 react + redux,后端使用 Node 和 MongoDB,通过 REST API 进行通信.

I have been using react + redux on the front-end along with Node and MongoDB on the backend communicating through REST API's.

对于这个新项目,我决定使用 React-Native + React Native for Web + Node + PostgreSQL.但是,我想知道我应该使用哪个框架来获取数据和状态/存储管理.

For this new project, I have decided to go with React-Native + React Native for Web + Node + PostgreSQL. However, I am wondering which framework I should use to the data fetching and state/store management.

到目前为止,redux 对我来说效果很好.但是,由于 JS 进化的性质.我对 Go 过去一直使用的堆栈持怀疑态度.

So far, redux worked for me nicely. However, due to the nature of JS evolution. I am a bit skeptical with go the same stack I have been using in the past.

如果我使用以下堆栈有什么优点和缺点

What are the pros and cons if I go with the following stack

React-Native + React-Native-For-Web + Redux + GraphQL + Node + PostgreSQL


React-Native + React-Native-For-Web + Relay + GraphQL + Node + PostgreSQL


React-Native + React-Native-For-Web + Apollo + GraphQL + Node + PostgreSQL

我读过很多文章,说明使用每个框架的好处,但内容和文章的数量有点吓人.我明白没有正确或错误的答案.但是,很高兴知道上述哪个堆栈可以很好地结合在一起 - 更少的学习曲线,良好的文档,可维护性,更少的解决方法.

I have read many articles stating the benefits of using each framework, but the amount of content and articles are a bit scary. I understand that there is no right or wrong answer. However, it would be nice to know which aforementioned stack goes nicely together keeping in mind - less learning curve, good documentation, maintainability, fewer workarounds.

推荐答案

我认为如果你来自 React + Redux 背景,那么 Apollo 应该是你的最佳选择!

I think if you're coming from a React + Redux background, then Apollo should be the way to go for you!

注意:如果您完全是 GraphQL 的新手,我建议您查看 How to GraphQL 在哪里您会找到有关 Relay 和 Apollo 的教程.

Note: If you're a complete newcomer to GraphQL, I recommend you check out How to GraphQL where you'll find tutorials both on Relay and Apollo.

一些信息:

  • Relay 非常强大,但也极其复杂,并且具有显着的学习曲线.
  • Apollo 构建在 Redux 之上,尽管这对您作为开发人员来说并不真正相关,因为商店对您隐藏.但是,使用了与 Redux 中类似的概念,例如用于使用 updateQueries 更新商店.
  • 将 Apollo 商店与您自己的 Redux 商店结合起来也非常简单想要管理服务器缓存数据以外的状态
  • 借助 Apollo,您还可以使用实时订阅
  • 我绝对不建议不要使用 Apollo 或 Relay,而只使用 Redux,因为这两个框架在发送查询、突变、缓存和 UI 更新方面都减轻了您的负担.但是,如果您正在寻找更轻量级的 GraphQL 客户端,您可能需要查看 Lokka.
  • Relay is very powerful but also extremely complex and comes with a notable learning curve.
  • Apollo builds on top of Redux though that's not really relevant for you as a developer, because the store is hidden from you. However, similar concepts as in Redux are used e.g. for updating the store with updateQueries.
  • It's also pretty straightfoward to combine the Apollo store with your own Redux store if you want to manage state other than the cached data from the server
  • With Apollo, you can also use realtime subscriptions
  • I would definitely recommend against not using Apollo or Relay and going with only Redux since both frameworks take notable work off your shoulders when it comes to sending queries, mutations, caching and UI updates. However, you might want to take a look at Lokka if you're looking for a more lightweight GraphQL client.

看看这篇深入文章比较 Relay 和 Apollo 以获取更多背景信息.

Take a look at this in-depth article comparing Relay and Apollo for more background info.

如果您想了解有关 Relay 和 Apollo 的更多信息,请查看如何使用 GraphQL 教程网站.

If you want to learn more about Relay and Apollo, check out the How to GraphQL tutorial website.

顺便说一句,如果您不想自己构建后端,另一个选择是 Graphcool(免责声明: 我为他们工作 :)).

By the way, another option for the backend if you don't want to build it yourself would be Graphcool (disclaimer: I work for them :)).

这篇关于使用 GraphQL 和 React-Native 的 Relay vs Redux vs Apollo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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