Errors: fix how error messages represent arrays #1333
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed this bug when I worked on #1332 I accidentally returned an array of types from typeResolver function and got this error:
The relevant part here is:
It required me some time in the debugger to figure out that I wrapped GraphQLObjectType into an array. But it's impossible to figure out this from error message itself:
graphql-js/src/execution/execute.js
Line 1088 in 2eccaad
String
converts arrays into a comma-separated list of values so if array consists of one element it just converts that element to string. So instead of[FooObject]
or something similar I gotFooObject
insider error.Since calling
validate
andvalidateSchema
are optional almost any error can be affected by this problem. So I think we need a library-wide solution to this problems.The ideal solution would be to use
utils.inspect
instead ofString
but it is Node-specific and couldn't be used in browsers.That's why I created
jsutils/inspect.js
: