Skip to content
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

Proper handling of custom scalar serialization/deserialization errors #154

Open
slavikovbasa opened this issue Jul 2, 2024 · 3 comments

Comments

@slavikovbasa
Copy link
Collaborator

slavikovbasa commented Jul 2, 2024

Having a scheme:

class Long(Scalar):
    @classmethod
    def parse(cls, value: typing.Any) -> int:
        return int(value)

    @classmethod
    def serialize(cls, value: typing.Any) -> int:
        return int(value)

GRAPH = Graph([
    Root([
        Field("longStub", Long, lambda fs: [fs[0].options["id"]], options=[Option("id", Long)])
    ])
])

Such a query is possible and results in a ValueError being thrown:

{
  longStub(id:"asdf")
}

It is possible to catch errors in parse/serialize methods of Scalar, but there is no way to return any validation errors to a client.
Would be nice to have either:

  1. Custom error that can be thrown from serialization methods and process it in hiku accordingly;
  2. Or a separate validation method for Scalar

Possibly there is the same problem with enums, haven't checked though.

@kindermax
Copy link
Collaborator

So basically we need to error propagation mechanism in denormalization ?

@slavikovbasa
Copy link
Collaborator Author

not sure if denormalization is the best place to do it, maybe somewhere after parsing?

@kindermax
Copy link
Collaborator

kindermax commented Jul 4, 2024

Yep, in case when we are parsing arguments we should catch parse errors and report them to user.

My msg about denormalization makes sense when we are serializing scalars. Also being able to report errors from denormalization phase needed for another case when value completion failed (because of null in not-nullable field) and we need to tell user that there is an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants