question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should I use GraphQL for fine-grained validation?

See original GitHub issue

For 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:closed
  • Created 8 years ago
  • Comments:31 (13 by maintainers)

github_iconTop GitHub Comments

6reactions
koistyacommented, Mar 8, 2016
4reactions
leebyroncommented, Jul 14, 2015

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 if num is the value NaN. NaN is not equal to anything, including itself. Everything else will be a number.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found