From 3b8dd5a39bc75eed4ab6e03d4a4db533d17e5832 Mon Sep 17 00:00:00 2001 From: Luke Sanwick Date: Thu, 28 May 2020 22:56:08 -0700 Subject: [PATCH] Add default Apollo Engine endpoint 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. --- packages/loaders/apollo-engine/src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/loaders/apollo-engine/src/index.ts b/packages/loaders/apollo-engine/src/index.ts index f57e5446ba7..cb4a3f5b8ae 100644 --- a/packages/loaders/apollo-engine/src/index.ts +++ b/packages/loaders/apollo-engine/src/index.ts @@ -4,7 +4,7 @@ import { buildClientSchema } from 'graphql'; export interface ApolloEngineOptions extends SingleFileOptions { engine: { - endpoint: string; + endpoint?: string; apiKey: string; }; graph: string; @@ -12,6 +12,8 @@ export interface ApolloEngineOptions extends SingleFileOptions { headers?: Record; } +const DEFAULT_APOLLO_ENDPOINT = 'https://engine-graphql.apollographql.com/api/graphql'; + export class ApolloEngineLoader implements SchemaLoader { loaderId() { return 'apollo-engine'; @@ -26,7 +28,7 @@ export class ApolloEngineLoader implements SchemaLoader { } async load(_: 'apollo-engine', options: ApolloEngineOptions): Promise { - 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,