question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

graphql/jsutils/instanceOf fails in development builds that rename variables

See original GitHub issue

graphql version used is: graphql@0.13.2.

shadow-cljs is a build tool for ClojureScript + JS that among other things enables using npm packages directly (via ClojureScript). To achieve this it uses the Closure Compiler extensively instead of the usual babel or webpack.

Closure will rename pretty aggressively and this causes some of the graphql/types/definition classnames to end up having the same constructor.name. The instanceOf check then falsely reports this as a problem and a check that is supposed to fail and return false throws an error instead.


Previous Report (before I figured out the problem)

A user reported a build issue when trying to use the the graphql package where I cannot figure out the cause. No compiler error or so occurs, only a runtime issue.

 Cannot use a "__Schema" 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.

There is definitely only one graphql instance in the code and it isn’t even used so it happens during initialization.

I sort of tracked this down to be a Closure Compiler issue which I reported here: https://github.com/google/closure-compiler/issues/2898

I thought I’d raise this here as well. Maybe someone has a clue what might be happening. I have not used the graphql package myself but I’d like to resolve this problem.

All code is available here: https://github.com/thheller/issue-248

The two failing builds are

simple is using source maps. pseudo is simple but without source maps, instead it is pretty printed and using pseudo names (easier to step through the actual code and not what it used to be).

And the working whitespace-only build https://code.thheller.com/issue-248/whitespace/

Really just hoping someone more familiar with the code has a clue what might be happening. Closure seems to be the cause here not graphql.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
thhellercommented, Jun 11, 2018

In a CLJS development build I want to use development mode JS dependencies. Forcing production mode kind of defeats the purpose of having a development mode in the first place.

Many packages provide useful extra information in dev mode and I don’t want to miss that. You are also attempting to provide useful information but just rely on a broken assumption to do it.

The problem you are trying to warn about cannot happen in shadow-cljs and it is very unfortunate that we are forced to add extra config for graphql (and just graphql, nothing else requires this) just to avoid running into an error generated by a confused graphql check when actually everything is OK and working as intended.

2reactions
leebyroncommented, Jun 11, 2018

This name checking behavior only occurs in non-production environments, since like you’re encountering - other build tools can rename source code.

Setting NODE_ENV=production before running a CLJS build or any other kind of minifying/obfuscating build is absolutely the right thing to do

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating to Apollo Server 4 - Apollo GraphQL Docs
In Apollo Server 4, expressMiddleware no longer supports Connect. An interested developer could build a Connect-specific middleware, and a PR to this migration ......
Read more >
Top 5 graphql-tools Code Examples - Snyk
Learn more about how to use graphql-tools, based on graphql-tools code examples created from the most popular ways it is used in public...
Read more >
error There was an error in your GraphQL query - Stack Overflow
src/templates/blogPost.js`), context: { // Data passed to context is available // in page queries as GraphQL variables. slug: slug, }, });.
Read more >
Schema Directives – GraphQL Tools
Using and implementing custom directives to transform schema types, fields, and arguments.
Read more >
Using the EntityService from JavaScript
The EntityService has many utilities and helpers that assist in the data transaction between the front end and back end. For example:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found