Skip to content
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

fix: check if property errors from response is an empty array #454

Merged
merged 4 commits into from
Feb 18, 2023

Conversation

RicsiToth
Copy link
Contributor

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.

Copy link
Member

@jasonkuhrt jasonkuhrt left a comment

Choose a reason for hiding this comment

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

Awesome thanks! Please add a test case and then I'll merge this.

Copy link
Member

@jasonkuhrt jasonkuhrt left a comment

Choose a reason for hiding this comment

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

Wrong button, tests please :)

@RicsiToth
Copy link
Contributor Author

RicsiToth commented Feb 17, 2023

I had to also edit the _helpers.ts file because the mocked errors property allowed only JSONObject, so I have also added the possibility of having JSONArray as a value for testing purposes.

@jasonkuhrt jasonkuhrt changed the title Added check if property errors from response is an empty array fix: check if property errors from response is an empty array Feb 18, 2023
@jasonkuhrt jasonkuhrt merged commit 4302ba1 into graffle-js:main Feb 18, 2023
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