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

Support @GQLValueTypes when rendering API #1126

Closed
jvican opened this issue Nov 4, 2021 · 4 comments · Fixed by #1127
Closed

Support @GQLValueTypes when rendering API #1126

jvican opened this issue Nov 4, 2021 · 4 comments · Fixed by #1127
Labels
enhancement New feature or request server Issue related to caliban server

Comments

@jvican
Copy link

jvican commented Nov 4, 2021

When using the render method on the GraphQL object, Caliban prints a schema that can be distributed to clients. However, this schema contains no information about value types and instead uses the underlying representation, which loses type information. The GQL Value types could be represented as scalars in the schema, right after the Long and DateTime definitions. I'd like to suggest that Caliban supports this feature either by default, or by opting in via either of the following mechanisms:

  1. A configuration option in the render method
  2. A GQLScalarType annotation that combines the semantics of GQLValueType and the scalar representation
@ghostdogpr
Copy link
Owner

The render function is only a reflection of the schema, so in order to change the generated GraphQL type, the Schema must be changed as well (so the type will be consistent in render, in introspection and when validating queries).

You can achieve this today with for example:

case class MyScalar(value: Int)

implicit val myScalarSchema: Schema[Any, MyScalar] = Schema.scalarSchema("MyScalar", None, IntValue(_))

Your second suggestion would work. To prevent breaking existing code, we could re-use GQLValueType but add a parameter isScalar: Boolean = false to turn on this behavior:

@GQLValueType(isScalar = true)
case class MyScalar(value: Int)

Does that sounds like what you wanted?

@ghostdogpr ghostdogpr added core enhancement New feature or request server Issue related to caliban server labels Nov 4, 2021
@ghostdogpr
Copy link
Owner

Turns out it was simple: #1127

@jvican
Copy link
Author

jvican commented Nov 5, 2021

Great! #1127 looks like what I need, thanks for the quick PR and prompt answer. Let me know when this is released as I'll use it right away. Had a brief look at the PR implementation and looks solid, nothing to add.

Your approach to customize the schema instance is something I've considered in the past but it's verbose enough for all my types that I've discarded it, the new solution to this problem is much better.

@ghostdogpr
Copy link
Owner

@jvican you're lucky, I was about to release so it made it into 1.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server Issue related to caliban server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants