Cannot use GraphQLObjectType "Query" from another module or realm
See original GitHub issueBug report
I’m trying to implement this middleware in my express
based graphql
server. However on doing so I receive an error which is only there when applying this middleware.
Received error
Error: Cannot use GraphQLObjectType "Query" 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.
Code
import path from "path";
import { ApolloServer, makeExecutableSchema } from "apollo-server-express";
import { importSchema } from "graphql-import";
import { applyMiddleware } from "graphql-middleware";
import { shield, allow } from "graphql-shield";
import Mutation from "./resolvers/Mutation";
import Query from "./resolvers/Query";
const schema = makeExecutableSchema({
typeDefs: importSchema(path.resolve("../src/schema.graphql")),
resolvers: {
Mutation,
Query
}
});
// No errors when you remove shield from the applyMiddleware call
const adjustedSchema = applyMiddleware(schema, shield({}, { fallbackRule: allow }));
export default new ApolloServer({
schema: adjustedSchema, // No errors when you pass schema: schema
resolverValidationOptions: {
requireResolversForResolveType: false
},
context: ctx => ctx
});
Versions used (all latest at this point in time)
"apollo-server-express": "^2.6.9",
"express": "^4.17.1",
"express-graphql": "^0.8.0",
"graphql": "^14.4.2",
"graphql-import": "^0.7.1",
"graphql-middleware": "^4.0.0",
"graphql-shield": "^6.0.4",
"prisma-binding": "^2.3.15"
How did I try to debug already
- Remove
node_modules
folder and runnpm install
- Search the
package-lock.json
file for other versions specified forgraphql
, not the case
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top Results From Across the Web
Error: Cannot use GraphQLObjectType "__Directive" from ...
Error: Cannot use GraphQLObjectType "__Directive" from another module or realm . Ensure that there is only one instance of "graphql" in the ...
Read more >Cannot use GraphQLObjectType "__Directive" from another ...
I get this error: ✖ Cannot use GraphQLObjectType "__Directive" from another module or realm. Ensure that there is only one instance of "graphql ......
Read more >Error Cannot use GraphQLScalarType [*Type*] from another ...
I am trying to use apollo:codegen to generate schema and interfaces. I go through everything I found on the net, but with no...
Read more >Duplicate graphql error - Strapi Community Forum
I get this error: Error: Cannot use GraphQLInputObjectType “FileInfoInput” from another module or realm. Ensure that there is only one instance ...
Read more >type-graphql/Lobby - Gitter
node_modules/graphql/type/definition.js:551:18) ag:s at GraphQLObjectType. ... -like-cannot-use-graphqlschema-object-object-from-another-module-or-realm-how ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nealoke thank you so much for sharing all the progress, the solution, everything. Thanks!
I am genuinely glad you resolved it! 🙂
I found the issue, and like I thought has nothing to do with this package. It basically was an issue with our setup which uses hoisting to pull all the dependencies to the root.
Inside the
webpack.config.js
I was usingwebpack-node-externals
but only for the modules in the package (eg.packages/api/node_modules
). So because most of the packages are pulled to the root it did not exclude these when building theserver.js
with webpack.Before
After