发送到GraphQL的突变查询不包括跟踪查询和我的Fat Query之间交集的结果。
这是我的Mutation课程:
getMutation() {
return Relay.QL`mutation { updateTag }`
}
getVariables() {
return {
id: this.props.id,
name: this.props.name,
isFollowed: this.props.isFollowed,
}
}
getFatQuery() {
return Relay.QL`
fragment on UpdateTagPayload {
viewer {
followedTags {
tagList {
name
}
}
}
}
`;
}
getConfigs() {
return [
{
type: 'FIELDS_CHANGE',
fieldIDs: {
viewer: this.props.viewerID,
},
},
]
}
这是生成的查询,发送到GraphQL:
mutation FollowTagMutation($input_0:UpdateTagInput!) {
updateTag(input:$input_0) {
clientMutationId
}
}
我希望我的Fat Query中定义的部分字段也在那里。
在控制台中,跟踪片段变量是一个空对象(Object{}
),跟踪片段查询只是空的。
所以看起来,当截获track和fat查询时,结果是一个空的Intersection Query。
对此有何帮助?我在这里缺少什么?
答案 0 :(得分:1)
所以,我的问题的解决方案是双重的:
使用this.props.relay.commitUpdate
代替Relay.Store.commitUpdate
:
此时,我真的不知道为什么(找不到关于此的文档),但使用后者只是在我的情况下不起作用。一旦我发现,我会更新这一点。
将我的Fat Query中的viewer
连接到我本地中继商店中的viewer
。
这与其他答案提供的建议有关(感谢@maplechori和@Ahmad Ferdous!)。
但是,没有必要在Mutation类中创建static fragments
位;我确保通过React组件中的Relay获取viewer { id }
,并通过props
将其传递给Mutation,因此它在getConfigs()
位中使用。
答案 1 :(得分:0)
我建议在FollowTagMutation上设置片段,然后在调用该变异的组件上使用$ {FollowTagMutation.getFragment(' viewer')}拉取它。
然后确保在Relay.Store.commitUpdate上传递查看器(新的FollowTagMutation(查看器:this.props.viewer .....在同一个组件上。
答案 2 :(得分:0)
(这适用于评论。我这里是为了维护代码格式。)
根据您的信息,我怀疑您需要提供查看器ID才能获得预期结果。将fragments
添加到FollowTagMutation
突变:
static fragments = {
viewer: () => Relay.QL`
fragment on Viewer {
id,
}
`,
};