How to use the @graphql-box/helpers.hasChildFields 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
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 / 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
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)) {
          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 async _analyzeField(
    field: FieldNode,
    cachedAncestorFieldData: CachedAncestorFieldData,
    cachedResponseData: CachedResponseData,
    options: RequestOptions,
    context: RequestContext,
  ): Promise {
    if (hasChildFields(field)) {
      await this._analyzeParentField(field, cachedAncestorFieldData, cachedResponseData, options, context);
    } else {
      await CacheManager._analyzeLeafField(field, cachedAncestorFieldData, cachedResponseData, options, context);
    }
  }
github badbatch / graphql-box / packages / cache-manager / src / main / index.ts View on Github external
const result = await this._checkCacheEntry(REQUEST_FIELD_PATHS, hashedRequestFieldCacheKey, options, context);

      if (result) {
        fieldData = this._mergeObjects(result.entry, fieldData);
      }

      await this._setCacheEntry(
        REQUEST_FIELD_PATHS,
        hashedRequestFieldCacheKey,
        fieldData,
        { cacheHeaders: { cacheControl: cacheability.printCacheControl() }, tag: options.tag },
        options,
        context,
      );

      if (hasChildFields(field)) {
        if (isEntity) {
          set(data, responseDataPath, { __cacheKey: `${REQUEST_FIELD_PATHS}::${hashedRequestFieldCacheKey}` });
        } else {
          unset(data, responseDataPath);
        }
      }
    }
  }