You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use this library to mock Apollo and am running into a few issues when using the generics (.query<Query, Variables>):
__typename is required and expects a predetermined value. String is a superset and won't work.
Workaround: __typename: () => "User" as const,
Interfaces (and possibly unions).. are a bit odd.
Some of these fields are only present in some implementations. .create has no awareness of this, but I do expect to perform .find on one collection to find any of the types, since a getAnimal query might return any type of animal.
I also end up defining defaults for all fields, even if they're not relevant to that type.
The __typename ends up determining what objects are compatible. I can no longer enforce a union here (e.g. Animal interface potentially has "Cat" | "Dog" | "Elephant") since the __typename determines how the type is matched and what fields must be present.
__typename can technically be undefined, but nullable only adds | null. I don't really want a default here.
Workaround: __typename: () => "Cat" as any, (or undefined as any will work too)
At this point it's a little easier to use .query<any, Variables>, but the types were otherwise helpful for developer experience and catching missing fields.
The text was updated successfully, but these errors were encountered:
I'm trying to use this library to mock Apollo and am running into a few issues when using the generics (
.query<Query, Variables>
):__typename
is required and expects a predetermined value.String
is a superset and won't work.__typename: () => "User" as const,
.create
has no awareness of this, but I do expect to perform.find
on one collection to find any of the types, since agetAnimal
query might return any type of animal.__typename
ends up determining what objects are compatible. I can no longer enforce a union here (e.g. Animal interface potentially has"Cat" | "Dog" | "Elephant"
) since the__typename
determines how the type is matched and what fields must be present.__typename
can technically beundefined
, butnullable
only adds| null
. I don't really want a default here.__typename: () => "Cat" as any,
(orundefined as any
will work too)At this point it's a little easier to use
.query<any, Variables>
, but the types were otherwise helpful for developer experience and catching missing fields.The text was updated successfully, but these errors were encountered: