Search code examples
relayjs

Fat Query fragment not included in the query sent to GraphQL


The mutation query that is being sent to GraphQL does not include the result of the intersection between the track query and my Fat Query.

This is my Mutation 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,
      },
    },
  ]
}

And this is the resulting query, sent to GraphQL:

mutation FollowTagMutation($input_0:UpdateTagInput!) {
  updateTag(input:$input_0) {
    clientMutationId
  }
}

I would expect part of the fields defined in my Fat Query to also be there.

In the console, the Tracked Fragment Variables is an empty object (Object{}), and the Tracked Fragment Query is just empty.

So it seems like, when the track and the fat query are intercepted, the result is an empty Intersection Query.

Any help on* this? What am I missing here?


Solution

  • So, the solution to my issue is two-folded:

    1. Use this.props.relay.commitUpdate, instead of Relay.Store.commitUpdate:

      At this point, I don't really know why (can't find docs about this), but using the latter just didn't work in my case. Once I find out, I'll update this point.

    2. Connect the viewer in my Fat Query to the viewer in the my local Relay store.

      This is related to the suggestions provided by the other answers here (thanks @maplechori and @Ahmad Ferdous!).

      However, it's not necessary to create the static fragments bit in the Mutation class; I just make sure to fetch viewer { id } via Relay in the React component, and pass it to the Mutation via props, so it's used in the getConfigs() bit.