zth / rescript-relay

Use Relay with ReScript.
https://rescript-relay-documentation.vercel.app/docs/getting-started
337 stars 50 forks source link

[RFC] Unions as regular variants #444

Closed zth closed 1 year ago

zth commented 1 year ago

This is a RFC for a feature we could put in a new major of RescriptRelay. Think of it as a "RescriptRelay 2.0", where we have more wiggle room to introduce breaking changes.

ReScript v11 will allow customizing the runtime representation of regular variants. This means we'll be able to easily move from polyvariants to regular variants for unions.

What as previously:

fragment SomeFragment on Group {
  groupType {
    ... on FullGroup {
      name
    }
   ... on CondensedGroup {
      shortName
   }
  }
}
type fragment_groupType_FullGroup = { name: string }
type fragment_groupType_CondensedGroup = { shortName: string }
type fragment_groupType = [#FullGroup(fragment_groupType_FullGroup) | #CondensedGroup(fragment_groupType_CondensedGroup) | #UnselectedUnionMember(string)]

Would now be:

@tag("__typename") type fragment_groupType = FullGroup({name: string}) | CondensedGroup({shortName: string}) | UnselectedUnionMember({__typename: string})

Pro's:

As for migration, we'll need to figure out a good way to allow easy migration from the old to the new representation. This is of course a top priority and while publishing this under a new major RescriptRelay 2.0, I'd never just push out stuff without having a clear idea of how to migrate to it as easily as possible.

What are your thoughts on the above?

If there's anything unclear in the points I make, please feel free to ask and I'll clarify.