Skip to content

Commit

Permalink
Move DEFAULT_UPLINK_ENDPOINTS to static member (#1977)
Browse files Browse the repository at this point in the history
* Move DEFAULT_UPLINK_ENDPOINTS to static member

This helps reduce the API surface and keeps data scoped to the manager
  • Loading branch information
benweatherman authored Jul 18, 2022
1 parent d1b56bf commit 8c4ecd6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
1 change: 1 addition & 0 deletions gateway-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This CHANGELOG pertains only to Apollo Federation packages in the 2.x range. The
- __BREAKING__: previously, directive applications within a `@key`, `@provides` or `@requires` were parsed but
not honored in any way. As this change reject such applications (at composition time), it could theoretically
require to remove some existing (ignored) directive applications within a `@key`, `@provides` or `@requires`.
- Move `DEFAULT_UPLINK_ENDPOINTS` to static member of `UplinkSupergraphManager` [PR #1977](https://github.com/apollographql/federation/pull/1977).

## 2.1.0-alpha.0

Expand Down
1 change: 0 additions & 1 deletion gateway-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,5 +1079,4 @@ export {
FailureToFetchSupergraphSdlAfterInit,
FailureToFetchSupergraphSdlDuringInit,
FailureToFetchSupergraphSdlFunctionParams,
DEFAULT_UPLINK_ENDPOINTS,
} from './supergraphManagers';
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import mockedEnv from 'mocked-env';

import { UplinkSupergraphManager } from '@apollo/gateway';

import { DEFAULT_UPLINK_ENDPOINTS } from '..';

let cleanUp: (() => void) | undefined;

const logger = {
Expand Down Expand Up @@ -31,7 +29,7 @@ describe('UplinkSupergraphManager', () => {
it('uses default uplink URLs', async () => {
const manager = new UplinkSupergraphManager({ apiKey, graphRef, logger });

expect(manager.uplinkEndpoints).toEqual(DEFAULT_UPLINK_ENDPOINTS);
expect(manager.uplinkEndpoints).toEqual(UplinkSupergraphManager.DEFAULT_UPLINK_ENDPOINTS);
});

it('can set uplink URLs via config', async () => {
Expand Down
35 changes: 18 additions & 17 deletions gateway-js/src/supergraphManagers/UplinkSupergraphManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@ import { getDefaultLogger } from '../../logger';
import { loadSupergraphSdlFromUplinks } from './loadSupergraphSdlFromStorage';
import { Fetcher } from '@apollo/utils.fetcher';

export const DEFAULT_UPLINK_ENDPOINTS = [
'https://uplink.api.apollographql.com/',
'https://aws.uplink.api.apollographql.com/',
];

function getUplinkEndpoints(): string[] {
/**
* Configuration priority order:
* 1. APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT environment variable
* 2. default (GCP and AWS)
*/
const envEndpoints =
process.env.APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT?.split(',');
return envEndpoints ?? DEFAULT_UPLINK_ENDPOINTS;
}

export type FailureToFetchSupergraphSdlFunctionParams = {
error: Error;
graphRef: string;
Expand Down Expand Up @@ -61,7 +45,13 @@ type State =
| { phase: 'stopped' };

export class UplinkSupergraphManager implements SupergraphManager {
public readonly uplinkEndpoints: string[] = getUplinkEndpoints();
public static readonly DEFAULT_UPLINK_ENDPOINTS = [
'https://uplink.api.apollographql.com/',
'https://aws.uplink.api.apollographql.com/',
];

public readonly uplinkEndpoints: string[] =
UplinkSupergraphManager.getUplinkEndpoints();
private apiKey: string;
private graphRef: string;
private fetcher: Fetcher = makeFetchHappen.defaults();
Expand Down Expand Up @@ -187,6 +177,17 @@ export class UplinkSupergraphManager implements SupergraphManager {
return this.state.nextFetchPromise;
}

/**
* Configuration priority order:
* 1. APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT environment variable
* 2. default (GCP and AWS)
*/
public static getUplinkEndpoints(): string[] {
const envEndpoints =
process.env.APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT?.split(',');
return envEndpoints ?? UplinkSupergraphManager.DEFAULT_UPLINK_ENDPOINTS;
}

private async updateSupergraphSdl(maxRetries: number): Promise<{
supergraphSdl: string;
minDelaySeconds: number;
Expand Down

0 comments on commit 8c4ecd6

Please sign in to comment.