-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Server: Don't throw validation error while creating remote relationship joining singular type with array type #5603
Server: Don't throw validation error while creating remote relationship joining singular type with array type #5603
Conversation
Review app for commit 22b4b28 deployed to Heroku: https://hge-ci-pull-5603.herokuapp.com |
CHANGELOG.md
Outdated
@@ -21,6 +21,7 @@ If you do have such headers configured, then you must update the header configur | |||
- server: add logs for action handlers | |||
- server: add request/response sizes in event triggers (and scheduled trigger) logs (#5463) | |||
- server: change startup log kind `db_migrate` to `catalog_migrate` (#5531) | |||
- server: don't throw validation error when creating remote relationships joining singleton type with array type with same base type (fixes #5133) |
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.
Does this really close 5133? I don't see any mention of list types there..
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.
Yes, it does. The issue doesn't mention anything about the list type, because the error message thrown is incorrect. Ideally, the error message should have been
Error remote relationship: cannot validate remote relationship because expected type \"[Int]\" but got \"Int\"
instead of
Error remote relationship: cannot validate remote relationship because expected type \"Int\" but got \"Int\"
The reason the list notation is omitted from the error message because of this line
This PR solves that issue.
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.
This error message can occur in another case too, while joining an [Int]
type to a Int
type, where the validation is justified but the error message will be the same
Error remote relationship: cannot validate remote relationship because expected type \"Int\" but got \"Int\"
which is not very helpful.
I'll fix the error message.
else (when | ||
(getBaseTy actualType /= getBaseTy expectedType) | ||
(Failure (pure $ ExpectedTypeButGot expectedType actualType))) | ||
-- The GraphQL spec says that, we can coerce a singleton value into an array |
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.
This comment is great. While you are here can you give assertType
a better name? I guess what we're actually doing here is asserting that actualType
is coercible to expectedType
?
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.
Also, is this deficient in other ways according to the spec?
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.
I guess what we're actually doing here is asserting that actualType is coercible to expectedType?
Yes, that's what we're doing. But I'm not sure, what can be a better name here? Perhaps, isTypeCoercible
?
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.
Also, is this deficient in other ways according to the spec?
Yes, it was. My patch would have allowed to make a remote relationship joining types [[Int]]
and [[[Int]]]
, which is illegal, as specified in the GraphQL spec.
I have fixed this in the next commit
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.
isTypeCoercible
sounds good to me!
Deploy preview for hasura-docs ready! Built with commit a34913f |
Review app for commit 32766d2 deployed to Heroku: https://hge-ci-pull-5603.herokuapp.com |
Review app for commit 0a34d58 deployed to Heroku: https://hge-ci-pull-5603.herokuapp.com |
...eries/remote_schemas/remote_relationships/setup_remote_rel_joining_singleton_with_array.yaml
Show resolved
Hide resolved
Co-authored-by: Tirumarai Selvan <tiru@hasura.io>
pure () | ||
isTypeCoercible :: G.GType -> G.GType -> Validation (NonEmpty ValidationError) () | ||
isTypeCoercible actualType expectedType = | ||
-- The GraphQL spec says that, a singleton type can be coerced into an array |
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.
I think technically "singleton" type is called named
type but we can fix this comment later.
CHANGELOG.md
Outdated
@@ -21,6 +21,7 @@ If you do have such headers configured, then you must update the header configur | |||
- server: add logs for action handlers | |||
- server: add request/response sizes in event triggers (and scheduled trigger) logs (#5463) | |||
- server: change startup log kind `db_migrate` to `catalog_migrate` (#5531) | |||
- server: allow remote relationships joining `type` column with `[type]` input argument as spec allows this coercion (fixes #5133) |
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.
oops, can you push this to Next release section also?
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.
Sure
Review app for commit a3704b4 deployed to Heroku: https://hge-ci-pull-5603.herokuapp.com |
else Failure (pure $ ExpectedTypeButGot expectedType actualType) | ||
-- we cannot coerce two types with different nesting levels, | ||
-- for example, we cannot coerce [Int] to [[Int]] | ||
else Failure (pure $ ExpectedTypeButGot expectedType actualType) |
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.
Can we simplify this code by using MultiwayIf
if | actualBaseType /= expectedBaseType -> raiseValidationError
| actualNestingLevel /= expectedNestingLevel && actualNestingLevel /= 0 -> raiseValidationError
| otherwise -> pure ()
where
raiseValidationError = Failure $ pure $ ExpectedTypeButGot expectedType actualType
Of course with appropriate comments.
Review app for commit d4e2955 deployed to Heroku: https://hge-ci-pull-5603.herokuapp.com |
Review app for commit 22d563c deployed to Heroku: https://hge-ci-pull-5603.herokuapp.com |
Review app for commit 95b0808 deployed to Heroku: https://hge-ci-pull-5603.herokuapp.com |
Review app https://hge-ci-pull-5603.herokuapp.com is deleted |
…-validation-bug-5133 hasura#5603
Closes #5133
The issue arises when the user tries to make a remote relationship type, joining a singleton type with an array type. For example, joining
Int
with[Int]
.Description
Changelog
CHANGELOG.md
is updated with user-facing content relevant to this PR. If no changelog is required, then add theno-changelog-required
label.Affected components
Related Issues
Solution and Design
Steps to test and verify
Limitations, known bugs & workarounds
Server checklist
Catalog upgrade
Does this PR change Hasura Catalog version?
Metadata
Does this PR add a new Metadata feature?
run_sql
auto manages the new metadata through schema diffing?run_sql
auto manages the definitions of metadata on renaming?export_metadata
/replace_metadata
supports the new metadata added?GraphQL
Breaking changes
No Breaking changes
There are breaking changes:
Metadata API
Existing
query
types:args
payload which is not backward compatibleJSON
schemaGraphQL API
Schema Generation:
NamedType
Schema Resolve:-
null
value for any input fieldsLogging
JSON
schema has changedtype
names have changed