dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.72k stars 1.31k forks source link

issues with generated file after react query v5 migration #9824

Open dominikabieder opened 5 months ago

dominikabieder commented 5 months ago

Which packages are impacted by your issue?

@graphql-codegen/cli

Describe the bug

I'm having several issues after migrating tanstack query to v5. Is there anything I might have missed in the codegen.ts? how can I fix the warnings in generated.ts.

how do I pass options to the query? the app doesn't want to start due to bad argument type

const currentUserQuery = useCurrentUserQuery({ enabled: !isLoggingIn });
TS2322: Type boolean is not assignable to type never

Your Example Website or App

can't share

Steps to Reproduce the Bug or Issue

  1. upgrade react query

Expected behavior

no warnings in generated.ts and no issues with useQuery or useMutation hooks

Screenshots or Videos

image

const currentUserQuery = useCurrentUserQuery({ enabled: !isLoggingIn }); TS2322: Type boolean is not assignable to type never

Platform

 "dependencies": {
    "@graphql-codegen/cli": "5.0.0",
    "@graphql-codegen/typescript-operations": "4.0.1",
    "@graphql-codegen/typescript-react-query": "6.0.0",
    "@graphql-eslint/eslint-plugin": "3.20.1",
    "@graphql-typed-document-node/core": "3.2.0",
    "@tanstack/eslint-plugin-query": "4.34.1",
    "@tanstack/react-query": "5.17.19",

Codegen Config File

import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
  overwrite: true,
  schema: '../schema.graphql',
  reactQueryVersion: 5,
  documents: 'src/**/*.graphql',
  generates: {
    'src/generated/generated.ts': {
      plugins: ['typescript', 'typescript-operations', 'typescript-react-query'],
      config: {
        fetcher: '../fetcher#fetcher',
        namingConvention: {
          enumValues: 'keep',
        },
      },
    },
  },
};

export default config;

Additional context

No response

U-4-E-A commented 4 months ago

With @tanstack/react-query v5, you need to specify your version in your codegen config: -

config: {
    reactQueryVersion: 5
}
dominikabieder commented 4 months ago

With @tanstack/react-query v5, you need to specify your version in your codegen config: -

config: {
    reactQueryVersion: 5
}

I have that :( fixed the formatting so it's more visible