-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Remove some instanceof checks #996
Conversation
@facebook-github-bot import |
Sorry, I can't do that @JenniferWang - this feature is only supported for non-employees; you can land via the internal pull request dashboard. |
I'd feel better about this if we did it comprehensively, although I know you're probably wanting to do the minimal amount of work to unblock yourself. Fun fact. If this makes it into a GraphQL update and you deploy the update in an environment with the old version still present somewhere, any code path that hits the old version will still hit the What do you think of having a module with a bunch of predicate functions ( |
@JenniferWang: Don't listen to the bot, we don't import in this repo anyway. The only way to get code deployed internally is to merge it here, cut a release, then install the release. Bear in mind, however, that this is the reference implementation relied on by many third-party (and FB) software products, so there's no way we should be merging without the CI being green, and ideally without allowing time for adequate review. |
@wincent would be really fantastic if this could be merged as this is one of the biggest time sinks when developing GraphQL tooling by linking NPM modules. |
I'm going to close this since tests are failing and it's not really a comprehensive solution. In my opinion this is more of a bandaid than a real solution since the real problem is that this package evolves in capabilities over time and the types and classes exported by one version may not behave correctly with functions from another version. In addition there are deep assumptions made in the package about singletons like build in scalar types or introspection types which we check via identity. Even if we were to change instanceof to brand-checks like this, we're still stuck with multiple versions resulting in weird or broken behavior. I also much prefer @wincent's suggestion of predicate functions. That provides an improved API and could allow for a centralized place to produce more descriptive error messages about duplicate graphql-js packages. |
I completely agree. @leebyron can you provide some background on what's the next step here? Is that something Facebook is planning to work on or are you suggesting that someone of the community should tackle this? I've come across this specific problem a dozen of times and I'm sure other library maintainers have experienced the same issues when multiple graphql-js versions are involved because of some dependency (this especially becomes a problem when linking modules). |
If you end up in the unfortunate situation of having multiple
graphql-js
node_modules
installed,instanceof
completely fails. While it's almost always preferable to reduce yournode_modules
installations so you don't have multiple instances of the same exact code, it may not always be possible. This fixes some of the cases for where it's not possible, specifically in util functions: those are the most likely to be shared across installation instances.To fix, we're adding
kind
field to every Schema type class, so we can compare viatype.kind === 'GraphQLObjectType
instead oftype instanceof GraphQLObjectType
.Note, there are still many many uses of
instanceof
ingraphql-js
, so it's still not safe to have two instances installed.