Skip to content

Commit

Permalink
Add default Apollo Engine endpoint (#1560)
Browse files Browse the repository at this point in the history
Generally, users are not going to provide a custom endpoint for fetching from the Apollo Engine, so make it optional and add a sensible default value.
  • Loading branch information
lsanwick committed May 29, 2020
1 parent da4615c commit 68c14f5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/loaders/apollo-engine/src/index.ts
Expand Up @@ -4,14 +4,16 @@ import { buildClientSchema } from 'graphql';

export interface ApolloEngineOptions extends SingleFileOptions {
engine: {
endpoint: string;
endpoint?: string;
apiKey: string;
};
graph: string;
variant: string;
headers?: Record<string, string>;
}

const DEFAULT_APOLLO_ENDPOINT = 'https://engine-graphql.apollographql.com/api/graphql';

export class ApolloEngineLoader implements SchemaLoader<ApolloEngineOptions> {
loaderId() {
return 'apollo-engine';
Expand All @@ -26,7 +28,7 @@ export class ApolloEngineLoader implements SchemaLoader<ApolloEngineOptions> {
}

async load(_: 'apollo-engine', options: ApolloEngineOptions): Promise<Source> {
const response = await fetch(options.engine.endpoint, {
const response = await fetch(options.engine.endpoint || DEFAULT_APOLLO_ENDPOINT, {
method: 'POST',
headers: {
'x-api-key': options.engine.apiKey,
Expand Down

0 comments on commit 68c14f5

Please sign in to comment.