dotansimha / dotansimha/graphql-code-generator-community
typescript-react-query Generated queries should reference a type that has common query keys/method (getKey, fetcher, callable)
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
Currently generated queries are callable and have additional keys for fetcher and getKey, however there is no type that defines this in a generic way so that multiple queries can be referenced in shared logic. We are using a CMS and get data based on parameters that come from the CMS, sometimes we need to prefetch queryA and queryB, other times it's queryA and queryC. Right now we have to use `any` type for the loop that prefetches all these queries for SSR.
Generated code should reference a generic type, something like
type GeneratedQuery = {
(): (variables: Types.Exact<{[key: string]: unknown}>, options?: UseQueryOptions) => UseQueryResult;
getKey: (variables: Types.Exact<{[key: string]: unknown}>) => [string, Types.Exact<{[key: string]: unknown}>];
fetcher: (variables: Types.Exact<{[key: string]: unknown}>, options?: RequestInit['headers']) => (queryString: string, variables: Types.Exact<{[key: string]: unknown}>, options: RequestInit['headers']) => Promise;
}
then generated queries would have `export const useMyQueryName: GeneratedQuery = ... `
These types are probably off but you get the idea, queries should reference a shared type
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.