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

feat: ast input support added #935

Merged
merged 3 commits into from
Jan 3, 2023
Merged

Conversation

Ceres6
Copy link
Contributor

@Ceres6 Ceres6 commented Dec 20, 2022

closes #804

JSON ast can be now used as input.

The change can be tested with the code of the test added at test/app-decorator.js

Comments are welcomed for both performance and security on the use of JSON.parse function

It should be decided whether this feature is desired.

Copy link
Collaborator

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Collaborator

@simoneb simoneb left a comment

Choose a reason for hiding this comment

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

lgtm

@simoneb
Copy link
Collaborator

simoneb commented Dec 20, 2022

@Ceres6 can you please check if there's a better, more secure (possibly faster) way to handle the JSON parsing? E.g. I came across this https://github.com/fastify/secure-json-parse, but I would check how this is done elsewhere in the codebase, including fastify

Copy link
Collaborator

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Could you add a test where the source of the query is a JSON but it's missing some key properties (not a valid ast?)

@Ceres6
Copy link
Contributor Author

Ceres6 commented Dec 21, 2022

@Ceres6 can you please check if there's a better, more secure (possibly faster) way to handle the JSON parsing? E.g. I came across this https://github.com/fastify/secure-json-parse, but I would check how this is done elsewhere in the codebase, including fastify

Fastify uses secure-json-parse, which adds some validation and options to the built-in JSON.parse this would be more secure, definitely not more efficient, but the trade might be worth.

Other options would be using other json-schema validation libraries as joi, ajv, fluent-json-schema, which are used in the Fastify ecosystem. This would require more code to be as precise as possible with the values accepted by the schema, and if we're too strict it could become harder to maintain.

WDYT? @simoneb

@Ceres6
Copy link
Contributor Author

Ceres6 commented Dec 21, 2022

Could you add a test where the source of the query is a JSON but it's missing some key properties (not a valid ast?)

Of course. I'll see what error throws in that case to see if we need better error handling to guide the client debug it.

@smolinari
Copy link
Contributor

I thought GraphQL does its own validation. Is this direct AST input bypassing that?

Scott

@Ceres6
Copy link
Contributor Author

Ceres6 commented Dec 21, 2022

I thought GraphQL does its own validation. Is this direct AST input bypassing that?

Scott

No, it is still be done some lines below in the validation phase. It's just the query -> ast conversion that we're skipping

@Ceres6
Copy link
Contributor Author

Ceres6 commented Dec 21, 2022

Test for the invalid AST added. Let me know if you want me to add an example to the examples folder or something to the documentation.

@Ceres6 Ceres6 requested a review from mcollina December 21, 2022 09:30
Copy link
Collaborator

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@Ceres6
Copy link
Contributor Author

Ceres6 commented Dec 21, 2022

How is it possible that there is a fail in windows 16.x if the only change between this commit and the previous is that I added a test? Besides it is passing in ubuntu 16.x and windows 18.x

@mcollina
Copy link
Collaborator

Flaky CI maybe?

@simoneb
Copy link
Collaborator

simoneb commented Dec 28, 2022

@mcollina wdyt about json parsing in this PR? is it ok to do it or shall we use a json parsing library such as https://github.com/fastify/secure-json-parse?

Copy link
Collaborator

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Maybe it's better to add a test with an external request.

@Ceres6
Copy link
Contributor Author

Ceres6 commented Jan 3, 2023

Maybe it's better to add a test with an external request.

Would app.inject be enough or should I listen to a port and then use any library to fetch the response?

Copy link
Collaborator

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit 984480c into mercurius-js:master Jan 3, 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.

Is there a way to receive query as AST?
4 participants