MCPcopy Create free account
hub / github.com/glideapps/quicktype / makeNullable

Function makeNullable

src/GraphQL.ts:73–88  ·  view source on GitHub ↗
(
    builder: TypeBuilder,
    tref: TypeRef,
    name: string,
    fieldName: string | null,
    containingTypeName: string
)

Source from the content-addressed store, hash-verified

71}
72
73function makeNullable(
74 builder: TypeBuilder,
75 tref: TypeRef,
76 name: string,
77 fieldName: string | null,
78 containingTypeName: string
79): TypeRef {
80 const typeNames = makeTypeNames(name, fieldName, containingTypeName);
81 const t = tref.deref();
82 if (!(t instanceof UnionType)) {
83 return builder.getUnionType(typeNames.names, false, OrderedSet([tref, builder.getPrimitiveType("null")]));
84 }
85 const [maybeNull, nonNulls] = removeNullFromUnion(t);
86 if (maybeNull) return tref;
87 return builder.getUnionType(typeNames, false, nonNulls.map(nn => nn.typeRef).add(builder.getPrimitiveType("null")));
88}
89
90function removeNull(builder: TypeBuilder, tref: TypeRef): TypeRef {
91 const t = tref.deref();

Callers 1

GQLQueryClass · 0.85

Calls 4

removeNullFromUnionFunction · 0.90
makeTypeNamesFunction · 0.85
addMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…