Should I use GraphQL for fine-grained validation?
See original GitHub issueFor example, I want to validate an email
field.
Should I define my own email scalar type
or just use GraphQLString
and validate the value in the resolve
function?
new GraphQLScalarType({
name: 'Email',
coerce: value => '' + value,
coerceLiteral: ast => ast.kind === Kind.STRING && ast.value.match(/somePattern/) ?
ast.value :
null
});
Similar question for checking the length
of a string. If I have a field that map to a VARCHAR(100)
in a MySQL database, should I create a specific scalar that check for a valid length? Not sure if it’s belongs to GraphQL… or if it is a good practise.
Any thoughts?
Thanks
Issue Analytics
- State:
- Created 8 years ago
- Comments:31 (13 by maintainers)
Top Results From Across the Web
Access Control Best Practices for GraphQL with Authentication ...
This post is part of our series about GraphQL security where we cover (almost) every vulnerability, to give you the right tools to ......
Read more >Fine grained security - GraphQLite
Using the @Security annotation, you can write an expression that can contain custom logic. For instance: Check that a user can access a...
Read more >Authorization through access control in GraphQL
When accessing the application via GraphQL, we must validate whether or not the user has access to the requested elements from the schema....
Read more >Externalized Authorization for GraphQL - Security Boulevard
Owners of the data that is being shared via GraphQL endpoints should be able to monitor all data requests and apply sufficient authorization...
Read more >Access Control in GraphQL
While you can use good libraries and protocols for much of the hard stuff in authentication, the opposite is true of authorization: This...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Example: Input validation and user-friendly error messages in GraphQL mutations on Medium.com
Thanks for the note, I’ll add a comment in code to explain what’s going on here.
+value
calls ToNumber internally.num === num
is a cheap way to identify ifnum
is the valueNaN
.NaN
is not equal to anything, including itself. Everything else will be a number.