dotansimha/graphql-code-generator-community

I get Cannot redeclare block-scoped variable with client preset

Sly777 opened this issue · 3 comments

Which packages are impacted by your issue?

@graphql-codegen/typescript-graphql-apollo

Describe the bug

I want to generate apollo hooks on new version of codegen but when I use client preset with typescript-react-apollo, they got conflict and creates same variables two times. If I don't use client preset, then it asks input - output on all queries.

example result;

export const ValidateMyPhoneDocument = gql`
    mutation validateMyPhone($test: String!) {
  validateMyPhone(test: $test)
}
    ` as unknown as DocumentNode<ValidateMyPhoneMutation, ValidateMyPhoneMutationVariables>;


export const ValidateMyPhoneDocument = gql`
    mutation validateMyPhone($test: String!) {
  validateMyPhone(test: $test)
}
    `;
export type ValidateMyPhoneMutationFn = Apollo.MutationFunction<ValidateMyPhoneMutation, ValidateMyPhoneMutationVariables>;

Your Example Website or App

Steps to Reproduce the Bug or Issue

  • use client preset and typescript-react-apollo
  • run codegen

Expected behavior

There are two options;

  • client preset and typescript-react-apollo work together and merge exports
  • client preset supports hooks

Screenshots or Videos

No response

Platform

  • OS: Mac Sonoma
  • NodeJS: 21
  • "@graphql-codegen/cli": "5.0.2"
  • "@graphql-codegen/client-preset": "4.2.5"
  • "@graphql-codegen/introspection": "4.0.3"
  • "@graphql-codegen/typescript-react-apollo": "^3.2.3"

Codegen Config File

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

const config: CodegenConfig = {
  overwrite: true,
  schema: [
    SCHEMAURL1,
    SCHEMAURL2
  ],
  documents: 'src/graphql/**/*.{ts,tsx}',
  generates: {
    'src/generated/gql/': {
      preset: 'client',
      plugins: ['typescript-react-apollo'],
      config: {
        documentMode: 'graphQLTag',
        withHooks: true,
      },
      presetConfig: {
        gqlTagName: 'gql',
      },
    },
    './graphql.schema.json': {
      plugins: ['introspection'],
    },
  },
};

export default config;

Additional context

No response