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
For example, I want to validate an
emailfield.Should I define my own
email scalar typeor just useGraphQLStringand validate the value in theresolvefunction?Similar question for checking the
lengthof a string. If I have a field that map to aVARCHAR(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