graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

Error: pluginHelpers.isDetailedError is not a function

Open christo8989 opened this issue 2 years ago • 5 comments

Which packages are impacted by your issue?

No response

Describe the bug

Doesn't print out the proper error message.

Your Example Website or App

none

Steps to Reproduce the Bug or Issue

I think any error will work?

Here is the real error:

AggregateError: GraphQL Document Validation failed with 1 errors;
Error 0: GraphQLDocumentError: Cannot query field "xxx" on type "Mutation".

Expected behavior

The error is printed out.

I added a solution below that does work.

Screenshots or Videos

No response

Platform

  • OS: macos
  • NodeJS: 16.19.1
  • graphql version: ^14.1.1
  • @graphql-codegen/* version(s): ^2.3.0

Codegen Config File

overwrite: true schema: 'http://localhost:4000/graphql' extensions: codegen: config: arrayInputCoercion: false immutableTypes: true namingConvention: keep scalars: DateOnly: string DateTime: string generates: src/generated/graphql.ts: plugins: - add: content: | /* eslint-disable / / prettier-ignore / / * * * * * * * * * * * * * * * * * * * * * * THIS FILE IS GENERATED, DO NOT EDIT! (use npm run codegen to update)
* * * * * * * * * * * * * * * * * * * * * * */ - typescript - typescript-operations

Additional context

class Renderer {
    constructor(tasks, options) {
        this.updateRenderer = new UpdateRenderer(tasks, options);
    }
    render() {
        return this.updateRenderer.render();
    }
    end(err) {
        this.updateRenderer.end(err);
        if (typeof err === 'undefined') {
            logUpdate.clear();
            return;
        }
        // persist the output
        logUpdate.done();
        // show errors
        if (err) {
            const errorCount = err.errors ? err.errors.length : 0;
            if (errorCount > 0) {
                const count = indentString(chalk.red.bold(`Found ${errorCount} error${errorCount > 1 ? 's' : ''}`), 1);
                const details = err.errors
                    .map(error => {
                    debugLog(`[CLI] Exited with an error`, error);
                    return { msg: pluginHelpers.isDetailedError(error) ? error.details : null, rawError: error }; // <========= breaking
                })
                    .map(({ msg, rawError }, i) => {
                    const source = err.errors[i].source;
                    msg = msg ? chalk.gray(indentString(commonTags.stripIndent(`${msg}`), 4)) : null;
                    const stack = rawError.stack ? chalk.gray(indentString(commonTags.stripIndent(rawError.stack), 4)) : null;
                    if (source) {
                        const sourceOfError = typeof source === 'string' ? source : source.name;
                        const title = indentString(`${logSymbols.error} ${sourceOfError}`, 2);
                        return [title, msg, stack, stack].filter(Boolean).join('\n');
                    }
                    return [msg, stack].filter(Boolean).join('\n');
                })
                    .join('\n\n');
                logUpdate.emit(['', count, details, ''].join('\n\n'));
            }
            else {
                const details = err.details ? err.details : '';
                logUpdate.emit(`${chalk.red.bold(`${indentString(err.message, 2)}`)}\n${details}\n${chalk.grey(err.stack)}`);
            }
        }
        logUpdate.done();
        printLogs();
    }
}

Solution

return { msg: error?.details ? error.details : null, rawError: error }; 

christo8989 avatar Mar 22 '23 23:03 christo8989

updated I was able to resolve the issue by doing the following:

  1. Delete node_modules
  2. npm i (all @graphql-codegen plugins)

Theres a big chance that you probably just need to update your codegen packages

brandon-irving avatar Apr 24 '23 14:04 brandon-irving

I am getting: pluginHelpers.DetailedError is not a constructor. Does anyone have idea about that? Not sure if I need to create an issue about this. "@graphql-codegen/cli": "2.3.0", "@graphql-codegen/introspection": "2.1.0", "@graphql-codegen/typescript": "2.4.1", "@graphql-codegen/typescript-operations": "2.2.1", "@graphql-codegen/typescript-react-apollo": "3.2.2",

What I did was to clone a repo, install packages and then: Screenshot 2023-06-02 at 12 53 12

update: I did a new clone of the repo and this time no error... didn't even have to upgrade the packages.🤔

staykova-sport-thieme avatar Jun 02 '23 10:06 staykova-sport-thieme

I am getting: pluginHelpers.DetailedError is not a constructor. Does anyone have idea about that? Not sure if I need to create an issue about this. "@graphql-codegen/cli": "2.3.0", "@graphql-codegen/introspection": "2.1.0", "@graphql-codegen/typescript": "2.4.1", "@graphql-codegen/typescript-operations": "2.2.1", "@graphql-codegen/typescript-react-apollo": "3.2.2",

What I did was to clone a repo, install packages and then: Screenshot 2023-06-02 at 12 53 12

I upgraded to all the latest and the error is gone!

"@graphql-codegen/cli": "^4.0.1",
    "@graphql-codegen/introspection": "^4.0.0",
    "@graphql-codegen/typescript": "^4.0.0",
    "@graphql-codegen/typescript-operations": "^4.0.0",
    "@graphql-codegen/typescript-react-query": "^4.1.0",

ro0t avatar Jun 02 '23 17:06 ro0t

image

I'm having the same error. Whenever I pass the @Arg to this function, graphql-codegen returns pluginHelpers.isDetailedError is not a function. I have many queries like that, including one that returns only one research and receive the very same arguments. I have tried to delete node_modules and upgrading packages, but nothing solves it for me.

image

walteraandrade avatar Jan 17 '24 12:01 walteraandrade

My case was fixed by making sure I have unique query aliases in .graphql files.

./bullets.graphql

query Bullets { # This has to be unique, you cannot have another query alias `query Bullets` in different .graphql file
  bulletsFired {
    speed
    hitEar
  }
}

./other.graphql

query Bullets { # this will cause error
}

jan-karnik avatar Aug 14 '24 15:08 jan-karnik