Graphql-code-generator: TypeError: func is not a function

Created on 8 Jan 2020  ·  10Comments  ·  Source: dotansimha/graphql-code-generator

When running graphql-codegen to generate typings, our team suddenly started to get this error today, after months of working without issues. I updated to latest version of all plugins, but the issue persists:

TypeError: func is not a function
    at <path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:259:19
    at Array.map (<anonymous>)
    at convertNameParts (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:259:10)
    at opts (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:425:24)
    at Object.convert (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:462:43)
    at TsVisitor.convertName (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:488:78)
    at TsVisitor._getTypeForNode (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:889:21)
    at TsVisitor.NamedType (<path-to-project-folder>/node_modules/@graphql-codegen/visitor-plugin-common/index.cjs.js:892:21)
    at TsVisitor.NamedType (<path-to-project-folder>/node_modules/@graphql-codegen/typescript/index.cjs.js:101:31)
    at Object.visit (<path-to-project-folder>/node_modules/graphql/language/visitor.js:242:26)
    at Object.plugin (<path-to-project-folder>/node_modules/@graphql-codegen/typescript/index.cjs.js:195:35)
    at executePlugin (<path-to-project-folder>/node_modules/@graphql-codegen/core/index.cjs.js:50:41)
    at <path-to-project-folder>/node_modules/@graphql-codegen/core/index.cjs.js:106:30
    at Array.map (<anonymous>)
    at Object.codegen (<path-to-project-folder>/node_modules/@graphql-codegen/core/index.cjs.js:96:54)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Update - seems like the issue is only above version 1.9.1.

Expected behavior
Generated types

Environment:

  • OS: MacOS 10.14.6
  • "@graphql-codegen/cli": "^1.11.2",
  • "@graphql-codegen/typescript": "^1.11.2",
  • "@graphql-codegen/typescript-apollo-angular": "^1.11.2",
  • "@graphql-codegen/typescript-operations": "^1.11.2",
  • "@graphql-codegen/typescript-resolvers": "^1.11.2",
  • NodeJS: 12.11.1

codegen.yml

schema: http://localhost:1337/graphql
generates:
  ./src/app/eddy/generated/graphql.ts:
    schema: ./src/app/eddy/modules/graphql/client-schema.ts
    documents: ./src/**/*.graphql
    config:
      ngModule: ../modules/graphql-lazy-service/graphql-lazy-service.module#GraphqlLazyServiceModule
    plugins:
      - typescript
      - typescript-operations
      - typescript-apollo-angular
  ./aveiro-server/src/graphql/generated/resolvers-types.ts:
    plugins:
      - typescript
      - typescript-resolvers
    config:
      scalars:
        ObjectId: GQLObjectId
        Date: GQLDate

require:
  - ts-node/register

Workaround
Fix versions in your package.json:
"@graphql-codegen/cli": "1.9.1",
"@graphql-codegen/typescript": "1.9.1",
"@graphql-codegen/typescript-apollo-angular": "1.9.1",
"@graphql-codegen/typescript-operations": "1.9.1",
"@graphql-codegen/typescript-resolvers": "1.9.1",

bug core

Most helpful comment

it looks graphql-codegen has a dependency of "change-case": "^3.0.0", but change-case has dependency of "pascal-case": "^2.0.0",
so I think we need to update change-case to latest version.
npm i -D change-case (it worked for me!)

or wait for maintainers to update the dependency to "change-case": "^4.1.1"

All 10 comments

same here...
up to 1.9.1 everything is OK.
from 1.10.0 I get this error.

I can confirm that the problem also starts with 1.10.0 in our project

@dauledk @evark Could you reproduce it using this codesandbox template?
https://codesandbox.io/s/github/dotansimha/graphql-code-generator-issue-sandbox-template

Hi @ardatan, to be honest, I don't know where to start - I am not very familiar with codesandbox. Given the link you provided me, how do I create an Angular project 🤷🏾‍♂️?
We are using an apollo express node.js + Angular project. I will just update the issue with our codegen.yml file, if it can maybe help. I was really hoping that the stack trace would tell you something 😅

@ardatan I tried reproducing this error, it's not easy but I finally found something! It seems like the error is not related to the setup (client or server) _at all_ - but has something to do with versioning - maybe npm.

When I removed the package-lock.json (something I otherwise always try to avoid as a solution) and did a fresh install with npm i @graphql-codegen/{cli,typescript,typescript-apollo-angular,typescript-operations,typescript-resolvers}@latest, the error was gone 🤔

Only thing is that now, I can't reproduce 🤷🏾‍♂️

OK! after deleting node_modules/package-lock.json and reinstall everything codegen works normally. It seems that some dependency is not updated with the normal update of the package. Full reinstall is needed.

In our case, the pascal-case dependency (v2.0.0) didn't match the included type definition. The type def is import { pascalCase } from 'pascal-case' where as the js seems to be exporting the func as default, e.g. import pascalCase from 'pascal-case'.

I just tried installing the latest version of pascal-case (v3.1.1) explicitly and it fixed the issue.

it looks graphql-codegen has a dependency of "change-case": "^3.0.0", but change-case has dependency of "pascal-case": "^2.0.0",
so I think we need to update change-case to latest version.
npm i -D change-case (it worked for me!)

or wait for maintainers to update the dependency to "change-case": "^4.1.1"

@ardatan is it fixed?

@dotansimha We don't use change-case anymore and I don't think even npm gets confused with ^ :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NickClark picture NickClark  ·  3Comments

bastman picture bastman  ·  3Comments

fvisticot picture fvisticot  ·  3Comments

edorivai picture edorivai  ·  3Comments

steebchen picture steebchen  ·  3Comments