You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This ends up causing some confusion in the code. For example, useDummyQuery() will have a unique entry in the react-query cache compared to useDummyQuery({}). This also causes issues with query invalidation, since the key used to invalidate needs to match:
const{ data, ... }=useDummyQuery()// elsewhere:queryClient.invalidateQueries({queryKey: useDummyQuery.getKey({})})// does not invalidate the above
Proposed solution:
If we default the query variable to an empty object then it should work as expected:
This may be a breaking change if users were invalidating based on exact query key matches without using the .getKey helper, although that seems unlikely:
// Technically this will no longer workqueryClient.invalidateQueries({queryKey: ['Dummy'],exact: true})
Your Example Website or App
none
Steps to Reproduce the Bug or Issue
Use graphQL Codegen with a query that takes no arguments. Make sure exposeQueryKeys is enabled.
When fetching data, use const { data } = useSomeQuery() without brackets
Have another button that invalidates the query with queryClient.invalidateQueries({ queryKey: useSomeQuery.getKey({}) }) with brackets
Notice tha this does not re-fetch the data.
Expected behavior
I would expect the query invalidation to force a refetch of the data
Which packages are impacted by your issue?
@graphql-codegen/typescript-react-query
Describe the bug
If a query does not have any required arguments, then the codegen plugin currently generates a hook that looks like this:
This ends up causing some confusion in the code. For example,
useDummyQuery()
will have a unique entry in the react-query cache compared touseDummyQuery({})
. This also causes issues with query invalidation, since the key used to invalidate needs to match:Proposed solution:
If we default the query variable to an empty object then it should work as expected:
This may be a breaking change if users were invalidating based on exact query key matches without using the
.getKey
helper, although that seems unlikely:Your Example Website or App
none
Steps to Reproduce the Bug or Issue
exposeQueryKeys
is enabled.const { data } = useSomeQuery()
without bracketsqueryClient.invalidateQueries({ queryKey: useSomeQuery.getKey({}) })
with bracketsNotice tha this does not re-fetch the data.
Expected behavior
I would expect the query invalidation to force a refetch of the data
Screenshots or Videos
No response
Platform
graphql
version: 16.8.0@graphql-codegen/typescript-react-query
version(s): 6.1.0Codegen Config File
Additional context
No response
The text was updated successfully, but these errors were encountered: