Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _filterField(
field: FieldNode,
fieldPathChecklist: FieldPathChecklist,
ancestorRequestFieldPath: string,
context: RequestContext,
): boolean {
const fieldsAndTypeNames = getChildFields(field);
if (!fieldsAndTypeNames) return false;
for (let i = fieldsAndTypeNames.length - 1; i >= 0; i -= 1) {
const { fieldNode: childField, typeName: childTypeName } = fieldsAndTypeNames[i];
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)) {
return _this._updateFieldNode(
node as FieldNode,
ancestors,
typeInfo,
fragmentDefinitions,
options,
context,
);
}
if (kind === INLINE_FRAGMENT) {
return _this._updateInlineFragmentNode(node as InlineFragmentNode, ancestors, typeInfo, options, context);
}
if (kind === VARIABLE) {
const variableName = getName(node) as string;
if (getKind(parent) === VARIABLE_DEFINITION) {
variableTypes[variableName] = _this._schema.getType(getVariableDefinitionType(parent));
}
return RequestParser._updateVariableNode(node as VariableNode, variableTypes[variableName], options);
}
return undefined;
},
leave(node: ASTNode): any {
private _getInlineFragmentType(
node: InlineFragmentNode,
typeInfo: TypeInfo,
): GraphQLOutputType | GraphQLNamedType | undefined {
if (!node.typeCondition) return undefined;
const name = getName(node.typeCondition) as string;
const parentType = typeInfo.getParentType();
if (!parentType || name === parentType.name) return undefined;
return this._schema.getType(name) || undefined;
}
inlineFragments.forEach(fragment => {
const fieldsAndTypeNames = getChildFields(fragment);
if (!fieldsAndTypeNames || !fieldsAndTypeNames.length) {
deleteInlineFragments(field, fragment);
filtered = true;
return;
}
if (fieldsAndTypeNames.length === 1) {
const { fieldNode } = fieldsAndTypeNames[0];
if (getName(fieldNode) === this._typeIDKey) {
deleteInlineFragments(field, fragment);
filtered = true;
}
}
});
private static _getFieldKeysAndPaths(field: FieldNode, options: KeysAndPathsOptions): KeysAndPaths {
const { index, requestFieldCacheKey = "", requestFieldPath = "", responseDataPath = "" } = options;
const name = getName(field) as string;
const updatedRequestFieldCacheKey = CacheManager._buildRequestFieldCacheKey(
name,
requestFieldCacheKey,
getArguments(field),
getDirectives(field),
index,
);
const fieldAliasOrName = getAlias(field) || name;
const updatedRequestFieldPath = isNumber(index)
? requestFieldPath
: CacheManager._buildKey(fieldAliasOrName, requestFieldPath);
const propNameOrIndex = isNumber(index) ? index : fieldAliasOrName;