[FEATURE] Allow empty fields for mutations
ohager opened this issue · comments
Is your feature request related to a problem? Please describe.
I have mutations which do not return anything (although I know it's against best practices) and I couldn't use gotql for these mutations as the resulting query string is syntactically wrong and causing Bad Request
gotql:info:parser Parsed query: mutation ($input: TransferInput!) { airdropPoints(args: $input) { } } +0ms
(node:20166) UnhandledPromiseRejectionWarning: Error: Runner error: Error when executing query: Response code 400 (Bad Request)
Describe the solution you'd like
Empty or nulled fields should not generate something like this:
mutation ($input: TransferInput!) { airdropPoints(args: $input) { } }
(mind the red marker on the left side, indicating a syntax error)
but this:
mutation ($input: TransferInput!) { airdropPoints(args: $input) }
Describe alternatives you've considered
As an alternative I need to make my mutations return something (which I actually consider and will do)
Additional context
I'm putting this as a feature request, as it is kind of my fault, that I'm not following best practices. Nevertheless, I think it's worth mentioning this situation which causes a syntax error on the query.
Thanks, for this pretty handy library! 🙏
Hey @ohager! Thanks for the feedback! And sorry for the delay on answering, I got a few problems this week, but I'll take a look into this issue on Thursday!
Unfortunately, GotQL has been designed following the guidelines on JS + GraphQL best practices, which don't include void mutations, but this seems to be a pretty interesting addition to the code.
My thoughts are to add a void: boolean
flag in the query object that defines if the mutation is empty or not. What do you think of that solution?
@khaosdoctor I'm totally fine with the fact, that gotql follows the best practices. Indeed, it makes me reflect my own API (I'm still new to GraphQL). Not sure, if a void flag is necessary. Why not just "render" a syntactically correct expression, when receiving an empty or null fields array? Tomorrow, I'll have some more time to propose a solution. I'd open a PR.
I think I'd "mess" around somewhere here: https://github.com/khaosdoctor/gotql/blob/master/src/modules/parser.ts#L242 😸
oia so, vi q vc mora perto de mim...rsrsrs
@khaosdoctor I'm totally fine with the fact, that gotql follows the best practices. Indeed, it makes me reflect my own API (I'm still new to GraphQL). Not sure, if a void flag is necessary. Why not just "render" a syntactically correct expression, when receiving an empty or null fields array? Tomorrow, I'll have some more time to propose a solution. I'd open a PR.
I think I'd "mess" around somewhere here:
master
/src/modules/parser.ts#L242 😸oia so, vi q vc mora perto de mim...rsrsrs
Hey! Thanks a log for the PR! That's a huge help since I'm doing a lot of things at once... I'll review both of them carefully to ensure no errors exist!
Olha só outro brasileiro!