Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
acc = selections.reduce((selectionAcc, selection) => {
switch (selection.kind) {
case "Field":
case "TypeCondition":
selectionAcc = maybePush(selectionAcc, selection.type);
break;
case "FragmentSpread":
selectionAcc = reduceTypesForDocument(selection, selectionAcc);
break;
default:
break;
}
return selectionAcc;
}, acc);
(acc: GraphQLType[], { type }: { type: GraphQLType }) => {
const t = this.getUnderlyingType(type);
if (this.isGlobalType(t)) {
return maybePush(acc, t);
}
return acc;
},
[]
private reduceTypesUsed = (
acc: (GraphQLType | GraphQLOutputType)[],
type: GraphQLType
) => {
if (isNonNullType(type)) {
type = getNullableType(type);
}
if (isListType(type)) {
type = type.ofType;
}
if (isInputObjectType(type) || isObjectType(type)) {
acc = maybePush(acc, type);
const fields = type.getFields();
acc = Object.keys(fields)
.map(key => fields[key] && fields[key].type)
.reduce(this.reduceTypesUsed, acc);
} else {
acc = maybePush(acc, type);
}
return acc;
};
private reduceSelection = (
acc: GraphQLType[],
selection: Selection
): GraphQLType[] => {
if (selection.kind === "Field" || selection.kind === "TypeCondition") {
const type = this.getUnderlyingType(selection.type);
if (this.isGlobalType(type)) {
acc = maybePush(acc, type);
}
}
if (selection.selectionSet) {
return selection.selectionSet.selections.reduce(
this.reduceSelection,
acc
);
}
return acc;
};
if (isNonNullType(type)) {
type = getNullableType(type);
}
if (isListType(type)) {
type = type.ofType;
}
if (isInputObjectType(type) || isObjectType(type)) {
acc = maybePush(acc, type);
const fields = type.getFields();
acc = Object.keys(fields)
.map(key => fields[key] && fields[key].type)
.reduce(this.reduceTypesUsed, acc);
} else {
acc = maybePush(acc, type);
}
return acc;
};