urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.

Home Page:https://urql.dev/goto/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

reexecuteQuery not using new variables

bhalsodkhushal opened this issue · comments

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

  • I can confirm that this is a bug report, and not a feature request, RFC, question, or discussion, for which GitHub Discussions should be used
  • Read the docs.
  • Follow our Code of Conduct

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