fix: check if property errors from response is an empty array #454
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.
Hello,
We have a project called courses 3 which is a learning management system. In this project, we started using UltraGraphQL as the back end. We have encountered error responses after making correct requests from the front end using the 'request' function from graphql-request. After checking out the error, it seems that the response had no error, but the function evaluated it otherwise. In the next sample, you can see the error which we have printed out from the front end.
Error: GraphQL Error (Code: 200): {"response":{"extensions":{},"data":{"courses_User":[{"courses_lastName":["Admin"],"courses_email":["[email protected]"]}],"@context":{"_type":"@type","courses_email":"http://www.courses.matfyz.sk/ontology#email","courses_User":"http://www.courses.matfyz.sk/ontology#User","_id":"@id","courses_lastName":"http://www.courses.matfyz.sk/ontology#lastName"}},"errors":[],"status":200,"headers":{"map":{"content-type":"application/json; charset=utf-8"}}},"request":{"query":"\n {\n courses_User {\n courses_email\n courses_lastName\n }\n }\n "}}
After digging around, I found out that the errors property from the response was an empty Array. This empty array when put in a condition like result.errors returned true. Because of this !result.errors was evaluated false and thus the variable successfullyPassedErrorPolicy at line 484 in src/index.ts was evaluated as false. This meant that the successful response was evaluated as unsuccessful returning ClientError.
I have fixed it by extending the condition by checking if the result.errors is an empty array.