Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer committed Feb 10, 2022
1 parent fc9580b commit 39b9ffb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/source/api/apollo-gateway.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ Provide this field **only** if you are using managed federation _and_ your use c

The maximum number of times the gateway retries a failed poll request to Apollo Uplink, cycling through its list of [`uplinkEndpoints`](#uplinkendpoints).

The default value is three times your number of `uplinkEndpoints` (i.e., `6` in almost all cases).
The default value is to try each of your uplinkEndpoints three times (i.e., 5 retries with the default list of two endpoints).

Provide this field **only** if you are using managed federation.

Expand Down
2 changes: 1 addition & 1 deletion gateway-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class ApolloGateway implements GraphQLService {
apiKey: this.apolloConfig!.key!,
uplinkEndpoints,
maxRetries:
this.config.uplinkMaxRetries ?? uplinkEndpoints.length * 3,
this.config.uplinkMaxRetries ?? uplinkEndpoints.length * 3 - 1, // -1 for the initial request
subgraphHealthCheck: this.config.serviceHealthCheck,
fetcher: this.fetcher,
logger: this.logger,
Expand Down
2 changes: 1 addition & 1 deletion gateway-js/src/supergraphManagers/UplinkFetcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class UplinkFetcher implements SupergraphManager {
fetcher: this.config.fetcher,
compositionId: this.compositionId ?? null,
maxRetries: this.config.maxRetries,
roundRobinSeed: this.fetchCount,
roundRobinSeed: this.fetchCount++,
});

if (!result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,37 +66,24 @@ export async function loadSupergraphSdlFromUplinks({
maxRetries: number,
roundRobinSeed: number,
}) : Promise<SupergraphSdlUpdate | null> {
let lastException = null;
let result: SupergraphSdlUpdate | null = null;

await retry(
async () => {
result = await loadSupergraphSdlFromStorage({
// This Promise resolves with either an updated supergraph or null if no change.
// This Promise can reject in the case that none of the retries are successful,
// in which case it will reject with the most frequently encountered error.
return retry(
() =>
loadSupergraphSdlFromStorage({
graphRef,
apiKey,
endpoint: endpoints[roundRobinSeed++ % endpoints.length],
errorReportingEndpoint,
fetcher,
compositionId,
});

// If we make it here, we didn't throw on this attempt. We'll clear
// any error we might've captured so we don't throw it below.
lastException = null;
return result;
},
}),
{
retries: maxRetries,
onRetry(err) {
lastException = err;
},
},
);

if (lastException !== null) {
throw lastException;
}
return result;
}

export async function loadSupergraphSdlFromStorage({
Expand Down

0 comments on commit 39b9ffb

Please sign in to comment.