-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
graphql 16 not supported #9230
Comments
@saihaj can you please take a look? |
I tried investigating this, so seems like something specific to plugins that we are creating locally beacuse looking and trying in the repo everything is working as expected. |
Ah. Recently bumped the graphql package from v15 to v16 and seeing the same issue. My packages:
The import type { CodegenConfig } from "@graphql-codegen/cli";
const config: CodegenConfig = {
overwrite: true,
schema: "<path_to_endpoint>",
documents: "./**/*.ts",
generates: {
"./__generated__/globalTypes.ts": {
plugins: ["typescript"],
config: {
namingConvention: {
enumValues: "keep",
},
},
},
"./": {
preset: "near-operation-file",
presetConfig: {
baseTypesPath: "./__generated__/globalTypes.ts",
importTypesNamespace: "GlobalTypes",
extension: ".types.ts",
folder: "__generated__",
overwrite: true,
},
plugins: ["typescript-operations", "typescript-compatibility"],
config: {
preResolveTypes: true,
flattenGeneratedTypes: true,
},
},
},
hooks: {
afterAllFileWrite: [
"eslint --fix --rule '@typescript-eslint/no-namespace: \"off\"'",
"prettier --write",
],
},
};
export default config; |
I'm having the exact same issue pointing to a local plugin, using the example code from the docs. Downgrading to |
I also updated from v15 to v16 and I'm having the same issue. @saihaj thanks for looking at this. |
I have been poking around in this a bit because I have been increasingly more frustrated with codegen holding back my move to graphql@16 and honestly, this seems like this one might be on the This is the function responsible for resolving the visitFn (one for enter and one for leave): Note the comments for the different cases as well as the types. The visitor defined is simply not valid anymore in graphql@16. You can either have a general enter and leave, separate enter and leave per kind or an implementation per kind that's understood as its enter function. What's not allowed is to set leave to an object of functions per kind. It was allowed in graphql@15. The types reflect this properly, using the visitor in the OP does throw a compiler error. Poking around some more, I found the PR that removed this form of visitor which argues that such a visitor can always be rewritten to the second form mentioned above: graphql/graphql-js#2957 Knowing this, we can write a helper function to transform an existing visitor of that "4th form" to the "2nd form" (dirty JS because I was running low on time; might revisit with proper typings): const convertLegacyVisitor = (visitor) => {
const newVisitor = {};
const { enter, leave } = visitor;
if (enter && typeof enter === "object") {
for (const key in enter) {
newVisitor[key] = { enter: enter[key]};
}
}
if (leave && typeof leave === "object") {
for (const key in leave) {
newVisitor[key] ??= { leave: leave[key]};
}
}
return newVisitor;
}; Which can be used like so: const visitor = {
FieldDefinition(node) {
// This function triggered per each field
},
ObjectTypeDefinition(node) {
// This function triggered per each type
}
}
const patchedVisitor = convertLegacyVisitor({leave: visitor});
const result = visit(astNode, patchedVisitor); What I don't know is whether any of the plugins still use the old, now unsupported syntax but I would assume that unless there are any At the very least it's a docs issue which should be easily remedied. Either by including that ugly piece of code of mine from above or changing the visitor to use one of the three allowed forms. |
Update: Since I am also developing a custom plugin at work, I was curious how this project solved the issue of not being able to create class instances anymore to handle leaving. Turns out, you can also do much simpler than I did above by replacing |
Able to reproduce this bug when trying to use
|
Which packages are impacted by your issue?
@graphql-codegen/cli
Describe the bug
Note - this is not a duplicate of #6937, this is to point out that issue is not actually complete.
The example in the docs does not work with graphql 16: https://the-guild.dev/graphql/codegen/docs/custom-codegen/using-visitor
The example does work if I downgrade to graphql 15.
Specifically this plugin example:
Running this results in
visitFn.call is not a function
.This is outlined in #6937, which is closed, but the issue persists as other recent comments on that issue indicate.
Your Example Website or App
https://codesandbox.io/p/sandbox/headless-cloud-6z6r45
Steps to Reproduce the Bug or Issue
npm run codegen
in the terminalExpected behavior
Visitor function should not error.
Screenshots or Videos
Platform
graphql
version: 16.6@graphql-codegen/*
version(s): all latest, see sandboxCodegen Config File
See sandbox, copied from docs
Additional context
No response
The text was updated successfully, but these errors were encountered: