-
-
Notifications
You must be signed in to change notification settings - Fork 247
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
Validate input types #1347
Validate input types #1347
Conversation
case IntValue.IntNumber(value) => IO.succeed(Value.FloatValue(value.toDouble)) | ||
case IntValue.LongNumber(value) => IO.succeed(Value.FloatValue(value.toDouble)) | ||
case IntValue.BigIntNumber(value) => IO.succeed(Value.FloatValue(BigDecimal(value))) | ||
case v => IO.fail(ValidationError(s"Cannot coerce $v into number", "")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should we format coercion errors? With some errors context similar to Validator.scala
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the path was available that would be the bext UX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
@@ -10,9 +11,17 @@ case class RootType( | |||
additionalTypes: List[__Type] = List.empty, | |||
additionalDirectives: List[__Directive] = List.empty | |||
) { | |||
private val primitiveTypes: List[__Type] = List( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to include only those that are actually used in other parts of the schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see the problem you mentioned though. Maybe instead of adding these to the schema, just add them during the validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I changed that in 102a38a!
Ok @ghostdogpr I've cleaned this up now, hopefully it should be good to go 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some minor comments
I've fixed the imports now @ghostdogpr 👍 |
I'm opening this at this point as a reference for further discussion.
Yesterday I ran across a case where we incorrectly validate the following query:
which will incorrectly execute for the following input
{"var": null}
(which resulted in some frontend tooling on our breaking down in weird ways).What happens is that Caliban properly validates that the variable can be assigned to the argument (works since
Int!
is more specific thanInt
), and that the provided value of the variable (null
can be assigned toInt
). However, the query isn't valid in the first place sincenull
shouldn't have been assignable toInt!
in the first place.However, a lot of the validation errors end up becoming really wonky, especially in the case of mismatched input types since we'll only add used types to the "known" types and not e.g all scalars, which means that we end up with a lot of errors of the likes of
Int is not an input type
rather than(Variable 'x' usage is not allowed because its type doesn't match the schema (Int instead of String).
, which I think is undesirable. I think a work-around for this would be to expand the types of the schema to always include the primitive typesString
,Float
,Int
andBoolean
. What do you think?