dotansimha / dotansimha/graphql-code-generator-community
TypeScript React-Query: Pass options to custom fetch function
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
**Is your feature request related to a problem? Please describe.**
I need to access the useQuery options from a custom fetcher (ex: options.meta). This will allow query-specific headers to be sent while using a custom fetch function.
[Custom Fetcher Documentation](https://www.graphql-code-generator.com/docs/plugins/typescript-react-query#using-custom-fetcher)
**Describe the solution you'd like**
Add the existing variable from the generated hook to the custom fetch function's bind statement.
### Current generated hook
```
export const useAdminsQuery = <
TData = AdminsQuery,
TError = Error
>(
variables?: AdminsQueryVariables,
options?: UseQueryOptions
) =>
useQuery(
variables === undefined ? ['Admins'] : ['Admins', variables],
useFetchData(AdminsDocument).bind(null, variables),
options
);
```
### Proposed change generated hook
*add `, options` to the bind call*
```
export const useAdminsQuery = <
TData = AdminsQuery,
TError = Error
>(
variables?: AdminsQueryVariables,
options?: UseQueryOptions
) =>
useQuery(
variables === undefined ? ['Admins'] : ['Admins', variables],
useFetchData(AdminsDocument).bind(null, variables, options),
options
);
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the TypeScript React-Query plugin's generated hook shown in the issue and read the linked custom fetcher documentation. Trace how the existing variables value is bound to the fetch function, then verify generated hooks pass options through so a custom fetcher can access options.meta.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100