sangria-graphql / sangria

Scala GraphQL implementation
https://sangria-graphql.github.io
Apache License 2.0
1.96k stars 226 forks source link

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

Open filosganga opened 1 year ago

filosganga commented 1 year ago

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.

yanns commented 1 month ago

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?