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.63k stars 451 forks source link

reexecuteQuery not using new variables #3468

Closed bhalsodkhushal closed 9 months ago

bhalsodkhushal commented 9 months ago

Describe the bug

I am using urql version 4.0.5.

For fetching data i am calling below request using useQuery hook.

const [result, reexecuteQuery] = useQuery({
    query: GetUserQuery,
    variables: { userId: 1 },
});

For fetching new user data i am calling reexecuteQuery as per document, but it not working.

reexecuteQuery({ variables: { userId: 3 } });

Reproduction

reexecuteQuery({ variables: { userId: 3 } });

Urql version

4.0.5

Validations

kitten commented 9 months ago

As per the TSDocs/TypeScript typings and our docs, executeQuery is not a state setter and does not accept variables. It accepts an OperationContext object:

This is also not a pattern that makes much sense. Either, you need to track your variables in state, and update that state, as it's an input to useQuery, or, if you're doing programmatic queries, you can use the Client directly (e.g. via useClient)

As per the issue template, I'm converting this to a discussion, since it's a usage issue/question