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

react-query plugin with graphql-request fetcher generates invalid infinite query if query has no arguments

Open iscekic opened this issue 2 years ago • 9 comments

Describe the bug

The latest version introduces an issue where, if an infinite query has no arguments, the react-query plugin generates invalid types.

Your Example Website or App

/

Steps to Reproduce the Bug or Issue

  1. write a query without arguments
  2. observe type error in generated code

The error comes from the 3rd argument passed to fetcher:

error TS2345: Argument of type '{ [x: string]: any; }' is not assignable to parameter of type 'Exact<{ [key: string]: never; }>'.
  'string' index signatures are incompatible.
    Type 'any' is not assignable to type 'never'.

Expected behavior

No error.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: 16.7.1
  • graphql version: 16.6.0
    "@graphql-codegen/cli": "^2.13.7",
    "@graphql-codegen/typescript": "^2.8.0",
    "@graphql-codegen/typescript-graphql-request": "^4.5.7",
    "@graphql-codegen/typescript-operations": "^2.5.5",
    "@graphql-codegen/typescript-react-query": "^4.0.3",

Codegen Config File

scalars omitted to keep it short

overwrite: true
generates:
  src/modules/common/generated/client.graphql.ts:
    documents: "src/**/*.graphql"
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-react-query"
    config:
      dedupeFragments: true
      immutableTypes: true
      skipTypename: true
      maybeValue: T | null | undefined
      namingConvention:
        enumValues: keep
        typeNames: keep
      strictScalars: true
      fetcher: graphql-request
      exposeQueryKeys: true
      addInfiniteQuery: true

Additional context

Only happens in latest version.

iscekic avatar Oct 24 '22 10:10 iscekic