@aws-amplify/api-graphql 4.0.1-console-preview.a1c533e.0 → 4.0.1-console-preview.f7f118b.0

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.
Files changed (39) hide show
  1. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +2 -2
  2. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +2 -3
  3. package/lib/internals/InternalGraphQLAPI.js +92 -65
  4. package/lib/tsconfig.tsbuildinfo +290 -197
  5. package/lib/types/index.d.ts +4 -4
  6. package/lib/utils/errors/validation.d.ts +2 -3
  7. package/lib/utils/errors/validation.js +10 -10
  8. package/lib/utils/index.d.ts +1 -1
  9. package/lib/utils/index.js +2 -2
  10. package/lib/utils/resolveConfig.d.ts +8 -4
  11. package/lib/utils/resolveConfig.js +13 -7
  12. package/lib/utils/resolveLibraryOptions.d.ts +11 -0
  13. package/lib/utils/resolveLibraryOptions.js +13 -0
  14. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +2 -2
  15. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +3 -4
  16. package/lib-esm/internals/InternalGraphQLAPI.js +93 -66
  17. package/lib-esm/tsconfig.tsbuildinfo +290 -197
  18. package/lib-esm/types/index.d.ts +4 -4
  19. package/lib-esm/utils/errors/validation.d.ts +2 -3
  20. package/lib-esm/utils/errors/validation.js +10 -10
  21. package/lib-esm/utils/index.d.ts +1 -1
  22. package/lib-esm/utils/index.js +1 -1
  23. package/lib-esm/utils/resolveConfig.d.ts +8 -4
  24. package/lib-esm/utils/resolveConfig.js +13 -7
  25. package/lib-esm/utils/resolveLibraryOptions.d.ts +11 -0
  26. package/lib-esm/utils/resolveLibraryOptions.js +11 -0
  27. package/package.json +6 -7
  28. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +7 -6
  29. package/src/internals/InternalGraphQLAPI.ts +75 -31
  30. package/src/types/index.ts +7 -4
  31. package/src/utils/errors/validation.ts +10 -10
  32. package/src/utils/index.ts +1 -1
  33. package/src/utils/resolveConfig.ts +24 -9
  34. package/src/utils/resolveLibraryOptions.ts +13 -0
  35. package/lib/utils/resolveCredentials.d.ts +0 -12
  36. package/lib/utils/resolveCredentials.js +0 -22
  37. package/lib-esm/utils/resolveCredentials.d.ts +0 -12
  38. package/lib-esm/utils/resolveCredentials.js +0 -20
  39. package/src/utils/resolveCredentials.ts +0 -14
@@ -2,7 +2,7 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
2
2
  import { Source, DocumentNode, GraphQLError } from 'graphql';
3
3
  export { OperationTypeNode } from 'graphql';
4
4
  import { Observable } from 'rxjs';
5
- import { APIAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
5
+ import { GraphQLAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
6
6
  export { CONTROL_MSG, ConnectionState } from './PubSub';
7
7
  /**
8
8
  * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
@@ -10,7 +10,7 @@ export { CONTROL_MSG, ConnectionState } from './PubSub';
10
10
  export interface GraphQLOptions {
11
11
  query: string | DocumentNode;
12
12
  variables?: Record<string, DocumentType>;
13
- authMode?: APIAuthMode;
13
+ authMode?: GraphQLAuthMode;
14
14
  authToken?: string;
15
15
  /**
16
16
  * @deprecated This property should not be used
@@ -133,7 +133,7 @@ export declare type GraphqlSubscriptionMessage<T> = {
133
133
  };
134
134
  export interface AWSAppSyncRealTimeProviderOptions {
135
135
  appSyncGraphqlEndpoint?: string;
136
- authenticationType?: APIAuthMode;
136
+ authenticationType?: GraphQLAuthMode;
137
137
  query?: string;
138
138
  variables?: Record<string, unknown>;
139
139
  apiKey?: string;
@@ -165,7 +165,7 @@ export declare type GraphQLOperation = Source | string;
165
165
  export interface GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> {
166
166
  query: TYPED_GQL_STRING | DocumentNode;
167
167
  variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
168
- authMode?: APIAuthMode;
168
+ authMode?: GraphQLAuthMode;
169
169
  authToken?: string;
170
170
  /**
171
171
  * @deprecated This property should not be used
@@ -1,8 +1,7 @@
1
1
  import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';
2
2
  export declare enum APIValidationErrorCode {
3
- NoAppId = "NoAppId",
4
- NoCredentials = "NoCredentials",
3
+ NoAuthSession = "NoAuthSession",
5
4
  NoRegion = "NoRegion",
6
- NoDefaultAuthMode = "NoDefaultAuthMode"
5
+ NoCustomEndpoint = "NoCustomEndpoint"
7
6
  }
8
7
  export declare const validationErrorMap: AmplifyErrorMap<APIValidationErrorCode>;
@@ -5,22 +5,22 @@ var _a;
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var APIValidationErrorCode;
7
7
  (function (APIValidationErrorCode) {
8
- APIValidationErrorCode["NoAppId"] = "NoAppId";
9
- APIValidationErrorCode["NoCredentials"] = "NoCredentials";
8
+ APIValidationErrorCode["NoAuthSession"] = "NoAuthSession";
10
9
  APIValidationErrorCode["NoRegion"] = "NoRegion";
11
- APIValidationErrorCode["NoDefaultAuthMode"] = "NoDefaultAuthMode";
10
+ APIValidationErrorCode["NoCustomEndpoint"] = "NoCustomEndpoint";
12
11
  })(APIValidationErrorCode = exports.APIValidationErrorCode || (exports.APIValidationErrorCode = {}));
13
12
  exports.validationErrorMap = (_a = {},
14
- _a[APIValidationErrorCode.NoAppId] = {
15
- message: 'Missing application id.',
16
- },
17
- _a[APIValidationErrorCode.NoCredentials] = {
18
- message: 'Credentials should not be empty.',
13
+ _a[APIValidationErrorCode.NoAuthSession] = {
14
+ message: 'Auth session should not be empty.',
19
15
  },
16
+ // TODO: re-enable when working in all test environments:
17
+ // [APIValidationErrorCode.NoEndpoint]: {
18
+ // message: 'Missing endpoint',
19
+ // },
20
20
  _a[APIValidationErrorCode.NoRegion] = {
21
21
  message: 'Missing region.',
22
22
  },
23
- _a[APIValidationErrorCode.NoDefaultAuthMode] = {
24
- message: 'Missing default auth mode',
23
+ _a[APIValidationErrorCode.NoCustomEndpoint] = {
24
+ message: 'Custom endpoint region is present without custom endpoint.',
25
25
  },
26
26
  _a);
@@ -1,2 +1,2 @@
1
1
  export { resolveConfig } from './resolveConfig';
2
- export { resolveCredentials } from './resolveCredentials';
2
+ export { resolveLibraryOptions } from './resolveLibraryOptions';
@@ -4,5 +4,5 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  var resolveConfig_1 = require("./resolveConfig");
6
6
  exports.resolveConfig = resolveConfig_1.resolveConfig;
7
- var resolveCredentials_1 = require("./resolveCredentials");
8
- exports.resolveCredentials = resolveCredentials_1.resolveCredentials;
7
+ var resolveLibraryOptions_1 = require("./resolveLibraryOptions");
8
+ exports.resolveLibraryOptions = resolveLibraryOptions_1.resolveLibraryOptions;
@@ -1,8 +1,12 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
1
2
  /**
2
3
  * @internal
3
4
  */
4
- export declare const resolveConfig: () => {
5
- endpoint: string;
6
- region: string;
7
- defaultAuthMode: import("@aws-amplify/core/lib-esm/libraryUtils").APIAuthMode;
5
+ export declare const resolveConfig: (amplify: AmplifyClassV6) => {
6
+ apiKey: string | undefined;
7
+ customEndpoint: string | undefined;
8
+ customEndpointRegion: string | undefined;
9
+ defaultAuthMode: "apiKey" | "oidc" | "userPool" | "iam" | "lambda" | "none" | undefined;
10
+ endpoint: string | undefined;
11
+ region: string | undefined;
8
12
  };
@@ -2,16 +2,22 @@
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- var core_1 = require("@aws-amplify/core");
6
5
  var errors_1 = require("./errors");
7
6
  /**
8
7
  * @internal
9
8
  */
10
- exports.resolveConfig = function () {
9
+ exports.resolveConfig = function (amplify) {
11
10
  var _a, _b;
12
- var _c = (_b = (_a = core_1.Amplify.getConfig().API) === null || _a === void 0 ? void 0 : _a.GraphQL) !== null && _b !== void 0 ? _b : {}, region = _c.region, defaultAuthMode = _c.defaultAuthMode, endpoint = _c.endpoint;
13
- errors_1.assertValidationError(!!endpoint, errors_1.APIValidationErrorCode.NoAppId);
14
- errors_1.assertValidationError(!!region, errors_1.APIValidationErrorCode.NoRegion);
15
- errors_1.assertValidationError(!!defaultAuthMode, errors_1.APIValidationErrorCode.NoDefaultAuthMode);
16
- return { endpoint: endpoint, region: region, defaultAuthMode: defaultAuthMode };
11
+ var _c = (_b = (_a = amplify.getConfig().API) === null || _a === void 0 ? void 0 : _a.GraphQL) !== null && _b !== void 0 ? _b : {}, apiKey = _c.apiKey, customEndpoint = _c.customEndpoint, customEndpointRegion = _c.customEndpointRegion, defaultAuthMode = _c.defaultAuthMode, endpoint = _c.endpoint, region = _c.region;
12
+ // TODO: re-enable when working in all test environments:
13
+ // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);
14
+ errors_1.assertValidationError(!(!customEndpoint && customEndpointRegion), errors_1.APIValidationErrorCode.NoCustomEndpoint);
15
+ return {
16
+ apiKey: apiKey,
17
+ customEndpoint: customEndpoint,
18
+ customEndpointRegion: customEndpointRegion,
19
+ defaultAuthMode: defaultAuthMode,
20
+ endpoint: endpoint,
21
+ region: region,
22
+ };
17
23
  };
@@ -0,0 +1,11 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const resolveLibraryOptions: (amplify: AmplifyClassV6) => {
6
+ headers: ((options: {
7
+ query: string;
8
+ variables?: Record<string, import("@aws-amplify/core/lib-esm/libraryUtils").DocumentType> | undefined;
9
+ }) => Promise<Record<string, string>>) | undefined;
10
+ withCredentials: boolean | undefined;
11
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ /**
6
+ * @internal
7
+ */
8
+ exports.resolveLibraryOptions = function (amplify) {
9
+ var _a, _b, _c, _d, _e, _f;
10
+ var headers = (_c = (_b = (_a = amplify.libraryOptions) === null || _a === void 0 ? void 0 : _a.API) === null || _b === void 0 ? void 0 : _b.GraphQL) === null || _c === void 0 ? void 0 : _c.headers;
11
+ var withCredentials = (_f = (_e = (_d = amplify.libraryOptions) === null || _d === void 0 ? void 0 : _d.API) === null || _e === void 0 ? void 0 : _e.GraphQL) === null || _f === void 0 ? void 0 : _f.withCredentials;
12
+ return { headers: headers, withCredentials: withCredentials };
13
+ };
@@ -1,5 +1,5 @@
1
1
  import { Observable } from 'rxjs';
2
- import { APIAuthMode, CustomUserAgentDetails, DocumentType } from '@aws-amplify/core/internals/utils';
2
+ import { GraphQLAuthMode, CustomUserAgentDetails, DocumentType } from '@aws-amplify/core/internals/utils';
3
3
  import { PubSubContentObserver } from '../../types/PubSub';
4
4
  import { SUBSCRIPTION_STATUS } from '../constants';
5
5
  export declare type ObserverQuery = {
@@ -13,7 +13,7 @@ export declare type ObserverQuery = {
13
13
  };
14
14
  export interface AWSAppSyncRealTimeProviderOptions {
15
15
  appSyncGraphqlEndpoint?: string;
16
- authenticationType?: APIAuthMode;
16
+ authenticationType?: GraphQLAuthMode;
17
17
  query?: string;
18
18
  variables?: Record<string, DocumentType>;
19
19
  apiKey?: string;
@@ -4,11 +4,10 @@ import { __assign, __awaiter, __generator, __read } from "tslib";
4
4
  import { Observable } from 'rxjs';
5
5
  import { GraphQLError } from 'graphql';
6
6
  import * as url from 'url';
7
- import { v4 as uuid } from 'uuid';
8
7
  import { Buffer } from 'buffer';
9
8
  import { Hub, fetchAuthSession } from '@aws-amplify/core';
10
9
  import { signRequest } from '@aws-amplify/core/internals/aws-client-utils';
11
- import { Logger, NonRetryableError, USER_AGENT_HEADER, getAmplifyUserAgent, isNonRetryableError, jitteredExponentialRetry, } from '@aws-amplify/core/internals/utils';
10
+ import { Logger, NonRetryableError, USER_AGENT_HEADER, getAmplifyUserAgent, isNonRetryableError, jitteredExponentialRetry, amplifyUuid, AmplifyUrl, } from '@aws-amplify/core/internals/utils';
12
11
  import { CONTROL_MSG, ConnectionState, } from '../../types/PubSub';
13
12
  import { AMPLIFY_SYMBOL, AWS_APPSYNC_REALTIME_HEADERS, CONNECTION_INIT_TIMEOUT, DEFAULT_KEEP_ALIVE_TIMEOUT, DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT, MAX_DELAY_MS, MESSAGE_TYPES, NON_RETRYABLE_CODES, SOCKET_STATUS, START_ACK_TIMEOUT, SUBSCRIPTION_STATUS, CONNECTION_STATE_CHANGE, } from '../constants';
14
13
  import { ConnectionStateMonitor, CONNECTION_CHANGE, } from '../../utils/ConnectionStateMonitor';
@@ -95,7 +94,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
95
94
  }
96
95
  else {
97
96
  var subscriptionStartActive_1 = false;
98
- var subscriptionId_1 = uuid();
97
+ var subscriptionId_1 = amplifyUuid();
99
98
  var startSubscription_1 = function () {
100
99
  if (!subscriptionStartActive_1) {
101
100
  subscriptionStartActive_1 = true;
@@ -776,7 +775,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
776
775
  signed_params = signRequest({
777
776
  headers: request.headers,
778
777
  method: request.method,
779
- url: new URL(request.url),
778
+ url: new AmplifyUrl(request.url),
780
779
  body: request.data,
781
780
  }, {
782
781
  // TODO: What do we need to do to remove these !'s?
@@ -2,11 +2,12 @@ import { __assign, __awaiter, __generator, __read } from "tslib";
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import { print, parse, GraphQLError, } from 'graphql';
5
- import { ConsoleLogger as Logger, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils';
5
+ import { ConsoleLogger as Logger, getAmplifyUserAgent, AmplifyUrl, } from '@aws-amplify/core/internals/utils';
6
6
  import { GraphQLAuthError, } from '../types';
7
7
  import { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';
8
8
  import { post, cancel as cancelREST, updateRequestToBeCancellable, } from '@aws-amplify/api-rest/internals';
9
9
  import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
10
+ import { resolveConfig, resolveLibraryOptions } from '../utils';
10
11
  var USER_AGENT_HEADER = 'x-amz-user-agent';
11
12
  var logger = new Logger('GraphQLAPI');
12
13
  export var graphqlOperation = function (query, variables, authToken) {
@@ -26,7 +27,12 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
26
27
  * @param {Object} options - Configuration object for API
27
28
  */
28
29
  function InternalGraphQLAPIClass(options) {
29
- this._api = { post: post, updateRequestToBeCancellable: updateRequestToBeCancellable };
30
+ this._api = {
31
+ post: post,
32
+ cancelREST: cancelREST,
33
+ isCancelErrorREST: isCancelErrorREST,
34
+ updateRequestToBeCancellable: updateRequestToBeCancellable,
35
+ };
30
36
  this._options = options;
31
37
  logger.debug('API Options', this._options);
32
38
  }
@@ -35,18 +41,18 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
35
41
  };
36
42
  InternalGraphQLAPIClass.prototype._headerBasedAuth = function (amplify, authMode, additionalHeaders) {
37
43
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
38
- var _a, _b;
44
+ var _a;
39
45
  return __awaiter(this, void 0, void 0, function () {
40
- var config, _c, region, appSyncGraphqlEndpoint, apiKey, defaultAuthMode, authenticationType, headers, _d, session, token, e_1;
41
- return __generator(this, function (_e) {
42
- switch (_e.label) {
46
+ var config, _b, region, appSyncGraphqlEndpoint, apiKey, defaultAuthMode, authenticationType, headers, _c, session, token, e_1;
47
+ return __generator(this, function (_d) {
48
+ switch (_d.label) {
43
49
  case 0:
44
50
  config = amplify.getConfig();
45
- _c = ((_a = config.API) === null || _a === void 0 ? void 0 : _a.GraphQL) || {}, region = _c.region, appSyncGraphqlEndpoint = _c.endpoint, apiKey = _c.apiKey, defaultAuthMode = _c.defaultAuthMode;
51
+ _b = resolveConfig(amplify), region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, apiKey = _b.apiKey, defaultAuthMode = _b.defaultAuthMode;
46
52
  authenticationType = authMode || defaultAuthMode || 'iam';
47
53
  headers = {};
48
- _d = authenticationType;
49
- switch (_d) {
54
+ _c = authenticationType;
55
+ switch (_c) {
50
56
  case 'apiKey': return [3 /*break*/, 1];
51
57
  case 'iam': return [3 /*break*/, 2];
52
58
  case 'oidc': return [3 /*break*/, 4];
@@ -65,17 +71,17 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
65
71
  return [3 /*break*/, 11];
66
72
  case 2: return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
67
73
  case 3:
68
- session = _e.sent();
74
+ session = _d.sent();
69
75
  if (session.credentials === undefined) {
70
76
  throw new Error(GraphQLAuthError.NO_CREDENTIALS);
71
77
  }
72
78
  return [3 /*break*/, 11];
73
79
  case 4:
74
- _e.trys.push([4, 6, , 7]);
80
+ _d.trys.push([4, 6, , 7]);
75
81
  token = void 0;
76
82
  return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
77
83
  case 5:
78
- token = (_b = (_e.sent()).tokens) === null || _b === void 0 ? void 0 : _b.accessToken.toString();
84
+ token = (_a = (_d.sent()).tokens) === null || _a === void 0 ? void 0 : _a.accessToken.toString();
79
85
  if (!token) {
80
86
  throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);
81
87
  }
@@ -84,7 +90,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
84
90
  };
85
91
  return [3 /*break*/, 7];
86
92
  case 6:
87
- e_1 = _e.sent();
93
+ e_1 = _d.sent();
88
94
  throw new Error(GraphQLAuthError.NO_CURRENT_USER);
89
95
  case 7: return [3 /*break*/, 11];
90
96
  case 8:
@@ -96,11 +102,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
96
102
  };
97
103
  return [3 /*break*/, 11];
98
104
  case 9: return [3 /*break*/, 11];
99
- case 10:
100
- headers = {
101
- Authorization: null,
102
- };
103
- return [3 /*break*/, 11];
105
+ case 10: return [3 /*break*/, 11];
104
106
  case 11: return [2 /*return*/, headers];
105
107
  }
106
108
  });
@@ -151,49 +153,77 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
151
153
  InternalGraphQLAPIClass.prototype._graphql = function (amplify, _a, additionalHeaders, abortController, customUserAgentDetails) {
152
154
  var query = _a.query, variables = _a.variables, authMode = _a.authMode;
153
155
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
154
- var _b;
155
156
  return __awaiter(this, void 0, void 0, function () {
156
- var config, _c, region, appSyncGraphqlEndpoint, customGraphqlEndpoint, customEndpointRegion, headers, _d, _e, _f, _g, _h, body, endpoint, error, response, responseBody, result, err_1, errors;
157
- var _j;
158
- return __generator(this, function (_k) {
159
- switch (_k.label) {
157
+ var _b, region, appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, _c, customHeaders, withCredentials, headers, _d, _e, _f, _g, _h, _j, _k, body, signingServiceInfo, endpoint, error, response, responseBody, result, err_1, errors;
158
+ var _l;
159
+ return __generator(this, function (_m) {
160
+ switch (_m.label) {
160
161
  case 0:
161
- config = amplify.getConfig();
162
- _c = ((_b = config.API) === null || _b === void 0 ? void 0 : _b.GraphQL) || {}, region = _c.region, appSyncGraphqlEndpoint = _c.endpoint;
163
- customGraphqlEndpoint = null;
164
- customEndpointRegion = null;
162
+ _b = resolveConfig(amplify), region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, customEndpoint = _b.customEndpoint, customEndpointRegion = _b.customEndpointRegion;
163
+ _c = resolveLibraryOptions(amplify), customHeaders = _c.headers, withCredentials = _c.withCredentials;
165
164
  _d = [{}];
166
- _e = !customGraphqlEndpoint;
165
+ _e = !customEndpoint;
167
166
  if (!_e) return [3 /*break*/, 2];
168
167
  return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
169
168
  case 1:
170
- _e = (_k.sent());
171
- _k.label = 2;
169
+ _e = (_m.sent());
170
+ _m.label = 2;
172
171
  case 2:
173
172
  _f = [__assign.apply(void 0, _d.concat([(_e)]))];
174
- _g = customGraphqlEndpoint;
173
+ _g = customEndpoint;
175
174
  if (!_g) return [3 /*break*/, 6];
176
175
  if (!customEndpointRegion) return [3 /*break*/, 4];
177
176
  return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
178
177
  case 3:
179
- _h = _k.sent();
178
+ _h = _m.sent();
180
179
  return [3 /*break*/, 5];
181
180
  case 4:
182
- _h = { Authorization: null };
183
- _k.label = 5;
181
+ _h = {};
182
+ _m.label = 5;
184
183
  case 5:
185
184
  _g = (_h);
186
- _k.label = 6;
185
+ _m.label = 6;
187
186
  case 6:
188
- headers = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _f.concat([((_g) ||
189
- {})])), additionalHeaders]), (!customGraphqlEndpoint && (_j = {},
190
- _j[USER_AGENT_HEADER] = getAmplifyUserAgent(customUserAgentDetails),
191
- _j))]);
187
+ _j = [__assign.apply(void 0, _f.concat([((_g) ||
188
+ {})]))];
189
+ _k = customHeaders;
190
+ if (!_k) return [3 /*break*/, 8];
191
+ return [4 /*yield*/, customHeaders({
192
+ query: print(query),
193
+ variables: variables,
194
+ })];
195
+ case 7:
196
+ _k = (_m.sent());
197
+ _m.label = 8;
198
+ case 8:
199
+ headers = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _j.concat([(_k)])), additionalHeaders]), (!customEndpoint && (_l = {},
200
+ _l[USER_AGENT_HEADER] = getAmplifyUserAgent(customUserAgentDetails),
201
+ _l))]);
192
202
  body = {
193
203
  query: print(query),
194
204
  variables: variables || null,
195
205
  };
196
- endpoint = customGraphqlEndpoint || appSyncGraphqlEndpoint;
206
+ /**
207
+ * We do not send the signing service info to the REST API under the
208
+ * following conditions (i.e. it will not sign the request):
209
+ * - there is a custom endpoint but no region
210
+ * - the auth mode is `none`, or `apiKey`
211
+ * - the auth mode is a type other than the types listed below
212
+ */
213
+ if ((customEndpoint && !customEndpointRegion) ||
214
+ (authMode !== 'oidc' &&
215
+ authMode !== 'userPool' &&
216
+ authMode !== 'iam' &&
217
+ authMode !== 'lambda')) {
218
+ signingServiceInfo = null;
219
+ }
220
+ else {
221
+ signingServiceInfo = {
222
+ service: !customEndpointRegion ? 'appsync' : 'execute-api',
223
+ region: !customEndpointRegion ? region : customEndpointRegion,
224
+ };
225
+ }
226
+ endpoint = customEndpoint || appSyncGraphqlEndpoint;
197
227
  if (!endpoint) {
198
228
  error = new GraphQLError('No graphql endpoint provided.');
199
229
  throw {
@@ -201,42 +231,40 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
201
231
  errors: [error],
202
232
  };
203
233
  }
204
- _k.label = 7;
205
- case 7:
206
- _k.trys.push([7, 10, , 11]);
234
+ _m.label = 9;
235
+ case 9:
236
+ _m.trys.push([9, 12, , 13]);
207
237
  return [4 /*yield*/, this._api.post({
208
- url: new URL(endpoint),
238
+ url: new AmplifyUrl(endpoint),
209
239
  options: {
210
240
  headers: headers,
211
241
  body: body,
212
- signingServiceInfo: {
213
- service: 'appsync',
214
- region: region,
215
- },
242
+ signingServiceInfo: signingServiceInfo,
243
+ withCredentials: withCredentials,
216
244
  },
217
245
  abortController: abortController,
218
246
  })];
219
- case 8:
220
- responseBody = (_k.sent()).body;
247
+ case 10:
248
+ responseBody = (_m.sent()).body;
221
249
  return [4 /*yield*/, responseBody.json()];
222
- case 9:
223
- result = _k.sent();
250
+ case 11:
251
+ result = _m.sent();
224
252
  response = result;
225
- return [3 /*break*/, 11];
226
- case 10:
227
- err_1 = _k.sent();
253
+ return [3 /*break*/, 13];
254
+ case 12:
255
+ err_1 = _m.sent();
228
256
  // If the exception is because user intentionally
229
257
  // cancelled the request, do not modify the exception
230
258
  // so that clients can identify the exception correctly.
231
- if (isCancelErrorREST(err_1)) {
259
+ if (this._api.isCancelErrorREST(err_1)) {
232
260
  throw err_1;
233
261
  }
234
262
  response = {
235
263
  data: {},
236
264
  errors: [new GraphQLError(err_1.message, null, null, null, null, err_1)],
237
265
  };
238
- return [3 /*break*/, 11];
239
- case 11:
266
+ return [3 /*break*/, 13];
267
+ case 13:
240
268
  errors = response.errors;
241
269
  if (errors && errors.length) {
242
270
  throw response;
@@ -252,7 +280,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
252
280
  * @return {boolean} - A boolean indicating if the error was from an api request cancellation
253
281
  */
254
282
  InternalGraphQLAPIClass.prototype.isCancelError = function (error) {
255
- return isCancelErrorREST(error);
283
+ return this._api.isCancelErrorREST(error);
256
284
  };
257
285
  /**
258
286
  * Cancels an inflight request. Only applicable for graphql queries and mutations
@@ -260,23 +288,22 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
260
288
  * @returns - A boolean indicating if the request was cancelled
261
289
  */
262
290
  InternalGraphQLAPIClass.prototype.cancel = function (request, message) {
263
- return cancelREST(request, message);
291
+ return this._api.cancelREST(request, message);
264
292
  };
265
293
  InternalGraphQLAPIClass.prototype._graphqlSubscribe = function (amplify, _a, additionalHeaders, customUserAgentDetails) {
266
294
  var query = _a.query, variables = _a.variables, authMode = _a.authMode;
267
295
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
268
- var _b;
269
- var GraphQL = ((_b = amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).GraphQL;
296
+ var config = resolveConfig(amplify);
270
297
  if (!this.appSyncRealTime) {
271
298
  this.appSyncRealTime = new AWSAppSyncRealTimeProvider();
272
299
  }
273
300
  return this.appSyncRealTime.subscribe({
274
301
  query: print(query),
275
302
  variables: variables,
276
- appSyncGraphqlEndpoint: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.endpoint,
277
- region: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.region,
278
- authenticationType: authMode !== null && authMode !== void 0 ? authMode : GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.defaultAuthMode,
279
- apiKey: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.apiKey,
303
+ appSyncGraphqlEndpoint: config === null || config === void 0 ? void 0 : config.endpoint,
304
+ region: config === null || config === void 0 ? void 0 : config.region,
305
+ authenticationType: config === null || config === void 0 ? void 0 : config.defaultAuthMode,
306
+ apiKey: config === null || config === void 0 ? void 0 : config.apiKey,
280
307
  additionalHeaders: additionalHeaders,
281
308
  }, customUserAgentDetails);
282
309
  };