dotansimha / graphql-code-generator-community

MIT License
114 stars 144 forks source link

I get Cannot redeclare block-scoped variable with client preset #685

Open Sly777 opened 5 months ago

Sly777 commented 5 months ago

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

Expected behavior

There are two options;

Screenshots or Videos

No response

Platform

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

JoshFransix commented 1 day ago

I just hit this error today, any solutions?