apollographql / apollographql/apollo-client

RefetchQueriesFunction does not receive mutation result as first parameter and is not documented

Open
#7,481 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🏓 awaiting-team-response
Dominant language
TypeScript
Stars
19.8k
Forks
2.9k
Avg merge
11h 14m
Merged PRs (30d)
18

Description

Intended outcome:

Inside reftechQueries, I need the response of the original mutation to use the result as a variable for the refetch query.
I saw, even if not really documented, that a RefetchQueriesFunction is accepted as refetchQueries.
Trying to retro-engineer how this function would work, I print the arguments received to the console an see that the response is sent as first argument!
Typescript tells me that the function should return a Array<string | PureQueryOptions>.
Great, this is exactly what I need.

Actual outcome:

The actual outcome is, at runtime the first argument that as the exact same shape as data in

const { data } = useQuery(...)
//      ^

is undefined. (the prop inside data is actually undefined).
So for a mutation called addPost, data.addPost will be undefined at runtime.
The fact that the console shows the data on console.log is probably due to a pointer value being updated and the console shows the updated value.

So, I see two options here:
1/ My retro-engineering is wrong and the RefetchQueriesFunction should be documented.
2/ My retro-engineering is right and something is wrong in the implementation of RefetchQueriesFunction. Maybe response is not awaited properly or something ?

How to reproduce the issue:

I guess this is pretty straightforward, if you need any additional info just tell me :)

Versions

System:
    OS: Linux 4.19 Alpine Linux
Binaries:
    Node: 12.16.3 - /usr/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.5 - /usr/bin/npm
npmPackages:
    @apollo/client: ^3.2.0 => 3.2.0
    apollo-upload-client: ^14.1.1 => 14.1.1

I'm open to creating a PR if needed.
Thanks for your wonderful work 👏

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the refetchQueries option and RefetchQueriesFunction behavior described in the issue, then reproduce the addPost mutation case with Apollo Client 3.2.0. The issue names no source file or test; done means establishing whether the mutation result is available as the first argument and either correcting that behavior or documenting the supported contract.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.