Add tests to check that genqlient handles covariance #203
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I didn't realize until today that implementations of GraphQL interfaces
are actually allowed to be covariant: if the interface has a field
f: T
, then the implementations may have fieldsf: U
whereU
is asubtype of
T
(for exampleU
may be an implementation of theinterface
T
, orU
may beT!
ifT
is non-nullable. (I thought ithad to be
f: T
exactly.) So I figured I'd add a test and see whatbreaks.
Surprisingly, and despite the fact that Go interfaces do not allow
covariance, everything... worked? There's at least one place where it's
possible we could ideally use a more specific type [1], but for now I
just wanted to make sure we at least write something that builds and is
vaguely reasonable. Of course I'm not sure if there's anything I've
missed (some day I need to find a fuzzing engine that can fuzz GraphQL).
[1] Specifically, the field
CovariantInterfaceImplementationRandomItemTopic.Next
might ideallyhave type
...NextContentTopic
, not...NextContent
; we know it's atopic. This doesn't directly cause covariance problems in Go: the method
GetNext
still returns...NextContent
so the interface matches. Butthat trick doesn't work for the sibling field
.Related
which isslice-typed: or rather, we'd need the method to copy the slice to the
correct type. (Not to mention the implemention of any change here would
require a bunch of plumbing because the AST doesn't quite have what we
want.) So it's probably best to just keep this as-is for simplicity and
consistency.
Test plan: make check
I have: