Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const childFieldName = getName(childField);
if (childFieldName === this._typeIDKey || childFieldName === TYPE_NAME_KEY) continue;
const { requestFieldPath } = CacheManager._getFieldKeysAndPaths(childField, {
requestFieldPath: ancestorRequestFieldPath,
});
const { hasData, typeUnused } = CacheManager._checkFieldPathChecklist(
fieldPathChecklist.get(requestFieldPath),
childTypeName,
);
if (hasData || typeUnused) {
if (!hasChildFields(childField)) {
deleteChildFields(field, childField);
} else if (this._filterField(childField, fieldPathChecklist, requestFieldPath, context)) {
deleteChildFields(field, childField);
}
}
}
this._filterInlineFragments(field);
this._filterIDsAndTypeNames(field);
return !hasChildFields(field);
}
private _filterIDsAndTypeNames(field: FieldNode): boolean {
const fieldsAndTypeNames = getChildFields(field);
if (!fieldsAndTypeNames || fieldsAndTypeNames.length > 3) return false;
const fieldNames = fieldsAndTypeNames.map(({ fieldNode }) => getName(fieldNode) as string);
if (fieldNames.length === 2 && fieldNames.every(name => name === this._typeIDKey || name === TYPE_NAME_KEY)) {
deleteChildFields(
field,
fieldsAndTypeNames.map(({ fieldNode }) => fieldNode),
);
return true;
}
if ((fieldNames.length === 1 && fieldNames[0] === this._typeIDKey) || fieldNames[0] === TYPE_NAME_KEY) {
const { fieldNode } = fieldsAndTypeNames[0];
deleteChildFields(field, fieldNode);
return true;
}
return false;
}
{ fieldPathChecklist }: CachedResponseData,
context: RequestContext,
): void {
const queryNode = getOperationDefinitions(ast, context.operation)[0];
const fieldsAndTypeNames = getChildFields(queryNode);
if (!fieldsAndTypeNames) return;
for (let i = fieldsAndTypeNames.length - 1; i >= 0; i -= 1) {
const { fieldNode } = fieldsAndTypeNames[i];
const { requestFieldPath } = CacheManager._getFieldKeysAndPaths(fieldNode, {
requestFieldPath: context.operation,
});
if (this._filterField(fieldNode, fieldPathChecklist, requestFieldPath, context)) {
deleteChildFields(queryNode, fieldNode);
}
}
context.queryFiltered = true;
}
if (!fieldsAndTypeNames || fieldsAndTypeNames.length > 3) return false;
const fieldNames = fieldsAndTypeNames.map(({ fieldNode }) => getName(fieldNode) as string);
if (fieldNames.length === 2 && fieldNames.every(name => name === this._typeIDKey || name === TYPE_NAME_KEY)) {
deleteChildFields(
field,
fieldsAndTypeNames.map(({ fieldNode }) => fieldNode),
);
return true;
}
if ((fieldNames.length === 1 && fieldNames[0] === this._typeIDKey) || fieldNames[0] === TYPE_NAME_KEY) {
const { fieldNode } = fieldsAndTypeNames[0];
deleteChildFields(field, fieldNode);
return true;
}
return false;
}