Graphql-code-generator: Typescript errors in generated file

Created on 25 Nov 2019  路  2Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug
I am getting a couple of errors on my generated file:
Every import { DocumentNode } from 'graphql'; yields a Cannot find module 'graphql'. error, even though I have graphql as a dev dependency.

Another error is at the export interface IntrospectionResultData { section, which is as follows ("possibleTypes": [] is empty because I cannot provide my graphql schema :( ):

      export interface IntrospectionResultData {
        __schema: {
          types: {
            kind: string;
            name: string;
            possibleTypes: {
              name: string;
            }[];
          }[];
        };
      }
      const result: IntrospectionResultData = {
  "__schema": {
    "types": [
      {
        "kind": "INTERFACE",
        "name": "Node",
        "possibleTypes": []
      }
    ]
  }
};
      export default result;

This yields two errors, Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. and Initializers are not allowed in ambient contexts..
The formatting and indentation seems off. It is exactly as I pasted it above.

My codegen.yml config file:

overwrite: true
schema: ""
documents:
  - "./src/**/*.gql"
  - "./src/**/*.ts"
generates:
  src/@types/graphql.d.ts:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-graphql-files-modules"
      - "fragment-matcher"

Environment:

  • OS: Windows 10 latest updates
  • "@graphql-codegen/cli": "^1.8.3",
  • "@graphql-codegen/fragment-matcher": "^1.8.3",
  • "@graphql-codegen/typescript": "^1.8.3",
  • "@graphql-codegen/typescript-graphql-files-modules": "^1.8.3",
  • "@graphql-codegen/typescript-operations": "^1.8.3",
  • NodeJS: 13.2.0 (Currently using 64-bit executable)
  • Typescript: 3.7.2
  • graphql: "^14.5.8",
waiting-for-answer

Most helpful comment

Fragment matcher has code inside so it cannot be .d.ts. Could change it to graphql.ts without .d and try again?

All 2 comments

Fragment matcher has code inside so it cannot be .d.ts. Could change it to graphql.ts without .d and try again?

Worked, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iamdanthedev picture iamdanthedev  路  3Comments

rogerg93 picture rogerg93  路  3Comments

jackhkmatthews picture jackhkmatthews  路  3Comments

zenVentzi picture zenVentzi  路  3Comments

quolpr picture quolpr  路  3Comments