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

It is impossible to override an built-in scalar #1000

Open
filosganga opened this issue May 16, 2023 · 1 comment
Open

It is impossible to override an built-in scalar #1000

filosganga opened this issue May 16, 2023 · 1 comment

Comments

@filosganga
Copy link
Contributor

Sangria comes with a set of built-in scalar.

However, sometime the builtin implementation does not fit the requirements, for example, some people would like to represent a BigDecimal always as string.

If the user defines a custom scalar with the same name of a builtin, it is ignored rather than override the builtin one.

I think it should be good instead to allow overriding the builtin scalars and use them only as fallback.

filosganga added a commit to filosganga/sangria that referenced this issue May 16, 2023
filosganga added a commit to filosganga/sangria that referenced this issue May 16, 2023
filosganga added a commit to filosganga/sangria that referenced this issue May 16, 2023
@yanns
Copy link
Contributor

yanns commented Sep 5, 2024

We're using custom scalars like:

  implicit val UUIDType: ScalarAlias[UUID, String] = ScalarAlias[UUID, String](
    StringType,
    toScalar = _.toString,
    fromScalar = idString =>
      try Right(UUID.fromString(idString))
      catch {
        case _: IllegalArgumentException => Left(IDViolation)
      })

Have you tried that approach?

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

No branches or pull requests

2 participants