Graphql-js: Problem of package development using GraphQL

Created on 25 May 2018  ยท  9Comments  ยท  Source: graphql/graphql-js

I develop a package that uses graphql. It has peerDeps:

"peerDependencies": {
    "@types/graphql": "~0.10.4 || ~0.11.0 || ~0.12.0 || ~0.13.0",
    "graphql": "~0.10.4 || ~0.11.0 || ~0.12.0 || ~0.13.0"
  }

Using standart package development flow, I make a repo of this package, link it with yarn link, then go to test project and add it via yarn link package/name.

And on printSchema in the package I get:

Error: Cannot use GraphQLObjectType "__Directive" 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.

resolutions in both packages don't work.

And I see no options to suppress this behavior.

I think that there should be such option, to suppress this check on such cases (maybe via env variable or something else), in other case I don't understand, how to develop and check packages locally

Most helpful comment

So they, are in different places and have different node_modules

@terion-name I see. I can't think of any good solution to this problem that we could implement inside graphql-js ๐Ÿ˜ž
Possible workaround: copy node_modules/graphql somewhere and run yarn link in it and also link it in two projects you mentioned.

All 9 comments

Ah, sorry, found pull request and understood, that this can be suppressed by seting node env to production

https://github.com/graphql/graphql-js/pull/1174

@terion-name Note: that by disabling this check you don't solve the underlying problem there is very high chance that graphql-js will start to behave unpredictably.

@IvanGoncharov yes, it didn't solve the problem :(
Now getting Error: Unknown type: __Directive. and nothing works.

Any ideas how to handle this?

@terion-name Can you please run npm ls graphql and post the output here?

You almost certainly have multiple instances of the GraphQL.js module being pulled in and interacting with each other. This can happen when you attempt to use multiple different versions.

Yarn's "resolutions" key in package.json is a good way to enforce a specific version for an entire installation, which can help you solve this problem

@leebyron resolutions doesn't work. because, as I've written, I am linking a package that is in develop to project it is developed for via yarn link. So they, are in different places and have different node_modules

@IvanGoncharov in project:

โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ UNMET DEPENDENCY [email protected]
โ”‚ โ””โ”€โ”€ UNMET DEPENDENCY [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ””โ”€โ”€ [email protected] 
โ””โ”€โ”ฌ [email protected]
  โ””โ”€โ”ฌ [email protected]
    โ””โ”€โ”€ [email protected]  deduped

in package (that is linked and which code causes error):

โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ UNMET DEPENDENCY [email protected]
โ”‚ โ””โ”€โ”€ UNMET DEPENDENCY [email protected]
โ””โ”€โ”ฌ [email protected]
  โ””โ”€โ”€ [email protected] 

So they, are in different places and have different node_modules

@terion-name I see. I can't think of any good solution to this problem that we could implement inside graphql-js ๐Ÿ˜ž
Possible workaround: copy node_modules/graphql somewhere and run yarn link in it and also link it in two projects you mentioned.

@IvanGoncharov ok, I've found a workaround: remove node_modules in developing package and add it to test project with yarn add file:...

This has drawbacks, like problems with build of package and need to re-add on each change, but this is better than nothing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dotansimha picture dotansimha  ยท  3Comments

henry74 picture henry74  ยท  4Comments

adriano-di-giovanni picture adriano-di-giovanni  ยท  3Comments

galki picture galki  ยท  3Comments

davide-ganito picture davide-ganito  ยท  4Comments