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

Problem of package development using GraphQL #1358

Closed
terion-name opened this issue May 25, 2018 · 9 comments
Closed

Problem of package development using GraphQL #1358

terion-name opened this issue May 25, 2018 · 9 comments

Comments

@terion-name
Copy link

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

@terion-name
Copy link
Author

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

#1174

@IvanGoncharov
Copy link
Member

IvanGoncharov commented May 25, 2018

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

@terion-name
Copy link
Author

@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 terion-name reopened this May 25, 2018
@IvanGoncharov
Copy link
Member

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

@leebyron
Copy link
Contributor

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

@terion-name
Copy link
Author

terion-name commented May 25, 2018

@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

@terion-name
Copy link
Author

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

@IvanGoncharov
Copy link
Member

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.

@terion-name
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants