How to use the @graphql-box/helpers.EventAsyncIterator 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 / subscribe / src / main / index.ts View on Github external
rootValue: rootValue || this._rootValue,
      schema: this._schema,
      subscribeFieldResolver: subscribeFieldResolver || this._subscribeFieldResolver,
    };

    try {
      const subscribeResult = await this._subscribe(subscribeArgs);

      if (isAsyncIterable(subscribeResult)) {
        forAwaitEach(subscribeResult, async ({ data, errors }: ExecutionResult) => {
          const resolvedResult = await subscriberResolver({ data, errors });
          this._eventEmitter.emit(hash, resolvedResult);
        });
      }

      const eventAsyncIterator = new EventAsyncIterator(this._eventEmitter, hash);
      return eventAsyncIterator.getIterator();
    } catch (error) {
      return Promise.reject(error);
    }
  }
}
github badbatch / graphql-box / packages / websocket-manager / src / main / index.ts View on Github external
): Promise> {
    if (!this._isSocketOpen()) {
      return Promise.reject(new Error("@graphql-box/websocket-manager expected the websocket to be open."));
    }

    try {
      this._websocket.send(
        JSON.stringify({
          context: WebsocketManager._getMessageContext(context),
          subscription: request,
          subscriptionID: hash,
        }),
      );

      this._subscriptions.set(hash, subscriberResolver);
      const eventAsyncIterator = new EventAsyncIterator(this._eventEmitter, hash);
      return eventAsyncIterator.getIterator();
    } catch (error) {
      return Promise.reject(error);
    }
  }
github badbatch / graphql-box / packages / worker-client / src / main / index.ts View on Github external
private async _subscribe(
    request: string,
    options: RequestOptions,
    context: RequestContext,
  ): Promise> {
    try {
      this._worker.postMessage({
        context: WorkerClient._getMessageContext(context),
        method: SUBSCRIBE,
        options,
        request,
        type: GRAPHQL_BOX,
      });

      const eventAsyncIterator = new EventAsyncIterator(this._eventEmitter, context.boxID);
      return eventAsyncIterator.getIterator();
    } catch (error) {
      return Promise.reject(error);
    }
  }
}