我有一个页面使用GraphQL中继连接取得drafts
。GraphQL中继突变配置RANGE_ADD的连接父母名称
query {
connections {
drafts(first: 10) {
edges {
node {
... on Draft {
id
}
}
}
}
}
}
在这个页面中,我也通过CreateDraftMutation
创建草稿。
mutation {
createDraft(input: {
clientMutationId: "1"
content: "content"
}) {
draft {
id
content
}
}
}
在此突变后,我希望Relay将创建的草稿添加到其存储中。突变配置的最佳人选是RANGE_ADD,这是记录如下:
https://facebook.github.io/relay/docs/guides-mutations.html
RANGE_ADD 鉴于父母,连接和新创建的边缘的名称在响应负载继电器将增加节点到商店并根据指定的范围行为将其附加到连接。
参数
parentName:串 在响应中的字段名,表示连接的父
的parentID:字符串 包含连接
connectionName中的父节点的数据ID:字符串 表示连接的响应中的字段名称
edgeName:string 在响应中的字段名,表示新创建的边缘
rangeBehaviors:{[呼叫:字符串]:GraphQLMutatorConstants.RANGE_OPERATIONS}
之间印刷,点分隔GraphQL按字母顺序调用的地图,并且我们希望在这些调用影响下将新边缘添加到连接时展现的行为。行为可以是'append','ignore','prepend','refetch'或'remove'之一。
从文档的例子都按如下:
class IntroduceShipMutation extends Relay.Mutation {
// This mutation declares a dependency on the faction
// into which this ship is to be introduced.
static fragments = {
faction:() => Relay.QL`fragment on Faction { id }`,
};
// Introducing a ship will add it to a faction's fleet, so we
// specify the faction's ships connection as part of the fat query.
getFatQuery() {
return Relay.QL`
fragment on IntroduceShipPayload {
faction { ships },
newShipEdge,
}
`;
}
getConfigs() {
return [{
type: 'RANGE_ADD',
parentName: 'faction',
parentID: this.props.faction.id,
connectionName: 'ships',
edgeName: 'newShipEdge',
rangeBehaviors: {
// When the ships connection is not under the influence
// of any call, append the ship to the end of the connection
'': 'append',
// Prepend the ship, wherever the connection is sorted by age
'orderby(newest)': 'prepend',
},
}];
}
/* ... */
}
如果父是派那样明显,这是小菜一碟,但我一直有很难识别parentName和parentID,如果它直接来自查询连接。
我该怎么做?
编辑:
这是如何导出查询。
export default new GraphQLObjectType({
name: 'Query',
fields:() => ({
node: nodeField,
viewer: {
type: viewerType,
resolve:() => ({}),
},
connections: {
type: new GraphQLObjectType({
name: 'Connections',
这反过来继电器容器
export default Relay.createContainer(MakeRequestPage, {
fragments: {
connections:() => Relay.QL`
fragment on Connections {
在您的查询中连接是一个GraphQL对象还是连接? –
@AhmadFerdousBinAlam我添加了下面的代码片段。 'Connections'GraphQLObjectType带有连接字段的字段。 – lustdante