graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

[React Query] addInfiniteQuery option imports QueryFunctionContext without usage

Open evancloutier opened this issue 3 years ago • 3 comments

Hi there! I've been having lots of success with code generation using the React Query plugin.

Was adding the addInfiniteQuery option into my codegen.yml file, and noticed that it imports QueryFunctionContext from react-query unnecessarily according to my configuration. This sets off my ESLint rules, and I'm currently having to remove the import manually before committing any code.

The line in question is here: https://github.com/dotansimha/graphql-code-generator/blob/master/packages/plugins/typescript/react-query/src/visitor.ts

I've provided my codegen.yml below – perhaps it is an issue of my custom fetching function? Happy to push up a PR to resolve this.

overwrite: true
schema: "http://localhost:4000/v1/graph"
documents: "graphql/**/index.ts"
generates:
  graphql/generated.ts:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-react-query"
    config:
      addInfiniteQuery: true
      exposeFetcher: true
      exposeMutationKeys: true
      exposeQueryKeys: true
      fetcher:
        func: ../utils/gql-fetch#gqlFetch
      fetchParams:
        headers:
          Content-Type: application/json
      maybeValue: T
    hooks:
      afterOneFileWrite:
        - prettier --write

evancloutier avatar Apr 28 '22 13:04 evancloutier

We are also manually removing this unused import.

@jrwpatterson I believe it was added on the first commit that added the useInfiniteQuery hook (awesome job, this is working perfectly 👌, thank you) . Do you know how we can detect if this import is necessary, and only add it if it is?

https://github.com/dotansimha/graphql-code-generator/commit/f7a320a2d6378730e2b3b716c8b4184ac8c79640#diff-38f7b7f89098e5486e40c54e00569d09eb7b873bc8d4a7118aa39a1ce1c1be68R114

nelsonprsousa avatar Jul 06 '22 12:07 nelsonprsousa

@evancloutier did you already submit a PR for this?

sandergo90 avatar Jul 26 '22 07:07 sandergo90

@evancloutier did you already submit a PR for this?

I haven't – I don't have the context on how or why the import is necessary.

evancloutier avatar Jul 29 '22 22:07 evancloutier