-
Notifications
You must be signed in to change notification settings - Fork 575
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
base: main
Are you sure you want to change the base?
fix: describe behaviour for onValidate maskError (see discussion question) #3899
Conversation
|
const onValidatePlugin: Plugin = { | ||
onValidate({ setResult }) { | ||
setResult([ | ||
createGraphQLError('UNMASKED ERROR', { extensions: { code: 'VALIDATION_ERROR' } }), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
See discussion question for the description: #3900