feat: Add validation queries (WIP) #294
Open
+361
−32
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.
This is a first version of having validation queries for mutations. The idea is to have an API that will work similarly to what
AshPhoenix.Form.validate
does, in other words, instead of having to duplicate validation logic in the frontend, the frontend can call the validation query and get the data directly from the backend.Right now there are some issues with this PR:
One possible argument against this is that this would make using the validation api harder for the frontend developer since they would need to have a specific query for a the validation query and one for the mutation, while if both are mutations, then the only change is the function name.
Also, another thing to think about is that maybe we could instead of generating a new graphql api only to validate, we could add a
validate
input to the mutation itself and then the frontend keeps using the same API for both cases, just changing thevalidate
boolean to define when validate and when submit (honestly, now that I think about it, I think this would be probably the best solution both in our side and also for implementing in the frontend).I implemented it for create and update actions, I didn't do it for generic actions, maybe we should have that too?
I'm not sure if I should add support for all the other options that
create
andupdate
actions have in their schema to the validation actions.I didn't add any unit tests for now since this has a great chance to change.
Here is a resource that I used to test it out:
Contributor checklist