0

I am trying to do a RANGE_ADD mutation using what is now known as Relay Classic (this probably is resolved with Modern). I get the error:

Warning: writeRelayUpdatePayload(): Expected response payload to include the newly created edge `newThingEdge` and its `node` field. Did you forget to update the `RANGE_ADD` mutation config?

So, yes, the payload is not sending the anything more than the clientMutationId in the expected response shape because the request mutation is not asking for it.

According to @Joe Savona here, https://github.com/facebook/relay/issues/521, this might be happening if there is no intersecting container requesting for this data. But that's not entirely true for me. My Route is requesting:

things: (Component) => Relay.QL`
    query {
      allThings(variable: $variable) {
        ${Component.getFragment('things')},
      }
    }
`,

while my fatQuery is requesting for:

fragment on AddMockThing {
  allThings(variable: "${variable}", first: 100) {
    edges { 
      node {
        id,
      },
    },
  },
  newThingEdge
}

Now you may say these aren't the same queries, because of the extra first: 100 in the getFatQuery version, but if I don't use that, I get the error:

Error: Error: You supplied the 'edges' field on a connection named 'allThings', but you did not supply an argument necessary to do so. Use either the 'find', 'first', or 'last' argument.

On the other hand, if I add first: 100 to the Route query, I get the error: Error: Invalid root field 'allThings'; Relay only supports root fields with zero or one argument.

Stuck between a fatQuery and a hard place. Would appreciate the help!

Varun Arora
  • 332
  • 4
  • 8

1 Answers1

0

You're getting a validation error because the Relay compiler is looking for a connection argument (first: X). You can disable this particular validation by adding the @relay(pattern: true) directive. This marks the fat query as a ‘pattern’ to match against, rather than as something concrete.

fragment on AddMockThing @relay(pattern: true) {
  allThings(variable: "${variable}") {
    edges { 
      node {
        id,
      },
    },
  },
  newThingEdge
}

More info here: https://stackoverflow.com/a/34112045/802047

steveluscher
  • 4,144
  • 24
  • 42
  • Thanks @steveluscher! It'll be a while before I jump back into that code to use your suggestion (and replace my workaround), so just wanted to acknowledge it for now. – Varun Arora Sep 25 '17 at 06:15