graphql-code-generator-community
graphql-code-generator-community copied to clipboard
I get Cannot redeclare block-scoped variable with client preset
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
clientpreset andtypescript-react-apollo - run codegen
Expected behavior
There are two options;
clientpreset andtypescript-react-apollowork together and merge exportsclientpreset 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
I just hit this error today, any solutions?
I have the same problem ;(
Either you use the preset or you use the typescript-react-apollo plugin. They both have different purposes so yes they will have conflicts.