-
Notifications
You must be signed in to change notification settings - Fork 7
Use a Django Form to validate the login form #38
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 attempts to use Graphene-Django's integration with Django Forms to validate our login form.
Advantages
This could be useful going forward because:
Our forms will need to have validation, and that validation will need to be done by a trusted agent (i.e. server-side). Django Forms are basically built to solve this kind of problem, though obviously we wouldn't really be needing their rendering functionality.
We need to have a mechanism for reporting per-field errors and non-field errors, which this solution gives us.
Using Django Forms nicely moves validation into a business logic layer that is separate from the specifics of GraphQL, which is recommended by the GraphQL documentation.
I'm still vague on this one, but using Django Forms might make it easier to eventually add progressive enhancement, allowing users without JS (or with malfunctioning JS) to use the site.
Risks
The Graphene-Django documentation for forms integration states:
So that doesn't exactly fill me with confidence. And aside from that, the documentation itself seems to either be wrong or out-of-date or something, so I had additional problems getting this working (though I did contribute some changes upstream at graphql-python/graphene-django#499).
But on the other hand, the codebase for the forms integration isn't that big and it's fairly easy to understand, so we could potentially contribute upstream or fork the code.
To do
window.alertwith a generic message).phone_number), rather than GraphQL's lower-camel-case names (e.g.phoneNumber). See if we can fix this.File an issue to eventually remove theFiled as Get rid of temporary code once Apollo 1.7.1 or later is released #42.fixInvalidGlobaltypesReferences()function added here once Apollo 1.7.1 or later is released.