您的位置:首页 > Web前端 > React

GraphQL Relay Specification #Facebook Relay文档翻译#

2015-09-26 16:01 555 查看
原文地址

上一篇 Babel Relay Plugin

Relay文档翻译目录

The three core assumptions that Relay makes about a GraphQL server are that it

provides:

Relay使用的GraphQL server得满足以下三点核心假设:

A mechanism for refetching an object.

重新获取对象的机制

A description of how to page through connections.

如何在connection上进行分页描述

Structure around mutations to make them predictable.

对mutation进行结构化,让他们变得可预测

This example demonstrates all three of these assumptions.

下面的例子说明了这三点假设。

This example is not comprehensive, but it is designed to quickly introduce

these core assumptions, to provide some context before diving into

the more detailed specification or the library.

这个例子并不深刻,只是给你可以快速的预览,有助于你日后深入了解。

The premise of the example is that we want to use GraphQL to query for

information about ships and factions in the original Star Wars

trilogy.

例子的前提是我们希望用GraphQL来查询在星球大战三部曲中ships和factions的信息。

It is assumed that the reader is already familiar with GraphQL; if not,

the README for GraphQL.js is a

good place to start.

这里假设您已经熟悉GraphQL,如果不请阅读README GraphQL.js

It is also assumed that the reader is already familiar with Star Wars; if not,

the 1977 version of Star Wars is a good place to start, though the 1997

Special Edition will serve for the purposes of this document.

当然还希望您是了解星球大战的,如果不,1977、1997的版本您可以看看。

Schema

The schema described below will be used to demonstrate the functionality

that a GraphQL server used by Relay should implement. The two core types

are a faction and a ship in the Star Wars universe, where a faction

has many ships associated with it. The schema below is the output of the

GraphQL.js
schemaPrinter
.

下面的schema被用于说明Relay使用的GraphQL server应该实现哪些功能。在星球大战中有两个核心类型faction和ship,一个faction可以有很多ship。以下schema是用过GraphQL.js
schemaPrinter
打印输出的。

interface Node {
id: ID!
}

type Faction : Node {
id: ID!
name: String
ships: ShipConnection
}

type Ship : Node {
id: ID!
name: String
}

type ShipConnection {
edges: [ShipEdge]
pageInfo: PageInfo!
}

type ShipEdge {
cursor: String!
node: Ship
}

type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}

type Query {
rebels: Faction
empire: Faction
node(id: ID!): Node
}

input IntroduceShipInput {
factionId: String!
shipNamed: String!
clientMutationId: String!
}

type IntroduceShipPayload {
faction: Faction
ship: Ship
clientMutationId: String!
}

type Mutation {
introduceShip(input: IntroduceShipInput!): IntroduceShipPayload
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息