question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Got a duplicate identifier issue

See original GitHub issue

Describe the bug

The graphql codegen generate duplicate identifier. cf the codesandbox


export type NavigationItemsQueryVariables = Exact<{ [key: string]: never; }>;


export type NavigationItemsQuery = { __typename?: 'Query', homePage?: { __typename?: 'HomePage', id: string, navigation: Array<{ __typename?: 'NavigationItem', id: string, slug?: string | null, title?: string | null }> } | null };


      export interface PossibleTypesResultData {
        possibleTypes: {
          [key: string]: string[]
        }
      }
      const result: PossibleTypesResultData = {
  "possibleTypes": {
    "HomePageNavigationItems": [
      "NavigationItem"
    ],
    "Node": [
      "Article",
      "Asset",
      "FieldOfWork",
      "HomePage",
      "NavigationItem",
      "ScheduledOperation",
      "ScheduledRelease",
      "User"
    ],
    "ScheduledOperationAffectedDocument": [
      "Article",
      "Asset",
      "FieldOfWork",
      "HomePage",
      "NavigationItem"
    ]
  }
};
      export default result;
    
export type NavigationItemsQueryVariables = Exact<{ [key: string]: never; }>;


export type NavigationItemsQuery = { __typename?: 'Query', homePage?: { __typename?: 'HomePage', id: string, navigation: Array<{ __typename?: 'NavigationItem', id: string, slug?: string | null, title?: string | null }> } | null };

Your Example Website or App

https://stackblitz.com/edit/github-mvhfsr?file=graphql/generated/index.ts

Steps to Reproduce the Bug or Issue

  1. Run yarn codegen
  2. Check the graphql/generated/index.ts file

Expected behavior

No duplicate identifier

Screenshots or Videos

No response

Platform

  • OS: MacOS
  • NodeJS: v16.13.2
  • graphql 16.5.0
    "@graphql-codegen/cli": "2.9.1",
    "@graphql-codegen/fragment-matcher": "3.3.0",
    "@graphql-codegen/introspection": "2.2.0",
    "@graphql-codegen/typescript": "2.7.2",
    "@graphql-codegen/typescript-graphql-request": "^4.5.2",
    "@graphql-codegen/typescript-operations": "2.5.2",
    "@graphql-codegen/typescript-react-apollo": "3.3.2",
    "@types/node": "^18.0.6",
    "@types/react": "^18.0.15",

Codegen Config File

overwrite: true schema: “https://api-eu-central-1.hygraph.com/v2/cl335cxsw434p01z87rv1ba3t/master” documents: “graphql/queries/*.{ts,tsx,gql,graphql}” generates: ./graphql/generated/index.ts: plugins: - typescript - typescript-operations - fragment-matcher - typescript-operations - typescript-graphql-request config: namingConvention: enumValues: change-case-all#titleCase

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:5
  • Comments:9

github_iconTop GitHub Comments

4reactions
ardatancommented, Oct 21, 2022

@RomanBaiocco You get duplicate error because client preset is defined with plugins. You get validation error because you don’t have tsx extension as output in TS Config.

2reactions
RomanBaioccocommented, Oct 21, 2022

@ardatan Thank you so much for the response! I’ll remove the client preset and see if that fixes it

Edit: It did! You’re amazing, thank you again!

For anyone who runs into this in the future, in codegen.ts I changed

generates: {
    'app/javascript/generated/graphql': {
      preset: 'client',
      plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
    },
  }

to

generates: {
  "app/javascript/generated/graphql.tsx": {
    plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
  },
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Confusing "duplicate identifier" Typescript error message
When I ran npm start , I got a bunch of duplicate identifier errors. SOLUTION: From the project root folder run: rm -r...
Read more >
How to fix the "duplicate identifier" error in TypeScript
If the answer to the previous question is yes, then you just found the reason to the “duplicate identifier” error. Remove the lines...
Read more >
Fix TS2300 Duplicate identifier error in TypeScript with React
Have you updated your "react" and "@types/react" dependencies and now see error TS2300 and TS2717? Let me help you understand and fix these ......
Read more >
How to fix: Duplicate identifier - Google Merchant Center Help
How to fix: Duplicate identifier ... There are multiple products in your product data that have the same product identifiers (for example, the...
Read more >
Duplicate identifier errors. : r/typescript - Reddit
This is probably a rookie question but I have a folder that I use for TS practice, code snippets, and notes. What do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found