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
Proposition for an improvement on how interface
is handled
#315
Comments
Hey, thanks for the question! This comes up from time to time, and I agree fully, I also don't like the current representation and would prefer the alternative you show. However, these types are coming directly from the Relay compiler, so it's Relay itself that is a bit opinionated here in what types they output. This is an area the Relay team (and contributors) are working on improving (see for example facebook/relay#3280), so with a bit of luck things will improve very soon. As a work around, what I do is (edit: exactly what you say you're already doing but would prefer not to do 😆 ) I duplicate all selections in the inline fragment spreads. I know this removes most of the interface benefits 😉 So it's not an actual solution. But it's a workaround you can use while we wait for the typegen situation to improve upstream, that I believe will give you the type/runtime representation you're after. Also - happy you're trying |
Thanks for the quick reply! I am glad to hear your opinion on this and I am grateful for the explanation! Looking forward these improvements from Relay team. I will try to contribute to the docs about interfaces! |
I'm closing this for now, but I'll make sure to ping you when the Relay team moves forward with underlying improvements on this. Thanks for the docs contributions, really great! |
Hi!
Not long ago, we moved from
rescript-apollo-client
torescript-relay
and we are loving it so much!However, we miss how we worked with
interfaces
.For sure you will know how it works here, in
rescript-relay
, but for the sake of how it works inrescript-apollo-client
, I will write down both approaches.Given:
In
rescript-relay
by trying to get only type specific fields, it would result in polymorphic value:This is fairly okay, but we would prefer to have
title
out of type specific inline fragments and to specify it once above:Right here, we don't like two things, first of which is that we have these type specific fields as optional (which is completely valid of course) while they are defined as mandatory in schema and secondly that we don't have something simple and readable to
switch
on. Havingswitch
on a tuple of optional values is a valid thing but it can get pretty messy:This second example, in
rescript-apollo-client
would return something like this:They basically just add a
fragment
record field, which is a polymorphic variant. This polymorphic variant is identical to the one we have in the first example.With this result, we could have something like this, which we would prefer more:
Again, this is just our preference and opinion on this matter, and a food for thoughts.
As I already mentioned, we recently moved to
rescript-relay
so, please, let me know if we are missing something out.Thanks!
The text was updated successfully, but these errors were encountered: