How to use the @graphql-box/helpers.getChildFields 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
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,
      );
github badbatch / graphql-box / packages / cache-manager / src / main / index.ts View on Github external
private _filterQuery(
    { ast }: RequestData,
    { 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 / request-parser / src / main / index.ts View on Github external
private _addFieldToNode(node: FieldNode | InlineFragmentNode, key: string): void {
    if (!hasChildFields(node, key)) {
      const mockAST = parse(`{${key}}`);
      const queryNode = getOperationDefinitions(mockAST, QUERY)[0];
      const fieldsAndTypeNames = getChildFields(queryNode, key);
      if (!fieldsAndTypeNames) return;

      const { fieldNode } = fieldsAndTypeNames[0];
      addChildField(node, fieldNode, this._schema, key);
    }
  }
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);
github badbatch / graphql-box / packages / cache-manager / src / main / index.ts View on Github external
private async _setDataEntityAndRequestFieldPathCacheEntries(
    requestData: RequestData,
    responseData: ResponseDataForCaching,
    options: RequestOptions,
    context: RequestContext,
  ): Promise {
    const operationNode = getOperationDefinitions(requestData.ast, context.operation)[0];
    const fieldsAndTypeNames = getChildFields(operationNode);
    if (!fieldsAndTypeNames) return;

    await Promise.all(
      fieldsAndTypeNames.map(({ fieldNode }) => {
        return this._parseFieldDataEntityAndRequestFieldPathCacheEntryData(
          fieldNode,
          { requestFieldPath: context.operation },
          responseData,
          options,
          context,
        );
      }),
    );
  }