@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.
- package/lib/GraphQLAPI.d.ts +1 -1
- package/lib/GraphQLAPI.js +23 -30
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +467 -582
- package/lib/index.js +1 -1
- package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib/internals/InternalGraphQLAPI.js +204 -246
- package/lib/internals/v6.js +3 -3
- package/lib/tsconfig.tsbuildinfo +180 -20
- package/lib/types/index.d.ts +17 -3
- package/lib/utils/ConnectionStateMonitor.js +51 -64
- package/lib/utils/ReachabilityMonitor/index.js +2 -2
- package/lib/utils/ReachabilityMonitor/index.native.js +4 -6
- package/lib/utils/ReconnectionMonitor.js +20 -24
- package/lib/utils/errors/APIError.js +7 -11
- package/lib/utils/errors/assertValidationError.js +4 -4
- package/lib/utils/errors/validation.js +5 -6
- package/lib/utils/resolveConfig.js +9 -10
- package/lib/utils/resolveLibraryOptions.js +4 -5
- package/lib-esm/GraphQLAPI.d.ts +1 -1
- package/lib-esm/GraphQLAPI.js +22 -30
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +458 -574
- package/lib-esm/Providers/constants.js +10 -10
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib-esm/internals/InternalGraphQLAPI.js +201 -244
- package/lib-esm/internals/v6.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +180 -20
- package/lib-esm/types/index.d.ts +17 -3
- package/lib-esm/types/index.js +1 -1
- package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
- package/lib-esm/utils/ReachabilityMonitor/index.js +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +1 -3
- package/lib-esm/utils/ReconnectionMonitor.js +19 -24
- package/lib-esm/utils/errors/APIError.js +6 -11
- package/lib-esm/utils/errors/assertValidationError.js +2 -2
- package/lib-esm/utils/errors/validation.js +5 -6
- package/lib-esm/utils/resolveConfig.js +8 -9
- package/lib-esm/utils/resolveLibraryOptions.js +4 -5
- package/package.json +6 -6
- package/src/GraphQLAPI.ts +3 -2
- package/src/internals/InternalGraphQLAPI.ts +35 -10
- package/src/types/index.ts +38 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
33
|
+
this.reconnectSetTimeoutId = setTimeout(() => {
|
|
35
34
|
// Reconnect now
|
|
36
|
-
|
|
35
|
+
this._triggerReconnect();
|
|
37
36
|
// Retry reconnect every periodically until it works
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
59
|
-
this.reconnectObservers.forEach(
|
|
60
|
-
|
|
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
|
-
|
|
65
|
-
this.reconnectObservers.forEach(
|
|
66
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
17
|
-
Object.setPrototypeOf(
|
|
18
|
-
return _this;
|
|
14
|
+
this.constructor = APIError;
|
|
15
|
+
Object.setPrototypeOf(this, APIError.prototype);
|
|
19
16
|
}
|
|
20
|
-
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
11
|
+
const { message, recoverySuggestion } = validation_1.validationErrorMap[name];
|
|
12
12
|
if (!assertion) {
|
|
13
|
-
throw new APIError_1.APIError({ name
|
|
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 =
|
|
13
|
-
|
|
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
|
-
|
|
19
|
+
[APIValidationErrorCode.NoRegion]: {
|
|
21
20
|
message: 'Missing region.',
|
|
22
21
|
},
|
|
23
|
-
|
|
22
|
+
[APIValidationErrorCode.NoCustomEndpoint]: {
|
|
24
23
|
message: 'Custom endpoint region is present without custom endpoint.',
|
|
25
24
|
},
|
|
26
|
-
|
|
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
|
-
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
|
-
exports.resolveConfig =
|
|
10
|
-
|
|
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
|
|
17
|
-
customEndpoint
|
|
18
|
-
customEndpointRegion
|
|
19
|
-
defaultAuthMode
|
|
20
|
-
endpoint
|
|
21
|
-
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 =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
};
|
package/lib-esm/GraphQLAPI.d.ts
CHANGED
|
@@ -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
|
/**
|
package/lib-esm/GraphQLAPI.js
CHANGED
|
@@ -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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
42
|
-
return
|
|
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
|
-
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
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);
|