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

Transform enum values' names with a macro setting #350

Merged
merged 1 commit into from
May 10, 2018

Conversation

fehu
Copy link
Contributor

@fehu fehu commented Mar 22, 2018

Added a derivation setting for transforming GraphQL enum values, similar to TransformFieldNames.

Use case

Since graphql has no definition scopes, the following scala enums will cause collision:

sealed trait Color
object Color {
  case object Red extends Color
  case object Blue extends Color
  case object Green extends Color
  // etc
}

sealed trait TrafficLight
object TrafficLight {
  case object Red extends TrafficLight
  case object Yellow extends TrafficLight
  case object Green extends TrafficLight
}

The solution might be adding a prefix to graphql enum values, renaming, for example, traffic light colors to TrafficLightRed, TrafficLightYellow and TrafficLightGreen.


The proposed setting should allow to do it in bulk.

@OlegIlyenko
Copy link
Member

Thanks a lot for working this feature! 👍 At the first glance it looks good to me, but I would like to give it nor in-depth review soon.

the following scala enums will cause collision

I also wanted to mention that this scenario should work quite fine even without name transformation. Enum value names and type names do not collide with each other.

@fehu
Copy link
Contributor Author

fehu commented Mar 23, 2018

Thanks for the tip, I thought that enum names would collide. Anyway, this setting might be useful in some other case.

@OlegIlyenko OlegIlyenko added this to the v1.4.1 milestone May 10, 2018
@OlegIlyenko OlegIlyenko merged commit 1b87fd1 into sangria-graphql:master May 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants