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

2.12.3: Error: Cannot use GraphQLSchema "[object GraphQLSchema]" from another module or realm #1296

Closed
joncursi opened this issue May 23, 2019 · 22 comments · Fixed by #1355
Closed

Comments

@joncursi
Copy link

After upgrading from apollo@2.12.2 --> apollo@2.12.3, I started receiving the following error while trying to download my schema:

> apollo service:download --endpoint=$API_ENDPOINT_PROXY/v2/graphql graphql-schema.json

  ✔ Loading Apollo Project
  ✖ Saving schema to graphql-schema.json
    → spurious results.
Error: Cannot use GraphQLSchema "[object GraphQLSchema]" from another module or realm.
Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.
https://yarnpkg.com/en/docs/selective-version-resolutions
Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.
    at instanceOf (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/jsutils/instanceOf.js:37:13)
    at isSchema (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/type/schema.js:34:34)
    at assertSchema (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/type/schema.js:38:4)
    at validateSchema (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/type/validate.js:53:28)
    at assertValidSchema (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/type/validate.js:77:16)
    at assertValidExecutionArguments (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/execution/execute.js:146:35)
    at executeImpl (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/execution/execute.js:67:3)
    at execute (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/execution/execute.js:62:256)
    at Object.introspectionFromSchema (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/node_modules/graphql/utilities/introspectionFromSchema.js:38:37)
    at Task.task (~/Sites/nextradata/mmdp/src/mmdp-app/node_modules/apollo/lib/commands/service/download.js:21:82)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! mmdp-app@0.0.7 update:schema: `apollo service:download --endpoint=$API_ENDPOINT_PROXY/v2/graphql graphql-schema.json`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the mmdp-app@0.0.7 update:schema script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/joncursi/.npm/_logs/2019-05-23T20_52_56_722Z-debug.log
ERROR: "update:schema" exited with 2.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mmdp-app@0.0.7 update: `dotenv -e .env -- npm-run-all update:schema update:types`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the mmdp-app@0.0.7 update script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/joncursi/.npm/_logs/2019-05-23T20_52_56_754Z-debug.log

Downgrading back to 2.12.2 causes the error to go away.

@mikea
Copy link

mikea commented May 28, 2019

This seems to be caused by changing required dependency in apollo package from "^14.2.1" to "~14.2.1"

Which is caused by: #1291

@Baldrani
Copy link

Even tough I've downgraded it does not fix anything for me :/

"dependencies": {
        "@ckeditor/ckeditor5-build-classic": "^12.0.0",
        "@ckeditor/ckeditor5-media-embed": "^11.1.0",
        "@ckeditor/ckeditor5-react": "^1.1.1",
        "@date-io/date-fns": "^1.3.6",
        "@stfy/react-editor.js": "^0.1.5",
        "@types/ckeditor__ckeditor5-core": "^11.0.2",
        "@types/crypto-js": "^3.1.43",
        "antd": "^3.19.1",
        "apollo": "^2.12.2",
        "apollo-boost": "^0.3.1",
        "apollo-client": "^2.6.0",
        "apollo-link-http": "1.5.11",
        "apollo-upload-client": "^10.0.0",
        "autoprefixer": "9.4.9",
        "axios": "^0.18.0",
        "babel-core": "^7.0.0-bridge.0",
        "babel-jest": "^23.4.2",
        "babel-loader": "8.0.5",
        "babel-preset-react-app": "^7.0.1",
        "case-sensitive-paths-webpack-plugin": "2.2.0",
        "chalk": "2.4.2",
        "css-loader": "2.1.0",
        "date-fns": "^2.0.0-alpha.27",
        "dotenv": "6.2.0",
        "dotenv-expand": "4.2.0",
        "extract-text-webpack-plugin": "^4.0.0-beta.0",
        "file-loader": "3.0.1",
        "fork-ts-checker-webpack-plugin": "^0.5.2",
        "formik": "^1.5.7",
        "fs-extra": "7.0.1",
        "graphql": "14.1.1",
        "html-webpack-plugin": "^4.0.0-beta.5",
        "jest": "^24.8.0",
        "material-ui-formik-components": "^0.2.4",
        "material-ui-pickers": "^2.2.4",
        "moment": "^2.24.0",
        "node-sass": "^4.10.0",
        "object-assign": "4.1.1",
        "postcss-flexbugs-fixes": "4.1.0",
        "postcss-loader": "3.0.0",
        "promise": "8.0.2",
        "ra-core": "^2.9.2",
        "ra-data-graphcool": "^2.8.2",
        "ra-data-graphql": "^2.8.2",
        "ra-data-graphql-simple": "^2.8.2",
        "ra-input-rich-text": "^2.9.2",
        "raf": "3.4.1",
        "react": "16.8.3",
        "react-admin": "^2.9.2",
        "react-apollo": "^2.5.6",
        "react-dev-utils": "^7.0.3",
        "react-dom": "16.8.2",
        "react-intl": "^2.9.0",
        "react-loader-spinner": "^2.3.0",
        "react-router-dom": "^4.3.1",
        "react-select": "^2.4.4",
        "react-sticky": "^6.0.3",
        "react-stripe-checkout": "^2.6.3",
        "react-toastify": "^5.2.1",
        "resolve": "1.10.0",
        "sass-loader": "^7.1.0",
        "source-map-loader": "^0.2.1",
        "style-loader": "0.23.1",
        "styled-components": "4.1.3",
        "sw-precache-webpack-plugin": "0.11.5",
        "terser-webpack-plugin": "^1.3.0",
        "ts-jest": "24.0.0",
        "ts-loader": "^5.3.3",
        "tsconfig-paths-webpack-plugin": "^3.2.0",
        "tslint": "^5.17.0",
        "tslint-config-prettier": "^1.18.0",
        "tslint-react": "^3.2.0",
        "url-loader": "1.1.2",
        "webpack": "4.29.6",
        "webpack-dev-server": "3.2.1",
        "webpack-manifest-plugin": "2.0.4",
        "whatwg-fetch": "3.0.0",
        "yup": "^0.26.10"
    },
    "devDependencies": {
        "@ant-design/icons": "^1.1.16",
        "@babel/cli": "^7.0.0",
        "@babel/core": "^7.4.5",
        "@babel/preset-env": "^7.4.5",
        "@babel/preset-react": "^7.0.0",
        "@types/graphql": "^14.0.7",
        "@types/jest": "^24.0.13",
        "@types/node": "^11.13.13",
        "@types/react": "16.8.6",
        "@types/react-dom": "^16.8.2",
        "@types/react-intl": "^2.3.17",
        "@types/react-router-dom": "^4.3.3",
        "@types/styled-components": "^4.1.15",
        "@types/yup": "^0.26.13",
        "babel-plugin-react-intl": "^3.1.1",
        "jest-haste-map": "^24.8.0",
        "jest-resolve": "^24.8.0",
        "prop-types": "^15.7.2",
        "react-intl-translations-manager": "^5.0.3",
        "react-test-renderer": "^16.8.6",
        "typescript": "^3.5.1"
    },

If this complete list could signifie somethinkg to you ?

@flippidippi
Copy link

If you are using npm:

  • Copy the version of graphql from your node_modules/apollo/package.json
    • For me at the time of writing it's "graphql": "~14.2.1
  • Paste that in your project's package.json to make sure it matches exactly what apollo is using
  • Run rm -rf node_modules/
  • Run npm i
  • Run npm dedupe

@githubflub
Copy link

githubflub commented Oct 6, 2019

I changed my backend's folder structure around and started getting this error while using serverless-offline and refreshing the local version of my UI. The fix for me was to change this line in my webpack config

externals: [ nodeExternals() ],

to

externals: [ nodeExternals({ modulesDir: path.resolve(__dirname, 'node_modules') }) ],

This fix probably doesn't apply to you if you are using a standard folder structure. I don't even know why this worked.

@Sceat
Copy link

Sceat commented Feb 8, 2020

@flippidippi dedupe can't work if we are in a monorepo submodule whith a local import as those imports will not have anything left in there node modules

@vuki656
Copy link

vuki656 commented Apr 7, 2020

If you are using npm:

  • Copy the version of graphql from your node_modules/apollo/package.json

    • For me at the time of writing it's "graphql": "~14.2.1
  • Paste that in your project's package.json to make sure it matches exactly what apollo is using

  • Run rm -rf node_modules/

  • Run npm i

  • Run npm dedupe

In case anyone has a variable version like this 14.0.2 - 14.2.0 || ^14.3.1,:

  1. Pick one and put it in both your packadge.json and in node_modules/apollo/packadge.json
  2. Delete node_modules/apollo/node_modules
  3. CD into node_modules/apollo/
  4. Install deps in node_modules/apollo/
  5. Install deps in your project

@hamzahsn
Copy link

@Sceat did you made it work for you in monorepo ?

@Sceat
Copy link

Sceat commented Jun 12, 2020

@Sceat did you made it work for you in monorepo ?

Nop it's not possible, neither to link other project using Graphql.js this realm security is imo useless and makes things overcomplex, i resolved it by refactoring my whole monorepo to import 'graphql' in only one place. Note that this security also prevent us from using a commonjs library that use graphql & using it ourselve through esm, that said i also moved away from all that heavy apollo stuff which has enough line of code to sink the earth into a black hole 😁 good luck my friend, i opted to write my own graphql solution on top of the graphqljs lib

@hamzahsn
Copy link

have you tried to use resolutions in package.json ?

@Sceat
Copy link

Sceat commented Jun 12, 2020

Yup, and all sort of others things like burning sand in a cup shouting chinese words but no success..

@hamzahsn
Copy link

@Sceat well, it works for me now with apollo schema:download but I have a small issue with apollo codegen:generate, anyway, I have made resolutions in top package.json file and that did the fix

@xsats
Copy link

xsats commented Aug 20, 2020

@Sceat well, it works for me now with apollo schema:download but I have a small issue with apollo codegen:generate, anyway, I have made resolutions in top package.json file and that did the fix

Would you mind sharing more about your 'resolutions' fix if possible? I'm not too sure how to set it up correctly. Thanks

@Sceat
Copy link

Sceat commented Aug 20, 2020

This is not a fix as it doesn't work lol, i don't even remember exactly but it's like putting graphql with a precise version in the resolutions field of the package.json

I made my own tools

@xsats
Copy link

xsats commented Aug 20, 2020

To onlookers facing a similar problem, I ended up adding yarn resolutions to the base package.json in my yarn workspaces monorepo, specifying a version of GraphQL that previously worked fine.

'"resolutions": {
"graphql": "^14.3.2"
}"'

This fully resolved the duplicate GraphQL dependency error above.

@Sceat
Copy link

Sceat commented Aug 21, 2020

@xsats Downgrading the version is not viable

@xsats
Copy link

xsats commented Aug 21, 2020

@xsats Downgrading the version is not viable

Ok, just mentioning here as it is an appropriate fix for our particular scenario

@achempak
Copy link

Just to add on here, I was able to do what @xsats did, but using "graphql": "^15.0.0". There was no need to downgrade the version. All I did was

  1. Remove node_modules in the base directory of the monorepo
  2. Add "resolutions":{"graphql":"^15.0.0"} to the package.json in the base directory
  3. Run yarn install in the base directory

@aroshasum
Copy link

I got this exact error when my .npmrc did not have proper entries such as username and password. We are using jFrog to normalise package installation and .npmrc should be located at root. Hope this will help someone

@chetvertkoff
Copy link

chetvertkoff commented May 11, 2021

I had a similar problem when using the apollo-link-schema package. You should just replace your modules with @apollo/client... https://www.apollographql.com/docs/react/migrating/apollo-client-3-migration/ . For example, apollo-link-schema is now @apollo/client/link/schema, etc.
If you using Vue, then '@apollo/client/core' instead '@apollo/client'

@JoCa96
Copy link

JoCa96 commented Apr 19, 2022

I am unable to understand where this error comes from...

My command:
apollo codegen:generate -c apollo.config.js --target typescript --excludes=node_modules/* --includes=./src/apollo/queries/*.ts --tagName=gql --outputFlat src/graphql-schema

The error:

    ✖ Generating query files with 'typescript' target
    → spurious results.
    Error: Cannot use GraphQLObjectType "QueryType" from another 
    module or realm.

My graphql dependencies:

npm ls graphql        
my-package
├─┬ @apollo/client@3.5.10
│ ├─┬ @graphql-typed-document-node/core@3.1.1
│ │ └── graphql@15.8.0 deduped
│ └── graphql@15.8.0 deduped
├─┬ @vue/apollo-composable@4.0.0-alpha.16
│ └── graphql@15.8.0 deduped
├─┬ apollo@2.33.10
│ ├─┬ @apollographql/apollo-tools@0.5.3
│ │ └── graphql@15.8.0 deduped
│ ├─┬ apollo-graphql@0.9.6
│ │ └── graphql@15.8.0 deduped
│ ├─┬ apollo-language-server@1.26.8
│ │ ├─┬ @apollo/federation@0.27.0
│ │ │ └── graphql@15.8.0 deduped
│ │ ├─┬ @apollographql/graphql-language-service-interface@2.0.2
│ │ │ ├─┬ @apollographql/graphql-language-service-parser@2.0.2
│ │ │ │ └── graphql@14.7.0 deduped
│ │ │ ├─┬ @apollographql/graphql-language-service-types@2.0.2
│ │ │ │ └── graphql@14.7.0 deduped
│ │ │ ├─┬ @apollographql/graphql-language-service-utils@2.0.2
│ │ │ │ └── graphql@14.7.0 deduped
│ │ │ └── graphql@14.7.0 deduped
│ │ ├─┬ apollo-link-error@1.1.13
│ │ │ └─┬ apollo-link-http-common@0.2.16
│ │ │   └── graphql@15.8.0 deduped
│ │ ├─┬ apollo-link-http@1.5.17
│ │ │ └── graphql@15.8.0 deduped
│ │ ├─┬ apollo-link@1.2.14
│ │ │ ├─┬ apollo-utilities@1.3.4
│ │ │ │ └── graphql@15.8.0 deduped
│ │ │ └── graphql@15.8.0 deduped
│ │ ├─┬ apollo-server-errors@2.5.0
│ │ │ └── graphql@15.8.0 deduped
│ │ └── graphql@14.7.0
│ ├─┬ graphql-tag@2.12.4
│ │ └── graphql@15.8.0 deduped
│ └── graphql@15.8.0 deduped
├─┬ graphql-tag@2.12.6
│ └── graphql@15.8.0 deduped
└── graphql@15.8.0

All use graphql@15.8.0 except some sub-dependencies of apollo

@amritk
Copy link

amritk commented May 10, 2022

This still seems to be an issue, should we re-open?

@forrestwilkins
Copy link

@amritk This is still an issue for me as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.