@graphql-tools/apollo-engine-loader 7.3.2-alpha-b93d3b57.0 → 7.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SCHEMA_QUERY = exports.ApolloEngineLoader = void 0;
4
- const tslib_1 = require("tslib");
5
- const utils_1 = require("@graphql-tools/utils");
6
- const fetch_1 = require("@whatwg-node/fetch");
7
- const sync_fetch_1 = tslib_1.__importDefault(require("sync-fetch"));
1
+ import { parseGraphQLSDL, AggregateError } from '@graphql-tools/utils';
2
+ import { fetch } from '@whatwg-node/fetch';
3
+ import syncFetch from 'sync-fetch';
8
4
  const DEFAULT_APOLLO_ENDPOINT = 'https://engine-graphql.apollographql.com/api/graphql';
9
5
  /**
10
6
  * This loader loads a schema from Apollo Engine
11
7
  */
12
- class ApolloEngineLoader {
8
+ export class ApolloEngineLoader {
13
9
  getFetchArgs(options) {
14
10
  return [
15
11
  options.engine.endpoint || DEFAULT_APOLLO_ENDPOINT,
@@ -25,7 +21,7 @@ class ApolloEngineLoader {
25
21
  ...options.headers,
26
22
  },
27
23
  body: JSON.stringify({
28
- query: exports.SCHEMA_QUERY,
24
+ query: SCHEMA_QUERY,
29
25
  variables: {
30
26
  id: options.graph,
31
27
  tag: options.variant,
@@ -45,12 +41,12 @@ class ApolloEngineLoader {
45
41
  return [];
46
42
  }
47
43
  const fetchArgs = this.getFetchArgs(options);
48
- const response = await (0, fetch_1.fetch)(...fetchArgs);
44
+ const response = await fetch(...fetchArgs);
49
45
  const { data, errors } = await response.json();
50
46
  if (errors) {
51
- throw new utils_1.AggregateError(errors, 'Introspection from Apollo Engine failed; \n ' + errors.map((e) => e.message).join('\n'));
47
+ throw new AggregateError(errors, 'Introspection from Apollo Engine failed; \n ' + errors.map((e) => e.message).join('\n'));
52
48
  }
53
- const source = (0, utils_1.parseGraphQLSDL)(pointer, data.service.schema.document, options);
49
+ const source = parseGraphQLSDL(pointer, data.service.schema.document, options);
54
50
  return [source];
55
51
  }
56
52
  loadSync(pointer, options) {
@@ -58,20 +54,19 @@ class ApolloEngineLoader {
58
54
  return [];
59
55
  }
60
56
  const fetchArgs = this.getFetchArgs(options);
61
- const response = (0, sync_fetch_1.default)(...fetchArgs);
57
+ const response = syncFetch(...fetchArgs);
62
58
  const { data, errors } = response.json();
63
59
  if (errors) {
64
- throw new utils_1.AggregateError(errors, 'Introspection from Apollo Engine failed; \n ' + errors.map((e) => e.message).join('\n'));
60
+ throw new AggregateError(errors, 'Introspection from Apollo Engine failed; \n ' + errors.map((e) => e.message).join('\n'));
65
61
  }
66
- const source = (0, utils_1.parseGraphQLSDL)(pointer, data.service.schema.document, options);
62
+ const source = parseGraphQLSDL(pointer, data.service.schema.document, options);
67
63
  return [source];
68
64
  }
69
65
  }
70
- exports.ApolloEngineLoader = ApolloEngineLoader;
71
66
  /**
72
67
  * @internal
73
68
  */
74
- exports.SCHEMA_QUERY = `
69
+ export const SCHEMA_QUERY = /* GraphQL */ `
75
70
  query GetSchemaByTag($tag: String!, $id: ID!) {
76
71
  service(id: $id) {
77
72
  ... on Service {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/apollo-engine-loader",
3
- "version": "7.3.2-alpha-b93d3b57.0",
3
+ "version": "7.3.2",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -0,0 +1,27 @@
1
+ import { Source, BaseLoaderOptions, Loader } from '@graphql-tools/utils';
2
+ /**
3
+ * Additional options for loading from Apollo Engine
4
+ */
5
+ export interface ApolloEngineOptions extends BaseLoaderOptions {
6
+ engine: {
7
+ endpoint?: string;
8
+ apiKey: string;
9
+ };
10
+ graph: string;
11
+ variant: string;
12
+ headers?: Record<string, string>;
13
+ }
14
+ /**
15
+ * This loader loads a schema from Apollo Engine
16
+ */
17
+ export declare class ApolloEngineLoader implements Loader<ApolloEngineOptions> {
18
+ private getFetchArgs;
19
+ canLoad(ptr: string): Promise<boolean>;
20
+ canLoadSync(ptr: string): boolean;
21
+ load(pointer: string, options: ApolloEngineOptions): Promise<Source[]>;
22
+ loadSync(pointer: string, options: ApolloEngineOptions): Source[];
23
+ }
24
+ /**
25
+ * @internal
26
+ */
27
+ export declare const SCHEMA_QUERY = "\n query GetSchemaByTag($tag: String!, $id: ID!) {\n service(id: $id) {\n ... on Service {\n __typename\n schema(tag: $tag) {\n document\n }\n }\n }\n }\n";