Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Improve type generation accuracy #192

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
14 changes: 9 additions & 5 deletions src/TypeScriptGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,16 @@ function selectionsToAST(
// It might be some other type then the listed concrete types. We try to
// figure out which types remain here.
let possibleTypesLeft: TypeID[] | null = null;
const innerType = nodeType !== null ? schema.getRawType(nodeType) : null;
if (innerType !== null && schema.isUnion(innerType)) {
const innerType =
nodeType !== null ? schema.getNullableType(nodeType) : null;
if (
innerType !== null &&
(schema.isUnion(innerType) || schema.isInterface(innerType))
renanmav marked this conversation as resolved.
Show resolved Hide resolved
) {
const typesSeen = Object.keys(byConcreteType);
possibleTypesLeft = schema
.getUnionTypes(innerType)
.filter(type => !typesSeen.includes(type.name));
possibleTypesLeft = Array.from(schema.getPossibleTypes(innerType)).filter(
type => !typesSeen.includes(type.name)
);
}

// If we don't know which types are left we set the value to "%other",
Expand Down