Search code examples
graphqlrelayjsrelaygraphql-js

Using NODE_DELETE without refetching data


Using a NODE_DELETE requires the parent, and to actually return the parent of the connection:

Relay Error when deleting: RelayMutationQuery: Invalid field name on fat query

Unfortunately, using this refetches ALL my nested items, which is simply unacceptable for my use case.

  fragment on deleteItemNested @relay(pattern: true) {
    id
    ok
    item {
      nested {
        edges {
          node { id }
        }
      }
    }
    clientMutationId
  }

Is there a way to delete an item from a connection/list without refetching all data? Trying not to fetch for the edges in nested results in nested being just an empty object.


Solution

  • All the nested items are refetched because @relay(pattern: true) was used in the query. This makes the query to match against the tracked query, which already includes the nested fields. See an excellent answer by steveluscher to the question Purpose of @relay(pattern:true).

    The code example of NODE_DELETE in mutation documentation is worth taking a look.