Receive 'Cannot use GraphQLSchema' error when using makeExecutableSchema in junction with SchemaLink
Hi, everyone!
When trying to run GraphQL w/o a server, providing SchemaLink created using makeExecutableSchema, I receive an error when running a query:
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 new ApolloError (https://t0i3t.csb.app/node_modules/@apollo/client/errors/ApolloError.js:42:24)
at ObservableQuery.getCurrentResult (https://t0i3t.csb.app/node_modules/@apollo/client/core/ObservableQuery.js:123:18)
at QueryData._this.getQueryResult (https://t0i3t.csb.app/node_modules/@apollo/client/react/data/QueryData.js:42:53)
at QueryData.getExecuteResult (https://t0i3t.csb.app/node_modules/@apollo/client/react/data/QueryData.js:160:23)
at QueryData.execute (https://t0i3t.csb.app/node_modules/@apollo/client/react/data/QueryData.js:113:47)
at eval (https://t0i3t.csb.app/node_modules/@apollo/client/react/hooks/utils/useBaseQuery.js:56:55)
at useDeepMemo (https://t0i3t.csb.app/node_modules/@apollo/client/react/hooks/utils/useDeepMemo.js:19:14)
at useBaseQuery (https://t0i3t.csb.app/node_modules/@apollo/client/react/hooks/utils/useBaseQuery.js:55:50)
at useQuery (https://t0i3t.csb.app/node_modules/@apollo/client/react/hooks/useQuery.js:14:46)
at Message (https://t0i3t.csb.app/src/App.js:59:40)
at renderWithHooks (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:16260:18)
at updateFunctionComponent (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:18347:20)
at beginWork$1 (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:20176:16)
at beginWork$$1 (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:25756:14)
at performUnitOfWork (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:24695:12)
at workLoopSync (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:24671:22)
at performSyncWorkOnRoot (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:24270:11)
at eval (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:12199:24)
at unstable_runWithPriority (https://t0i3t.csb.app/node_modules/scheduler/cjs/scheduler.development.js:697:12)
at runWithPriority$2 (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:12149:10)
at flushSyncCallbackQueueImpl (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:12194:7)
at flushSyncCallbackQueue (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:12182:3)
at scheduleUpdateOnFiber (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:23709:9)
at dispatchAction (https://t0i3t.csb.app/node_modules/react-dom/cjs/react-dom.development.js:17076:5)"
My dependencies are:
"@apollo/client": "3.0.1",
"@graphql-tools/schema": "6.0.13",
"graphql": "15.3.0",
"react": "16.12.0",
"react-dom": "16.12.0",
From what I can gather, I have only one graphql available so I'm not even sure that the message hits in the right direction.
The demo is available here
I don't have a GraphQL server available at my disposal. After considering the @rest directive I've come to the conclusion that having full-bodied resolvers would be cleaner and would easily integrate into the existing codebase.
Hi @MikeWinfied . I ran that sandbox code locally and couldn't reproduce the issue. Is the code where you're seeing the issue also being run on Code Sandbox or are you getting that same error when running the code locally?
Hi, @danielrearden! Thanks for your quick reply! I'm seeing the same error on my local environment. The code on sandbox is a boiled-down version to trace down the issue.
@danielrearden @MikeWinfied We don't have graphql as dependency in our packages. Maybe it is @apollo/client that has graphql as its dependency.
@ardatan does it mean that the issue should be redirected to @apollo/client?
@ardatan I thought it might be an issue with @apollo/client too, but npm ls shows only the one version installed. And the code runs fine for me as long as its not on Code Sandbox
@MikeWinfied can you try removing node_modules and then running npm install or yarn install? You can also verify that there's not more than one version being installed by running npm ls graphql (it should only show the one version).
@danielrearden, the same 😓 The removal didn't help and yarn list --pattern graphql yields only one version of GrahpQL:
├─ @graphql-tools/[email protected]
├─ @graphql-tools/[email protected]
├─ [email protected]
└─ [email protected]
You might get the same error even with the same version of graphql if you have multiple instances of GraphQL, i.e. if was not always being used as a peer dependency, or if sometimes uses as a fork of graphql.
Did apollo fork graphql at some point internally?
Not sure if above is relevant or even actually true in full, just thinking out loud (sort of).
https://github.com/graphql/graphql-js/issues/2523#issuecomment-659457211
Hi, @danielrearden! Should I address my issue elsewhere?
It's interesting that everything works fine if one downgrades graphql-js to 14.7.0.
Based on the comment in the issue linked above, it sounds like this error might be specific to @apollo/client@3 like @ardatan originally suggested :/
Workers?
https://github.com/graphql/graphql-js/issues/2801#issuecomment-696768674
Running into this when trying to use the approach mentioned by OP in a Cypress Component Test. Tried to work around it by dynamically importing all needed dependencies, but cypress doesn't support that currently in that scenario.
"@apollo/client": "3.3.0-beta.13",
"@graphql-tools/schema": "^6.2.4",
"cypress": "^5.4.0",
"cypress-react-unit-test": "^4.16.1",
After some digging, what I found so far is that the default cypress webpack bundle ends up using different entry points for the graphql module:
@graphql-tools/schema seems to use the esm version (.mjs)
/* harmony import */ var graphql__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! graphql */ "./node_modules/graphql/index.mjs");
while @apollo/client/link/schema seems to use the commonjs version (.js)
/* harmony import */ var graphql_execution_execute__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! graphql/execution/execute */ "./node_modules/graphql/execution/execute.js");
Submitted an PR over at apollo-client (https://github.com/apollographql/apollo-client/issues/7184) which fixes the issue for me. If you'd like to see if it works for you as well, feel free to test with
"@apollo/client": "github:stoically/apollo-client-dist",
as dependency
Is this issue still relevant?
The fix that went into 3.3.0-beta14 and 3.2.5 solved it for me
Ok closing this issue then because the issue seems unrelated to graphql-tools.
Hi @stoically , have you been able to fix this issue?, I'm getting the same issue with Cypress as well, it seems that there is an issue when using
import { makeExecutableSchema } from '@graphql-tools/schema'
makeExecutableSchema({ typeDefs: schema })
Any ideas ? Thank you
Could you please create a reproduction in a different issue? Thanks!