Skip to content Skip to sidebar Skip to footer

Relay Error When Deleting: Relaymutationquery: Invalid Field Name On Fat Query

I'm running into an issue when I attempt to commit a deletion mutation. When I commit, I get the error Uncaught Invariant Violation: RelayMutationQuery: Invalid field name on fat q

Solution 1:

This error is referring to the fact that you reference the "company" in your getConfigs() implementation. The NODE_DELETE config tells Relay how to construct the mutation query by mapping nodes in the store (e.g. parentID) to fields on the fat query (e.g. parentName).

Although you might not necessarily need it today, you should add the company to the mutation payload & fat query here, since the company is being affected by this change. More specifically, the company's employees connection is being modified :)

Solution 2:

NevilleS' solution solved it for me:

I added a globalId to the root field (in my case an object called "verify") and I also changed my mutation on the server to return an edge, rather than just the underlying type. I also added the root "verify" object to the mutation output fields: it would make sense that the client's relay mutation needs that to know which object owns the connection, where to put the new edge.

exportconstVerify = newGraphQLObjectType({
name: 'Verify',
fields: () => ({
  id: globalIdField('Verify'),
  verifications: {
    args: connectionArgs,
    type: VerificationConnection,
    resolve: (rootValue, args) =>connectionFromArray(rootValue.verifications, args)
  },

Adding "verify" and "verificationEdge" to the mutation's output fields.

exportconstAddVerifiedSchool = mutationWithClientMutationId({
name: 'AddVerifiedSchool',
inputFields: {
  verification: {
    type: VerifiedSchoolInput
  }
},
outputFields: {
  success: {
    type: GraphQLBoolean,
    resolve: () =>true
  },
  verificationEdge: {
    type: VerificationEdge,
    resolve: ({verification, context}) => {
      console.log('verification', verification);
      return verification
    }
  },
  verify: {
    type: Verify,
    resolve: ({verification, context}) => {
      return context.rootValue
    }
  }
},

Adding the verify field to the fat query, and (the globalId "id" from verify) to the fragments, and using the new globalId to identify the node where the connection exists.

static fragments = {
  verify: () =>Relay.QL`fragment on Verify { id }`,
  action: () =>Relay.QL`fragment on Action { name url }`
};

getConfigs() {
  return [{
    type: 'RANGE_ADD',
    parentName: 'verify',
    parentID: this.props.verify.id,
    connectionName: 'verifications',
    edgeName: 'verificationEdge',
    rangeBehaviors: {
      '': 'append'
    }
  }];
}

getFatQuery() {
  returnRelay.QL`
  fragment on AddVerifiedSchoolPayload {
    verification {
      ${VerifiedSchool.getFragment('verification')}
    }
    verify {
      id
    }
  }`
}

Post a Comment for "Relay Error When Deleting: Relaymutationquery: Invalid Field Name On Fat Query"