-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix: useQuery returns called value based on skip option. #9798
Fix: useQuery returns called value based on skip option. #9798
Conversation
@KucharskiPiotr: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
it('should set called to false when skip option is true', async () => { | ||
const query = gql`{ hello }`; | ||
const mocks = [ | ||
{ | ||
request: { query }, | ||
result: { data: { hello: "world" } }, | ||
}, | ||
]; | ||
|
||
const cache = new InMemoryCache(); | ||
const wrapper = ({ children }: any) => ( | ||
<MockedProvider mocks={mocks} cache={cache}>{children}</MockedProvider> | ||
); | ||
|
||
const { result, unmount } = renderHook( | ||
() => useQuery(query, { skip: true }), | ||
{ wrapper }, | ||
); | ||
|
||
expect(result.current.called).toBe(false); | ||
unmount(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following test is copy-paste of the test above (should set called to true by default
) with added { skip: true }
parameter to useQuery
and changed expected value to be false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, and thanks for adding tests @KucharskiPiotr!
Changed returned `called` value of `QueryResult` to be false, when the `skip` parameter of `QueryHookOptions` is set to true. Otherwise, `called` value should return true like it used to do by default.
1951015
to
f9e8b35
Compare
@KucharskiPiotr These changes have been soft-published in |
Changed returned
called
value ofQueryResult
to be false, whenthe
skip
parameter ofQueryHookOptions
is set to true. Otherwise,called
value should return true like it used to do by default.Checklist:
Reason to change:
useQuery
result documentation states thatcalled
value should betrue
only if the query has been executed. Currently, whenuseQuery
is called with option{ skip: true }
, the value ofcalled
remainstrue
, even though the network request hasn't been done. This was discussed in #7931.This Pull Request changes value of
called
to be based on theskip
option - if the option was set totrue
, thecalled
value will be set tofalse
, which should work as expected.