Object Identification #Facebook Relay文档翻译#
2015-09-26 16:13
579 查看
原文地址
上一篇 GraphQL Relay Specification
Relay文档翻译目录
Both
expose this capability to Relay through the
field on the root query type.
The
These two work in concert to allow refetching; if we pass the
that field to the
Let’s see this in action, and query for the ID of the rebels:
我们来看如下实践,用于查询rebel的ID
returns
So now we know the ID of the Rebels in our system. We can now refetch them:
现在我们知道了Rebel的ID,我们可以重新获取他们:
returns
If we do the same thing with the Empire, we’ll find that it returns a different
ID, and we can refetch it as well:
如果我们在Emipre上做同样的事情,它将返回不同的ID,我们同样可以重新获取它。
yields
and
yields
The
refetching. A system without globally unique IDs can usually synthesize them
by combining the type with the type-specific ID, which is what was done
in this example.
The IDs we got back were base64 strings. IDs are designed to be opaque (the
only thing that should be passed to the
unaltered result of querying
9a30
m), and base64ing
a string is a useful convention in GraphQL to remind viewers that the string is
an opaque identifier.
我们获得的ID是base64的字符串。ID被设计为不透明的,唯一应该传递给
Complete details on how the server should behave are
available in the
GraphQL Object Identification spec.
服务端应该如何处理的详细介绍请见GraphQL Object Identification spec.
上一篇 GraphQL Relay Specification
Relay文档翻译目录
Both
Factionand
Shiphave identifiers that we can use to refetch them. We
expose this capability to Relay through the
Nodeinterface and the
node
field on the root query type.
Faction和
Ship都有标识符,我们可以用它来重新获取他们。我们通过
Node接口和root query type上的
node字段来将这个能力暴露给Relay。
The
Nodeinterface contains a single field,
id, which is a
ID!. The
noderoot field takes a single argument, a
ID!, and returns a
Node.
These two work in concert to allow refetching; if we pass the
idreturned in
that field to the
nodefield, we get the object back.
Node接口包含一个单一的
id字段,它不能为空
ID!。root上的
node字段,接收一个不为空的ID作参数,返回一个
Node。他俩协调一致的工作使得重新获取对象成为可能。如果我们给
node字段传递
id,我们将得到对应对象。
Let’s see this in action, and query for the ID of the rebels:
我们来看如下实践,用于查询rebel的ID
query RebelsQuery { rebels { id name } }
returns
{ "rebels": { "id": "RmFjdGlvbjox", "name": "Alliance to Restore the Republic" } }
So now we know the ID of the Rebels in our system. We can now refetch them:
现在我们知道了Rebel的ID,我们可以重新获取他们:
query RebelsRefetchQuery { node(id: "RmFjdGlvbjox") { id ... on Faction { name } } }
returns
{ "node": { "id": "RmFjdGlvbjox", "name": "Alliance to Restore the Republic" } }
If we do the same thing with the Empire, we’ll find that it returns a different
ID, and we can refetch it as well:
如果我们在Emipre上做同样的事情,它将返回不同的ID,我们同样可以重新获取它。
query EmpireQuery { empire { id name } }
yields
{ "empire": { "id": "RmFjdGlvbjoy", "name": "Galactic Empire" } }
and
query EmpireRefetchQuery { node(id: "RmFjdGlvbjoy") { id ... on Faction { name } } }
yields
{ "node": { "id": "RmFjdGlvbjoy", "name": "Galactic Empire" } }
The
Nodeinterface and
nodefield assume globally unique IDs for this
refetching. A system without globally unique IDs can usually synthesize them
by combining the type with the type-specific ID, which is what was done
in this example.
Node接口和
node字段假设用的是全局的唯一ID。如果一个系统没有全局唯一ID,通常可以人工合成他们,可以根据该类型特定ID,这个例子中就是这么做的。
The IDs we got back were base64 strings. IDs are designed to be opaque (the
only thing that should be passed to the
idargument on
nodeis the
unaltered result of querying
idon some object in the syste
9a30
m), and base64ing
a string is a useful convention in GraphQL to remind viewers that the string is
an opaque identifier.
我们获得的ID是base64的字符串。ID被设计为不透明的,唯一应该传递给
node的id参数是在本系统中用于查其他对象是所用的不可改变的
id。base64的字符串很好的提示了用户这个字符串是不透明的。
Complete details on how the server should behave are
available in the
GraphQL Object Identification spec.
服务端应该如何处理的详细介绍请见GraphQL Object Identification spec.
相关文章推荐
- Facebook's New Real-time Messaging System: HBase to Store 135+ Billion Messages a Month
- Facebook获得TechCrunch Crunchies 2009最佳奖
- 网页上facebook分享功能具体实现
- JSONP获取Twitter和Facebook文章数的具体步骤
- iOS 5 cocos2d 游戏开发 3ff8 实战:第4章 你的第一个游戏
- 7月国外最新技术文章翻译汇总(IT技术)
- windows phone 8 的新特性
- Facebook图片存储架构技术全解析
- Facebook揭秘HipHop项目 PHP程序大提速
- 使用Html5开发Android和iOS应用:HBuilder、Html5Plus、MUI
- 基于 Facebook 的开发笔记
- Titanium 快速入门
- Titanium 用户界面之布局结构及核心代码块
- 月光微博客
- 月光微博客
- 月光微博客
- 月光微博客
- 月光微博客