Improve error reporting for union member types - #2472
Conversation
| } | ||
|
|
||
| const includedTypeNames = Object.create(null); | ||
| const includedInvalidTypes = Object.create(null); |
There was a problem hiding this comment.
I think it strange behavior where after fixing one error you would get the same error in the next location.
We should definitely prevent implicit cascading errors but I think we should never mask explicit errors made by the user.
Also if we add this error reduction trick we need to add it in many other places (e.g. if you implement non-interface types) for consistency.
So I think moving check to the beginning of the loop and adding continue would be enough.
There was a problem hiding this comment.
Note that this does not hide any errors - there is only one message, but all locations are reported and the same message applies to them all.
2ca0fda to
3eba0c8
Compare
✅ Deploy Preview for compassionate-pike-271cb3 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
@Cito I went ahead and rebased against main. |
yaacovCR
left a comment
There was a problem hiding this comment.
Seems like a good idea, left some comments/questions!
| } | ||
|
|
||
| const includedTypeNames = new Set<string>(); | ||
| const includedInvalidTypes = new Set<string>(); |
There was a problem hiding this comment.
can we just changed this to a single Set, visitedTypeNames?
| ); | ||
| includedInvalidTypes.add(typeString); | ||
| } | ||
| continue; |
There was a problem hiding this comment.
this reminds me of #4181 => what do you think about changing the error message string to something that references both errors, at least if there are repetitions?
'Something like Union type can only include unique Object types, ....'
What do you think?
3eba0c8 to
d390b94
Compare
First make sure that the included type is an object type, because that would be the more severe problem. Only then we can be sure that the type has a name and check for duplicates. Also, create only one error per different non-object type.
d390b94 to
53af201
Compare
|
@Cito is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel. A member of the Team first needs to authorize it. |
First make sure that the included type is an object type, because that would be the more severe problem. Only then we can be sure that the type has a name and check for duplicates. Also, create only one error per different non-object type.