@aws-amplify/api-graphql 4.0.1-console-preview.d745d43.0 → 4.0.1-ssr-api.df60e41.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 (41) hide show
  1. package/lib/GraphQLAPI.d.ts +1 -1
  2. package/lib/GraphQLAPI.js +23 -30
  3. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +467 -582
  4. package/lib/index.js +1 -1
  5. package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
  6. package/lib/internals/InternalGraphQLAPI.js +204 -246
  7. package/lib/internals/v6.js +3 -3
  8. package/lib/tsconfig.tsbuildinfo +180 -20
  9. package/lib/types/index.d.ts +17 -3
  10. package/lib/utils/ConnectionStateMonitor.js +51 -64
  11. package/lib/utils/ReachabilityMonitor/index.js +2 -2
  12. package/lib/utils/ReachabilityMonitor/index.native.js +4 -6
  13. package/lib/utils/ReconnectionMonitor.js +20 -24
  14. package/lib/utils/errors/APIError.js +7 -11
  15. package/lib/utils/errors/assertValidationError.js +4 -4
  16. package/lib/utils/errors/validation.js +5 -6
  17. package/lib/utils/resolveConfig.js +9 -10
  18. package/lib/utils/resolveLibraryOptions.js +4 -5
  19. package/lib-esm/GraphQLAPI.d.ts +1 -1
  20. package/lib-esm/GraphQLAPI.js +22 -30
  21. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +458 -574
  22. package/lib-esm/Providers/constants.js +10 -10
  23. package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
  24. package/lib-esm/internals/InternalGraphQLAPI.js +201 -244
  25. package/lib-esm/internals/v6.js +1 -1
  26. package/lib-esm/tsconfig.tsbuildinfo +180 -20
  27. package/lib-esm/types/index.d.ts +17 -3
  28. package/lib-esm/types/index.js +1 -1
  29. package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
  30. package/lib-esm/utils/ReachabilityMonitor/index.js +1 -1
  31. package/lib-esm/utils/ReachabilityMonitor/index.native.js +1 -3
  32. package/lib-esm/utils/ReconnectionMonitor.js +19 -24
  33. package/lib-esm/utils/errors/APIError.js +6 -11
  34. package/lib-esm/utils/errors/assertValidationError.js +2 -2
  35. package/lib-esm/utils/errors/validation.js +5 -6
  36. package/lib-esm/utils/resolveConfig.js +8 -9
  37. package/lib-esm/utils/resolveLibraryOptions.js +4 -5
  38. package/package.json +6 -6
  39. package/src/GraphQLAPI.ts +3 -2
  40. package/src/internals/InternalGraphQLAPI.ts +35 -10
  41. package/src/types/index.ts +38 -8
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var constants_1 = require("../Providers/constants");
3
+ const constants_1 = require("../Providers/constants");
4
4
  var ReconnectEvent;
5
5
  (function (ReconnectEvent) {
6
6
  ReconnectEvent["START_RECONNECT"] = "START_RECONNECT";
@@ -12,31 +12,30 @@ var ReconnectEvent;
12
12
  * Attempting to reconnect only once creates unrecoverable states when the network state isn't
13
13
  * supported by the browser, so this keeps retrying every minute until halted.
14
14
  */
15
- var ReconnectionMonitor = /** @class */ (function () {
16
- function ReconnectionMonitor() {
15
+ class ReconnectionMonitor {
16
+ constructor() {
17
17
  this.reconnectObservers = [];
18
18
  }
19
19
  /**
20
20
  * Add reconnect observer to the list of observers to alert on reconnect
21
21
  */
22
- ReconnectionMonitor.prototype.addObserver = function (reconnectObserver) {
22
+ addObserver(reconnectObserver) {
23
23
  this.reconnectObservers.push(reconnectObserver);
24
- };
24
+ }
25
25
  /**
26
26
  * Given a reconnect event, start the appropriate behavior
27
27
  */
28
- ReconnectionMonitor.prototype.record = function (event) {
29
- var _this = this;
28
+ record(event) {
30
29
  if (event === ReconnectEvent.START_RECONNECT) {
31
30
  // If the reconnection hasn't been started
32
31
  if (this.reconnectSetTimeoutId === undefined &&
33
32
  this.reconnectIntervalId === undefined) {
34
- this.reconnectSetTimeoutId = setTimeout(function () {
33
+ this.reconnectSetTimeoutId = setTimeout(() => {
35
34
  // Reconnect now
36
- _this._triggerReconnect();
35
+ this._triggerReconnect();
37
36
  // Retry reconnect every periodically until it works
38
- _this.reconnectIntervalId = setInterval(function () {
39
- _this._triggerReconnect();
37
+ this.reconnectIntervalId = setInterval(() => {
38
+ this._triggerReconnect();
40
39
  }, constants_1.RECONNECT_INTERVAL);
41
40
  }, constants_1.RECONNECT_DELAY);
42
41
  }
@@ -51,22 +50,19 @@ var ReconnectionMonitor = /** @class */ (function () {
51
50
  this.reconnectSetTimeoutId = undefined;
52
51
  }
53
52
  }
54
- };
53
+ }
55
54
  /**
56
55
  * Complete all reconnect observers
57
56
  */
58
- ReconnectionMonitor.prototype.close = function () {
59
- this.reconnectObservers.forEach(function (reconnectObserver) {
60
- var _a;
61
- (_a = reconnectObserver.complete) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
57
+ close() {
58
+ this.reconnectObservers.forEach(reconnectObserver => {
59
+ reconnectObserver.complete?.();
62
60
  });
63
- };
64
- ReconnectionMonitor.prototype._triggerReconnect = function () {
65
- this.reconnectObservers.forEach(function (reconnectObserver) {
66
- var _a;
67
- (_a = reconnectObserver.next) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
61
+ }
62
+ _triggerReconnect() {
63
+ this.reconnectObservers.forEach(reconnectObserver => {
64
+ reconnectObserver.next?.();
68
65
  });
69
- };
70
- return ReconnectionMonitor;
71
- }());
66
+ }
67
+ }
72
68
  exports.ReconnectionMonitor = ReconnectionMonitor;
@@ -2,21 +2,17 @@
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 tslib_1 = require("tslib");
6
- var utils_1 = require("@aws-amplify/core/internals/utils");
5
+ const utils_1 = require("@aws-amplify/core/internals/utils");
7
6
  /**
8
7
  * @internal
9
8
  */
10
- var APIError = /** @class */ (function (_super) {
11
- tslib_1.__extends(APIError, _super);
12
- function APIError(params) {
13
- var _this = _super.call(this, params) || this;
9
+ class APIError extends utils_1.AmplifyError {
10
+ constructor(params) {
11
+ super(params);
14
12
  // Hack for making the custom error class work when transpiled to es5
15
13
  // TODO: Delete the following 2 lines after we change the build target to >= es2015
16
- _this.constructor = APIError;
17
- Object.setPrototypeOf(_this, APIError.prototype);
18
- return _this;
14
+ this.constructor = APIError;
15
+ Object.setPrototypeOf(this, APIError.prototype);
19
16
  }
20
- return APIError;
21
- }(utils_1.AmplifyError));
17
+ }
22
18
  exports.APIError = APIError;
@@ -2,15 +2,15 @@
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 APIError_1 = require("./APIError");
6
- var validation_1 = require("./validation");
5
+ const APIError_1 = require("./APIError");
6
+ const validation_1 = require("./validation");
7
7
  /**
8
8
  * @internal
9
9
  */
10
10
  function assertValidationError(assertion, name) {
11
- var _a = validation_1.validationErrorMap[name], message = _a.message, recoverySuggestion = _a.recoverySuggestion;
11
+ const { message, recoverySuggestion } = validation_1.validationErrorMap[name];
12
12
  if (!assertion) {
13
- throw new APIError_1.APIError({ name: name, message: message, recoverySuggestion: recoverySuggestion });
13
+ throw new APIError_1.APIError({ name, message, recoverySuggestion });
14
14
  }
15
15
  }
16
16
  exports.assertValidationError = assertValidationError;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
- var _a;
5
4
  Object.defineProperty(exports, "__esModule", { value: true });
6
5
  var APIValidationErrorCode;
7
6
  (function (APIValidationErrorCode) {
@@ -9,18 +8,18 @@ var APIValidationErrorCode;
9
8
  APIValidationErrorCode["NoRegion"] = "NoRegion";
10
9
  APIValidationErrorCode["NoCustomEndpoint"] = "NoCustomEndpoint";
11
10
  })(APIValidationErrorCode = exports.APIValidationErrorCode || (exports.APIValidationErrorCode = {}));
12
- exports.validationErrorMap = (_a = {},
13
- _a[APIValidationErrorCode.NoAuthSession] = {
11
+ exports.validationErrorMap = {
12
+ [APIValidationErrorCode.NoAuthSession]: {
14
13
  message: 'Auth session should not be empty.',
15
14
  },
16
15
  // TODO: re-enable when working in all test environments:
17
16
  // [APIValidationErrorCode.NoEndpoint]: {
18
17
  // message: 'Missing endpoint',
19
18
  // },
20
- _a[APIValidationErrorCode.NoRegion] = {
19
+ [APIValidationErrorCode.NoRegion]: {
21
20
  message: 'Missing region.',
22
21
  },
23
- _a[APIValidationErrorCode.NoCustomEndpoint] = {
22
+ [APIValidationErrorCode.NoCustomEndpoint]: {
24
23
  message: 'Custom endpoint region is present without custom endpoint.',
25
24
  },
26
- _a);
25
+ };
@@ -2,22 +2,21 @@
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 errors_1 = require("./errors");
5
+ const errors_1 = require("./errors");
6
6
  /**
7
7
  * @internal
8
8
  */
9
- exports.resolveConfig = function (amplify) {
10
- var _a, _b;
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;
9
+ exports.resolveConfig = (amplify) => {
10
+ const { apiKey, customEndpoint, customEndpointRegion, defaultAuthMode, endpoint, region, } = amplify.getConfig().API?.GraphQL ?? {};
12
11
  // TODO: re-enable when working in all test environments:
13
12
  // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);
14
13
  errors_1.assertValidationError(!(!customEndpoint && customEndpointRegion), errors_1.APIValidationErrorCode.NoCustomEndpoint);
15
14
  return {
16
- apiKey: apiKey,
17
- customEndpoint: customEndpoint,
18
- customEndpointRegion: customEndpointRegion,
19
- defaultAuthMode: defaultAuthMode,
20
- endpoint: endpoint,
21
- region: region,
15
+ apiKey,
16
+ customEndpoint,
17
+ customEndpointRegion,
18
+ defaultAuthMode,
19
+ endpoint,
20
+ region,
22
21
  };
23
22
  };
@@ -5,9 +5,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  /**
6
6
  * @internal
7
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 };
8
+ exports.resolveLibraryOptions = (amplify) => {
9
+ const headers = amplify.libraryOptions?.API?.GraphQL?.headers;
10
+ const withCredentials = amplify.libraryOptions?.API?.GraphQL?.withCredentials;
11
+ return { headers, withCredentials };
13
12
  };
@@ -19,7 +19,7 @@ export declare class GraphQLAPIClass extends InternalGraphQLAPIClass {
19
19
  * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
20
20
  * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
21
21
  */
22
- graphql<T = any>(amplify: AmplifyClassV6, options: GraphQLOptions, additionalHeaders?: {
22
+ graphql<T = any>(amplify: AmplifyClassV6 | (() => Promise<AmplifyClassV6>), options: GraphQLOptions, additionalHeaders?: {
23
23
  [key: string]: string;
24
24
  }): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
25
25
  /**
@@ -1,25 +1,17 @@
1
- import { __extends } from "tslib";
2
1
  import { Category, ApiAction } from '@aws-amplify/core/internals/utils';
3
2
  import { InternalGraphQLAPIClass } from './internals';
4
- export var graphqlOperation = function (query, variables, authToken) {
5
- if (variables === void 0) { variables = {}; }
6
- return ({
7
- query: query,
8
- variables: variables,
9
- authToken: authToken,
10
- });
11
- };
3
+ export const graphqlOperation = (query, variables = {}, authToken) => ({
4
+ query,
5
+ variables,
6
+ authToken,
7
+ });
12
8
  /**
13
9
  * Export Cloud Logic APIs
14
10
  */
15
- var GraphQLAPIClass = /** @class */ (function (_super) {
16
- __extends(GraphQLAPIClass, _super);
17
- function GraphQLAPIClass() {
18
- return _super !== null && _super.apply(this, arguments) || this;
19
- }
20
- GraphQLAPIClass.prototype.getModuleName = function () {
11
+ export class GraphQLAPIClass extends InternalGraphQLAPIClass {
12
+ getModuleName() {
21
13
  return 'GraphQLAPI';
22
- };
14
+ }
23
15
  /**
24
16
  * Executes a GraphQL operation
25
17
  *
@@ -27,29 +19,29 @@ var GraphQLAPIClass = /** @class */ (function (_super) {
27
19
  * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
28
20
  * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
29
21
  */
30
- GraphQLAPIClass.prototype.graphql = function (amplify, options, additionalHeaders) {
31
- return _super.prototype.graphql.call(this, amplify, options, additionalHeaders, {
22
+ graphql(amplify,
23
+ // amplify: AmplifyClassV6 | (() => Promise<AmplifyClassV6>),
24
+ options, additionalHeaders) {
25
+ return super.graphql(amplify, options, additionalHeaders, {
32
26
  category: Category.API,
33
- action: ApiAction.GraphQl
27
+ action: ApiAction.GraphQl,
34
28
  });
35
- };
29
+ }
36
30
  /**
37
31
  * Checks to see if an error thrown is from an api request cancellation
38
32
  * @param error - Any error
39
33
  * @returns A boolean indicating if the error was from an api request cancellation
40
34
  */
41
- GraphQLAPIClass.prototype.isCancelError = function (error) {
42
- return _super.prototype.isCancelError.call(this, error);
43
- };
35
+ isCancelError(error) {
36
+ return super.isCancelError(error);
37
+ }
44
38
  /**
45
39
  * Cancels an inflight request. Only applicable for graphql queries and mutations
46
40
  * @param {any} request - request to cancel
47
41
  * @returns A boolean indicating if the request was cancelled
48
42
  */
49
- GraphQLAPIClass.prototype.cancel = function (request, message) {
50
- return _super.prototype.cancel.call(this, request, message);
51
- };
52
- return GraphQLAPIClass;
53
- }(InternalGraphQLAPIClass));
54
- export { GraphQLAPIClass };
55
- export var GraphQLAPI = new GraphQLAPIClass(null);
43
+ cancel(request, message) {
44
+ return super.cancel(request, message);
45
+ }
46
+ }
47
+ export const GraphQLAPI = new GraphQLAPIClass(null);