Khan / Khan/genqlient

Provide a method to get each fragment

Open
#113 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
1.3k
Forks
143
Avg merge
4h 50m
Merged PRs (30d)
1

Description

If you have a query like
```graphql
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.

Contributor guide

Open the contributing guide

Research direction

Start by tracing how QFI and other shared-field methods are generated, then compare the Fragment and FragmentImpl handling described in the issue. Check issue #30 before proceeding; done means the generated interface provides access to the underlying Fragment without requiring callers to switch over every concrete implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, graphql
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.