Skip to content

fix: describe behaviour for onValidate maskError (see discussion question) #3899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aryascripts
Copy link
Contributor

@aryascripts aryascripts commented Mar 17, 2025

See discussion question for the description: #3900

Copy link

changeset-bot bot commented Mar 17, 2025

⚠️ No Changeset found

Latest commit: dc58a89

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

const onValidatePlugin: Plugin = {
onValidate({ setResult }) {
setResult([
createGraphQLError('UNMASKED ERROR', { extensions: { code: 'VALIDATION_ERROR' } }),
Copy link
Member

@ardatan ardatan Mar 17, 2025

Choose a reason for hiding this comment

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

GraphQLError instances are not masked. The errors are masked only if it is an error is not an instance of GraphQLError.
And the result of validate function is GraphQLError[] so it is expected to return an array of GraphQLError. Yoga doesn't expect validate to return non GraphQL errors so they are not sent to maskError function. So running an extra maskError for validation errors are unnecesary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @ardatan! We realize that the default maskError function does not act on GraphQLErrors at all, but we want to mask GraphQLErrors as well.

However, even if we write a custom maskError function, it is not triggered at all for GraphQLErrors.

Would it be better to use onResultProcess to update the result with the masked error?

Copy link
Member

@ardatan ardatan Mar 20, 2025

Choose a reason for hiding this comment

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

Yes!, You can use onResultProcess to modify the final response, or you can basically use onValidateDone if you want to modify validation errors specifically.

@aryascripts aryascripts changed the title fix: describe bug for onValidate maskError (see discussion question) fix: describe behaviour for onValidate maskError (see discussion question) Mar 17, 2025
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.

2 participants