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

Mutations #Facebook Relay文档翻译#

2015-09-28 10:48 821 查看
原文地址

上一篇 Connection

Relay文档翻译目录

Relay uses a common pattern for mutations, where they are root fields on the

mutation type with a single argument,
input
, and where the input and output

both contain a client mutation identifier used to reconcile requests and

responses.

Relay使用通用模式来处理mutation,定义为mutation type带有一个参数input的根字段,这里的输入输出都包含客户端mutation标识符用于撮合请求与响应。

By convention, mutations are named as verbs, their inputs are the name with

“Input” appended at the end, and they return an object that is the name with

“Payload” appended.

按照约定,mutation的名字用动词,他们的输入名字以’Input’结尾,返回的对象的名字以’Payload’结尾。

So for our
introduceShip
mutation, we create two types:
IntroduceShipInput


and
IntroduceShipPayload
:

input IntroduceShipInput {
factionId: ID!
shipName: String!
clientMutationId: String!
}

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


With this input and payload, we can issue the following mutation:

mutation AddBWingQuery($input: IntroduceShipInput!) {
introduceShip(input: $input) {
ship {
id
name
}
faction {
name
}
clientMutationId
}
}


with these params:

{
"input": {
"shipName": "B-Wing",
"factionId": "1",
"clientMutationId": "abcde"
}
}


and we’ll get this result:

{
"introduceShip": {
"ship": {
"id": "U2hpcDo5",
"name": "B-Wing"
},
"faction": {
"name": "Alliance to Restore the Republic"
},
"clientMutationId": "abcde"
}
}


Complete details on how the server should behave are

available in the GraphQL Input Object Mutations

spec.

服务器端应该如何处理的详细说明请见GraphQL Input Object Mutations

spec.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息