genqlient icon indicating copy to clipboard operation
genqlient copied to clipboard

Provide a method to get each fragment

Open benjaminjkraft opened this issue 4 years ago • 0 comments

If you have a query like

query Q {
  f { # type: I (interface)
    ...Fragment # on I (or J which implements I)
  }
}

Now, resp.F is a QFI which implements Fragment. But the concrete type is, say, *QFImpl which embeds a *FragmentImpl. Say you want to call some function that wants a Fragment; you pass it resp.F and that works. But now say it wants to type-switch; it might think it can switch on e.g. *FragmentImpl, but actually you passed it a *QFImpl, so it can't! (It may not even know about QFI!)

Right now what you probably have to do is switch on all the implementations, and extract their embed .FragmentImpl, and pass those, what a mess. Instead we could put on QFI a method GetFragment() Fragment just like we do for other shared fields. In practice this will mostly be obviated by #30, after which you can dispense with QFI/*QFImpl entirely, but it may be worth adding anyway.

benjaminjkraft avatar Sep 25 '21 00:09 benjaminjkraft