dotansimha / dotansimha/graphql-code-generator-community

[React Query] addInfiniteQuery option imports QueryFunctionContext without usage

Open
#187 4 comments 5 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

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.

```yaml
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
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in packages/plugins/typescript/react-query/src/visitor.ts and inspect how addInfiniteQuery generates imports when a custom fetcher is configured. Reproduce the supplied codegen.yml configuration, then verify generated output no longer includes an unused QueryFunctionContext import and remains valid under ESLint.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.