Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
toniopelo opened this issue Dec 15, 2020 · 3 comments
Labels
🏓 awaiting-team-response requires input from the apollo team

Comments

@toniopelo
Copy link

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 👏

@toniopelo toniopelo changed the title RefetchQueriesFunction does not send mutation result as first parameter and is not documented RefetchQueriesFunction does not receive mutation result as first parameter and is not documented Dec 15, 2020
@toniopelo
Copy link
Author

toniopelo commented Dec 15, 2020

Problem seems to be located here:

refetchQueries = refetchQueries(storeResult!);

I guess storeResult is not defined yet because this line is not executed yet ?

storeResult = result;

And the use of let to define storeResult tends to confirm the weird behavior of console.log as the variable pointer value is just updated later on.

let storeResult: FetchResult<T> | null;

@toniopelo
Copy link
Author

I will probably create a PR for this but I'd like to ensure that my understanding of the problem is right.
Anybody ?

@fikrikarim
Copy link

Having similar problem here.

In my case, the refetchQueries function actually receive the mutation result and it's working as intended. It's just that the argument is not properly typed yet, and it's marked as any, instead of the type of the mutation result.

I saw on the roadmap that there would be a rework for refetchQueries, so I guess this could be fixed on version 3.4.0

@bignimbus bignimbus added the 🏓 awaiting-team-response requires input from the apollo team label Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏓 awaiting-team-response requires input from the apollo team
Projects
None yet
Development

No branches or pull requests

3 participants