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

Add transformer that excludes fields / inputs based on directives #2293

Merged
merged 11 commits into from
Jun 27, 2024

Conversation

kyri-petrou
Copy link
Collaborator

Kind of experimental work based on transformers to allow excluding fields / input arguments based on the @GQLTag annotation.

This can be particularly helpful for schema versioning, e.g., having a /beta and a /v1 endpoint, and excluding fields from /v1 until we're happy with them without breaking compatibility in the APIs

@kyri-petrou
Copy link
Collaborator Author

kyri-petrou commented Jun 25, 2024

Following @paulpdaniels comment here, I realised we were missing an opportunity to make the transformer work on any directive instead of just the caliban-provided annotations.

So now users can do the following:

final case class Experimental extends GQLDirective("experimental")
final case class Internal extends GQLDirective("internal")

val apiA: GraphQL[Any] = api.transform(Transformer.ExcludeDirectives(Experimental()))
val apiB: GraphQL[Any] = api.transform(Transformer.ExcludeDirectives(Experimental(), Internal()))

/**
* Annotation used to provide directives to a schema type
*/
open class GQLDirective(val directive: Directive) extends StaticAnnotation
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this an open class in Scala 3, so that users can extend it without having to add the import scala.language.adhocExtensions import. More info on open classes here

@kyri-petrou kyri-petrou changed the title Add transformer that excludes fields / inputs based on tags Add transformer that excludes fields / inputs based on directives Jun 25, 2024
@kyri-petrou
Copy link
Collaborator Author

@paulpdaniels I'll merge this PR in, in case there is anything else you'd like me to address let me know and I can do it in a followup PR

@kyri-petrou kyri-petrou merged commit 7078afb into series/2.x Jun 27, 2024
10 checks passed
@kyri-petrou kyri-petrou deleted the schema-tag-transformer branch June 27, 2024 06:04
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

Successfully merging this pull request may close these issues.

3 participants