@aws-amplify/api-graphql 4.0.1-console-preview.5f040a2.0 → 4.0.1-console-preview.23dc225.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/Providers/AWSAppSyncRealTimeProvider/index.d.ts +2 -2
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +2 -3
- package/lib/internals/InternalGraphQLAPI.js +92 -65
- package/lib/tsconfig.tsbuildinfo +309 -199
- package/lib/types/index.d.ts +4 -4
- package/lib/utils/errors/validation.d.ts +2 -3
- package/lib/utils/errors/validation.js +10 -10
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +2 -2
- package/lib/utils/resolveConfig.d.ts +8 -4
- package/lib/utils/resolveConfig.js +13 -7
- package/lib/utils/resolveLibraryOptions.d.ts +11 -0
- package/lib/utils/resolveLibraryOptions.js +13 -0
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +2 -2
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +3 -4
- package/lib-esm/internals/InternalGraphQLAPI.js +93 -66
- package/lib-esm/tsconfig.tsbuildinfo +309 -199
- package/lib-esm/types/index.d.ts +4 -4
- package/lib-esm/utils/errors/validation.d.ts +2 -3
- package/lib-esm/utils/errors/validation.js +10 -10
- package/lib-esm/utils/index.d.ts +1 -1
- package/lib-esm/utils/index.js +1 -1
- package/lib-esm/utils/resolveConfig.d.ts +8 -4
- package/lib-esm/utils/resolveConfig.js +13 -7
- package/lib-esm/utils/resolveLibraryOptions.d.ts +11 -0
- package/lib-esm/utils/resolveLibraryOptions.js +11 -0
- package/package.json +6 -7
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +7 -6
- package/src/internals/InternalGraphQLAPI.ts +75 -31
- package/src/types/index.ts +7 -4
- package/src/utils/errors/validation.ts +10 -10
- package/src/utils/index.ts +1 -1
- package/src/utils/resolveConfig.ts +24 -9
- package/src/utils/resolveLibraryOptions.ts +13 -0
- package/lib/utils/resolveCredentials.d.ts +0 -12
- package/lib/utils/resolveCredentials.js +0 -22
- package/lib-esm/utils/resolveCredentials.d.ts +0 -12
- package/lib-esm/utils/resolveCredentials.js +0 -20
- package/src/utils/resolveCredentials.ts +0 -14
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
import {
|
|
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
5
|
export declare type ObserverQuery = {
|
|
@@ -13,7 +13,7 @@ export declare type ObserverQuery = {
|
|
|
13
13
|
};
|
|
14
14
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
15
15
|
appSyncGraphqlEndpoint?: string;
|
|
16
|
-
authenticationType?:
|
|
16
|
+
authenticationType?: GraphQLAuthMode;
|
|
17
17
|
query?: string;
|
|
18
18
|
variables?: Record<string, DocumentType>;
|
|
19
19
|
apiKey?: string;
|
|
@@ -6,7 +6,6 @@ var tslib_1 = require("tslib");
|
|
|
6
6
|
var rxjs_1 = require("rxjs");
|
|
7
7
|
var graphql_1 = require("graphql");
|
|
8
8
|
var url = tslib_1.__importStar(require("url"));
|
|
9
|
-
var uuid_1 = require("uuid");
|
|
10
9
|
var buffer_1 = require("buffer");
|
|
11
10
|
var core_1 = require("@aws-amplify/core");
|
|
12
11
|
var aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
@@ -97,7 +96,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
97
96
|
}
|
|
98
97
|
else {
|
|
99
98
|
var subscriptionStartActive_1 = false;
|
|
100
|
-
var subscriptionId_1 =
|
|
99
|
+
var subscriptionId_1 = utils_1.amplifyUuid();
|
|
101
100
|
var startSubscription_1 = function () {
|
|
102
101
|
if (!subscriptionStartActive_1) {
|
|
103
102
|
subscriptionStartActive_1 = true;
|
|
@@ -778,7 +777,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
778
777
|
signed_params = aws_client_utils_1.signRequest({
|
|
779
778
|
headers: request.headers,
|
|
780
779
|
method: request.method,
|
|
781
|
-
url: new
|
|
780
|
+
url: new utils_1.AmplifyUrl(request.url),
|
|
782
781
|
body: request.data,
|
|
783
782
|
}, {
|
|
784
783
|
// TODO: What do we need to do to remove these !'s?
|
|
@@ -9,6 +9,7 @@ var types_1 = require("../types");
|
|
|
9
9
|
var api_rest_1 = require("@aws-amplify/api-rest");
|
|
10
10
|
var internals_1 = require("@aws-amplify/api-rest/internals");
|
|
11
11
|
var AWSAppSyncRealTimeProvider_1 = require("../Providers/AWSAppSyncRealTimeProvider");
|
|
12
|
+
var utils_2 = require("../utils");
|
|
12
13
|
var USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
13
14
|
var logger = new utils_1.ConsoleLogger('GraphQLAPI');
|
|
14
15
|
exports.graphqlOperation = function (query, variables, authToken) {
|
|
@@ -28,7 +29,12 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
28
29
|
* @param {Object} options - Configuration object for API
|
|
29
30
|
*/
|
|
30
31
|
function InternalGraphQLAPIClass(options) {
|
|
31
|
-
this._api = {
|
|
32
|
+
this._api = {
|
|
33
|
+
post: internals_1.post,
|
|
34
|
+
cancelREST: internals_1.cancel,
|
|
35
|
+
isCancelErrorREST: api_rest_1.isCancelError,
|
|
36
|
+
updateRequestToBeCancellable: internals_1.updateRequestToBeCancellable,
|
|
37
|
+
};
|
|
32
38
|
this._options = options;
|
|
33
39
|
logger.debug('API Options', this._options);
|
|
34
40
|
}
|
|
@@ -37,18 +43,18 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
37
43
|
};
|
|
38
44
|
InternalGraphQLAPIClass.prototype._headerBasedAuth = function (amplify, authMode, additionalHeaders) {
|
|
39
45
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
40
|
-
var _a
|
|
46
|
+
var _a;
|
|
41
47
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
42
|
-
var config,
|
|
43
|
-
return tslib_1.__generator(this, function (
|
|
44
|
-
switch (
|
|
48
|
+
var config, _b, region, appSyncGraphqlEndpoint, apiKey, defaultAuthMode, authenticationType, headers, _c, session, token, e_1;
|
|
49
|
+
return tslib_1.__generator(this, function (_d) {
|
|
50
|
+
switch (_d.label) {
|
|
45
51
|
case 0:
|
|
46
52
|
config = amplify.getConfig();
|
|
47
|
-
|
|
53
|
+
_b = utils_2.resolveConfig(amplify), region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, apiKey = _b.apiKey, defaultAuthMode = _b.defaultAuthMode;
|
|
48
54
|
authenticationType = authMode || defaultAuthMode || 'iam';
|
|
49
55
|
headers = {};
|
|
50
|
-
|
|
51
|
-
switch (
|
|
56
|
+
_c = authenticationType;
|
|
57
|
+
switch (_c) {
|
|
52
58
|
case 'apiKey': return [3 /*break*/, 1];
|
|
53
59
|
case 'iam': return [3 /*break*/, 2];
|
|
54
60
|
case 'oidc': return [3 /*break*/, 4];
|
|
@@ -67,17 +73,17 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
67
73
|
return [3 /*break*/, 11];
|
|
68
74
|
case 2: return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
|
|
69
75
|
case 3:
|
|
70
|
-
session =
|
|
76
|
+
session = _d.sent();
|
|
71
77
|
if (session.credentials === undefined) {
|
|
72
78
|
throw new Error(types_1.GraphQLAuthError.NO_CREDENTIALS);
|
|
73
79
|
}
|
|
74
80
|
return [3 /*break*/, 11];
|
|
75
81
|
case 4:
|
|
76
|
-
|
|
82
|
+
_d.trys.push([4, 6, , 7]);
|
|
77
83
|
token = void 0;
|
|
78
84
|
return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
|
|
79
85
|
case 5:
|
|
80
|
-
token = (
|
|
86
|
+
token = (_a = (_d.sent()).tokens) === null || _a === void 0 ? void 0 : _a.accessToken.toString();
|
|
81
87
|
if (!token) {
|
|
82
88
|
throw new Error(types_1.GraphQLAuthError.NO_FEDERATED_JWT);
|
|
83
89
|
}
|
|
@@ -86,7 +92,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
86
92
|
};
|
|
87
93
|
return [3 /*break*/, 7];
|
|
88
94
|
case 6:
|
|
89
|
-
e_1 =
|
|
95
|
+
e_1 = _d.sent();
|
|
90
96
|
throw new Error(types_1.GraphQLAuthError.NO_CURRENT_USER);
|
|
91
97
|
case 7: return [3 /*break*/, 11];
|
|
92
98
|
case 8:
|
|
@@ -98,11 +104,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
98
104
|
};
|
|
99
105
|
return [3 /*break*/, 11];
|
|
100
106
|
case 9: return [3 /*break*/, 11];
|
|
101
|
-
case 10:
|
|
102
|
-
headers = {
|
|
103
|
-
Authorization: null,
|
|
104
|
-
};
|
|
105
|
-
return [3 /*break*/, 11];
|
|
107
|
+
case 10: return [3 /*break*/, 11];
|
|
106
108
|
case 11: return [2 /*return*/, headers];
|
|
107
109
|
}
|
|
108
110
|
});
|
|
@@ -153,49 +155,77 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
153
155
|
InternalGraphQLAPIClass.prototype._graphql = function (amplify, _a, additionalHeaders, abortController, customUserAgentDetails) {
|
|
154
156
|
var query = _a.query, variables = _a.variables, authMode = _a.authMode;
|
|
155
157
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
156
|
-
var _b;
|
|
157
158
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
158
|
-
var
|
|
159
|
-
var
|
|
160
|
-
return tslib_1.__generator(this, function (
|
|
161
|
-
switch (
|
|
159
|
+
var _b, region, appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, _c, customHeaders, withCredentials, headers, _d, _e, _f, _g, _h, _j, _k, body, signingServiceInfo, endpoint, error, response, responseBody, result, err_1, errors;
|
|
160
|
+
var _l;
|
|
161
|
+
return tslib_1.__generator(this, function (_m) {
|
|
162
|
+
switch (_m.label) {
|
|
162
163
|
case 0:
|
|
163
|
-
|
|
164
|
-
_c = (
|
|
165
|
-
customGraphqlEndpoint = null;
|
|
166
|
-
customEndpointRegion = null;
|
|
164
|
+
_b = utils_2.resolveConfig(amplify), region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, customEndpoint = _b.customEndpoint, customEndpointRegion = _b.customEndpointRegion;
|
|
165
|
+
_c = utils_2.resolveLibraryOptions(amplify), customHeaders = _c.headers, withCredentials = _c.withCredentials;
|
|
167
166
|
_d = [{}];
|
|
168
|
-
_e = !
|
|
167
|
+
_e = !customEndpoint;
|
|
169
168
|
if (!_e) return [3 /*break*/, 2];
|
|
170
169
|
return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
|
|
171
170
|
case 1:
|
|
172
|
-
_e = (
|
|
173
|
-
|
|
171
|
+
_e = (_m.sent());
|
|
172
|
+
_m.label = 2;
|
|
174
173
|
case 2:
|
|
175
174
|
_f = [tslib_1.__assign.apply(void 0, _d.concat([(_e)]))];
|
|
176
|
-
_g =
|
|
175
|
+
_g = customEndpoint;
|
|
177
176
|
if (!_g) return [3 /*break*/, 6];
|
|
178
177
|
if (!customEndpointRegion) return [3 /*break*/, 4];
|
|
179
178
|
return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
|
|
180
179
|
case 3:
|
|
181
|
-
_h =
|
|
180
|
+
_h = _m.sent();
|
|
182
181
|
return [3 /*break*/, 5];
|
|
183
182
|
case 4:
|
|
184
|
-
_h = {
|
|
185
|
-
|
|
183
|
+
_h = {};
|
|
184
|
+
_m.label = 5;
|
|
186
185
|
case 5:
|
|
187
186
|
_g = (_h);
|
|
188
|
-
|
|
187
|
+
_m.label = 6;
|
|
189
188
|
case 6:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
_j = [tslib_1.__assign.apply(void 0, _f.concat([((_g) ||
|
|
190
|
+
{})]))];
|
|
191
|
+
_k = customHeaders;
|
|
192
|
+
if (!_k) return [3 /*break*/, 8];
|
|
193
|
+
return [4 /*yield*/, customHeaders({
|
|
194
|
+
query: graphql_1.print(query),
|
|
195
|
+
variables: variables,
|
|
196
|
+
})];
|
|
197
|
+
case 7:
|
|
198
|
+
_k = (_m.sent());
|
|
199
|
+
_m.label = 8;
|
|
200
|
+
case 8:
|
|
201
|
+
headers = tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0, _j.concat([(_k)])), additionalHeaders]), (!customEndpoint && (_l = {},
|
|
202
|
+
_l[USER_AGENT_HEADER] = utils_1.getAmplifyUserAgent(customUserAgentDetails),
|
|
203
|
+
_l))]);
|
|
194
204
|
body = {
|
|
195
205
|
query: graphql_1.print(query),
|
|
196
206
|
variables: variables || null,
|
|
197
207
|
};
|
|
198
|
-
|
|
208
|
+
/**
|
|
209
|
+
* We do not send the signing service info to the REST API under the
|
|
210
|
+
* following conditions (i.e. it will not sign the request):
|
|
211
|
+
* - there is a custom endpoint but no region
|
|
212
|
+
* - the auth mode is `none`, or `apiKey`
|
|
213
|
+
* - the auth mode is a type other than the types listed below
|
|
214
|
+
*/
|
|
215
|
+
if ((customEndpoint && !customEndpointRegion) ||
|
|
216
|
+
(authMode !== 'oidc' &&
|
|
217
|
+
authMode !== 'userPool' &&
|
|
218
|
+
authMode !== 'iam' &&
|
|
219
|
+
authMode !== 'lambda')) {
|
|
220
|
+
signingServiceInfo = null;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
signingServiceInfo = {
|
|
224
|
+
service: !customEndpointRegion ? 'appsync' : 'execute-api',
|
|
225
|
+
region: !customEndpointRegion ? region : customEndpointRegion,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
endpoint = customEndpoint || appSyncGraphqlEndpoint;
|
|
199
229
|
if (!endpoint) {
|
|
200
230
|
error = new graphql_1.GraphQLError('No graphql endpoint provided.');
|
|
201
231
|
throw {
|
|
@@ -203,42 +233,40 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
203
233
|
errors: [error],
|
|
204
234
|
};
|
|
205
235
|
}
|
|
206
|
-
|
|
207
|
-
case
|
|
208
|
-
|
|
236
|
+
_m.label = 9;
|
|
237
|
+
case 9:
|
|
238
|
+
_m.trys.push([9, 12, , 13]);
|
|
209
239
|
return [4 /*yield*/, this._api.post({
|
|
210
|
-
url: new
|
|
240
|
+
url: new utils_1.AmplifyUrl(endpoint),
|
|
211
241
|
options: {
|
|
212
242
|
headers: headers,
|
|
213
243
|
body: body,
|
|
214
|
-
signingServiceInfo:
|
|
215
|
-
|
|
216
|
-
region: region,
|
|
217
|
-
},
|
|
244
|
+
signingServiceInfo: signingServiceInfo,
|
|
245
|
+
withCredentials: withCredentials,
|
|
218
246
|
},
|
|
219
247
|
abortController: abortController,
|
|
220
248
|
})];
|
|
221
|
-
case
|
|
222
|
-
responseBody = (
|
|
249
|
+
case 10:
|
|
250
|
+
responseBody = (_m.sent()).body;
|
|
223
251
|
return [4 /*yield*/, responseBody.json()];
|
|
224
|
-
case
|
|
225
|
-
result =
|
|
252
|
+
case 11:
|
|
253
|
+
result = _m.sent();
|
|
226
254
|
response = result;
|
|
227
|
-
return [3 /*break*/,
|
|
228
|
-
case
|
|
229
|
-
err_1 =
|
|
255
|
+
return [3 /*break*/, 13];
|
|
256
|
+
case 12:
|
|
257
|
+
err_1 = _m.sent();
|
|
230
258
|
// If the exception is because user intentionally
|
|
231
259
|
// cancelled the request, do not modify the exception
|
|
232
260
|
// so that clients can identify the exception correctly.
|
|
233
|
-
if (
|
|
261
|
+
if (this._api.isCancelErrorREST(err_1)) {
|
|
234
262
|
throw err_1;
|
|
235
263
|
}
|
|
236
264
|
response = {
|
|
237
265
|
data: {},
|
|
238
266
|
errors: [new graphql_1.GraphQLError(err_1.message, null, null, null, null, err_1)],
|
|
239
267
|
};
|
|
240
|
-
return [3 /*break*/,
|
|
241
|
-
case
|
|
268
|
+
return [3 /*break*/, 13];
|
|
269
|
+
case 13:
|
|
242
270
|
errors = response.errors;
|
|
243
271
|
if (errors && errors.length) {
|
|
244
272
|
throw response;
|
|
@@ -254,7 +282,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
254
282
|
* @return {boolean} - A boolean indicating if the error was from an api request cancellation
|
|
255
283
|
*/
|
|
256
284
|
InternalGraphQLAPIClass.prototype.isCancelError = function (error) {
|
|
257
|
-
return
|
|
285
|
+
return this._api.isCancelErrorREST(error);
|
|
258
286
|
};
|
|
259
287
|
/**
|
|
260
288
|
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
@@ -262,23 +290,22 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
262
290
|
* @returns - A boolean indicating if the request was cancelled
|
|
263
291
|
*/
|
|
264
292
|
InternalGraphQLAPIClass.prototype.cancel = function (request, message) {
|
|
265
|
-
return
|
|
293
|
+
return this._api.cancelREST(request, message);
|
|
266
294
|
};
|
|
267
295
|
InternalGraphQLAPIClass.prototype._graphqlSubscribe = function (amplify, _a, additionalHeaders, customUserAgentDetails) {
|
|
268
296
|
var query = _a.query, variables = _a.variables, authMode = _a.authMode;
|
|
269
297
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
270
|
-
var
|
|
271
|
-
var GraphQL = ((_b = amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).GraphQL;
|
|
298
|
+
var config = utils_2.resolveConfig(amplify);
|
|
272
299
|
if (!this.appSyncRealTime) {
|
|
273
300
|
this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();
|
|
274
301
|
}
|
|
275
302
|
return this.appSyncRealTime.subscribe({
|
|
276
303
|
query: graphql_1.print(query),
|
|
277
304
|
variables: variables,
|
|
278
|
-
appSyncGraphqlEndpoint:
|
|
279
|
-
region:
|
|
280
|
-
authenticationType:
|
|
281
|
-
apiKey:
|
|
305
|
+
appSyncGraphqlEndpoint: config === null || config === void 0 ? void 0 : config.endpoint,
|
|
306
|
+
region: config === null || config === void 0 ? void 0 : config.region,
|
|
307
|
+
authenticationType: config === null || config === void 0 ? void 0 : config.defaultAuthMode,
|
|
308
|
+
apiKey: config === null || config === void 0 ? void 0 : config.apiKey,
|
|
282
309
|
additionalHeaders: additionalHeaders,
|
|
283
310
|
}, customUserAgentDetails);
|
|
284
311
|
};
|