dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.82k stars 1.33k forks source link

Plugin typescript does not export a valid JS object with "plugin" function. #7784

Open lemiesz opened 2 years ago

lemiesz commented 2 years ago

Keep getting the following issue

    Plugin typescript does not export a valid JS object with "plugin" function.

    Make sure your custom plugin is written in the following form:

    module.exports = {
      plugin: (schema, documents, config) => {
        return 'my-custom-plugin-content';
      },
    };

my dependencies are as follows

    "@graphql-codegen/cli": "^2.4.8",
    "@graphql-codegen/near-operation-file-preset": "^2.2.9",
    "@graphql-codegen/typescript": "^2.4.8",
    "@graphql-codegen/typescript-apollo-client-helpers": "^2.1.15",
    "@graphql-codegen/typescript-operations": "^2.3.5",
    "@graphql-codegen/typescript-react-apollo": "^3.2.11",

and my codegen.yml is

overwrite: true
schema: "./schema.gql"
generates:
  schema.ts:
    plugins:
      - "typescript"
  ./:
    preset: near-operation-file
    presetConfig:
      extension: .generated.ts
      baseTypesPath: "./schema.ts"
    documents: '../**/src/**/*.gql'
    plugins:
      - add:
          content: '/* eslint-disable */'
      - "typescript-operations"
      - "typescript-react-apollo"
      - "typescript-apollo-client-helpers"
    config:
      exportFragmentSpreadSubTypes: true
    hooks:
      afterAllFileWrite:
        - eslint --fix
        - prettier --write

Following instructions found here https://github.com/dotansimha/graphql-code-generator/pull/6716 I can resolve the issue by installing @babel/runtime however this is not a could option as installing @babel/runtime causes other things in my code base to fail

maykon-oliveira commented 1 year ago

Same here