Skip to content

Improve error reporting for union member types - #2472

Open
Cito wants to merge 1 commit into
graphql:17.x.xfrom
Cito:fix-validation-order
Open

Improve error reporting for union member types#2472
Cito wants to merge 1 commit into
graphql:17.x.xfrom
Cito:fix-validation-order

Conversation

@Cito

@Cito Cito commented Mar 4, 2020

Copy link
Copy Markdown
Member

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.

Comment thread src/type/validate.js Outdated
}

const includedTypeNames = Object.create(null);
const includedInvalidTypes = Object.create(null);

@IvanGoncharov IvanGoncharov Mar 6, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Base automatically changed from master to main January 27, 2021 11:10
@IvanGoncharov IvanGoncharov added this to the post-16.0.0 milestone Aug 23, 2021
@yaacovCR
yaacovCR force-pushed the fix-validation-order branch from 2ca0fda to 3eba0c8 Compare September 30, 2024 13:57
@yaacovCR
yaacovCR requested a review from a team as a code owner September 30, 2024 13:57
@netlify

netlify Bot commented Sep 30, 2024

Copy link
Copy Markdown

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit d390b94
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/66fab0103790eb00087500dc
😎 Deploy Preview https://deploy-preview-2472--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@yaacovCR

Copy link
Copy Markdown
Contributor

@Cito I went ahead and rebased against main.

@yaacovCR yaacovCR left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good idea, left some comments/questions!

Comment thread src/type/validate.ts
}

const includedTypeNames = new Set<string>();
const includedInvalidTypes = new Set<string>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just changed this to a single Set, visitedTypeNames?

Comment thread src/type/validate.ts
);
includedInvalidTypes.add(typeString);
}
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@yaacovCR
yaacovCR force-pushed the fix-validation-order branch from 3eba0c8 to d390b94 Compare September 30, 2024 14:05
@yaacovCR
yaacovCR changed the base branch from next to 17.x.x March 5, 2026 22:33
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.
@Cito
Cito force-pushed the fix-validation-order branch from d390b94 to 53af201 Compare June 4, 2026 13:03
@vercel

vercel Bot commented Jun 4, 2026

Copy link
Copy Markdown

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants