Skip to content

Commit

Permalink
feat: select support added for react-query components (#83)
Browse files Browse the repository at this point in the history
* select support added for react-query

* typo fix

* fix: missing TSelectData on UseQueryOptions added

* infer fetcher response type and support for blob

* fix: use TData instead of TSelectData and infer queryResult

* merge error fixed
  • Loading branch information
needim authored Aug 30, 2022
1 parent 3a15e0c commit 01574bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useListPets = (variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, ListPetsResponse>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, ListPetsResponse>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), () => fetchListPets({ ...fetcherOptions, ...variables }), {
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), () => fetchListPets({ ...fetcherOptions, ...variables }), {
...options,
...queryOptions
}); };
Expand Down Expand Up @@ -231,7 +231,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useListPets = (variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, ListPetsResponse>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, ListPetsResponse>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), () => fetchListPets({ ...fetcherOptions, ...variables }), {
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), () => fetchListPets({ ...fetcherOptions, ...variables }), {
...options,
...queryOptions
}); };
Expand Down Expand Up @@ -357,7 +357,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useListPets = (variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, ListPetsResponse>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, ListPetsResponse>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), () => fetchListPets({ ...fetcherOptions, ...variables }), {
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), () => fetchListPets({ ...fetcherOptions, ...variables }), {
...options,
...queryOptions
}); };
Expand Down Expand Up @@ -454,7 +454,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useListPets = (variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, ListPetsResponse>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, ListPetsResponse>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), () => fetchListPets({ ...fetcherOptions, ...variables }), {
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), () => fetchListPets({ ...fetcherOptions, ...variables }), {
...options,
...queryOptions
}); };
Expand Down Expand Up @@ -1162,7 +1162,7 @@ describe("generateReactQueryComponents", () => {
/**
* Get all the pets
*/
export const useListPets = (variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, ListPetsResponse>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, ListPetsResponse>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), () => fetchListPets({ ...fetcherOptions, ...variables }), {
export const useListPets = <TData = ListPetsResponse>(variables: ListPetsVariables, options?: Omit<reactQuery.UseQueryOptions<ListPetsResponse, ListPetsError, TData>, \\"queryKey\\" | \\"queryFn\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ListPetsResponse, ListPetsError, TData>(queryKeyFn({ path: \\"/pets\\", operationId: \\"listPets\\", variables }), () => fetchListPets({ ...fetcherOptions, ...variables }), {
...options,
...queryOptions
}); };
Expand Down
17 changes: 14 additions & 3 deletions plugins/typescript/src/generators/generateReactQueryComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ const createQueryHook = ({
undefined,
f.createArrowFunction(
undefined,
undefined,
[f.createTypeParameterDeclaration("TData", undefined, dataType)],
[
f.createParameterDeclaration(
undefined,
Expand Down Expand Up @@ -527,7 +527,14 @@ const createQueryHook = ({
f.createIdentifier("reactQuery"),
f.createIdentifier("useQuery")
),
[dataType, errorType, dataType],
[
dataType,
errorType,
f.createTypeReferenceNode(
f.createIdentifier("TData"),
[]
),
],
[
f.createCallExpression(
f.createIdentifier("queryKeyFn"),
Expand Down Expand Up @@ -608,7 +615,11 @@ const createUseQueryOptionsType = (
f.createIdentifier("reactQuery"),
f.createIdentifier("UseQueryOptions")
),
[dataType, errorType, dataType]
[
dataType,
errorType,
f.createTypeReferenceNode(f.createIdentifier("TData"), []),
]
),
f.createUnionTypeNode([
f.createLiteralTypeNode(f.createStringLiteral("queryKey")),
Expand Down

0 comments on commit 01574bc

Please sign in to comment.