Skip to content
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

Invariant Violation: 12 #8515

Closed
aakashbacancy opened this issue Jul 19, 2021 · 2 comments
Closed

Invariant Violation: 12 #8515

aakashbacancy opened this issue Jul 19, 2021 · 2 comments

Comments

@aakashbacancy
Copy link

aakashbacancy commented Jul 19, 2021

I'm encountering an Invariant Violation: Invariant Violation: 12 error and the console is suggesting to check out https://github.com/apollographql/invariant-packages. Didn't help me much.

I tried to find out the solution on the above link and on the internet and also ran grep -r InvariantError node_modules/**/bundle.cjs.js on my system but I can not find this error.

I'm kinda stuck because every new apollo client version has different Invariant violation errors defined with tagging numbers and I'm not sure which error exactly is this? Also, how can I generate invariantErrorCodes.js for my version like this? #6665

Versions:
"apollo-client": "2.6.10"

Thanks!

@benjamn
Copy link
Member

benjamn commented Jul 19, 2021

@aakashbacancy The instructions at https://github.com/apollographql/invariant-packages only apply to versions of Apollo Client that include #6665 (@apollo/[email protected] and later), and we are not planning to port those changes back to [email protected] (note the change in package names from apollo-client to @apollo/client). Please consider updating to AC3 when you have time!

However, it's still relatively easy to track down these error codes, once you know the trick(s). In this case, I installed your version of apollo-client with npm i [email protected] and then greped for 12:

% grep -r 12 node_modules/apollo-client | head -n 5
node_modules/apollo-client/bundle.umd.js:      process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(options.query, 12) : (0, _tsInvariant.invariant)(options.query, 'query option is required. You must specify your GraphQL document ' + 'in the query option.');
node_modules/apollo-client/bundle.cjs.js:    process.env.NODE_ENV === "production" ? (0, _tsInvariant.invariant)(options.query, 12) : (0, _tsInvariant.invariant)(options.query, 'query option is required. You must specify your GraphQL document ' + 'in the query option.');
node_modules/apollo-client/package.json:  "_integrity": "sha512-jiPlMTN6/5CjZpJOkGeUV0mb4zxx33uXWdj/xQCfAMkuNAC3HN7CvYDyMHHEzmcQ5GV12LszWoQ/VlxET24CtA==",
node_modules/apollo-client/package.json:    "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
node_modules/apollo-client/bundle.esm.js:        process.env.NODE_ENV === "production" ? invariant(options.query, 12) : invariant(options.query, 'query option is required. You must specify your GraphQL document ' +

While there are some false positives here, all the invariant-related lines point to this code:

public query<T>(options: QueryOptions): Promise<ApolloQueryResult<T>> {
invariant(
options.query,
'query option is required. You must specify your GraphQL document ' +
'in the query option.',
);

Are you calling client.query(options) somewhere without including options.query?

@aakashbacancy
Copy link
Author

@benjamn Thanks for a quick reply. I figured it out that when you send undefined in the query field, it throws the above error.

Actually, It was a typo issue, and because of that, I imported a query that was never defined.

Thanks!

@benjamn benjamn closed this as completed Jul 29, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants