问题标签 [relayjs]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
graphql - Relayjs Graphql 用户认证
是否可以仅通过 graphql 服务器结合中继和反应来验证具有不同角色的用户?
我环顾四周,找不到关于这个主题的太多信息。
在我当前的设置中,具有不同角色的登录功能仍然通过传统的 REST API...(使用 json Web 令牌“保护”)。
javascript - 你将如何在 React-Relay 应用程序中进行文件上传?
文件上传似乎是一种突变。它通常伴随着其他数据。但它是一个很大的二进制 blob,所以我不确定 GraphQL 如何处理它。您如何将文件上传集成到使用 Relay 构建的应用程序中?
javascript - Multiple react-router-relay routes using same Relay root query with different fragment fields
I am running into an issue where when requesting data within two adjacent react-router-relay route components using the same root query, the graphql server query in the second route component invalidates the data previously retrieved from the first.
As an example:
I am using a workaround to attach fields to a 'viewer' root node, in order to query for arrays of data from a root field:
My schema.js includes the following definitions for the viewer (User) type and the root:
And the root:
Now, in the main.jsx application entry point, I am defining the following routes:
with ViewerQueries.js containing:
Now, if the App
component includes the following graphql fragment:
And the AllCars
component includes the following:
what happens is that on rendering of the App component on path '/', the array of cars is returned without problems. However, once the '/cars' path is rendered, the resulting array on `this.props.viewer.cars' is empty. In addition, returning to the path '/' to cause a re-rendering of the App component now also returns an empty array.
On the back-end, it appears the AllCars component causes an additional POST /graphql 200 277.369 ms - 94
trip to the server to fetch the new type
specified in the fragment.
If the AllCars component only includes the 'name' field, Relay correctly doesn't make another server request, but instead populates the array with data (supposedly cached from the initial App component server request).
Shouldn't it be possible to get the array of cars from either component, with Relay getting any additional data fields specified in the fragments regardless of the order they appear in the routes?
Any help would be greatly appreciated!
graphql - 什么时候应该使用 Relay GraphQL 连接,什么时候应该使用普通列表?
在 Relay GraphQL 中,连接和列表都类似于数组,但它们具有不同的特性。我应该什么时候使用每个?
javascript - 查询组合如何在中继中的容器和路由之间工作?
我已经阅读了材料,但我仍然不明白。
此示例路线出现:
(我故意替换user
为X
上面对生成的 GraphQL 查询没有影响的地方,以确保它对 graphql 组合没有影响)
它将与此容器配对:
这可能会组成如下内容:
但这里的逻辑是什么?也许它User
从片段中获取类型,然后寻找一种方法来获取该类型作为查询中匹配内容的直接后代?也就是说,它通过编译 GraphQL 知道在query { user(id: $userID) { X } }
X 中标记了可以找到用户类型的位置。
到目前为止,我看到的唯一示例在路由器中有一个非常简单的线性查询。可以更复杂吗?如果您进行的查询在两个不同的方向上进行并最终接近两个不同的用户对象源会发生什么?它怎么会知道你想要哪个?我认为这样的查询是不允许的。我还假设它在这些查询中查找的唯一位置是最深点,因此如果您的路由器查询类似于query { user(id: "52") { bestFriend } }
bestFriend 也是用户的位置,它将给您 bestFriend 而不是用户 52。
它甚至允许有一个以上深度的查询吗?我试过了,我得到了这个错误:
不变违规:Relay.QL:预期查询
user
为空。例如,使用node(id: $id)
,而不是node(id: $id) { ... }
也许路线比我想象的更简单?也许你能做的只有一个层次的深度?
relayjs - 什么是适合 relayjs 的后端?
我无法理解如何连接支持 relayjs 的后端。GraphQL/Relay 会自动帮助存储查询吗?即,如果我实现一个 REST 后端,它返回一个包含所有内容的 json blob,Relay 会负责数据查询优化吗?我不完全确定中继和后端/数据库之间的抽象。
graphql - GraphQL 查询/突变的响应
我有一个关于 GraphQL 查询/突变的响应在以下每种情况下应该是什么样子的问题:
- 有结果,没有错误
- 出了点问题,一个或多个错误
- 既有结果又有一些错误
我不确定后者是否可能,但我似乎记得在某处读过它可能发生。例如,在多个突变的情况下,假设有两个,其中每个突变都是按顺序处理的。如果第一个突变很好,我认为上面的案例#3 可能会发生,但是在第二个突变的执行过程中会发生错误,但我不确定。
无论如何,响应应该如何?像下面的那些?(JSON 中的示例,每个都对应于之前的案例。)或者还有其他更惯用的方法吗?也许 Relay 提供了一些关于它应该是什么样子的指导方针?我找不到任何好的资源。
1:
2:
3:
谢谢。
javascript - 从 Relay.js 商店获取 React 组件之外的数据
我有一个用例,我想在反应组件之外使用来自 Relay 存储的一些数据。所以考虑如何将数据获取到某个商店。
一种选择是在组件获取数据后将这些数据放入组件中的“存储”中。
但我更希望能够创建类似于定义其要求的反应组件的存储,但不呈现并且可以从任何其他文件中被要求。
我以为我可以使用 react 组件,但是要实例化组件,我需要将其渲染为 dom,这在这种情况下没有意义。
任何想法如何很好地实现这一目标?
relayjs - RelayJS 乐观更新导致导航
假设你有一个简单的应用程序,它有一个“创建事物”按钮,当你点击它时,你导航到一个新的 URL 来编辑那个东西。现在假设您不想在显示编辑界面之前等待服务器为您分配 ID。
你会怎么做?暂时在 URL 中写“新”,直到 ID 可用,然后将其换掉?在客户端分配一个 ID 并希望它不会与现有 ID 冲突?无论哪种方式,您都需要阻止 Relay 获取尚未真正存在的信息。你会怎么做?
reactjs - 有没有办法在没有 GraphQL 的情况下使用 Relay?
我正在我的 React 应用程序中尝试 Relay,它默认使用 GraphQL。它看起来像这样(Score
是一些 React.js 组件):
问题是:我可以使用自定义 API 函数将数据返回到片段中吗?像这样: