graphql / graphql-js

A reference implementation of GraphQL for JavaScript
http://graphql.org/graphql-js/
MIT License
20.04k stars 2.02k forks source link

npm link with graphql package breaks application #4113

Closed chdanielmueller closed 3 months ago

chdanielmueller commented 3 months ago

Hi there,

I get an error while developing a package which adds functionality to graphql. My issue is the check to verify that only one instance of graphql is in use. If I npm link my package to my graphql server it does no longer run since the error gets thrown. npm link does (as far as I understand) also use the node_modules of my linked package. Which results in another instance of graphql which I want in this specific case.

The error in question:

Cannot use ${className} "${stringifiedValue}" 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.

Source of the error: https://github.com/graphql/graphql-js/blob/main/src/jsutils/instanceOf.ts

I was wondering if an environment variable which circumvents this exception would be something that can be considered. I am opening a PR with the change.

Thanks, Daniel

JoviDeCroock commented 3 months ago

Duplicate of https://github.com/graphql/graphql-js/issues/3713

chdanielmueller commented 3 months ago

@JoviDeCroock Thanks. I need to level up my search skills 😅