dotansimha / graphql-code-generator-community

MIT License
118 stars 153 forks source link

[typescript react-query] unused `pageParamKey` when calling `useInfiniteQuery`. #174

Open ndthinh8796 opened 2 years ago

ndthinh8796 commented 2 years ago

Describe the bug Unused pageParamKey in file https://github.com/dotansimha/graphql-code-generator/blob/master/packages/plugins/typescript/react-query/src/fetcher-graphql-request.ts

I think this:

    return `export const useInfinite${operationName} = <
      TData = ${operationResultType},
      TError = ${this.visitor.config.errorType}
    >(
      pageParamKey: keyof ${operationVariablesTypes},
      client: GraphQLClient,
      ${variables},
      ${options},
      headers?: RequestInit['headers']
    ) =>
    ${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
      ${generateInfiniteQueryKey(node, hasRequiredVariables)},
      (metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(client, ${documentVariableName}, {...variables, ...(metaData.pageParam ?? {})}, headers)(),
      options
    );`;

should be change to:

    return `export const useInfinite${operationName} = <
      TData = ${operationResultType},
      TError = ${this.visitor.config.errorType}
    >(
      pageParamKey: keyof ${operationVariablesTypes},
      client: GraphQLClient,
      ${variables},
      ${options},
      headers?: RequestInit['headers']
    ) =>
    ${hookConfig.infiniteQuery.hook}<${operationResultType}, TError, TData>(
      ${generateInfiniteQueryKey(node, hasRequiredVariables)},
      (metaData) => fetcher<${operationResultType}, ${operationVariablesTypes}>(client, ${documentVariableName}, {...variables, [pageParamKey]: metaData.pageParam }, headers)(),
      options
    );`;
EandrewJones commented 2 years ago

Any intention to fix this or should I create a PR?

The infinite query does not work correctly if it isn't passing the page param to the correct variable. Plus, even if you write a temporary solution, the generator overwrites the fix anytime you update your api and need to regenerate the hooks.

saihaj commented 2 years ago

@EandrewJones go for it! Would love to review and land it in :)

EandrewJones commented 2 years ago

Great -- will look to push something in the coming week or two.

Best

Evan Jones Website: www.ea-jones.com

On Sun, Oct 16, 2022 at 10:52 AM Saihajpreet Singh @.***> wrote:

@EandrewJones https://github.com/EandrewJones go for it! Would love to review and land it in :)

— Reply to this email directly, view it on GitHub https://github.com/dotansimha/graphql-code-generator-community/issues/174, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ2T6AKUYIEJSUNZNUCLH63WDQJCNANCNFSM5OR5NJPA . You are receiving this because you were mentioned.Message ID: @.***>

EandrewJones commented 2 years ago

@saihaj Will you please assign me the issue?

StampixSMO commented 1 year ago

Did this change get lost? I'm on 4.1.0 and this still happens

tonypee commented 1 year ago

yah same - wondering what this is?

pigeonvictor commented 1 year ago

Yes same here, I have now this unused param

giubatt commented 1 year ago

also having this issue, seems something was reverted

sumicet commented 1 year ago

Same here

gabrielavoll commented 1 year ago

also same 😢

saalihou commented 1 year ago

Seems like the fix was reverted here (https://github.com/dotansimha/graphql-code-generator-community/pull/25) due to another bug

happyso commented 11 months ago

still same ...

saihaj commented 11 months ago

@happyso you are facing issue in @graphql-codegen/typescript-react-query@5.0.0?