graphql-codegen-factories icon indicating copy to clipboard operation
graphql-codegen-factories copied to clipboard

using `graphql-codegen-factories/operations` fails on `this.schema.getRootType`

Open jsve opened this issue 1 year ago • 10 comments

With plugins as:

plugins: [
   'typescript',
   'typescript-operations',
   'typescript-urql',
   'graphql-codegen-factories/schema',
   'graphql-codegen-factories/operations',
],

I get this error message [FAILED] this.schema.getRootType is not a function

jsve avatar Feb 06 '23 19:02 jsve

Could you share a reproduction please? Feel free to use the minimal example as a starting point: https://stackblitz.com/github/zhouzi/graphql-codegen-factories/tree/main/examples/minimal?file=package.json

It could come from a specificity in the schema, a graphql version, mixing some plugins together or anything. With a reproduction, it'll be much easier to track down what's going wrong 🙏

zhouzi avatar Feb 12 '23 06:02 zhouzi

@jsve are you still having issues using the plugin? It'd be really helpful if you could share a reproduction.

zhouzi avatar Feb 27 '23 16:02 zhouzi

I am closing this issue but feel free to reopen with more details.

zhouzi avatar Mar 25 '23 06:03 zhouzi

Same issue with the latest graphql codegen:

"@graphql-codegen/cli": "5.0.0",
"@graphql-codegen/client-preset": "4.1.0",

alexsandiiarov avatar Nov 10 '23 01:11 alexsandiiarov

And still same:

        "@graphql-codegen/cli": "5.0.2",
        "@graphql-codegen/client-preset": "4.2.4",

Changing to these three instead of preset doesn't work either:

        "@graphql-codegen/typescript": "4.0.6",
        "@graphql-codegen/typescript-operations": "4.2.0",
        "@graphql-codegen/typescript-react-apollo": "4.3.0",

Looks to me like the format of the schema in the file graphql-codegen-factories/build/operations/FactoriesOperationsVisitor.js is not GraphQLSchema or an extension of it.

Cordazar avatar Feb 26 '24 10:02 Cordazar

I'll update the versions and see if I can reproduce this bug.

zhouzi avatar Feb 26 '24 10:02 zhouzi

Running console.log(Object.getOwnPropertyNames(this.schema.__proto__)); gives:

[
  'constructor',
  'getQueryType',
  'getMutationType',
  'getSubscriptionType',
  'getTypeMap',
  'getType',
  'getPossibleTypes',
  'getImplementations',
  'isPossibleType',
  'isSubType',
  'getDirectives',
  'getDirective',
  'toConfig'
]

Cordazar avatar Feb 26 '24 11:02 Cordazar

Thanks for sharing! I suspect the issue is that the plugin doesn't use the same version of the packages as the project. But I will have to run some tests.

zhouzi avatar Feb 26 '24 13:02 zhouzi

@Cordazar could you share the parts of your package.json that are related to graphql/codegen, please?

zhouzi avatar Mar 03 '24 09:03 zhouzi

    "@graphql-codegen/add": "5.0.2",
    "@graphql-codegen/cli": "5.0.2",
    "@graphql-codegen/client-preset": "4.2.4",
    "@graphql-codegen/typescript": "4.0.6",
    "@graphql-codegen/typescript-operations": "4.2.0",
    "@graphql-codegen/typescript-react-apollo": "4.3.0",
    "graphql-codegen-typescript-mock-data": "3.7.1",

I've tried it both with the preset: 'client' option and also manually by using the plugins directly:

    'typescript',
    'typescript-operations',
    'typescript-react-apollo',
    'graphql-codegen-factories/schema',
    'graphql-codegen-factories/operations'

Cordazar avatar Mar 04 '24 19:03 Cordazar