@aws-amplify/api-graphql 4.0.1-console-preview.3d7f188.0 → 4.0.1-server-generate-client.1e317a1.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 +2 -2
- package/lib/GraphQLAPI.js +4 -6
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +36 -36
- package/lib/Providers/constants.js +5 -4
- package/lib/index.js +5 -4
- package/lib/internals/APIClient.d.ts +101 -0
- package/lib/internals/APIClient.js +443 -0
- package/lib/internals/InternalGraphQLAPI.d.ts +2 -2
- package/lib/internals/InternalGraphQLAPI.js +36 -18
- package/lib/internals/generateClient.d.ts +12 -0
- package/lib/internals/generateClient.js +30 -0
- package/lib/internals/generateModelsProperty.d.ts +4 -0
- package/lib/internals/generateModelsProperty.js +169 -0
- package/lib/internals/index.d.ts +1 -0
- package/lib/internals/index.js +8 -5
- package/lib/internals/types.d.ts +10 -0
- package/lib/internals/types.js +2 -0
- package/lib/internals/v6.js +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -6619
- package/lib/types/PubSub.d.ts +2 -2
- package/lib/types/PubSub.js +3 -2
- package/lib/types/index.d.ts +25 -22
- package/lib/types/index.js +4 -3
- package/lib/utils/ConnectionStateMonitor.d.ts +3 -3
- package/lib/utils/ConnectionStateMonitor.js +7 -6
- package/lib/utils/ReachabilityMonitor/index.d.ts +1 -1
- package/lib/utils/ReachabilityMonitor/index.js +3 -1
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -1
- package/lib/utils/ReachabilityMonitor/index.native.js +3 -1
- package/lib/utils/ReconnectionMonitor.js +2 -1
- package/lib/utils/errors/APIError.js +1 -0
- package/lib/utils/errors/assertValidationError.js +1 -0
- package/lib/utils/errors/index.js +5 -4
- package/lib/utils/errors/validation.js +2 -1
- package/lib/utils/index.js +3 -2
- package/lib/utils/resolveConfig.d.ts +1 -1
- package/lib/utils/resolveConfig.js +4 -2
- package/lib/utils/resolveLibraryOptions.d.ts +1 -1
- package/lib/utils/resolveLibraryOptions.js +3 -1
- package/lib/utils/resolveOwnerFields.d.ts +12 -0
- package/lib/utils/resolveOwnerFields.js +63 -0
- package/lib-esm/GraphQLAPI.d.ts +2 -2
- package/lib-esm/GraphQLAPI.js +1 -5
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +28 -29
- package/lib-esm/internals/APIClient.d.ts +101 -0
- package/lib-esm/internals/APIClient.js +432 -0
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +2 -2
- package/lib-esm/internals/InternalGraphQLAPI.js +22 -6
- package/lib-esm/internals/generateClient.d.ts +12 -0
- package/lib-esm/internals/generateClient.js +26 -0
- package/lib-esm/internals/generateModelsProperty.d.ts +4 -0
- package/lib-esm/internals/generateModelsProperty.js +165 -0
- package/lib-esm/internals/index.d.ts +1 -0
- package/lib-esm/internals/index.js +1 -0
- package/lib-esm/internals/types.d.ts +10 -0
- package/lib-esm/internals/types.js +1 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -6619
- package/lib-esm/types/PubSub.d.ts +2 -2
- package/lib-esm/types/index.d.ts +25 -22
- package/lib-esm/utils/ConnectionStateMonitor.d.ts +3 -3
- package/lib-esm/utils/ConnectionStateMonitor.js +2 -2
- package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -1
- package/lib-esm/utils/resolveConfig.d.ts +1 -1
- package/lib-esm/utils/resolveLibraryOptions.d.ts +1 -1
- package/lib-esm/utils/resolveOwnerFields.d.ts +12 -0
- package/lib-esm/utils/resolveOwnerFields.js +59 -0
- package/package.json +12 -6
- package/src/GraphQLAPI.ts +2 -6
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +2 -3
- package/src/internals/APIClient.ts +583 -0
- package/src/internals/InternalGraphQLAPI.ts +36 -10
- package/src/internals/generateClient.ts +30 -0
- package/src/internals/generateModelsProperty.ts +192 -0
- package/src/internals/index.ts +1 -0
- package/src/internals/types.ts +15 -0
- package/src/types/index.ts +7 -1
- package/src/utils/resolveOwnerFields.ts +65 -0
package/lib/GraphQLAPI.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
|
2
2
|
import { GraphQLOptions, GraphQLResult } from './types';
|
|
3
3
|
import { InternalGraphQLAPIClass } from './internals';
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
|
-
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string
|
|
5
|
+
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string) => {
|
|
6
6
|
query: any;
|
|
7
7
|
variables: {};
|
|
8
8
|
authToken: string | undefined;
|
|
@@ -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/GraphQLAPI.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLAPI = exports.GraphQLAPIClass = exports.graphqlOperation = void 0;
|
|
3
4
|
var tslib_1 = require("tslib");
|
|
4
|
-
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
5
5
|
var internals_1 = require("./internals");
|
|
6
|
-
|
|
6
|
+
var graphqlOperation = function (query, variables, authToken) {
|
|
7
7
|
if (variables === void 0) { variables = {}; }
|
|
8
8
|
return ({
|
|
9
9
|
query: query,
|
|
@@ -11,6 +11,7 @@ exports.graphqlOperation = function (query, variables, authToken) {
|
|
|
11
11
|
authToken: authToken,
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
|
+
exports.graphqlOperation = graphqlOperation;
|
|
14
15
|
/**
|
|
15
16
|
* Export Cloud Logic APIs
|
|
16
17
|
*/
|
|
@@ -30,10 +31,7 @@ var GraphQLAPIClass = /** @class */ (function (_super) {
|
|
|
30
31
|
* @returns An Observable if the query is a subscription query, else a promise of the graphql result.
|
|
31
32
|
*/
|
|
32
33
|
GraphQLAPIClass.prototype.graphql = function (amplify, options, additionalHeaders) {
|
|
33
|
-
return _super.prototype.graphql.call(this, amplify, options, additionalHeaders
|
|
34
|
-
category: utils_1.Category.API,
|
|
35
|
-
action: utils_1.ApiAction.GraphQl
|
|
36
|
-
});
|
|
34
|
+
return _super.prototype.graphql.call(this, amplify, options, additionalHeaders);
|
|
37
35
|
};
|
|
38
36
|
/**
|
|
39
37
|
* Checks to see if an error thrown is from an api request cancellation
|
|
@@ -2,7 +2,7 @@ import { Observable } from 'rxjs';
|
|
|
2
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
|
-
export
|
|
5
|
+
export type ObserverQuery = {
|
|
6
6
|
observer: PubSubContentObserver;
|
|
7
7
|
query: string;
|
|
8
8
|
variables: Record<string, DocumentType>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AWSAppSyncRealTimeProvider = void 0;
|
|
3
4
|
var tslib_1 = require("tslib");
|
|
4
5
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
7
|
var rxjs_1 = require("rxjs");
|
|
7
8
|
var graphql_1 = require("graphql");
|
|
9
|
+
var url = tslib_1.__importStar(require("url"));
|
|
8
10
|
var buffer_1 = require("buffer");
|
|
9
11
|
var core_1 = require("@aws-amplify/core");
|
|
10
12
|
var aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
@@ -21,8 +23,8 @@ var standardDomainPattern = /^https:\/\/\w{26}\.appsync\-api\.\w{2}(?:(?:\-\w{2,
|
|
|
21
23
|
var customDomainPath = '/realtime';
|
|
22
24
|
var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
23
25
|
function AWSAppSyncRealTimeProvider(options) {
|
|
24
|
-
var _this = this;
|
|
25
26
|
if (options === void 0) { options = {}; }
|
|
27
|
+
var _this = this;
|
|
26
28
|
this.socketStatus = constants_1.SOCKET_STATUS.CLOSED;
|
|
27
29
|
this.keepAliveTimeout = constants_1.DEFAULT_KEEP_ALIVE_TIMEOUT;
|
|
28
30
|
this.subscriptionObserverMap = new Map();
|
|
@@ -38,7 +40,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
38
40
|
provider: _this,
|
|
39
41
|
connectionState: connectionState,
|
|
40
42
|
},
|
|
41
|
-
message: "Connection state is "
|
|
43
|
+
message: "Connection state is ".concat(connectionState),
|
|
42
44
|
});
|
|
43
45
|
_this.connectionState = connectionState;
|
|
44
46
|
// Trigger START_RECONNECT when the connection is disrupted
|
|
@@ -95,7 +97,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
95
97
|
}
|
|
96
98
|
else {
|
|
97
99
|
var subscriptionStartActive_1 = false;
|
|
98
|
-
var subscriptionId_1 = utils_1.amplifyUuid();
|
|
100
|
+
var subscriptionId_1 = (0, utils_1.amplifyUuid)();
|
|
99
101
|
var startSubscription_1 = function () {
|
|
100
102
|
if (!subscriptionStartActive_1) {
|
|
101
103
|
subscriptionStartActive_1 = true;
|
|
@@ -113,7 +115,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
113
115
|
subscriptionId: subscriptionId_1,
|
|
114
116
|
customUserAgentDetails: customUserAgentDetails,
|
|
115
117
|
}).catch(function (err) {
|
|
116
|
-
logger.debug(PubSub_1.CONTROL_MSG.REALTIME_SUBSCRIPTION_INIT_ERROR
|
|
118
|
+
logger.debug("".concat(PubSub_1.CONTROL_MSG.REALTIME_SUBSCRIPTION_INIT_ERROR, ": ").concat(err));
|
|
117
119
|
_this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED);
|
|
118
120
|
});
|
|
119
121
|
startSubscriptionPromise.finally(function () {
|
|
@@ -158,7 +160,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
158
160
|
return [3 /*break*/, 5];
|
|
159
161
|
case 3:
|
|
160
162
|
err_1 = _a.sent();
|
|
161
|
-
logger.debug("Error while unsubscribing "
|
|
163
|
+
logger.debug("Error while unsubscribing ".concat(err_1));
|
|
162
164
|
return [3 /*break*/, 5];
|
|
163
165
|
case 4:
|
|
164
166
|
this._removeSubscriptionObserver(subscriptionId_1);
|
|
@@ -171,8 +173,8 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
171
173
|
});
|
|
172
174
|
};
|
|
173
175
|
AWSAppSyncRealTimeProvider.prototype._startSubscriptionWithAWSAppSyncRealTime = function (_a) {
|
|
174
|
-
var options = _a.options, observer = _a.observer, subscriptionId = _a.subscriptionId, customUserAgentDetails = _a.customUserAgentDetails;
|
|
175
176
|
var _b;
|
|
177
|
+
var options = _a.options, observer = _a.observer, subscriptionId = _a.subscriptionId, customUserAgentDetails = _a.customUserAgentDetails;
|
|
176
178
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
177
179
|
var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, _c, graphql_headers, _d, additionalHeaders, subscriptionState, data, dataString, headerObj, _e, _f, subscriptionMessage, stringToAWSRealTime, err_2, _g, subscriptionFailedCallback, subscriptionReadyCallback;
|
|
178
180
|
var _h;
|
|
@@ -209,7 +211,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
209
211
|
_f = [tslib_1.__assign.apply(void 0, _e.concat([(_j.sent())]))];
|
|
210
212
|
return [4 /*yield*/, graphql_headers()];
|
|
211
213
|
case 2:
|
|
212
|
-
headerObj = tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0, _f.concat([(_j.sent())])), additionalHeaders]), (_h = {}, _h[utils_1.USER_AGENT_HEADER] = utils_1.getAmplifyUserAgent(customUserAgentDetails), _h)]);
|
|
214
|
+
headerObj = tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0, _f.concat([(_j.sent())])), additionalHeaders]), (_h = {}, _h[utils_1.USER_AGENT_HEADER] = (0, utils_1.getAmplifyUserAgent)(customUserAgentDetails), _h)]);
|
|
213
215
|
subscriptionMessage = {
|
|
214
216
|
id: subscriptionId,
|
|
215
217
|
payload: {
|
|
@@ -271,15 +273,15 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
271
273
|
// Capture the error only when the network didn't cause disruption
|
|
272
274
|
if (this.connectionState !== PubSub_1.ConnectionState.ConnectionDisruptedPendingNetwork) {
|
|
273
275
|
// When the error is non-retriable, error out the observable
|
|
274
|
-
if (utils_1.isNonRetryableError(err)) {
|
|
276
|
+
if ((0, utils_1.isNonRetryableError)(err)) {
|
|
275
277
|
observer.error({
|
|
276
278
|
errors: [
|
|
277
|
-
tslib_1.__assign({}, new graphql_1.GraphQLError(PubSub_1.CONTROL_MSG.CONNECTION_FAILED
|
|
279
|
+
tslib_1.__assign({}, new graphql_1.GraphQLError("".concat(PubSub_1.CONTROL_MSG.CONNECTION_FAILED, ": ").concat(message))),
|
|
278
280
|
],
|
|
279
281
|
});
|
|
280
282
|
}
|
|
281
283
|
else {
|
|
282
|
-
logger.debug(PubSub_1.CONTROL_MSG.CONNECTION_FAILED
|
|
284
|
+
logger.debug("".concat(PubSub_1.CONTROL_MSG.CONNECTION_FAILED, ": ").concat(message));
|
|
283
285
|
}
|
|
284
286
|
var subscriptionFailedCallback = (this.subscriptionObserverMap.get(subscriptionId) || {}).subscriptionFailedCallback;
|
|
285
287
|
// Notify concurrent unsubscription
|
|
@@ -377,7 +379,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
377
379
|
if (typeof message.data !== 'string') {
|
|
378
380
|
return;
|
|
379
381
|
}
|
|
380
|
-
logger.debug("subscription message from AWS AppSync RealTime: "
|
|
382
|
+
logger.debug("subscription message from AWS AppSync RealTime: ".concat(message.data));
|
|
381
383
|
var _a = JSON.parse(String(message.data)), _b = _a.id, id = _b === void 0 ? '' : _b, payload = _a.payload, type = _a.type;
|
|
382
384
|
var _c = this.subscriptionObserverMap.get(id) || {}, _d = _c.observer, observer = _d === void 0 ? null : _d, _e = _c.query, query = _e === void 0 ? '' : _e, _f = _c.variables, variables = _f === void 0 ? {} : _f, startAckTimeoutId = _c.startAckTimeoutId, subscriptionReadyCallback = _c.subscriptionReadyCallback, subscriptionFailedCallback = _c.subscriptionFailedCallback;
|
|
383
385
|
logger.debug({ id: id, observer: observer, query: query, variables: variables });
|
|
@@ -386,12 +388,12 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
386
388
|
observer.next(payload);
|
|
387
389
|
}
|
|
388
390
|
else {
|
|
389
|
-
logger.debug("observer not found for id: "
|
|
391
|
+
logger.debug("observer not found for id: ".concat(id));
|
|
390
392
|
}
|
|
391
393
|
return;
|
|
392
394
|
}
|
|
393
395
|
if (type === constants_1.MESSAGE_TYPES.GQL_START_ACK) {
|
|
394
|
-
logger.debug("subscription ready for "
|
|
396
|
+
logger.debug("subscription ready for ".concat(JSON.stringify({ query: query, variables: variables })));
|
|
395
397
|
if (typeof subscriptionReadyCallback === 'function') {
|
|
396
398
|
subscriptionReadyCallback();
|
|
397
399
|
}
|
|
@@ -441,10 +443,10 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
441
443
|
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
442
444
|
subscriptionState: subscriptionState,
|
|
443
445
|
});
|
|
444
|
-
logger.debug(PubSub_1.CONTROL_MSG.CONNECTION_FAILED
|
|
446
|
+
logger.debug("".concat(PubSub_1.CONTROL_MSG.CONNECTION_FAILED, ": ").concat(JSON.stringify(payload)));
|
|
445
447
|
observer.error({
|
|
446
448
|
errors: [
|
|
447
|
-
tslib_1.__assign({}, new graphql_1.GraphQLError(PubSub_1.CONTROL_MSG.CONNECTION_FAILED
|
|
449
|
+
tslib_1.__assign({}, new graphql_1.GraphQLError("".concat(PubSub_1.CONTROL_MSG.CONNECTION_FAILED, ": ").concat(JSON.stringify(payload)))),
|
|
448
450
|
],
|
|
449
451
|
});
|
|
450
452
|
if (startAckTimeoutId)
|
|
@@ -456,7 +458,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
456
458
|
}
|
|
457
459
|
};
|
|
458
460
|
AWSAppSyncRealTimeProvider.prototype._errorDisconnect = function (msg) {
|
|
459
|
-
logger.debug("Disconnect error: "
|
|
461
|
+
logger.debug("Disconnect error: ".concat(msg));
|
|
460
462
|
if (this.awsRealTimeSocket) {
|
|
461
463
|
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED);
|
|
462
464
|
this.awsRealTimeSocket.close();
|
|
@@ -526,7 +528,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
526
528
|
discoverableEndpoint = discoverableEndpoint
|
|
527
529
|
.replace('https://', protocol)
|
|
528
530
|
.replace('http://', protocol);
|
|
529
|
-
awsRealTimeUrl = discoverableEndpoint
|
|
531
|
+
awsRealTimeUrl = "".concat(discoverableEndpoint, "?header=").concat(headerQs, "&payload=").concat(payloadQs);
|
|
530
532
|
return [4 /*yield*/, this._initializeRetryableHandshake(awsRealTimeUrl)];
|
|
531
533
|
case 3:
|
|
532
534
|
_a.sent();
|
|
@@ -564,7 +566,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
564
566
|
switch (_a.label) {
|
|
565
567
|
case 0:
|
|
566
568
|
logger.debug("Initializaling retryable Handshake");
|
|
567
|
-
return [4 /*yield*/, utils_1.jitteredExponentialRetry(this._initializeHandshake.bind(this), [awsRealTimeUrl], constants_1.MAX_DELAY_MS)];
|
|
569
|
+
return [4 /*yield*/, (0, utils_1.jitteredExponentialRetry)(this._initializeHandshake.bind(this), [awsRealTimeUrl], constants_1.MAX_DELAY_MS)];
|
|
568
570
|
case 1:
|
|
569
571
|
_a.sent();
|
|
570
572
|
return [2 /*return*/];
|
|
@@ -579,7 +581,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
579
581
|
return tslib_1.__generator(this, function (_b) {
|
|
580
582
|
switch (_b.label) {
|
|
581
583
|
case 0:
|
|
582
|
-
logger.debug("Initializing handshake "
|
|
584
|
+
logger.debug("Initializing handshake ".concat(awsRealTimeUrl));
|
|
583
585
|
_b.label = 1;
|
|
584
586
|
case 1:
|
|
585
587
|
_b.trys.push([1, 4, , 5]);
|
|
@@ -606,19 +608,19 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
606
608
|
if (_this.awsRealTimeSocket) {
|
|
607
609
|
var ackOk_1 = false;
|
|
608
610
|
_this.awsRealTimeSocket.onerror = function (error) {
|
|
609
|
-
logger.debug("WebSocket error "
|
|
611
|
+
logger.debug("WebSocket error ".concat(JSON.stringify(error)));
|
|
610
612
|
};
|
|
611
613
|
_this.awsRealTimeSocket.onclose = function (event) {
|
|
612
|
-
logger.debug("WebSocket closed "
|
|
614
|
+
logger.debug("WebSocket closed ".concat(event.reason));
|
|
613
615
|
rej(new Error(JSON.stringify(event)));
|
|
614
616
|
};
|
|
615
617
|
_this.awsRealTimeSocket.onmessage = function (message) {
|
|
616
618
|
if (typeof message.data !== 'string') {
|
|
617
619
|
return;
|
|
618
620
|
}
|
|
619
|
-
logger.debug("subscription message from AWS AppSyncRealTime: "
|
|
621
|
+
logger.debug("subscription message from AWS AppSyncRealTime: ".concat(message.data, " "));
|
|
620
622
|
var data = JSON.parse(message.data);
|
|
621
|
-
var type = data.type, _a = data.payload, _b =
|
|
623
|
+
var type = data.type, _a = data.payload, _b = _a === void 0 ? {} : _a, _c = _b.connectionTimeoutMs, connectionTimeoutMs = _c === void 0 ? constants_1.DEFAULT_KEEP_ALIVE_TIMEOUT : _c;
|
|
622
624
|
if (type === constants_1.MESSAGE_TYPES.GQL_CONNECTION_ACK) {
|
|
623
625
|
ackOk_1 = true;
|
|
624
626
|
if (_this.awsRealTimeSocket) {
|
|
@@ -630,7 +632,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
630
632
|
_this._errorDisconnect(PubSub_1.CONTROL_MSG.CONNECTION_CLOSED);
|
|
631
633
|
};
|
|
632
634
|
_this.awsRealTimeSocket.onclose = function (event) {
|
|
633
|
-
logger.debug("WebSocket closed "
|
|
635
|
+
logger.debug("WebSocket closed ".concat(event.reason));
|
|
634
636
|
_this._errorDisconnect(PubSub_1.CONTROL_MSG.CONNECTION_CLOSED);
|
|
635
637
|
};
|
|
636
638
|
}
|
|
@@ -638,7 +640,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
638
640
|
return;
|
|
639
641
|
}
|
|
640
642
|
if (type === constants_1.MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
|
|
641
|
-
var
|
|
643
|
+
var _d = data.payload, _e = _d === void 0 ? {} : _d, _f = _e.errors, _g = _f === void 0 ? [] : _f, _h = tslib_1.__read(_g, 1), _j = _h[0], _k = _j === void 0 ? {} : _j, _l = _k.errorType, errorType = _l === void 0 ? '' : _l, _m = _k.errorCode, errorCode = _m === void 0 ? 0 : _m;
|
|
642
644
|
rej({ errorType: errorType, errorCode: errorCode });
|
|
643
645
|
}
|
|
644
646
|
};
|
|
@@ -649,7 +651,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
649
651
|
var checkAckOk_1 = function (ackOk) {
|
|
650
652
|
if (!ackOk) {
|
|
651
653
|
_this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CONNECTION_FAILED);
|
|
652
|
-
rej(new Error("Connection timeout: ack from AWSAppSyncRealTime was not received after "
|
|
654
|
+
rej(new Error("Connection timeout: ack from AWSAppSyncRealTime was not received after ".concat(constants_1.CONNECTION_INIT_TIMEOUT, " ms")));
|
|
653
655
|
}
|
|
654
656
|
};
|
|
655
657
|
setTimeout(function () { return checkAckOk_1(ackOk_1); }, constants_1.CONNECTION_INIT_TIMEOUT);
|
|
@@ -694,14 +696,12 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
694
696
|
none: this._customAuthHeader,
|
|
695
697
|
};
|
|
696
698
|
if (!(!authenticationType || !headerHandler[authenticationType])) return [3 /*break*/, 1];
|
|
697
|
-
logger.debug("Authentication type "
|
|
699
|
+
logger.debug("Authentication type ".concat(authenticationType, " not supported"));
|
|
698
700
|
return [2 /*return*/, undefined];
|
|
699
701
|
case 1:
|
|
700
702
|
handler = headerHandler[authenticationType];
|
|
701
|
-
host = appSyncGraphqlEndpoint
|
|
702
|
-
|
|
703
|
-
: undefined;
|
|
704
|
-
logger.debug("Authenticating with " + JSON.stringify(authenticationType));
|
|
703
|
+
host = url.parse(appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
|
|
704
|
+
logger.debug("Authenticating with ".concat(JSON.stringify(authenticationType)));
|
|
705
705
|
resolvedApiKey = void 0;
|
|
706
706
|
if (authenticationType === 'apiKey') {
|
|
707
707
|
resolvedApiKey = apiKey;
|
|
@@ -723,13 +723,13 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
723
723
|
});
|
|
724
724
|
};
|
|
725
725
|
AWSAppSyncRealTimeProvider.prototype._awsAuthTokenHeader = function (_a) {
|
|
726
|
-
var host = _a.host;
|
|
727
726
|
var _b, _c;
|
|
727
|
+
var host = _a.host;
|
|
728
728
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
729
729
|
var session;
|
|
730
730
|
return tslib_1.__generator(this, function (_d) {
|
|
731
731
|
switch (_d.label) {
|
|
732
|
-
case 0: return [4 /*yield*/, core_1.fetchAuthSession()];
|
|
732
|
+
case 0: return [4 /*yield*/, (0, core_1.fetchAuthSession)()];
|
|
733
733
|
case 1:
|
|
734
734
|
session = _d.sent();
|
|
735
735
|
return [2 /*return*/, {
|
|
@@ -766,16 +766,16 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
766
766
|
region: region,
|
|
767
767
|
service: 'appsync',
|
|
768
768
|
};
|
|
769
|
-
return [4 /*yield*/, core_1.fetchAuthSession()];
|
|
769
|
+
return [4 /*yield*/, (0, core_1.fetchAuthSession)()];
|
|
770
770
|
case 1:
|
|
771
771
|
creds = (_b.sent()).credentials;
|
|
772
772
|
request = {
|
|
773
|
-
url: ""
|
|
773
|
+
url: "".concat(appSyncGraphqlEndpoint).concat(canonicalUri),
|
|
774
774
|
data: payload,
|
|
775
775
|
method: 'POST',
|
|
776
776
|
headers: tslib_1.__assign({}, constants_1.AWS_APPSYNC_REALTIME_HEADERS),
|
|
777
777
|
};
|
|
778
|
-
signed_params = aws_client_utils_1.signRequest({
|
|
778
|
+
signed_params = (0, aws_client_utils_1.signRequest)({
|
|
779
779
|
headers: request.headers,
|
|
780
780
|
method: request.method,
|
|
781
781
|
url: new utils_1.AmplifyUrl(request.url),
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RECONNECT_INTERVAL = exports.RECONNECT_DELAY = exports.DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT = exports.DEFAULT_KEEP_ALIVE_TIMEOUT = exports.START_ACK_TIMEOUT = exports.CONNECTION_INIT_TIMEOUT = exports.AWS_APPSYNC_REALTIME_HEADERS = exports.SOCKET_STATUS = exports.SUBSCRIPTION_STATUS = exports.MESSAGE_TYPES = exports.CONNECTION_STATE_CHANGE = exports.NON_RETRYABLE_CODES = exports.MAX_DELAY_MS = exports.AMPLIFY_SYMBOL = void 0;
|
|
3
4
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
5
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
6
|
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
6
|
-
exports
|
|
7
|
+
Object.defineProperty(exports, "AMPLIFY_SYMBOL", { enumerable: true, get: function () { return utils_1.AMPLIFY_SYMBOL; } });
|
|
7
8
|
exports.MAX_DELAY_MS = 5000;
|
|
8
9
|
exports.NON_RETRYABLE_CODES = [400, 401, 403];
|
|
9
10
|
exports.CONNECTION_STATE_CHANGE = 'ConnectionStateChange';
|
|
@@ -59,19 +60,19 @@ var MESSAGE_TYPES;
|
|
|
59
60
|
* This message type is for sending error messages from AWS AppSync RealTime to the client
|
|
60
61
|
*/
|
|
61
62
|
MESSAGE_TYPES["GQL_ERROR"] = "error";
|
|
62
|
-
})(MESSAGE_TYPES
|
|
63
|
+
})(MESSAGE_TYPES || (exports.MESSAGE_TYPES = MESSAGE_TYPES = {}));
|
|
63
64
|
var SUBSCRIPTION_STATUS;
|
|
64
65
|
(function (SUBSCRIPTION_STATUS) {
|
|
65
66
|
SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["PENDING"] = 0] = "PENDING";
|
|
66
67
|
SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["CONNECTED"] = 1] = "CONNECTED";
|
|
67
68
|
SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["FAILED"] = 2] = "FAILED";
|
|
68
|
-
})(SUBSCRIPTION_STATUS
|
|
69
|
+
})(SUBSCRIPTION_STATUS || (exports.SUBSCRIPTION_STATUS = SUBSCRIPTION_STATUS = {}));
|
|
69
70
|
var SOCKET_STATUS;
|
|
70
71
|
(function (SOCKET_STATUS) {
|
|
71
72
|
SOCKET_STATUS[SOCKET_STATUS["CLOSED"] = 0] = "CLOSED";
|
|
72
73
|
SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
|
|
73
74
|
SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
|
|
74
|
-
})(SOCKET_STATUS
|
|
75
|
+
})(SOCKET_STATUS || (exports.SOCKET_STATUS = SOCKET_STATUS = {}));
|
|
75
76
|
exports.AWS_APPSYNC_REALTIME_HEADERS = {
|
|
76
77
|
accept: 'application/json, text/javascript',
|
|
77
78
|
'content-encoding': 'amz-1.0',
|
package/lib/index.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
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
|
+
exports.CONNECTION_STATE_CHANGE = exports.graphqlOperation = exports.GraphQLAPIClass = exports.GraphQLAPI = void 0;
|
|
5
6
|
var tslib_1 = require("tslib");
|
|
6
7
|
var GraphQLAPI_1 = require("./GraphQLAPI");
|
|
7
|
-
exports
|
|
8
|
-
exports
|
|
9
|
-
exports
|
|
8
|
+
Object.defineProperty(exports, "GraphQLAPI", { enumerable: true, get: function () { return GraphQLAPI_1.GraphQLAPI; } });
|
|
9
|
+
Object.defineProperty(exports, "GraphQLAPIClass", { enumerable: true, get: function () { return GraphQLAPI_1.GraphQLAPIClass; } });
|
|
10
|
+
Object.defineProperty(exports, "graphqlOperation", { enumerable: true, get: function () { return GraphQLAPI_1.graphqlOperation; } });
|
|
10
11
|
tslib_1.__exportStar(require("./types"), exports);
|
|
11
12
|
var constants_1 = require("./Providers/constants");
|
|
12
|
-
exports
|
|
13
|
+
Object.defineProperty(exports, "CONNECTION_STATE_CHANGE", { enumerable: true, get: function () { return constants_1.CONNECTION_STATE_CHANGE; } });
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
type ListArgs = {
|
|
2
|
+
selectionSet?: string[];
|
|
3
|
+
filter?: {};
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param GraphQL response object
|
|
8
|
+
* @returns response object with `items` properties flattened
|
|
9
|
+
*/
|
|
10
|
+
export declare const flattenItems: (obj: Record<string, any>) => Record<string, any>;
|
|
11
|
+
export declare function initializeModel(client: any, modelName: string, result: any[], modelIntrospection: any): any[];
|
|
12
|
+
export declare const graphQLOperationsInfo: {
|
|
13
|
+
CREATE: {
|
|
14
|
+
operationPrefix: "create";
|
|
15
|
+
usePlural: boolean;
|
|
16
|
+
};
|
|
17
|
+
READ: {
|
|
18
|
+
operationPrefix: "get";
|
|
19
|
+
usePlural: boolean;
|
|
20
|
+
};
|
|
21
|
+
UPDATE: {
|
|
22
|
+
operationPrefix: "update";
|
|
23
|
+
usePlural: boolean;
|
|
24
|
+
};
|
|
25
|
+
DELETE: {
|
|
26
|
+
operationPrefix: "delete";
|
|
27
|
+
usePlural: boolean;
|
|
28
|
+
};
|
|
29
|
+
LIST: {
|
|
30
|
+
operationPrefix: "list";
|
|
31
|
+
usePlural: boolean;
|
|
32
|
+
};
|
|
33
|
+
ONCREATE: {
|
|
34
|
+
operationPrefix: "onCreate";
|
|
35
|
+
usePlural: boolean;
|
|
36
|
+
};
|
|
37
|
+
ONUPDATE: {
|
|
38
|
+
operationPrefix: "onUpdate";
|
|
39
|
+
usePlural: boolean;
|
|
40
|
+
};
|
|
41
|
+
ONDELETE: {
|
|
42
|
+
operationPrefix: "onDelete";
|
|
43
|
+
usePlural: boolean;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export type ModelOperation = keyof typeof graphQLOperationsInfo;
|
|
47
|
+
/**
|
|
48
|
+
* Generates nested Custom Selection Set IR from path
|
|
49
|
+
*
|
|
50
|
+
* @param modelIntrospection
|
|
51
|
+
* @param modelName
|
|
52
|
+
* @param selectionSet - array of object paths
|
|
53
|
+
* @example
|
|
54
|
+
* ### Given
|
|
55
|
+
* `selectionSet = ['id', 'comments.post.id']`
|
|
56
|
+
* ### Returns
|
|
57
|
+
* ```ts
|
|
58
|
+
* {
|
|
59
|
+
* id: '',
|
|
60
|
+
* comments: {
|
|
61
|
+
* items: { post: { id: '' } }
|
|
62
|
+
* }
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function customSelectionSetToIR(modelIntrospection: any, modelName: string, selectionSet: string[]): Record<string, string | object>;
|
|
67
|
+
/**
|
|
68
|
+
* Stringifies selection set IR
|
|
69
|
+
* * @example
|
|
70
|
+
* ### Given
|
|
71
|
+
* ```ts
|
|
72
|
+
* {
|
|
73
|
+
* id: '',
|
|
74
|
+
* comments: {
|
|
75
|
+
* items: { post: { id: '' } }
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
* ### Returns
|
|
80
|
+
* `'id comments { items { post { id } } }'`
|
|
81
|
+
*/
|
|
82
|
+
export declare function selectionSetIRToString(obj: Record<string, string | any>): string;
|
|
83
|
+
export declare function generateSelectionSet(modelIntrospection: any, modelName: string, selectionSet?: string[]): string;
|
|
84
|
+
export declare function generateGraphQLDocument(modelIntrospection: any, modelName: string, modelOperation: ModelOperation, listArgs?: ListArgs): string;
|
|
85
|
+
export declare function buildGraphQLVariables(modelDefinition: any, operation: ModelOperation, arg: any, modelIntrospection: any): object;
|
|
86
|
+
/**
|
|
87
|
+
* Iterates over mutation input values and resolves any model inputs to their corresponding join fields/values
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ### Usage
|
|
91
|
+
* ```ts
|
|
92
|
+
* const result = normalizeMutationInput({ post: post }, model, modelDefinition);
|
|
93
|
+
* ```
|
|
94
|
+
* ### Result
|
|
95
|
+
* ```ts
|
|
96
|
+
* { postId: "abc123" }
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
*/
|
|
100
|
+
export declare function normalizeMutationInput(mutationInput: any, model: any, modelDefinition: any): Record<string, unknown>;
|
|
101
|
+
export {};
|