带有GraphQL和React-Native的Relay vs Redux vs Apollo [英] Relay vs Redux vs Apollo with GraphQL and React-Native

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

问题描述

我必须从头开始一个新的(Web +本机)项目(中型应用程序).由于存在过多的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 + Web的React Native + 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进化的本质.我对过去使用的相同堆栈持怀疑态度.

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的新手,我建议您查看如何使用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.

一些信息:

  • 中继功能非常强大,但也非常复杂,并具有明显的学习曲线.
  • Apollo构建在Redux之上,尽管这对于您作为开发人员而言并不重要,因为商店对您而言是隐藏的.但是,例如使用与Redux中类似的概念.用于使用 updateQueries 来更新商店./li>
  • 如果您将将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天全站免登陆