generate TS type guard functions for types, unions and interfaces based on __typename
helios1138 opened this issue · 0 comments
helios1138 commented
e.g. for GraphQL like
type FooBar = Foo | Bar
generate a function
export function isFooBar(obj: any): obj is FooBar {
if (!obj.__typename) {
throw new Error('__typename is required')
}
return ~['Foo', 'Bar'].indexOf(obj.__typename)
}
and similar ones for interfaces and specific types