How to use the @graphql-box/helpers.rehydrateCacheMetadata 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 / worker-client / src / main / index.ts View on Github external
private _onMessage = async ({ data }: MessageEvent): Promise => {
    if (!isPlainObject(data)) return;

    const { context, method, result, type } = data as MessageResponsePayload;
    if (type !== GRAPHQL_BOX || !isPlainObject(result)) return;

    const { _cacheMetadata, ...otherProps } = result;
    const response: MaybeRequestResult = { ...otherProps };
    if (_cacheMetadata) response._cacheMetadata = rehydrateCacheMetadata(_cacheMetadata);

    if (method === REQUEST) {
      const pending = this._pending.get(context.boxID);
      if (!pending) return;

      pending.resolve(response);
    } else if (method === SUBSCRIBE) {
      this._eventEmitter.emit(context.boxID, response);
    }
  };
github badbatch / graphql-box / packages / cache-manager / src / main / index.ts View on Github external
private _createCacheMetadata(
    { _cacheMetadata, headers }: RawResponseDataWithMaybeCacheMetadata,
    { operation }: RequestContext,
  ): CacheMetadata {
    const cacheMetadata = new Map();
    const cacheControl = (headers && headers.get(HEADER_CACHE_CONTROL)) || this._fallbackOperationCacheability;
    const cacheability = new Cacheability({ cacheControl });
    cacheMetadata.set(operation, cacheability);
    if (_cacheMetadata) rehydrateCacheMetadata(_cacheMetadata, cacheMetadata);
    return cacheMetadata;
  }
github badbatch / graphql-box / packages / cache-manager / src / main / index.ts View on Github external
public async checkQueryResponseCacheEntry(
    hash: string,
    options: RequestOptions,
    context: RequestContext,
  ): Promise {
    const result = await this._checkCacheEntry(QUERY_RESPONSES, hash, options, context);

    if (!result) return false;

    const { cacheMetadata, data } = result.entry as QueryResponseCacheEntry;

    return {
      cacheMetadata: rehydrateCacheMetadata(cacheMetadata),
      data,
    };
  }