@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
package/lib/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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 tslib_1 = require("tslib");
|
|
6
6
|
var GraphQLAPI_1 = require("./GraphQLAPI");
|
|
7
7
|
exports.GraphQLAPI = GraphQLAPI_1.GraphQLAPI;
|
|
8
8
|
exports.GraphQLAPIClass = GraphQLAPI_1.GraphQLAPIClass;
|
|
@@ -37,7 +37,7 @@ export declare class InternalGraphQLAPIClass {
|
|
|
37
37
|
* @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
|
|
38
38
|
* @returns An Observable if the query is a subscription query, else a promise of the graphql result.
|
|
39
39
|
*/
|
|
40
|
-
graphql<T = any>(amplify: AmplifyClassV6, { query: paramQuery, variables, authMode, authToken }: GraphQLOptions, additionalHeaders?: {
|
|
40
|
+
graphql<T = any>(amplify: AmplifyClassV6 | ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>), { query: paramQuery, variables, authMode, authToken }: GraphQLOptions, additionalHeaders?: {
|
|
41
41
|
[key: string]: string;
|
|
42
42
|
}, customUserAgentDetails?: CustomUserAgentDetails): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
|
|
43
43
|
private _graphql;
|
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var tslib_1 = require("tslib");
|
|
4
3
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
exports.graphqlOperation =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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';
|
|
23
22
|
};
|
|
24
23
|
/**
|
|
25
24
|
* Export Cloud Logic APIs
|
|
26
25
|
*/
|
|
27
|
-
|
|
26
|
+
class InternalGraphQLAPIClass {
|
|
28
27
|
/**
|
|
29
28
|
* Initialize GraphQL API with AWS configuration
|
|
30
29
|
* @param {Object} options - Configuration object for API
|
|
31
30
|
*/
|
|
32
|
-
|
|
31
|
+
constructor(options) {
|
|
33
32
|
this._api = {
|
|
34
33
|
post: internals_1.post,
|
|
35
34
|
cancelREST: internals_1.cancel,
|
|
@@ -39,88 +38,70 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
39
38
|
this._options = options;
|
|
40
39
|
logger.debug('API Options', this._options);
|
|
41
40
|
}
|
|
42
|
-
|
|
41
|
+
getModuleName() {
|
|
43
42
|
return 'InternalGraphQLAPI';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
_b = utils_2.resolveConfig(amplify), region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, apiKey = _b.apiKey, defaultAuthMode = _b.defaultAuthMode;
|
|
55
|
-
authenticationType = authMode || defaultAuthMode || 'iam';
|
|
56
|
-
headers = {};
|
|
57
|
-
_c = authenticationType;
|
|
58
|
-
switch (_c) {
|
|
59
|
-
case 'apiKey': return [3 /*break*/, 1];
|
|
60
|
-
case 'iam': return [3 /*break*/, 2];
|
|
61
|
-
case 'oidc': return [3 /*break*/, 4];
|
|
62
|
-
case 'userPool': return [3 /*break*/, 4];
|
|
63
|
-
case 'lambda': return [3 /*break*/, 8];
|
|
64
|
-
case 'none': return [3 /*break*/, 9];
|
|
65
|
-
}
|
|
66
|
-
return [3 /*break*/, 10];
|
|
67
|
-
case 1:
|
|
68
|
-
if (!apiKey) {
|
|
69
|
-
throw new Error(types_1.GraphQLAuthError.NO_API_KEY);
|
|
70
|
-
}
|
|
71
|
-
headers = {
|
|
72
|
-
'X-Api-Key': apiKey,
|
|
73
|
-
};
|
|
74
|
-
return [3 /*break*/, 11];
|
|
75
|
-
case 2: return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
|
|
76
|
-
case 3:
|
|
77
|
-
session = _d.sent();
|
|
78
|
-
if (session.credentials === undefined) {
|
|
79
|
-
throw new Error(types_1.GraphQLAuthError.NO_CREDENTIALS);
|
|
80
|
-
}
|
|
81
|
-
return [3 /*break*/, 11];
|
|
82
|
-
case 4:
|
|
83
|
-
_d.trys.push([4, 6, , 7]);
|
|
84
|
-
token = void 0;
|
|
85
|
-
return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
|
|
86
|
-
case 5:
|
|
87
|
-
token = (_a = (_d.sent()).tokens) === null || _a === void 0 ? void 0 : _a.accessToken.toString();
|
|
88
|
-
if (!token) {
|
|
89
|
-
throw new Error(types_1.GraphQLAuthError.NO_FEDERATED_JWT);
|
|
90
|
-
}
|
|
91
|
-
headers = {
|
|
92
|
-
Authorization: token,
|
|
93
|
-
};
|
|
94
|
-
return [3 /*break*/, 7];
|
|
95
|
-
case 6:
|
|
96
|
-
e_1 = _d.sent();
|
|
97
|
-
throw new Error(types_1.GraphQLAuthError.NO_CURRENT_USER);
|
|
98
|
-
case 7: return [3 /*break*/, 11];
|
|
99
|
-
case 8:
|
|
100
|
-
if (!additionalHeaders.Authorization) {
|
|
101
|
-
throw new Error(types_1.GraphQLAuthError.NO_AUTH_TOKEN);
|
|
102
|
-
}
|
|
103
|
-
headers = {
|
|
104
|
-
Authorization: additionalHeaders.Authorization,
|
|
105
|
-
};
|
|
106
|
-
return [3 /*break*/, 11];
|
|
107
|
-
case 9: return [3 /*break*/, 11];
|
|
108
|
-
case 10: return [3 /*break*/, 11];
|
|
109
|
-
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);
|
|
110
53
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
+
}
|
|
114
95
|
/**
|
|
115
96
|
* to get the operation type
|
|
116
97
|
* @param operation
|
|
117
98
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
99
|
+
getGraphqlOperationType(operation) {
|
|
100
|
+
const doc = graphql_1.parse(operation);
|
|
101
|
+
const definitions = doc.definitions;
|
|
102
|
+
const [{ operation: operationType }] = definitions;
|
|
122
103
|
return operationType;
|
|
123
|
-
}
|
|
104
|
+
}
|
|
124
105
|
/**
|
|
125
106
|
* Executes a GraphQL operation
|
|
126
107
|
*
|
|
@@ -128,14 +109,13 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
128
109
|
* @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
|
|
129
110
|
* @returns An Observable if the query is a subscription query, else a promise of the graphql result.
|
|
130
111
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
var query = typeof paramQuery === 'string'
|
|
112
|
+
graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken }, additionalHeaders, customUserAgentDetails) {
|
|
113
|
+
const query = typeof paramQuery === 'string'
|
|
134
114
|
? graphql_1.parse(paramQuery)
|
|
135
115
|
: graphql_1.parse(graphql_1.print(paramQuery));
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
116
|
+
const [operationDef = {}] = query.definitions.filter(def => def.kind === 'OperationDefinition');
|
|
117
|
+
const { operation: operationType } = operationDef;
|
|
118
|
+
const headers = additionalHeaders || {};
|
|
139
119
|
// if an authorization header is set, have the explicit authToken take precedence
|
|
140
120
|
if (authToken) {
|
|
141
121
|
headers.Authorization = authToken;
|
|
@@ -143,174 +123,152 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
143
123
|
switch (operationType) {
|
|
144
124
|
case 'query':
|
|
145
125
|
case 'mutation':
|
|
146
|
-
|
|
147
|
-
|
|
126
|
+
const abortController = new AbortController();
|
|
127
|
+
let responsePromise;
|
|
128
|
+
if (isAmplifyInstance(amplify)) {
|
|
129
|
+
responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const wrapper = amplifyInstance => this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails);
|
|
133
|
+
responsePromise = amplify(wrapper);
|
|
134
|
+
}
|
|
148
135
|
this._api.updateRequestToBeCancellable(responsePromise, abortController);
|
|
149
136
|
return responsePromise;
|
|
150
137
|
case 'subscription':
|
|
151
|
-
return this._graphqlSubscribe(amplify, { query
|
|
138
|
+
return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails);
|
|
152
139
|
default:
|
|
153
|
-
throw new Error(
|
|
140
|
+
throw new Error(`invalid operation type: ${operationType}`);
|
|
154
141
|
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
throw {
|
|
233
|
-
data: {},
|
|
234
|
-
errors: [error],
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
_m.label = 9;
|
|
238
|
-
case 9:
|
|
239
|
-
_m.trys.push([9, 12, , 13]);
|
|
240
|
-
return [4 /*yield*/, this._api.post({
|
|
241
|
-
url: new utils_1.AmplifyUrl(endpoint),
|
|
242
|
-
options: {
|
|
243
|
-
headers: headers,
|
|
244
|
-
body: body,
|
|
245
|
-
signingServiceInfo: signingServiceInfo,
|
|
246
|
-
withCredentials: withCredentials,
|
|
247
|
-
},
|
|
248
|
-
abortController: abortController,
|
|
249
|
-
})];
|
|
250
|
-
case 10:
|
|
251
|
-
responseBody = (_m.sent()).body;
|
|
252
|
-
return [4 /*yield*/, responseBody.json()];
|
|
253
|
-
case 11:
|
|
254
|
-
result = _m.sent();
|
|
255
|
-
response = result;
|
|
256
|
-
return [3 /*break*/, 13];
|
|
257
|
-
case 12:
|
|
258
|
-
err_1 = _m.sent();
|
|
259
|
-
// If the exception is because user intentionally
|
|
260
|
-
// cancelled the request, do not modify the exception
|
|
261
|
-
// so that clients can identify the exception correctly.
|
|
262
|
-
if (this.isCancelError(err_1)) {
|
|
263
|
-
throw err_1;
|
|
264
|
-
}
|
|
265
|
-
response = {
|
|
266
|
-
data: {},
|
|
267
|
-
errors: [new graphql_1.GraphQLError(err_1.message, null, null, null, null, err_1)],
|
|
268
|
-
};
|
|
269
|
-
return [3 /*break*/, 13];
|
|
270
|
-
case 13:
|
|
271
|
-
errors = response.errors;
|
|
272
|
-
if (errors && errors.length) {
|
|
273
|
-
throw response;
|
|
274
|
-
}
|
|
275
|
-
return [2 /*return*/, response];
|
|
276
|
-
}
|
|
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,
|
|
277
219
|
});
|
|
278
|
-
|
|
279
|
-
|
|
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
|
+
}
|
|
280
241
|
/**
|
|
281
242
|
* Checks to see if an error thrown is from an api request cancellation
|
|
282
243
|
* @param {any} error - Any error
|
|
283
244
|
* @return {boolean} - A boolean indicating if the error was from an api request cancellation
|
|
284
245
|
*/
|
|
285
|
-
|
|
246
|
+
isCancelError(error) {
|
|
286
247
|
return this._api.isCancelErrorREST(error);
|
|
287
|
-
}
|
|
248
|
+
}
|
|
288
249
|
/**
|
|
289
250
|
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
290
251
|
* @param {any} request - request to cancel
|
|
291
252
|
* @returns - A boolean indicating if the request was cancelled
|
|
292
253
|
*/
|
|
293
|
-
|
|
254
|
+
cancel(request, message) {
|
|
294
255
|
return this._api.cancelREST(request, message);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
299
|
-
var config = utils_2.resolveConfig(amplify);
|
|
256
|
+
}
|
|
257
|
+
_graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails) {
|
|
258
|
+
const config = utils_2.resolveConfig(amplify);
|
|
300
259
|
if (!this.appSyncRealTime) {
|
|
301
260
|
this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();
|
|
302
261
|
}
|
|
303
262
|
return this.appSyncRealTime.subscribe({
|
|
304
263
|
query: graphql_1.print(query),
|
|
305
|
-
variables
|
|
306
|
-
appSyncGraphqlEndpoint: config
|
|
307
|
-
region: config
|
|
308
|
-
authenticationType:
|
|
309
|
-
apiKey: config
|
|
310
|
-
additionalHeaders
|
|
264
|
+
variables,
|
|
265
|
+
appSyncGraphqlEndpoint: config?.endpoint,
|
|
266
|
+
region: config?.region,
|
|
267
|
+
authenticationType: authMode ?? config?.defaultAuthMode,
|
|
268
|
+
apiKey: config?.apiKey,
|
|
269
|
+
additionalHeaders,
|
|
311
270
|
}, customUserAgentDetails);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
}());
|
|
271
|
+
}
|
|
272
|
+
}
|
|
315
273
|
exports.InternalGraphQLAPIClass = InternalGraphQLAPIClass;
|
|
316
274
|
exports.InternalGraphQLAPI = new InternalGraphQLAPIClass(null);
|
package/lib/internals/v6.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const GraphQLAPI_1 = require("../GraphQLAPI");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
7
|
/**
|
|
8
8
|
* Invokes graphql operations against a graphql service, providing correct input and
|
|
9
9
|
* output types if Amplify-generated graphql from a recent version of the CLI/codegen
|
|
@@ -94,7 +94,7 @@ function graphql(options, additionalHeaders) {
|
|
|
94
94
|
* Neither of these can actually be validated at runtime. Hence, we don't perform
|
|
95
95
|
* any validation or type-guarding here.
|
|
96
96
|
*/
|
|
97
|
-
|
|
97
|
+
const result = GraphQLAPI_1.GraphQLAPI.graphql(this[types_1.__amplify], options, additionalHeaders);
|
|
98
98
|
return result;
|
|
99
99
|
}
|
|
100
100
|
exports.graphql = graphql;
|