Fat Query 片段不包含在发送到 GraphQL 的查询中

Fat Query fragment not included in the query sent to GraphQL

发送到 GraphQL 的突变查询不包括轨道查询和我的 Fat 查询的交集结果。

这是我的突变 class:

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 中定义的部分字段也存在。

在控制台中,Tracked Fragment Variables是一个空对象(Object{}),Tracked Fragment Query只是空的。

看来,track 和 fat query 被拦截时,结果是一个空的 Intersection Query。

有什么帮助*吗?我在这里错过了什么?

我建议在 FollowTagMutation 上设置片段,然后在调用该突变的组件上使用 ${FollowTagMutation.getFragment('viewer')} 拉取它。

然后确保在 Relay.Store.commitUpdate(new FollowTagMutation( viewer: this.props.viewer ..... 在同一组件上传递查看器。

(适合评论,我放在这里是为了保持代码格式。)

根据您的信息,我怀疑您需要提供查看器 ID 才能获得预期结果。添加 fragmentsFollowTagMutation 突变:

  static fragments = {
    viewer: () => Relay.QL`
      fragment on Viewer {
        id,
      }
    `,
  };

所以,我的问题的解决方案有两个:

  1. 使用this.props.relay.commitUpdate,而不是Relay.Store.commitUpdate

    在这一点上,我真的不知道为什么(找不到关于这个的文档),但在我的情况下使用后者是行不通的。一旦我发现,我会更新这一点。

  2. 将我的胖查询中的 viewer 连接到我本地中继存储中的 viewer

    这与此处其他答案提供的建议有关(感谢@maplechori 和@Ahmad Ferdous!)。

    但是,没有必要在 Mutation class 中创建 static fragments 位;我只是确保通过 React 组件中的 Relay 获取 viewer { id },并通过 props 将其传递给 Mutation,因此它在 getConfigs() 位中使用。