@aws-amplify/api-graphql 4.0.1-server-generate-client.1e317a1.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 +25 -30
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +468 -584
- package/lib/Providers/constants.js +4 -5
- package/lib/index.js +5 -6
- package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib/internals/InternalGraphQLAPI.js +203 -263
- package/lib/internals/index.d.ts +0 -1
- package/lib/internals/index.js +5 -8
- package/lib/internals/v6.js +3 -4
- package/lib/tsconfig.tsbuildinfo +6798 -1
- package/lib/types/PubSub.d.ts +2 -2
- package/lib/types/PubSub.js +2 -3
- package/lib/types/index.d.ts +39 -28
- package/lib/types/index.js +3 -4
- package/lib/utils/ConnectionStateMonitor.d.ts +3 -3
- package/lib/utils/ConnectionStateMonitor.js +51 -65
- package/lib/utils/ReachabilityMonitor/index.d.ts +1 -1
- package/lib/utils/ReachabilityMonitor/index.js +2 -4
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -1
- package/lib/utils/ReachabilityMonitor/index.native.js +4 -8
- package/lib/utils/ReconnectionMonitor.js +21 -26
- package/lib/utils/errors/APIError.js +7 -12
- package/lib/utils/errors/assertValidationError.js +4 -5
- package/lib/utils/errors/index.js +4 -5
- package/lib/utils/errors/validation.js +6 -8
- package/lib/utils/index.js +2 -3
- package/lib/utils/resolveConfig.d.ts +1 -1
- package/lib/utils/resolveConfig.js +10 -13
- package/lib/utils/resolveLibraryOptions.d.ts +1 -1
- package/lib/utils/resolveLibraryOptions.js +4 -7
- package/lib-esm/GraphQLAPI.d.ts +1 -1
- package/lib-esm/GraphQLAPI.js +25 -29
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +459 -575
- package/lib-esm/Providers/constants.js +10 -10
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib-esm/internals/InternalGraphQLAPI.js +197 -256
- package/lib-esm/internals/index.d.ts +0 -1
- package/lib-esm/internals/index.js +0 -1
- package/lib-esm/internals/v6.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +6798 -1
- package/lib-esm/types/PubSub.d.ts +2 -2
- package/lib-esm/types/index.d.ts +39 -28
- package/lib-esm/types/index.js +1 -1
- package/lib-esm/utils/ConnectionStateMonitor.d.ts +3 -3
- package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
- package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.js +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +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.d.ts +1 -1
- package/lib-esm/utils/resolveConfig.js +8 -9
- package/lib-esm/utils/resolveLibraryOptions.d.ts +1 -1
- package/lib-esm/utils/resolveLibraryOptions.js +4 -5
- package/package.json +6 -12
- package/src/GraphQLAPI.ts +6 -1
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +6 -5
- package/src/internals/InternalGraphQLAPI.ts +7 -8
- package/src/internals/index.ts +0 -1
- package/src/types/index.ts +39 -15
- package/lib/internals/APIClient.d.ts +0 -101
- package/lib/internals/APIClient.js +0 -443
- package/lib/internals/generateClient.d.ts +0 -12
- package/lib/internals/generateClient.js +0 -30
- package/lib/internals/generateModelsProperty.d.ts +0 -4
- package/lib/internals/generateModelsProperty.js +0 -169
- package/lib/internals/types.d.ts +0 -10
- package/lib/internals/types.js +0 -2
- package/lib/utils/resolveOwnerFields.d.ts +0 -12
- package/lib/utils/resolveOwnerFields.js +0 -63
- package/lib-esm/internals/APIClient.d.ts +0 -101
- package/lib-esm/internals/APIClient.js +0 -432
- package/lib-esm/internals/generateClient.d.ts +0 -12
- package/lib-esm/internals/generateClient.js +0 -26
- package/lib-esm/internals/generateModelsProperty.d.ts +0 -4
- package/lib-esm/internals/generateModelsProperty.js +0 -165
- package/lib-esm/internals/types.d.ts +0 -10
- package/lib-esm/internals/types.js +0 -1
- package/lib-esm/utils/resolveOwnerFields.d.ts +0 -12
- package/lib-esm/utils/resolveOwnerFields.js +0 -59
- package/src/internals/APIClient.ts +0 -583
- package/src/internals/generateClient.ts +0 -30
- package/src/internals/generateModelsProperty.ts +0 -192
- package/src/internals/types.ts +0 -15
- package/src/utils/resolveOwnerFields.ts +0 -65
|
@@ -1,10 +1,9 @@
|
|
|
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;
|
|
4
3
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
5
|
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
-
|
|
6
|
+
exports.AMPLIFY_SYMBOL = utils_1.AMPLIFY_SYMBOL;
|
|
8
7
|
exports.MAX_DELAY_MS = 5000;
|
|
9
8
|
exports.NON_RETRYABLE_CODES = [400, 401, 403];
|
|
10
9
|
exports.CONNECTION_STATE_CHANGE = 'ConnectionStateChange';
|
|
@@ -60,19 +59,19 @@ var MESSAGE_TYPES;
|
|
|
60
59
|
* This message type is for sending error messages from AWS AppSync RealTime to the client
|
|
61
60
|
*/
|
|
62
61
|
MESSAGE_TYPES["GQL_ERROR"] = "error";
|
|
63
|
-
})(MESSAGE_TYPES
|
|
62
|
+
})(MESSAGE_TYPES = exports.MESSAGE_TYPES || (exports.MESSAGE_TYPES = {}));
|
|
64
63
|
var SUBSCRIPTION_STATUS;
|
|
65
64
|
(function (SUBSCRIPTION_STATUS) {
|
|
66
65
|
SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["PENDING"] = 0] = "PENDING";
|
|
67
66
|
SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["CONNECTED"] = 1] = "CONNECTED";
|
|
68
67
|
SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["FAILED"] = 2] = "FAILED";
|
|
69
|
-
})(SUBSCRIPTION_STATUS
|
|
68
|
+
})(SUBSCRIPTION_STATUS = exports.SUBSCRIPTION_STATUS || (exports.SUBSCRIPTION_STATUS = {}));
|
|
70
69
|
var SOCKET_STATUS;
|
|
71
70
|
(function (SOCKET_STATUS) {
|
|
72
71
|
SOCKET_STATUS[SOCKET_STATUS["CLOSED"] = 0] = "CLOSED";
|
|
73
72
|
SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
|
|
74
73
|
SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
|
|
75
|
-
})(SOCKET_STATUS
|
|
74
|
+
})(SOCKET_STATUS = exports.SOCKET_STATUS || (exports.SOCKET_STATUS = {}));
|
|
76
75
|
exports.AWS_APPSYNC_REALTIME_HEADERS = {
|
|
77
76
|
accept: 'application/json, text/javascript',
|
|
78
77
|
'content-encoding': 'amz-1.0',
|
package/lib/index.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
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 tslib_1 = require("tslib");
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
7
6
|
var GraphQLAPI_1 = require("./GraphQLAPI");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
exports.GraphQLAPI = GraphQLAPI_1.GraphQLAPI;
|
|
8
|
+
exports.GraphQLAPIClass = GraphQLAPI_1.GraphQLAPIClass;
|
|
9
|
+
exports.graphqlOperation = GraphQLAPI_1.graphqlOperation;
|
|
11
10
|
tslib_1.__exportStar(require("./types"), exports);
|
|
12
11
|
var constants_1 = require("./Providers/constants");
|
|
13
|
-
|
|
12
|
+
exports.CONNECTION_STATE_CHANGE = constants_1.CONNECTION_STATE_CHANGE;
|
|
@@ -3,7 +3,7 @@ import { Observable } from 'rxjs';
|
|
|
3
3
|
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
4
4
|
import { CustomUserAgentDetails } from '@aws-amplify/core/internals/utils';
|
|
5
5
|
import { GraphQLResult, GraphQLOperation, GraphQLOptions } from '../types';
|
|
6
|
-
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string) => {
|
|
6
|
+
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string | undefined) => {
|
|
7
7
|
query: any;
|
|
8
8
|
variables: {};
|
|
9
9
|
authToken: string | undefined;
|
|
@@ -1,43 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InternalGraphQLAPI = exports.InternalGraphQLAPIClass = exports.graphqlOperation = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
3
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
exports.graphqlOperation = graphqlOperation;
|
|
26
|
-
var isAmplifyInstance = function (amplify) {
|
|
27
|
-
if (typeof amplify !== 'function') {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
const api_rest_1 = require("@aws-amplify/api-rest");
|
|
10
|
+
const internals_1 = require("@aws-amplify/api-rest/internals");
|
|
11
|
+
const AWSAppSyncRealTimeProvider_1 = require("../Providers/AWSAppSyncRealTimeProvider");
|
|
12
|
+
const utils_2 = require("../utils");
|
|
13
|
+
const USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
14
|
+
const logger = new core_1.ConsoleLogger('GraphQLAPI');
|
|
15
|
+
exports.graphqlOperation = (query, variables = {}, authToken) => ({
|
|
16
|
+
query,
|
|
17
|
+
variables,
|
|
18
|
+
authToken,
|
|
19
|
+
});
|
|
20
|
+
const isAmplifyInstance = (amplify) => {
|
|
21
|
+
return typeof amplify !== 'function';
|
|
31
22
|
};
|
|
32
23
|
/**
|
|
33
24
|
* Export Cloud Logic APIs
|
|
34
25
|
*/
|
|
35
|
-
|
|
26
|
+
class InternalGraphQLAPIClass {
|
|
36
27
|
/**
|
|
37
28
|
* Initialize GraphQL API with AWS configuration
|
|
38
29
|
* @param {Object} options - Configuration object for API
|
|
39
30
|
*/
|
|
40
|
-
|
|
31
|
+
constructor(options) {
|
|
41
32
|
this._api = {
|
|
42
33
|
post: internals_1.post,
|
|
43
34
|
cancelREST: internals_1.cancel,
|
|
@@ -47,88 +38,70 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
47
38
|
this._options = options;
|
|
48
39
|
logger.debug('API Options', this._options);
|
|
49
40
|
}
|
|
50
|
-
|
|
41
|
+
getModuleName() {
|
|
51
42
|
return 'InternalGraphQLAPI';
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
_b = (0, utils_2.resolveConfig)(amplify), region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, apiKey = _b.apiKey, defaultAuthMode = _b.defaultAuthMode;
|
|
63
|
-
authenticationType = authMode || defaultAuthMode || 'iam';
|
|
64
|
-
headers = {};
|
|
65
|
-
_c = authenticationType;
|
|
66
|
-
switch (_c) {
|
|
67
|
-
case 'apiKey': return [3 /*break*/, 1];
|
|
68
|
-
case 'iam': return [3 /*break*/, 2];
|
|
69
|
-
case 'oidc': return [3 /*break*/, 4];
|
|
70
|
-
case 'userPool': return [3 /*break*/, 4];
|
|
71
|
-
case 'lambda': return [3 /*break*/, 8];
|
|
72
|
-
case 'none': return [3 /*break*/, 9];
|
|
73
|
-
}
|
|
74
|
-
return [3 /*break*/, 10];
|
|
75
|
-
case 1:
|
|
76
|
-
if (!apiKey) {
|
|
77
|
-
throw new Error(types_1.GraphQLAuthError.NO_API_KEY);
|
|
78
|
-
}
|
|
79
|
-
headers = {
|
|
80
|
-
'X-Api-Key': apiKey,
|
|
81
|
-
};
|
|
82
|
-
return [3 /*break*/, 11];
|
|
83
|
-
case 2: return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
|
|
84
|
-
case 3:
|
|
85
|
-
session = _d.sent();
|
|
86
|
-
if (session.credentials === undefined) {
|
|
87
|
-
throw new Error(types_1.GraphQLAuthError.NO_CREDENTIALS);
|
|
88
|
-
}
|
|
89
|
-
return [3 /*break*/, 11];
|
|
90
|
-
case 4:
|
|
91
|
-
_d.trys.push([4, 6, , 7]);
|
|
92
|
-
token = void 0;
|
|
93
|
-
return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
|
|
94
|
-
case 5:
|
|
95
|
-
token = (_a = (_d.sent()).tokens) === null || _a === void 0 ? void 0 : _a.accessToken.toString();
|
|
96
|
-
if (!token) {
|
|
97
|
-
throw new Error(types_1.GraphQLAuthError.NO_FEDERATED_JWT);
|
|
98
|
-
}
|
|
99
|
-
headers = {
|
|
100
|
-
Authorization: token,
|
|
101
|
-
};
|
|
102
|
-
return [3 /*break*/, 7];
|
|
103
|
-
case 6:
|
|
104
|
-
e_1 = _d.sent();
|
|
105
|
-
throw new Error(types_1.GraphQLAuthError.NO_CURRENT_USER);
|
|
106
|
-
case 7: return [3 /*break*/, 11];
|
|
107
|
-
case 8:
|
|
108
|
-
if (!additionalHeaders.Authorization) {
|
|
109
|
-
throw new Error(types_1.GraphQLAuthError.NO_AUTH_TOKEN);
|
|
110
|
-
}
|
|
111
|
-
headers = {
|
|
112
|
-
Authorization: additionalHeaders.Authorization,
|
|
113
|
-
};
|
|
114
|
-
return [3 /*break*/, 11];
|
|
115
|
-
case 9: return [3 /*break*/, 11];
|
|
116
|
-
case 10: return [3 /*break*/, 11];
|
|
117
|
-
case 11: return [2 /*return*/, headers];
|
|
43
|
+
}
|
|
44
|
+
async _headerBasedAuth(amplify, authMode, additionalHeaders = {}) {
|
|
45
|
+
const config = amplify.getConfig();
|
|
46
|
+
const { region: region, endpoint: appSyncGraphqlEndpoint, apiKey, defaultAuthMode, } = utils_2.resolveConfig(amplify);
|
|
47
|
+
const authenticationType = authMode || defaultAuthMode || 'iam';
|
|
48
|
+
let headers = {};
|
|
49
|
+
switch (authenticationType) {
|
|
50
|
+
case 'apiKey':
|
|
51
|
+
if (!apiKey) {
|
|
52
|
+
throw new Error(types_1.GraphQLAuthError.NO_API_KEY);
|
|
118
53
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
54
|
+
headers = {
|
|
55
|
+
'X-Api-Key': apiKey,
|
|
56
|
+
};
|
|
57
|
+
break;
|
|
58
|
+
case 'iam':
|
|
59
|
+
const session = await amplify.Auth.fetchAuthSession();
|
|
60
|
+
if (session.credentials === undefined) {
|
|
61
|
+
throw new Error(types_1.GraphQLAuthError.NO_CREDENTIALS);
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case 'oidc':
|
|
65
|
+
case 'userPool':
|
|
66
|
+
try {
|
|
67
|
+
let token;
|
|
68
|
+
token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();
|
|
69
|
+
if (!token) {
|
|
70
|
+
throw new Error(types_1.GraphQLAuthError.NO_FEDERATED_JWT);
|
|
71
|
+
}
|
|
72
|
+
headers = {
|
|
73
|
+
Authorization: token,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
throw new Error(types_1.GraphQLAuthError.NO_CURRENT_USER);
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case 'lambda':
|
|
81
|
+
if (!additionalHeaders.Authorization) {
|
|
82
|
+
throw new Error(types_1.GraphQLAuthError.NO_AUTH_TOKEN);
|
|
83
|
+
}
|
|
84
|
+
headers = {
|
|
85
|
+
Authorization: additionalHeaders.Authorization,
|
|
86
|
+
};
|
|
87
|
+
break;
|
|
88
|
+
case 'none':
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
return headers;
|
|
94
|
+
}
|
|
122
95
|
/**
|
|
123
96
|
* to get the operation type
|
|
124
97
|
* @param operation
|
|
125
98
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
99
|
+
getGraphqlOperationType(operation) {
|
|
100
|
+
const doc = graphql_1.parse(operation);
|
|
101
|
+
const definitions = doc.definitions;
|
|
102
|
+
const [{ operation: operationType }] = definitions;
|
|
130
103
|
return operationType;
|
|
131
|
-
}
|
|
104
|
+
}
|
|
132
105
|
/**
|
|
133
106
|
* Executes a GraphQL operation
|
|
134
107
|
*
|
|
@@ -136,15 +109,13 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
136
109
|
* @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
|
|
137
110
|
* @returns An Observable if the query is a subscription query, else a promise of the graphql result.
|
|
138
111
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var operationType = operationDef.operation;
|
|
147
|
-
var headers = additionalHeaders || {};
|
|
112
|
+
graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken }, additionalHeaders, customUserAgentDetails) {
|
|
113
|
+
const query = typeof paramQuery === 'string'
|
|
114
|
+
? graphql_1.parse(paramQuery)
|
|
115
|
+
: graphql_1.parse(graphql_1.print(paramQuery));
|
|
116
|
+
const [operationDef = {}] = query.definitions.filter(def => def.kind === 'OperationDefinition');
|
|
117
|
+
const { operation: operationType } = operationDef;
|
|
118
|
+
const headers = additionalHeaders || {};
|
|
148
119
|
// if an authorization header is set, have the explicit authToken take precedence
|
|
149
120
|
if (authToken) {
|
|
150
121
|
headers.Authorization = authToken;
|
|
@@ -152,183 +123,152 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
152
123
|
switch (operationType) {
|
|
153
124
|
case 'query':
|
|
154
125
|
case 'mutation':
|
|
155
|
-
|
|
156
|
-
|
|
126
|
+
const abortController = new AbortController();
|
|
127
|
+
let responsePromise;
|
|
157
128
|
if (isAmplifyInstance(amplify)) {
|
|
158
|
-
responsePromise = this._graphql(amplify, { query
|
|
129
|
+
responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails);
|
|
159
130
|
}
|
|
160
131
|
else {
|
|
161
|
-
|
|
162
|
-
return _this._graphql(amplifyInstance, { query: query, variables: variables, authMode: authMode }, headers, abortController_1, customUserAgentDetails);
|
|
163
|
-
};
|
|
132
|
+
const wrapper = amplifyInstance => this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails);
|
|
164
133
|
responsePromise = amplify(wrapper);
|
|
165
134
|
}
|
|
166
|
-
this._api.updateRequestToBeCancellable(responsePromise,
|
|
135
|
+
this._api.updateRequestToBeCancellable(responsePromise, abortController);
|
|
167
136
|
return responsePromise;
|
|
168
137
|
case 'subscription':
|
|
169
|
-
return this._graphqlSubscribe(amplify, { query
|
|
138
|
+
return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails);
|
|
170
139
|
default:
|
|
171
|
-
throw new Error(
|
|
140
|
+
throw new Error(`invalid operation type: ${operationType}`);
|
|
172
141
|
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
throw {
|
|
251
|
-
data: {},
|
|
252
|
-
errors: [error],
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
_m.label = 9;
|
|
256
|
-
case 9:
|
|
257
|
-
_m.trys.push([9, 12, , 13]);
|
|
258
|
-
return [4 /*yield*/, this._api.post({
|
|
259
|
-
url: new utils_1.AmplifyUrl(endpoint),
|
|
260
|
-
options: {
|
|
261
|
-
headers: headers,
|
|
262
|
-
body: body,
|
|
263
|
-
signingServiceInfo: signingServiceInfo,
|
|
264
|
-
withCredentials: withCredentials,
|
|
265
|
-
},
|
|
266
|
-
abortController: abortController,
|
|
267
|
-
})];
|
|
268
|
-
case 10:
|
|
269
|
-
responseBody = (_m.sent()).body;
|
|
270
|
-
return [4 /*yield*/, responseBody.json()];
|
|
271
|
-
case 11:
|
|
272
|
-
result = _m.sent();
|
|
273
|
-
response = result;
|
|
274
|
-
return [3 /*break*/, 13];
|
|
275
|
-
case 12:
|
|
276
|
-
err_1 = _m.sent();
|
|
277
|
-
// If the exception is because user intentionally
|
|
278
|
-
// cancelled the request, do not modify the exception
|
|
279
|
-
// so that clients can identify the exception correctly.
|
|
280
|
-
if (this._api.isCancelErrorREST(err_1)) {
|
|
281
|
-
throw err_1;
|
|
282
|
-
}
|
|
283
|
-
response = {
|
|
284
|
-
data: {},
|
|
285
|
-
errors: [new graphql_1.GraphQLError(err_1.message, null, null, null, null, err_1)],
|
|
286
|
-
};
|
|
287
|
-
return [3 /*break*/, 13];
|
|
288
|
-
case 13:
|
|
289
|
-
errors = response.errors;
|
|
290
|
-
if (errors && errors.length) {
|
|
291
|
-
throw response;
|
|
292
|
-
}
|
|
293
|
-
return [2 /*return*/, response];
|
|
294
|
-
}
|
|
142
|
+
}
|
|
143
|
+
async _graphql(amplify, { query, variables, authMode }, additionalHeaders = {}, abortController, customUserAgentDetails) {
|
|
144
|
+
const { region: region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, } = utils_2.resolveConfig(amplify);
|
|
145
|
+
// Retrieve library options from Amplify configuration
|
|
146
|
+
const { headers: customHeaders, withCredentials } = utils_2.resolveLibraryOptions(amplify);
|
|
147
|
+
// TODO: Figure what we need to do to remove `!`'s.
|
|
148
|
+
const headers = {
|
|
149
|
+
...(!customEndpoint &&
|
|
150
|
+
(await this._headerBasedAuth(amplify, authMode, additionalHeaders))),
|
|
151
|
+
/**
|
|
152
|
+
* Custom endpoint headers.
|
|
153
|
+
* If there is both a custom endpoint and custom region present, we get the headers.
|
|
154
|
+
* If there is a custom endpoint but no region, we return an empty object.
|
|
155
|
+
* If neither are present, we return an empty object.
|
|
156
|
+
*/
|
|
157
|
+
...((customEndpoint &&
|
|
158
|
+
(customEndpointRegion
|
|
159
|
+
? await this._headerBasedAuth(amplify, authMode, additionalHeaders)
|
|
160
|
+
: {})) ||
|
|
161
|
+
{}),
|
|
162
|
+
// Custom headers included in Amplify configuration options:
|
|
163
|
+
...(customHeaders &&
|
|
164
|
+
(await customHeaders({
|
|
165
|
+
query: graphql_1.print(query),
|
|
166
|
+
variables,
|
|
167
|
+
}))),
|
|
168
|
+
// Headers from individual calls to `graphql`:
|
|
169
|
+
...additionalHeaders,
|
|
170
|
+
// User agent headers:
|
|
171
|
+
...(!customEndpoint && {
|
|
172
|
+
[USER_AGENT_HEADER]: utils_1.getAmplifyUserAgent(customUserAgentDetails),
|
|
173
|
+
}),
|
|
174
|
+
};
|
|
175
|
+
const body = {
|
|
176
|
+
query: graphql_1.print(query),
|
|
177
|
+
variables: variables || null,
|
|
178
|
+
};
|
|
179
|
+
let signingServiceInfo;
|
|
180
|
+
/**
|
|
181
|
+
* We do not send the signing service info to the REST API under the
|
|
182
|
+
* following conditions (i.e. it will not sign the request):
|
|
183
|
+
* - there is a custom endpoint but no region
|
|
184
|
+
* - the auth mode is `none`, or `apiKey`
|
|
185
|
+
* - the auth mode is a type other than the types listed below
|
|
186
|
+
*/
|
|
187
|
+
if ((customEndpoint && !customEndpointRegion) ||
|
|
188
|
+
(authMode !== 'oidc' &&
|
|
189
|
+
authMode !== 'userPool' &&
|
|
190
|
+
authMode !== 'iam' &&
|
|
191
|
+
authMode !== 'lambda')) {
|
|
192
|
+
signingServiceInfo = null;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
signingServiceInfo = {
|
|
196
|
+
service: !customEndpointRegion ? 'appsync' : 'execute-api',
|
|
197
|
+
region: !customEndpointRegion ? region : customEndpointRegion,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const endpoint = customEndpoint || appSyncGraphqlEndpoint;
|
|
201
|
+
if (!endpoint) {
|
|
202
|
+
const error = new graphql_1.GraphQLError('No graphql endpoint provided.');
|
|
203
|
+
throw {
|
|
204
|
+
data: {},
|
|
205
|
+
errors: [error],
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
let response;
|
|
209
|
+
try {
|
|
210
|
+
const { body: responseBody } = await this._api.post({
|
|
211
|
+
url: new utils_1.AmplifyUrl(endpoint),
|
|
212
|
+
options: {
|
|
213
|
+
headers,
|
|
214
|
+
body,
|
|
215
|
+
signingServiceInfo,
|
|
216
|
+
withCredentials,
|
|
217
|
+
},
|
|
218
|
+
abortController,
|
|
295
219
|
});
|
|
296
|
-
|
|
297
|
-
|
|
220
|
+
const result = await responseBody.json();
|
|
221
|
+
response = result;
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
// If the exception is because user intentionally
|
|
225
|
+
// cancelled the request, do not modify the exception
|
|
226
|
+
// so that clients can identify the exception correctly.
|
|
227
|
+
if (this.isCancelError(err)) {
|
|
228
|
+
throw err;
|
|
229
|
+
}
|
|
230
|
+
response = {
|
|
231
|
+
data: {},
|
|
232
|
+
errors: [new graphql_1.GraphQLError(err.message, null, null, null, null, err)],
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
const { errors } = response;
|
|
236
|
+
if (errors && errors.length) {
|
|
237
|
+
throw response;
|
|
238
|
+
}
|
|
239
|
+
return response;
|
|
240
|
+
}
|
|
298
241
|
/**
|
|
299
242
|
* Checks to see if an error thrown is from an api request cancellation
|
|
300
243
|
* @param {any} error - Any error
|
|
301
244
|
* @return {boolean} - A boolean indicating if the error was from an api request cancellation
|
|
302
245
|
*/
|
|
303
|
-
|
|
246
|
+
isCancelError(error) {
|
|
304
247
|
return this._api.isCancelErrorREST(error);
|
|
305
|
-
}
|
|
248
|
+
}
|
|
306
249
|
/**
|
|
307
250
|
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
308
251
|
* @param {any} request - request to cancel
|
|
309
252
|
* @returns - A boolean indicating if the request was cancelled
|
|
310
253
|
*/
|
|
311
|
-
|
|
254
|
+
cancel(request, message) {
|
|
312
255
|
return this._api.cancelREST(request, message);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
317
|
-
var config = (0, utils_2.resolveConfig)(amplify);
|
|
256
|
+
}
|
|
257
|
+
_graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails) {
|
|
258
|
+
const config = utils_2.resolveConfig(amplify);
|
|
318
259
|
if (!this.appSyncRealTime) {
|
|
319
260
|
this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();
|
|
320
261
|
}
|
|
321
262
|
return this.appSyncRealTime.subscribe({
|
|
322
|
-
query:
|
|
323
|
-
variables
|
|
324
|
-
appSyncGraphqlEndpoint: config
|
|
325
|
-
region: config
|
|
326
|
-
authenticationType:
|
|
327
|
-
apiKey: config
|
|
328
|
-
additionalHeaders
|
|
263
|
+
query: graphql_1.print(query),
|
|
264
|
+
variables,
|
|
265
|
+
appSyncGraphqlEndpoint: config?.endpoint,
|
|
266
|
+
region: config?.region,
|
|
267
|
+
authenticationType: authMode ?? config?.defaultAuthMode,
|
|
268
|
+
apiKey: config?.apiKey,
|
|
269
|
+
additionalHeaders,
|
|
329
270
|
}, customUserAgentDetails);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
}());
|
|
271
|
+
}
|
|
272
|
+
}
|
|
333
273
|
exports.InternalGraphQLAPIClass = InternalGraphQLAPIClass;
|
|
334
274
|
exports.InternalGraphQLAPI = new InternalGraphQLAPIClass(null);
|
package/lib/internals/index.d.ts
CHANGED
package/lib/internals/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateClient = exports.isCancelError = exports.cancel = exports.graphql = exports.InternalGraphQLAPIClass = exports.InternalGraphQLAPI = void 0;
|
|
4
3
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
5
|
var InternalGraphQLAPI_1 = require("./InternalGraphQLAPI");
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
exports.InternalGraphQLAPI = InternalGraphQLAPI_1.InternalGraphQLAPI;
|
|
7
|
+
exports.InternalGraphQLAPIClass = InternalGraphQLAPI_1.InternalGraphQLAPIClass;
|
|
9
8
|
var v6_1 = require("./v6");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var generateClient_1 = require("./generateClient");
|
|
14
|
-
Object.defineProperty(exports, "generateClient", { enumerable: true, get: function () { return generateClient_1.generateClient; } });
|
|
9
|
+
exports.graphql = v6_1.graphql;
|
|
10
|
+
exports.cancel = v6_1.cancel;
|
|
11
|
+
exports.isCancelError = v6_1.isCancelError;
|