Apollo-server: Cannot use graphql Schema from a submodule

Created on 8 Feb 2020  ยท  3Comments  ยท  Source: apollographql/apollo-server

Error

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.

How

When working in a monorepo and importing a graphql schema from a submodule made with makeExecutableSchema in another submodule

.
โ”œโ”€โ”€ ...
โ”œโ”€โ”€ packages                  
โ”‚   โ”œโ”€โ”€ bar              
โ”‚   โ”‚   โ””โ”€โ”€ package.json
โ”‚   โ”‚           # "apollo-server": "^2.10.0"       
โ”‚   โ”œโ”€โ”€ foo              
โ”‚   โ”‚   โ””โ”€โ”€ package.json
โ”‚   โ”‚           # "apollo-server": "^2.10.0"
โ”‚   โ”‚           # "foo": "file:../foo"             
โ”‚   โ””โ”€โ”€ ...                             
โ””โ”€โ”€ ...

repository: https://github.com/Sceat/graphql-dependency-duplication

Why

I guess @types/graphql-upload is breaking submodules by forcing a Graphql dependency, it should be a dev dependency on apollo-server-core, or DefinitelyTyped should use graphql as a peerDependency

Most helpful comment

as a quick workaround we can install graphql globally and link in every submodule

npm i -g graphql
npm link graphql # in /bar and /foo

All 3 comments

as a quick workaround we can install graphql globally and link in every submodule

npm i -g graphql
npm link graphql # in /bar and /foo

I meet the same issue when using webpack

"dependencies": {
    "apollo-server": "^2.18.2",
    "babel-loader": "^8.1.0",
    "graphql": "^15.3.0",
    "node-loader": "^1.0.0",
    "webpack": "^5.0.0",
    "webpack-node-externals": "^2.5.0"
  },
//webpack
mode: "development",
  target: "node",
  module: {
    rules: [
      {
        test: /\.(j|t)sx?$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            cacheDirectory: false
          },
        },
      }
    ],
  },
  resolve: {
    extensions: [".ts", ".tsx", ".js", ".jsx"],
  },

npm link graphql doesnt work for me,

bash > npm ls graphql
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ””โ”€โ”ฌ @types/[email protected]
โ”‚     โ””โ”€โ”€ [email protected]  deduped
โ””โ”€โ”€ [email protected] 

Refer the workaround #4637

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leinue picture leinue  ยท  3Comments

mathroc picture mathroc  ยท  3Comments

jminz picture jminz  ยท  3Comments

nevyn-lookback picture nevyn-lookback  ยท  3Comments

attdona picture attdona  ยท  3Comments