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

Warn when calling refetch({ variables }) instead of refetch(variables) #8702

Merged
merged 2 commits into from Aug 25, 2021

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Aug 25, 2021

The refetch method of ObservableQuery takes a single optional positional argument, specifying (additional) variables to include when refetching the query.

A common pitfall is passing an object containing a variables property to refetch (you may be thinking of setOptions?), which is almost always a mistake, unless the query declares a variable named $variables (uncommon).

This PR displays a helpful warning in these cases (with tests to prove it). For example:

Called refetch({"variables":["d","e"]}) for query QueryWithoutVariables, which does not declare a $variables variable.
Did you mean to call refetch(variables) instead of refetch({ variables })?

Related:

@benjamn benjamn force-pushed the warn-when-options-passed-to-refetch branch from 68dd1fb to dccaa81 Compare August 25, 2021 16:58
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woohoo I love this - thanks @benjamn!

Copy link
Contributor

@stemmlerjs stemmlerjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, thanks for the quick turnaround on this @benjamn! The console message looks great. I think this should help for sure.

@benjamn benjamn merged commit 8da60ee into main Aug 25, 2021
@benjamn benjamn deleted the warn-when-options-passed-to-refetch branch August 25, 2021 17:16
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants