Skip to content

Commit

Permalink
Add fetcher option to ApolloServerPluginUsageReporting
Browse files Browse the repository at this point in the history
  • Loading branch information
sachindshinde committed May 19, 2021
1 parent ca0a253 commit baa4b55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Expand Up @@ -5,7 +5,7 @@ import {
Logger,
GraphQLRequestContext,
} from 'apollo-server-types';
import { RequestAgent } from 'apollo-server-env';
import type { fetch, RequestAgent } from 'apollo-server-env';
import type { Trace } from 'apollo-reporting-protobuf';

export interface ApolloServerPluginUsageReportingOptions<TContext> {
Expand Down Expand Up @@ -156,6 +156,10 @@ export interface ApolloServerPluginUsageReportingOptions<TContext> {
* Apollo.
*/
requestAgent?: RequestAgent | false;
/**
* Specifies which Fetch API implementation to use when sending usage reports.
*/
fetcher?: typeof fetch;
/**
* How often to send reports to Apollo. We'll also send reports when the
* report gets big; see maxUncompressedReportSize.
Expand Down
Expand Up @@ -265,12 +265,13 @@ export function ApolloServerPluginUsageReporting<TContext>(
});
});

// Wrap fetch with async-retry for automatic retrying
// Wrap fetcher with async-retry for automatic retrying
const fetcher = options.fetcher ?? fetch;
const response: Response = await retry(
// Retry on network errors and 5xx HTTP
// responses.
async () => {
const curResponse = await fetch(
const curResponse = await fetcher(
(options.endpointUrl ||
'https://usage-reporting.api.apollographql.com') +
'/api/ingress/traces',
Expand Down

0 comments on commit baa4b55

Please sign in to comment.