Errors: fix how error messages represent arrays#1333
Merged
mjmahone merged 2 commits intographql:masterfrom Jun 1, 2018
Merged
Errors: fix how error messages represent arrays#1333mjmahone merged 2 commits intographql:masterfrom
mjmahone merged 2 commits intographql:masterfrom
Conversation
mjmahone
approved these changes
Jun 1, 2018
Contributor
mjmahone
left a comment
There was a problem hiding this comment.
This is great! Thanks for making array-errors more readable throughout the package.
IvanGoncharov
added a commit
that referenced
this pull request
Jun 1, 2018
Working on #1333 I noticed that you can pass arrays as scalars in a query variable, e.g. [SWAPI example](http://graphql.org/swapi-graphql/?query=query%20(%24id%3A%20ID)%20%7B%0A%20%20person(personID%3A%20%24id)%20%7B%0A%20%20%20%20name%0A%20%20%7D%0A%7D&variables=%7B%0A%20%20%22id%22%3A%20%5B1%5D%0A%7D) This PR is based on #925 but fixing same issue for types other than `String` e.g. ```js Number([1]) // 1 ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Stringconverts 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 gotFooObjectinsider error.Since calling
validateandvalidateSchemaare 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.inspectinstead ofStringbut it is Node-specific and couldn't be used in browsers.That's why I created
jsutils/inspect.js: