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

Receive 'Cannot use GraphQLSchema' error when using makeExecutableSchema in junction with SchemaLink #1790

Closed
MikeWinfied opened this issue Jul 16, 2020 · 20 comments

Comments

@MikeWinfied
Copy link

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.

@danielrearden
Copy link
Collaborator

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?

@MikeWinfied
Copy link
Author

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.

@ardatan
Copy link
Owner

ardatan commented Jul 16, 2020

@danielrearden @MikeWinfied We don't have graphql as dependency in our packages. Maybe it is @apollo/client that has graphql as its dependency.

@MikeWinfied
Copy link
Author

@ardatan does it mean that the issue should be redirected to @apollo/client?

@danielrearden
Copy link
Collaborator

@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

@danielrearden
Copy link
Collaborator

@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).

@MikeWinfied
Copy link
Author

@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]

@yaacovCR
Copy link
Collaborator

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).

@yaacovCR
Copy link
Collaborator

@MikeWinfied
Copy link
Author

Hi, @danielrearden! Should I address my issue elsewhere?
It's interesting that everything works fine if one downgrades graphql-js to 14.7.0.

@danielrearden
Copy link
Collaborator

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 :/

@yaacovCR
Copy link
Collaborator

yaacovCR commented Oct 6, 2020

Workers?

graphql/graphql-js#2801 (comment)

@stoically
Copy link

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",

@stoically
Copy link

stoically commented Oct 17, 2020

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");

@stoically
Copy link

stoically commented Oct 17, 2020

Submitted an PR over at apollo-client (apollographql/apollo-client#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

@ardatan
Copy link
Owner

ardatan commented Oct 27, 2020

Is this issue still relevant?

@stoically
Copy link

stoically commented Oct 27, 2020

The fix that went into 3.3.0-beta14 and 3.2.5 solved it for me

@ardatan
Copy link
Owner

ardatan commented Oct 27, 2020

Ok closing this issue then because the issue seems unrelated to graphql-tools.

@ardatan ardatan closed this as completed Oct 27, 2020
@rodrigo398
Copy link

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

@ardatan
Copy link
Owner

ardatan commented Sep 11, 2021

Could you please create a reproduction in a different issue? Thanks!

Repository owner locked as too heated and limited conversation to collaborators Sep 11, 2021
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

6 participants