Mutations #Facebook Relay文档翻译#

原文地址
上一篇 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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值