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 union type redirect #989

Merged
merged 4 commits into from
Aug 7, 2021

Conversation

paulpdaniels
Copy link
Collaborator

@paulpdaniels paulpdaniels commented Jul 31, 2021

Adds the ability to redirect a type union to to a different type. This allows you to reuse types between unions like:

sealed trait MyUnion
object MyUnion {
  @GQLValueType
  case class Redirect(value: UserProfile) extends MyUnion
  case class Error(msg: String) extends MyUnion
}

// Doesn't need to be part of the sealed trait anymore so can be reused for other types.
case class UserProfile(id: String, email: String)

producing a graphql union with the Redirect type removed and the UserProfile treated as part of the union instead.

type UserProfile {
  id: String!
  email: String!
}

type Error {
  msg: String!
}


union MyUnion = UserProfile | Error

@paulpdaniels paulpdaniels force-pushed the support-union-redirects branch from cf42b87 to 58650f9 Compare July 31, 2021 09:24
@paulpdaniels paulpdaniels marked this pull request as ready for review August 2, 2021 04:59
@paulpdaniels paulpdaniels requested a review from ghostdogpr August 2, 2021 04:59
@ghostdogpr
Copy link
Owner

Sorry, got a couple hectic days at work, will try to review tomorrow!

Copy link
Owner

@ghostdogpr ghostdogpr left a comment

Choose a reason for hiding this comment

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

Looks good!

Can you add some docs (I don't mind if you do it in another PR so I can merge it when I release)?

Also, can you fix the example in the PR, it doesn't seem complete (no annotation and the type names don't match). Could be useful if someone stumble upon it.

@paulpdaniels
Copy link
Collaborator Author

@ghostdogpr done!

@ghostdogpr ghostdogpr merged commit 2750d65 into ghostdogpr:master Aug 7, 2021
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.

2 participants