How to use the @graphql-box/helpers.deleteChildFields function in @graphql-box/helpers

To help you get started, we’ve selected a few @graphql-box/helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github badbatch / graphql-box / packages / cache-manager / src / main / index.ts View on Github external
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);
  }
github badbatch / graphql-box / packages / cache-manager / src / main / index.ts View on Github external
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;
  }
github badbatch / graphql-box / packages / cache-manager / src / main / index.ts View on Github external
{ 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;
  }
github badbatch / graphql-box / packages / cache-manager / src / main / index.ts View on Github external
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;
  }