urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.57k stars 444 forks source link

graphcache: Extra variables missing in updates #3355

Closed Undistraction closed 11 months ago

Undistraction commented 11 months ago

Describe the bug

I've just upgraded URQL to the latest packages, and I'm no longer receiving the extra arguments (documentation) that I pass in to a mutation in the Graphcache's updates. The arguments used by the query are still present, but the additional arguments are not.

Mutation:

const [, deleteLike] = useMutation(DeleteLikeMutation)
...
deleteLike({id, enrolmentId})

Relevant graphcache config:

updates: {
    Mutation: {
       deleteLike(
          result,
          { id },
          cache,
          { variables: { enrolmentId } }
        ) {
           // id is present
           // enrolmentId is not present (no key or value)
        }
      }
   }

Using the map exchange I have confirmed that the additional variable is present on the operation before it reaches the graphcache-exchange. I've also added some logging and confirmed that the variable is present when it is first processed by the graphcache-exchange.

Reproduction

To follow

Urql version

@urql/exchange-retry@^1.2.0
@urql/exchange-graphcache@^6.3.1
@urql/exchange-auth@^2.1.6
@urql/core@4.1.1
urql@4.0.5

Validations

kitten commented 11 months ago

Yes, extra variables are always present before an operation is sent onwards to the exchange that'll send it to the API. However, after forwarding these variables will be filtered. The code you link unfortunately has no relation to this. The operation variable there isn't an Operation type of @urql/core bit is rather an OperationDefinitionNode.

We're probably missing an operations.get call however to retrieve the prior operation with unchanged variables. I'll have to check this out more closely though, since there's been a few additional changes since this was introduced

Undistraction commented 11 months ago

@kitten yeah. Sorry. Deleted that update as I realised I'd gone down the wrong path.

I have confirmed that:

Undistraction commented 11 months ago

In case it's useful, here are the upgrades that caused the issue. Guessing it's the graphcache bump:

@urql/exchange-retry 1.2.0 No change
@urql/exchange-graphcache 6.1.4 => 6.3.1
@urql/exchange-auth 2.14 => 2.1.6
@urql/core 4.0.10 => 4.1.1
urql 4.04 => 4.0.5