How to use apollo-link-batch - 5 common examples

To help you get started, we’ve selected a few apollo-link-batch 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 Zimbra / zm-api-js-client / src / apollo / local-batch-link.ts View on Github external
})
				)
					.then((results: FetchResult[]) => {
						(emittedResponse = true) && notifier.emit('res', results);
						// we have data and can send it to back up the link chain
						observer.next(results);
						observer.complete();
						return results;
					})
					.catch(err => {
						emittedResponse || notifier.emit('res', err);
						observer.error(err);
					});
			});

		this.batcher = new BatchLink({
			batchInterval: options.batchInterval,
			batchHandler
		});
	}
github apollographql / apollo-link / packages / apollo-link-batch-http / src / __tests__ / batchHttpLink.ts View on Github external
const batchKey = () => 'hi';
    const batchHandler = operations => Observable.of();

    const batch = new LocalScopedLink({
      batchInterval: 20,
      batchMax: 20,
      batchKey,
      batchHandler,
    });

    const {
      batchInterval,
      batchMax,
      batchKey: batchKeyArg,
    } = BatchLink.mock.calls[0][0];

    expect(batchInterval).toBe(20);
    expect(batchMax).toBe(20);
    expect(batchKeyArg()).toEqual(batchKey());
  });
github apollographql / apollo-link / packages / apollo-link-batch-http / src / batchHttpLink.ts View on Github external
batchKey ||
      ((operation: Operation) => {
        const context = operation.getContext();

        const contextConfig = {
          http: context.http,
          options: context.fetchOptions,
          credentials: context.credentials,
          headers: context.headers,
        };

        //may throw error if config not serializable
        return selectURI(operation, uri) + JSON.stringify(contextConfig);
      });

    this.batcher = new BatchLink({
      batchInterval: this.batchInterval,
      batchMax: this.batchMax,
      batchKey,
      batchHandler,
    });
  }
github apollographql / apollo-angular / packages / apollo-angular-link-http-batch / src / HttpBatchLink.ts View on Github external
return () => {
          if (!sub.closed) {
            sub.unsubscribe();
          }
        };
      });
    };

    const batchKey =
      options.batchKey ||
      ((operation: Operation) => {
        return this.createBatchKey(operation);
      });

    this.batcher = new BatchLink({
      batchInterval: this.batchInterval,
      batchMax: this.batchMax,
      batchKey,
      batchHandler,
    });
  }
github drupal-graphql / drupal-decoupled-app / frontend / app / shared / apollo / createPersistedBatchLink.js View on Github external
id: queryMap[queryKey],
        };
      });

      apolloFetch(printedOperations)
        .then((data) => {
          observer.next(data);
          observer.complete();
        })
        .catch(observer.error.bind(observer));
    });
  };

  const apolloLink = new BatchHttpLink();
  return Object.assign(apolloLink, {
    batcher: new BatchLink({
      batchInterval: apolloLink.batchInterval,
      batchMax: apolloLink.batchMax,
      batchHandler: batchHandler.bind(apolloLink),
    }),
  });
};

apollo-link-batch

Apollo Link that performs batching and operation on batched Operations

MIT
Latest version published 4 years ago

Package Health Score

62 / 100
Full package analysis

Similar packages