How to use the @graphql-box/helpers.iterateChildFields 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
CacheManager._setCachedResponseData(
      { cacheability, data },
      cachedResponseData,
      keysAndPaths,
      { dataTypeName: get(data, TYPE_NAME_KEY), fieldTypeName: typeName },
      options,
      context,
    );

    if (!isObjectLike(data)) return;

    const objectLikeData = data as PlainObjectMap | any[];
    const promises: Array> = [];

    iterateChildFields(
      field,
      objectLikeData,
      (childField: FieldNode, childTypeName: string | undefined, childIndex?: number) => {
        promises.push(
          this._analyzeField(
            childField,
            { index: childIndex, requestFieldCacheKey, requestFieldPath, typeName: childTypeName, ...cachedFieldData },
            { ...cachedResponseData, data: cachedResponseData.data[propNameOrIndex] },
            options,
            context,
          ),
        );
      },
    );

    await Promise.all(promises);
github badbatch / graphql-box / packages / cache-manager / src / main / index.ts View on Github external
field: FieldNode,
    ancestorKeysAndPaths: AncestorKeysAndPaths,
    { cacheMetadata, data }: ResponseData,
    options: RequestOptions,
    context: RequestContext,
  ): void {
    const { requestFieldPath: ancestorRequestFieldPath } = ancestorKeysAndPaths;
    const keysAndPaths = CacheManager._getFieldKeysAndPaths(field, ancestorKeysAndPaths);
    const { requestFieldPath, responseDataPath } = keysAndPaths;
    const fieldData = get(data, responseDataPath, null);
    if (!isObjectLike(fieldData)) return;

    const objectLikeFieldData = fieldData as PlainObjectMap | any[];
    this._setFieldTypeCacheDirective(cacheMetadata, { ancestorRequestFieldPath, requestFieldPath }, context);

    iterateChildFields(
      field,
      objectLikeFieldData,
      (childField: FieldNode, typeName: string | undefined, childIndex?: number) => {
        this._setFieldCacheability(
          childField,
          { index: childIndex, requestFieldPath, responseDataPath },
          { cacheMetadata, data },
          options,
          context,
        );
      },
    );
  }
github badbatch / graphql-box / packages / cache-manager / src / main / index.ts View on Github external
private async _parseFieldDataEntityAndRequestFieldPathCacheEntryData(
    field: FieldNode,
    ancestorKeysAndPaths: AncestorKeysAndPaths,
    { cacheMetadata, dataEntityData, requestFieldPathData }: ResponseDataForCaching,
    options: RequestOptions,
    context: RequestContext,
  ): Promise {
    const keysAndPaths = CacheManager._getFieldKeysAndPaths(field, ancestorKeysAndPaths);
    const { requestFieldCacheKey, requestFieldPath, responseDataPath } = keysAndPaths;
    const fieldData = get(requestFieldPathData, responseDataPath, null);
    if (!isObjectLike(fieldData)) return;

    const objectLikeFieldData = fieldData as PlainObjectMap | any[];
    const promises: Array> = [];

    iterateChildFields(
      field,
      objectLikeFieldData,
      (childField: FieldNode, typeName: string | undefined, childIndex?: number) => {
        promises.push(
          this._parseFieldDataEntityAndRequestFieldPathCacheEntryData(
            childField,
            { index: childIndex, requestFieldCacheKey, requestFieldPath, responseDataPath },
            { cacheMetadata, dataEntityData, requestFieldPathData },
            options,
            context,
          ),
        );
      },
    );

    await Promise.all(promises);