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

typescript-react-query Generated queries should reference a type that has common query keys/method (getKey, fetcher, callable) #533

Open
ekcrisp opened this issue Dec 6, 2023 · 0 comments

Comments

@ekcrisp
Copy link

ekcrisp commented Dec 6, 2023

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 <TData> =  {
  (): (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<TData>;
}

then generated queries would have export const useMyQueryName: GeneratedQuery<MyQueryData> = ...

These types are probably off but you get the idea, queries should reference a shared type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant