mugli/learning-graphql

Validation for query variables

jsonmaur opened this issue · 0 comments

First of all, thanks a ton for this, it really helped me learn GraphQL. I wanted to suggest an addition in part 7 when you talk about creating custom scalar types for fine-grained validation. What you have there doesn't work at all if a query is using variables instead of arguments. That requires the validation to occur in parseValue instead of parseLiteral.

For example, if I have a custom scalar type defined using the docs you have currently (with only parseLiteral, this will be validated:

mutation {
  createUser (email: "invalidemail") { ... }
}

but this will not:

mutation signup ($email: Email!) {
  createUser (email: $email) { ... }
}

I'll submit a PR for this, hopefully it will clear things up for anyone using validation on queries with variables.