@aws-amplify/api-graphql 4.0.1-console-preview.11cf989.0 → 4.0.1-console-preview.4ae78ed.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 (36) hide show
  1. package/lib/GraphQLAPI.d.ts +12 -0
  2. package/lib/GraphQLAPI.js +16 -0
  3. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +3 -4
  4. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +17 -14
  5. package/lib/internals/InternalGraphQLAPI.d.ts +12 -0
  6. package/lib/internals/InternalGraphQLAPI.js +80 -39
  7. package/lib/internals/index.d.ts +1 -1
  8. package/lib/internals/index.js +2 -0
  9. package/lib/internals/v6.d.ts +12 -0
  10. package/lib/internals/v6.js +18 -0
  11. package/lib/tsconfig.tsbuildinfo +1064 -871
  12. package/lib/types/index.d.ts +4 -5
  13. package/lib/utils/resolveConfig.d.ts +1 -1
  14. package/lib/utils/resolveConfig.js +1 -1
  15. package/lib-esm/GraphQLAPI.d.ts +12 -0
  16. package/lib-esm/GraphQLAPI.js +16 -0
  17. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +3 -4
  18. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +17 -14
  19. package/lib-esm/internals/InternalGraphQLAPI.d.ts +12 -0
  20. package/lib-esm/internals/InternalGraphQLAPI.js +81 -40
  21. package/lib-esm/internals/index.d.ts +1 -1
  22. package/lib-esm/internals/index.js +1 -1
  23. package/lib-esm/internals/v6.d.ts +12 -0
  24. package/lib-esm/internals/v6.js +16 -0
  25. package/lib-esm/tsconfig.tsbuildinfo +1064 -871
  26. package/lib-esm/types/index.d.ts +4 -5
  27. package/lib-esm/utils/resolveConfig.d.ts +1 -1
  28. package/lib-esm/utils/resolveConfig.js +1 -1
  29. package/package.json +6 -5
  30. package/src/GraphQLAPI.ts +18 -0
  31. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +28 -29
  32. package/src/internals/InternalGraphQLAPI.ts +86 -42
  33. package/src/internals/index.ts +1 -1
  34. package/src/internals/v6.ts +18 -0
  35. package/src/types/index.ts +4 -5
  36. package/src/utils/resolveConfig.ts +1 -1
@@ -21,5 +21,17 @@ export declare class GraphQLAPIClass extends InternalGraphQLAPIClass {
21
21
  graphql<T = any>(options: GraphQLOptions, additionalHeaders?: {
22
22
  [key: string]: string;
23
23
  }): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
24
+ /**
25
+ * Checks to see if an error thrown is from an api request cancellation
26
+ * @param error - Any error
27
+ * @returns A boolean indicating if the error was from an api request cancellation
28
+ */
29
+ isCancelError(error: any): boolean;
30
+ /**
31
+ * Cancels an inflight request. Only applicable for graphql queries and mutations
32
+ * @param {any} request - request to cancel
33
+ * @returns A boolean indicating if the request was cancelled
34
+ */
35
+ cancel(request: Promise<any>, message?: string): boolean;
24
36
  }
25
37
  export declare const GraphQLAPI: GraphQLAPIClass;
package/lib/GraphQLAPI.js CHANGED
@@ -31,6 +31,22 @@ var GraphQLAPIClass = /** @class */ (function (_super) {
31
31
  GraphQLAPIClass.prototype.graphql = function (options, additionalHeaders) {
32
32
  return _super.prototype.graphql.call(this, options, additionalHeaders);
33
33
  };
34
+ /**
35
+ * Checks to see if an error thrown is from an api request cancellation
36
+ * @param error - Any error
37
+ * @returns A boolean indicating if the error was from an api request cancellation
38
+ */
39
+ GraphQLAPIClass.prototype.isCancelError = function (error) {
40
+ return _super.prototype.isCancelError.call(this, error);
41
+ };
42
+ /**
43
+ * Cancels an inflight request. Only applicable for graphql queries and mutations
44
+ * @param {any} request - request to cancel
45
+ * @returns A boolean indicating if the request was cancelled
46
+ */
47
+ GraphQLAPIClass.prototype.cancel = function (request, message) {
48
+ return _super.prototype.cancel.call(this, request, message);
49
+ };
34
50
  return GraphQLAPIClass;
35
51
  }(internals_1.InternalGraphQLAPIClass));
36
52
  exports.GraphQLAPIClass = GraphQLAPIClass;
@@ -1,8 +1,7 @@
1
1
  import { Observable } from 'rxjs';
2
+ import { APIAuthMode, CustomUserAgentDetails, DocumentType } from '@aws-amplify/core/internals/utils';
2
3
  import { PubSubContentObserver } from '../../types/PubSub';
3
4
  import { SUBSCRIPTION_STATUS } from '../constants';
4
- import { CustomUserAgentDetails, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
5
- import { DocumentType } from '@aws-amplify/api-rest';
6
5
  export declare type ObserverQuery = {
7
6
  observer: PubSubContentObserver;
8
7
  query: string;
@@ -14,7 +13,7 @@ export declare type ObserverQuery = {
14
13
  };
15
14
  export interface AWSAppSyncRealTimeProviderOptions {
16
15
  appSyncGraphqlEndpoint?: string;
17
- authenticationType?: GraphQLAuthMode;
16
+ authenticationType?: APIAuthMode;
18
17
  query?: string;
19
18
  variables?: Record<string, DocumentType>;
20
19
  apiKey?: string;
@@ -58,7 +57,7 @@ export declare class AWSAppSyncRealTimeProvider {
58
57
  private _initializeRetryableHandshake;
59
58
  private _initializeHandshake;
60
59
  private _awsRealTimeHeaderBasedAuth;
61
- private _awsRealTimeOPENIDHeader;
60
+ private _awsAuthTokenHeader;
62
61
  private _awsRealTimeApiKeyHeader;
63
62
  private _awsRealTimeIAMHeader;
64
63
  private _customAuthHeader;
@@ -9,12 +9,12 @@ var url = tslib_1.__importStar(require("url"));
9
9
  var uuid_1 = require("uuid");
10
10
  var buffer_1 = require("buffer");
11
11
  var core_1 = require("@aws-amplify/core");
12
- var PubSub_1 = require("../../types/PubSub");
13
12
  var aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
13
+ var utils_1 = require("@aws-amplify/core/internals/utils");
14
+ var PubSub_1 = require("../../types/PubSub");
14
15
  var constants_1 = require("../constants");
15
16
  var ConnectionStateMonitor_1 = require("../../utils/ConnectionStateMonitor");
16
17
  var ReconnectionMonitor_1 = require("../../utils/ReconnectionMonitor");
17
- var utils_1 = require("@aws-amplify/core/internals/utils");
18
18
  var logger = new utils_1.Logger('AWSAppSyncRealTimeProvider');
19
19
  var dispatchApiEvent = function (payload) {
20
20
  core_1.Hub.dispatch('api', payload, 'PubSub', constants_1.AMPLIFY_SYMBOL);
@@ -85,7 +85,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
85
85
  };
86
86
  AWSAppSyncRealTimeProvider.prototype.subscribe = function (options, customUserAgentDetails) {
87
87
  var _this = this;
88
- var _a = options || {}, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, query = _a.query, variables = _a.variables, authenticationType = _a.authenticationType, additionalHeaders = _a.additionalHeaders;
88
+ var _a = options || {}, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, query = _a.query, variables = _a.variables, authenticationType = _a.authenticationType, additionalHeaders = _a.additionalHeaders, apiKey = _a.apiKey;
89
89
  return new rxjs_1.Observable(function (observer) {
90
90
  if (!options || !appSyncGraphqlEndpoint) {
91
91
  observer.error({
@@ -109,6 +109,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
109
109
  authenticationType: authenticationType,
110
110
  appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
111
111
  additionalHeaders: additionalHeaders,
112
+ apiKey: apiKey,
112
113
  },
113
114
  observer: observer,
114
115
  subscriptionId: subscriptionId_1,
@@ -680,34 +681,36 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
680
681
  });
681
682
  };
682
683
  AWSAppSyncRealTimeProvider.prototype._awsRealTimeHeaderBasedAuth = function (_a) {
683
- var authenticationType = _a.authenticationType, payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, additionalHeaders = _a.additionalHeaders;
684
+ var apiKey = _a.apiKey, authenticationType = _a.authenticationType, payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, additionalHeaders = _a.additionalHeaders;
684
685
  return tslib_1.__awaiter(this, void 0, void 0, function () {
685
- var headerHandler, handler, host, apiKey, result;
686
+ var headerHandler, handler, host, resolvedApiKey, result;
686
687
  return tslib_1.__generator(this, function (_b) {
687
688
  switch (_b.label) {
688
689
  case 0:
689
690
  headerHandler = {
690
691
  apiKey: this._awsRealTimeApiKeyHeader.bind(this),
691
692
  iam: this._awsRealTimeIAMHeader.bind(this),
692
- jwt: this._awsRealTimeOPENIDHeader.bind(this),
693
- custom: this._customAuthHeader,
693
+ oidc: this._awsAuthTokenHeader.bind(this),
694
+ userPool: this._awsAuthTokenHeader.bind(this),
695
+ lambda: this._customAuthHeader,
696
+ none: this._customAuthHeader,
694
697
  };
695
- if (!(!authenticationType || !headerHandler[authenticationType.type])) return [3 /*break*/, 1];
698
+ if (!(!authenticationType || !headerHandler[authenticationType])) return [3 /*break*/, 1];
696
699
  logger.debug("Authentication type " + authenticationType + " not supported");
697
700
  return [2 /*return*/, undefined];
698
701
  case 1:
699
- handler = headerHandler[authenticationType.type];
702
+ handler = headerHandler[authenticationType];
700
703
  host = url.parse(appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
701
704
  logger.debug("Authenticating with " + JSON.stringify(authenticationType));
702
- apiKey = void 0;
703
- if (authenticationType.type === 'apiKey') {
704
- apiKey = authenticationType.apiKey;
705
+ resolvedApiKey = void 0;
706
+ if (authenticationType === 'apiKey') {
707
+ resolvedApiKey = apiKey;
705
708
  }
706
709
  return [4 /*yield*/, handler({
707
710
  payload: payload,
708
711
  canonicalUri: canonicalUri,
709
712
  appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
710
- apiKey: apiKey,
713
+ apiKey: resolvedApiKey,
711
714
  region: region,
712
715
  host: host,
713
716
  additionalHeaders: additionalHeaders,
@@ -719,7 +722,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
719
722
  });
720
723
  });
721
724
  };
722
- AWSAppSyncRealTimeProvider.prototype._awsRealTimeOPENIDHeader = function (_a) {
725
+ AWSAppSyncRealTimeProvider.prototype._awsAuthTokenHeader = function (_a) {
723
726
  var host = _a.host;
724
727
  var _b, _c;
725
728
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -41,6 +41,18 @@ export declare class InternalGraphQLAPIClass {
41
41
  [key: string]: string;
42
42
  }, customUserAgentDetails?: CustomUserAgentDetails): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
43
43
  private _graphql;
44
+ /**
45
+ * Checks to see if an error thrown is from an api request cancellation
46
+ * @param {any} error - Any error
47
+ * @return {boolean} - A boolean indicating if the error was from an api request cancellation
48
+ */
49
+ isCancelError(error: any): boolean;
50
+ /**
51
+ * Cancels an inflight request. Only applicable for graphql queries and mutations
52
+ * @param {any} request - request to cancel
53
+ * @returns - A boolean indicating if the request was cancelled
54
+ */
55
+ cancel(request: Promise<any>, message?: string): boolean;
44
56
  private _graphqlSubscribe;
45
57
  }
46
58
  export declare const InternalGraphQLAPI: InternalGraphQLAPIClass;
@@ -8,6 +8,7 @@ var core_1 = require("@aws-amplify/core");
8
8
  var utils_1 = require("@aws-amplify/core/internals/utils");
9
9
  var types_1 = require("../types");
10
10
  var api_rest_1 = require("@aws-amplify/api-rest");
11
+ var internals_1 = require("@aws-amplify/api-rest/internals");
11
12
  var AWSAppSyncRealTimeProvider_1 = require("../Providers/AWSAppSyncRealTimeProvider");
12
13
  var USER_AGENT_HEADER = 'x-amz-user-agent';
13
14
  var logger = new utils_1.ConsoleLogger('GraphQLAPI');
@@ -29,47 +30,50 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
29
30
  */
30
31
  function InternalGraphQLAPIClass(options) {
31
32
  this.Cache = core_1.Cache;
32
- this._api = { post: api_rest_1.post };
33
+ this._api = { post: internals_1.post, updateRequestToBeCancellable: internals_1.updateRequestToBeCancellable };
33
34
  this._options = options;
34
35
  logger.debug('API Options', this._options);
35
36
  }
36
37
  InternalGraphQLAPIClass.prototype.getModuleName = function () {
37
38
  return 'InternalGraphQLAPI';
38
39
  };
39
- InternalGraphQLAPIClass.prototype._headerBasedAuth = function (defaultAuthenticationType, additionalHeaders, customUserAgentDetails) {
40
+ InternalGraphQLAPIClass.prototype._headerBasedAuth = function (authMode, additionalHeaders) {
40
41
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
41
42
  var _a;
42
43
  return tslib_1.__awaiter(this, void 0, void 0, function () {
43
- var config, _b, region, appSyncGraphqlEndpoint, authenticationType, headers, _c, session, token, e_1;
44
+ var config, _b, region, appSyncGraphqlEndpoint, apiKey, defaultAuthMode, authenticationType, headers, _c, session, token, e_1;
44
45
  return tslib_1.__generator(this, function (_d) {
45
46
  switch (_d.label) {
46
47
  case 0:
47
48
  config = core_1.Amplify.getConfig();
48
- _b = config.API.AppSync, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, authenticationType = _b.defaultAuthMode;
49
+ _b = config.API.GraphQL, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, apiKey = _b.apiKey, defaultAuthMode = _b.defaultAuthMode;
50
+ authenticationType = authMode || defaultAuthMode || 'iam';
49
51
  headers = {};
50
- _c = authenticationType.type;
52
+ _c = authenticationType;
51
53
  switch (_c) {
52
54
  case 'apiKey': return [3 /*break*/, 1];
53
55
  case 'iam': return [3 /*break*/, 2];
54
- case 'jwt': return [3 /*break*/, 4];
55
- case 'custom': return [3 /*break*/, 8];
56
+ case 'oidc': return [3 /*break*/, 4];
57
+ case 'userPool': return [3 /*break*/, 4];
58
+ case 'lambda': return [3 /*break*/, 8];
59
+ case 'none': return [3 /*break*/, 9];
56
60
  }
57
- return [3 /*break*/, 9];
61
+ return [3 /*break*/, 10];
58
62
  case 1:
59
- if (!authenticationType.apiKey) {
63
+ if (!apiKey) {
60
64
  throw new Error(types_1.GraphQLAuthError.NO_API_KEY);
61
65
  }
62
66
  headers = {
63
- 'X-Api-Key': authenticationType.apiKey,
67
+ 'X-Api-Key': apiKey,
64
68
  };
65
- return [3 /*break*/, 10];
69
+ return [3 /*break*/, 11];
66
70
  case 2: return [4 /*yield*/, core_1.fetchAuthSession()];
67
71
  case 3:
68
72
  session = _d.sent();
69
73
  if (session.credentials === undefined) {
70
74
  throw new Error(types_1.GraphQLAuthError.NO_CREDENTIALS);
71
75
  }
72
- return [3 /*break*/, 10];
76
+ return [3 /*break*/, 11];
73
77
  case 4:
74
78
  _d.trys.push([4, 6, , 7]);
75
79
  token = void 0;
@@ -86,7 +90,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
86
90
  case 6:
87
91
  e_1 = _d.sent();
88
92
  throw new Error(types_1.GraphQLAuthError.NO_CURRENT_USER);
89
- case 7: return [3 /*break*/, 10];
93
+ case 7: return [3 /*break*/, 11];
90
94
  case 8:
91
95
  if (!additionalHeaders.Authorization) {
92
96
  throw new Error(types_1.GraphQLAuthError.NO_AUTH_TOKEN);
@@ -94,13 +98,14 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
94
98
  headers = {
95
99
  Authorization: additionalHeaders.Authorization,
96
100
  };
97
- return [3 /*break*/, 10];
98
- case 9:
101
+ return [3 /*break*/, 11];
102
+ case 9: return [3 /*break*/, 11];
103
+ case 10:
99
104
  headers = {
100
105
  Authorization: null,
101
106
  };
102
- return [3 /*break*/, 10];
103
- case 10: return [2 /*return*/, headers];
107
+ return [3 /*break*/, 11];
108
+ case 11: return [2 /*return*/, headers];
104
109
  }
105
110
  });
106
111
  });
@@ -137,7 +142,9 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
137
142
  switch (operationType) {
138
143
  case 'query':
139
144
  case 'mutation':
140
- var responsePromise = this._graphql({ query: query, variables: variables, authMode: authMode }, headers, customUserAgentDetails);
145
+ var abortController = new AbortController();
146
+ var responsePromise = this._graphql({ query: query, variables: variables, authMode: authMode }, headers, abortController, customUserAgentDetails);
147
+ this._api.updateRequestToBeCancellable(responsePromise, abortController);
141
148
  return responsePromise;
142
149
  case 'subscription':
143
150
  return this._graphqlSubscribe({ query: query, variables: variables, authMode: authMode }, headers, customUserAgentDetails);
@@ -145,23 +152,23 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
145
152
  throw new Error("invalid operation type: " + operationType);
146
153
  }
147
154
  };
148
- InternalGraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders, customUserAgentDetails) {
155
+ InternalGraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders, abortController, customUserAgentDetails) {
149
156
  var query = _a.query, variables = _a.variables, authMode = _a.authMode;
150
157
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
151
158
  return tslib_1.__awaiter(this, void 0, void 0, function () {
152
- var config, _b, region, appSyncGraphqlEndpoint, customGraphqlEndpoint, customEndpointRegion, headers, _c, _d, _e, _f, _g, body, endpoint, error, response, err_1, errors;
159
+ var config, _b, region, appSyncGraphqlEndpoint, customGraphqlEndpoint, customEndpointRegion, headers, _c, _d, _e, _f, _g, body, endpoint, error, response, responseBody, result, err_1, errors;
153
160
  var _h;
154
161
  return tslib_1.__generator(this, function (_j) {
155
162
  switch (_j.label) {
156
163
  case 0:
157
164
  config = core_1.Amplify.getConfig();
158
- _b = config.API.AppSync, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint;
165
+ _b = config.API.GraphQL, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint;
159
166
  customGraphqlEndpoint = null;
160
167
  customEndpointRegion = null;
161
168
  _c = [{}];
162
169
  _d = !customGraphqlEndpoint;
163
170
  if (!_d) return [3 /*break*/, 2];
164
- return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders, customUserAgentDetails)];
171
+ return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
165
172
  case 1:
166
173
  _d = (_j.sent());
167
174
  _j.label = 2;
@@ -170,7 +177,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
170
177
  _f = customGraphqlEndpoint;
171
178
  if (!_f) return [3 /*break*/, 6];
172
179
  if (!customEndpointRegion) return [3 /*break*/, 4];
173
- return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders, customUserAgentDetails)];
180
+ return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
174
181
  case 3:
175
182
  _g = _j.sent();
176
183
  return [3 /*break*/, 5];
@@ -198,24 +205,40 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
198
205
  }
199
206
  _j.label = 7;
200
207
  case 7:
201
- _j.trys.push([7, 9, , 10]);
202
- return [4 /*yield*/, this._api.post(endpoint, {
203
- headers: headers,
204
- body: body,
205
- region: region,
206
- serviceName: 'appsync',
208
+ _j.trys.push([7, 10, , 11]);
209
+ return [4 /*yield*/, this._api.post({
210
+ url: new URL(endpoint),
211
+ options: {
212
+ headers: headers,
213
+ body: body,
214
+ signingServiceInfo: {
215
+ service: 'appsync',
216
+ region: region,
217
+ },
218
+ },
219
+ abortController: abortController,
207
220
  })];
208
221
  case 8:
209
- response = _j.sent();
210
- return [3 /*break*/, 10];
222
+ responseBody = (_j.sent()).body;
223
+ return [4 /*yield*/, responseBody.json()];
211
224
  case 9:
225
+ result = _j.sent();
226
+ response = result;
227
+ return [3 /*break*/, 11];
228
+ case 10:
212
229
  err_1 = _j.sent();
230
+ // If the exception is because user intentionally
231
+ // cancelled the request, do not modify the exception
232
+ // so that clients can identify the exception correctly.
233
+ if (api_rest_1.isCancelError(err_1)) {
234
+ throw err_1;
235
+ }
213
236
  response = {
214
237
  data: {},
215
238
  errors: [new graphql_1.GraphQLError(err_1.message, null, null, null, null, err_1)],
216
239
  };
217
- return [3 /*break*/, 10];
218
- case 10:
240
+ return [3 /*break*/, 11];
241
+ case 11:
219
242
  errors = response.errors;
220
243
  if (errors && errors.length) {
221
244
  throw response;
@@ -225,21 +248,39 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
225
248
  });
226
249
  });
227
250
  };
251
+ /**
252
+ * Checks to see if an error thrown is from an api request cancellation
253
+ * @param {any} error - Any error
254
+ * @return {boolean} - A boolean indicating if the error was from an api request cancellation
255
+ */
256
+ InternalGraphQLAPIClass.prototype.isCancelError = function (error) {
257
+ return api_rest_1.isCancelError(error);
258
+ };
259
+ /**
260
+ * Cancels an inflight request. Only applicable for graphql queries and mutations
261
+ * @param {any} request - request to cancel
262
+ * @returns - A boolean indicating if the request was cancelled
263
+ */
264
+ InternalGraphQLAPIClass.prototype.cancel = function (request, message) {
265
+ return internals_1.cancel(request, message);
266
+ };
228
267
  InternalGraphQLAPIClass.prototype._graphqlSubscribe = function (_a, additionalHeaders, customUserAgentDetails) {
229
- var query = _a.query, variables = _a.variables, defaultAuthenticationType = _a.authMode, authToken = _a.authToken;
268
+ var query = _a.query, variables = _a.variables, authMode = _a.authMode;
230
269
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
231
270
  var _b;
232
- var AppSync = ((_b = core_1.Amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).AppSync;
271
+ var GraphQL = ((_b = core_1.Amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).GraphQL;
233
272
  if (!this.appSyncRealTime) {
234
273
  this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();
235
274
  }
236
275
  return this.appSyncRealTime.subscribe({
237
276
  query: graphql_1.print(query),
238
277
  variables: variables,
239
- appSyncGraphqlEndpoint: AppSync === null || AppSync === void 0 ? void 0 : AppSync.endpoint,
240
- region: AppSync === null || AppSync === void 0 ? void 0 : AppSync.region,
241
- authenticationType: AppSync === null || AppSync === void 0 ? void 0 : AppSync.defaultAuthMode,
242
- });
278
+ appSyncGraphqlEndpoint: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.endpoint,
279
+ region: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.region,
280
+ authenticationType: authMode !== null && authMode !== void 0 ? authMode : GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.defaultAuthMode,
281
+ apiKey: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.apiKey,
282
+ additionalHeaders: additionalHeaders,
283
+ }, customUserAgentDetails);
243
284
  };
244
285
  return InternalGraphQLAPIClass;
245
286
  }());
@@ -1,2 +1,2 @@
1
1
  export { InternalGraphQLAPI, InternalGraphQLAPIClass, } from './InternalGraphQLAPI';
2
- export { graphql } from './v6';
2
+ export { graphql, cancel, isCancelError } from './v6';
@@ -7,3 +7,5 @@ exports.InternalGraphQLAPI = InternalGraphQLAPI_1.InternalGraphQLAPI;
7
7
  exports.InternalGraphQLAPIClass = InternalGraphQLAPI_1.InternalGraphQLAPIClass;
8
8
  var v6_1 = require("./v6");
9
9
  exports.graphql = v6_1.graphql;
10
+ exports.cancel = v6_1.cancel;
11
+ exports.isCancelError = v6_1.isCancelError;
@@ -86,4 +86,16 @@ import { GraphQLOptionsV6, GraphQLResponseV6 } from '../types';
86
86
  export declare function graphql<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
87
87
  [key: string]: string;
88
88
  }): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
89
+ /**
90
+ * Cancels an inflight request. Only applicable for graphql queries and mutations
91
+ * @param {any} request - request to cancel
92
+ * @returns - A boolean indicating if the request was cancelled
93
+ */
94
+ export declare function cancel(promise: Promise<any>, message?: string): boolean;
95
+ /**
96
+ * Checks to see if an error thrown is from an api request cancellation
97
+ * @param {any} error - Any error
98
+ * @returns - A boolean indicating if the error was from an api request cancellation
99
+ */
100
+ export declare function isCancelError(error: any): boolean;
89
101
  export { GraphQLOptionsV6, GraphQLResponseV6 };
@@ -97,3 +97,21 @@ function graphql(options, additionalHeaders) {
97
97
  return result;
98
98
  }
99
99
  exports.graphql = graphql;
100
+ /**
101
+ * Cancels an inflight request. Only applicable for graphql queries and mutations
102
+ * @param {any} request - request to cancel
103
+ * @returns - A boolean indicating if the request was cancelled
104
+ */
105
+ function cancel(promise, message) {
106
+ return GraphQLAPI_1.GraphQLAPI.cancel(promise, message);
107
+ }
108
+ exports.cancel = cancel;
109
+ /**
110
+ * Checks to see if an error thrown is from an api request cancellation
111
+ * @param {any} error - Any error
112
+ * @returns - A boolean indicating if the error was from an api request cancellation
113
+ */
114
+ function isCancelError(error) {
115
+ return GraphQLAPI_1.GraphQLAPI.isCancelError(error);
116
+ }
117
+ exports.isCancelError = isCancelError;