@aws-amplify/api-graphql 3.4.11 → 4.0.1-console-preview.047a1dd.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/README.md +3 -0
- package/lib/GraphQLAPI.js +0 -5
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +67 -0
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +817 -0
- package/lib/Providers/constants.d.ts +95 -0
- package/lib/Providers/constants.js +103 -0
- package/lib/index.d.ts +0 -3
- package/lib/index.js +3 -9
- package/lib/internals/InternalGraphQLAPI.d.ts +4 -40
- package/lib/internals/InternalGraphQLAPI.js +89 -243
- package/lib/internals/index.d.ts +1 -0
- package/lib/internals/index.js +2 -1
- package/lib/internals/v6.d.ts +89 -0
- package/lib/internals/v6.js +99 -0
- package/lib/tsconfig.tsbuildinfo +5790 -0
- package/lib/types/PubSub.d.ts +27 -0
- package/lib/types/PubSub.js +46 -0
- package/lib/types/index.d.ts +184 -4
- package/lib/types/index.js +0 -3
- package/lib/utils/ConnectionStateMonitor.d.ts +41 -0
- package/lib/utils/ConnectionStateMonitor.js +143 -0
- package/lib/utils/ReachabilityMonitor/index.d.ts +3 -0
- package/lib/utils/ReachabilityMonitor/index.js +6 -0
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +3 -0
- package/lib/utils/ReachabilityMonitor/index.native.js +10 -0
- package/lib/utils/ReconnectionMonitor.d.ts +29 -0
- package/lib/utils/ReconnectionMonitor.js +72 -0
- package/lib/utils/errors/APIError.d.ts +7 -0
- package/lib/utils/errors/APIError.js +22 -0
- package/lib/utils/errors/assertValidationError.d.ts +5 -0
- package/lib/utils/errors/assertValidationError.js +16 -0
- package/lib/utils/errors/index.d.ts +3 -0
- package/lib/utils/errors/index.js +11 -0
- package/lib/utils/errors/validation.d.ts +8 -0
- package/lib/utils/errors/validation.js +26 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +8 -0
- package/lib/utils/resolveConfig.d.ts +8 -0
- package/lib/utils/resolveConfig.js +17 -0
- package/lib/utils/resolveCredentials.d.ts +12 -0
- package/lib/utils/resolveCredentials.js +22 -0
- package/lib-esm/GraphQLAPI.js +0 -5
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +67 -0
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +815 -0
- package/lib-esm/Providers/constants.d.ts +95 -0
- package/lib-esm/Providers/constants.js +100 -0
- package/lib-esm/index.d.ts +0 -3
- package/lib-esm/index.js +0 -4
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +4 -40
- package/lib-esm/internals/InternalGraphQLAPI.js +90 -244
- package/lib-esm/internals/index.d.ts +1 -0
- package/lib-esm/internals/index.js +1 -1
- package/lib-esm/internals/v6.d.ts +89 -0
- package/lib-esm/internals/v6.js +96 -0
- package/lib-esm/tsconfig.tsbuildinfo +5790 -0
- package/lib-esm/types/PubSub.d.ts +27 -0
- package/lib-esm/types/PubSub.js +44 -0
- package/lib-esm/types/index.d.ts +184 -4
- package/lib-esm/types/index.js +0 -3
- package/lib-esm/utils/ConnectionStateMonitor.d.ts +41 -0
- package/lib-esm/utils/ConnectionStateMonitor.js +141 -0
- package/lib-esm/utils/ReachabilityMonitor/index.d.ts +3 -0
- package/lib-esm/utils/ReachabilityMonitor/index.js +4 -0
- package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +3 -0
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +7 -0
- package/lib-esm/utils/ReconnectionMonitor.d.ts +29 -0
- package/lib-esm/utils/ReconnectionMonitor.js +70 -0
- package/lib-esm/utils/errors/APIError.d.ts +7 -0
- package/lib-esm/utils/errors/APIError.js +20 -0
- package/lib-esm/utils/errors/assertValidationError.d.ts +5 -0
- package/lib-esm/utils/errors/assertValidationError.js +13 -0
- package/lib-esm/utils/errors/index.d.ts +3 -0
- package/lib-esm/utils/errors/index.js +5 -0
- package/lib-esm/utils/errors/validation.d.ts +8 -0
- package/lib-esm/utils/errors/validation.js +24 -0
- package/lib-esm/utils/index.d.ts +2 -0
- package/lib-esm/utils/index.js +4 -0
- package/lib-esm/utils/resolveConfig.d.ts +8 -0
- package/lib-esm/utils/resolveConfig.js +15 -0
- package/lib-esm/utils/resolveCredentials.d.ts +12 -0
- package/lib-esm/utils/resolveCredentials.js +20 -0
- package/package.json +114 -114
- package/src/GraphQLAPI.ts +0 -2
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +1003 -0
- package/src/Providers/constants.ts +110 -0
- package/src/index.ts +0 -3
- package/src/internals/InternalGraphQLAPI.ts +62 -221
- package/src/internals/index.ts +2 -0
- package/src/internals/v6.ts +106 -0
- package/src/types/PubSub.ts +58 -0
- package/src/types/index.ts +234 -7
- package/src/utils/ConnectionStateMonitor.ts +195 -0
- package/src/utils/ReachabilityMonitor/index.native.ts +7 -0
- package/src/utils/ReachabilityMonitor/index.ts +4 -0
- package/src/utils/ReconnectionMonitor.ts +76 -0
- package/src/utils/errors/APIError.ts +18 -0
- package/src/utils/errors/assertValidationError.ts +19 -0
- package/src/utils/errors/index.ts +6 -0
- package/src/utils/errors/validation.ts +26 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/resolveConfig.ts +20 -0
- package/src/utils/resolveCredentials.ts +14 -0
- package/lib/.tsbuildinfo +0 -3
- package/lib/GraphQLAPI.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/internals/InternalGraphQLAPI.js.map +0 -1
- package/lib/internals/index.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/GraphQLAPI.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/internals/InternalGraphQLAPI.js.map +0 -1
- package/lib-esm/internals/index.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { __assign, __awaiter, __generator, __read
|
|
1
|
+
import { __assign, __awaiter, __generator, __read } from "tslib";
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
import { print, parse, GraphQLError, } from 'graphql';
|
|
5
|
-
import { Amplify,
|
|
6
|
-
import {
|
|
7
|
-
import { Auth } from '@aws-amplify/auth';
|
|
8
|
-
import { Cache } from '@aws-amplify/cache';
|
|
5
|
+
import { Amplify, Cache, fetchAuthSession } from '@aws-amplify/core';
|
|
6
|
+
import { ConsoleLogger as Logger, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils';
|
|
9
7
|
import { GraphQLAuthError, } from '../types';
|
|
10
|
-
import {
|
|
8
|
+
import { post } from '@aws-amplify/api-rest';
|
|
9
|
+
import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
|
|
11
10
|
var USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
12
11
|
var logger = new Logger('GraphQLAPI');
|
|
13
12
|
export var graphqlOperation = function (query, variables, authToken) {
|
|
@@ -27,146 +26,78 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
27
26
|
* @param {Object} options - Configuration object for API
|
|
28
27
|
*/
|
|
29
28
|
function InternalGraphQLAPIClass(options) {
|
|
30
|
-
this._api = null;
|
|
31
|
-
this.Auth = Auth;
|
|
32
29
|
this.Cache = Cache;
|
|
33
|
-
this.Credentials = Credentials;
|
|
34
30
|
this._options = options;
|
|
35
31
|
logger.debug('API Options', this._options);
|
|
36
32
|
}
|
|
37
33
|
InternalGraphQLAPIClass.prototype.getModuleName = function () {
|
|
38
34
|
return 'InternalGraphQLAPI';
|
|
39
35
|
};
|
|
40
|
-
|
|
41
|
-
* Configure API
|
|
42
|
-
* @param {Object} config - Configuration of the API
|
|
43
|
-
* @return {Object} - The current configuration
|
|
44
|
-
*/
|
|
45
|
-
InternalGraphQLAPIClass.prototype.configure = function (options) {
|
|
46
|
-
var _a = options || {}, _b = _a.API, API = _b === void 0 ? {} : _b, otherOptions = __rest(_a, ["API"]);
|
|
47
|
-
var opt = __assign(__assign({}, otherOptions), API);
|
|
48
|
-
logger.debug('configure GraphQL API', { opt: opt });
|
|
49
|
-
if (opt['aws_project_region']) {
|
|
50
|
-
opt = Object.assign({}, opt, {
|
|
51
|
-
region: opt['aws_project_region'],
|
|
52
|
-
header: {},
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
if (typeof opt.graphql_headers !== 'undefined' &&
|
|
56
|
-
typeof opt.graphql_headers !== 'function') {
|
|
57
|
-
logger.warn('graphql_headers should be a function');
|
|
58
|
-
opt.graphql_headers = undefined;
|
|
59
|
-
}
|
|
60
|
-
this._options = Object.assign({}, this._options, opt);
|
|
61
|
-
this.createInstance();
|
|
62
|
-
return this._options;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Create an instance of API for the library
|
|
66
|
-
* @return - A promise of true if Success
|
|
67
|
-
*/
|
|
68
|
-
InternalGraphQLAPIClass.prototype.createInstance = function () {
|
|
69
|
-
logger.debug('create Rest instance');
|
|
70
|
-
if (this._options) {
|
|
71
|
-
this._api = new RestClient(this._options);
|
|
72
|
-
// Share instance Credentials with client for SSR
|
|
73
|
-
this._api.Credentials = this.Credentials;
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
return Promise.reject('API not configured');
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
InternalGraphQLAPIClass.prototype._headerBasedAuth = function (defaultAuthenticationType, additionalHeaders) {
|
|
36
|
+
InternalGraphQLAPIClass.prototype._headerBasedAuth = function (defaultAuthenticationType, additionalHeaders, customUserAgentDetails) {
|
|
81
37
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
38
|
+
var _a;
|
|
82
39
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var
|
|
84
|
-
return __generator(this, function (
|
|
85
|
-
switch (
|
|
40
|
+
var config, _b, region, appSyncGraphqlEndpoint, authenticationType, headers, _c, session, token, e_1;
|
|
41
|
+
return __generator(this, function (_d) {
|
|
42
|
+
switch (_d.label) {
|
|
86
43
|
case 0:
|
|
87
|
-
|
|
88
|
-
|
|
44
|
+
config = Amplify.getConfig();
|
|
45
|
+
_b = config.API.AppSync, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, authenticationType = _b.defaultAuthMode;
|
|
89
46
|
headers = {};
|
|
90
|
-
|
|
91
|
-
switch (
|
|
92
|
-
case '
|
|
93
|
-
case '
|
|
94
|
-
case '
|
|
95
|
-
case '
|
|
96
|
-
case 'AWS_LAMBDA': return [3 /*break*/, 15];
|
|
47
|
+
_c = authenticationType.type;
|
|
48
|
+
switch (_c) {
|
|
49
|
+
case 'apiKey': return [3 /*break*/, 1];
|
|
50
|
+
case 'iam': return [3 /*break*/, 2];
|
|
51
|
+
case 'jwt': return [3 /*break*/, 4];
|
|
52
|
+
case 'custom': return [3 /*break*/, 8];
|
|
97
53
|
}
|
|
98
|
-
return [3 /*break*/,
|
|
54
|
+
return [3 /*break*/, 9];
|
|
99
55
|
case 1:
|
|
100
|
-
if (!apiKey) {
|
|
56
|
+
if (!authenticationType.apiKey) {
|
|
101
57
|
throw new Error(GraphQLAuthError.NO_API_KEY);
|
|
102
58
|
}
|
|
103
59
|
headers = {
|
|
104
|
-
|
|
105
|
-
'X-Api-Key': apiKey,
|
|
60
|
+
'X-Api-Key': authenticationType.apiKey,
|
|
106
61
|
};
|
|
107
|
-
return [3 /*break*/,
|
|
108
|
-
case 2: return [4 /*yield*/,
|
|
62
|
+
return [3 /*break*/, 10];
|
|
63
|
+
case 2: return [4 /*yield*/, fetchAuthSession()];
|
|
109
64
|
case 3:
|
|
110
|
-
|
|
111
|
-
if (
|
|
65
|
+
session = _d.sent();
|
|
66
|
+
if (session.credentials === undefined) {
|
|
112
67
|
throw new Error(GraphQLAuthError.NO_CREDENTIALS);
|
|
113
68
|
}
|
|
114
|
-
return [3 /*break*/,
|
|
69
|
+
return [3 /*break*/, 10];
|
|
115
70
|
case 4:
|
|
116
|
-
|
|
71
|
+
_d.trys.push([4, 6, , 7]);
|
|
117
72
|
token = void 0;
|
|
118
|
-
return [4 /*yield*/,
|
|
73
|
+
return [4 /*yield*/, fetchAuthSession()];
|
|
119
74
|
case 5:
|
|
120
|
-
|
|
121
|
-
if (!federatedInfo) return [3 /*break*/, 6];
|
|
122
|
-
token = federatedInfo.token;
|
|
123
|
-
return [3 /*break*/, 8];
|
|
124
|
-
case 6: return [4 /*yield*/, Auth.currentAuthenticatedUser()];
|
|
125
|
-
case 7:
|
|
126
|
-
currentUser = _c.sent();
|
|
127
|
-
if (currentUser) {
|
|
128
|
-
token = currentUser.token;
|
|
129
|
-
}
|
|
130
|
-
_c.label = 8;
|
|
131
|
-
case 8:
|
|
75
|
+
token = (_a = (_d.sent()).tokens) === null || _a === void 0 ? void 0 : _a.accessToken.toString();
|
|
132
76
|
if (!token) {
|
|
133
77
|
throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);
|
|
134
78
|
}
|
|
135
79
|
headers = {
|
|
136
80
|
Authorization: token,
|
|
137
81
|
};
|
|
138
|
-
return [3 /*break*/,
|
|
139
|
-
case
|
|
140
|
-
e_1 =
|
|
141
|
-
throw new Error(GraphQLAuthError.NO_CURRENT_USER);
|
|
142
|
-
case 10: return [3 /*break*/, 17];
|
|
143
|
-
case 11:
|
|
144
|
-
_c.trys.push([11, 13, , 14]);
|
|
145
|
-
return [4 /*yield*/, this.Auth.currentSession()];
|
|
146
|
-
case 12:
|
|
147
|
-
session = _c.sent();
|
|
148
|
-
headers = {
|
|
149
|
-
Authorization: session.getAccessToken().getJwtToken(),
|
|
150
|
-
};
|
|
151
|
-
return [3 /*break*/, 14];
|
|
152
|
-
case 13:
|
|
153
|
-
e_2 = _c.sent();
|
|
82
|
+
return [3 /*break*/, 7];
|
|
83
|
+
case 6:
|
|
84
|
+
e_1 = _d.sent();
|
|
154
85
|
throw new Error(GraphQLAuthError.NO_CURRENT_USER);
|
|
155
|
-
case
|
|
156
|
-
case
|
|
86
|
+
case 7: return [3 /*break*/, 10];
|
|
87
|
+
case 8:
|
|
157
88
|
if (!additionalHeaders.Authorization) {
|
|
158
89
|
throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);
|
|
159
90
|
}
|
|
160
91
|
headers = {
|
|
161
92
|
Authorization: additionalHeaders.Authorization,
|
|
162
93
|
};
|
|
163
|
-
return [3 /*break*/,
|
|
164
|
-
case
|
|
94
|
+
return [3 /*break*/, 10];
|
|
95
|
+
case 9:
|
|
165
96
|
headers = {
|
|
166
97
|
Authorization: null,
|
|
167
98
|
};
|
|
168
|
-
return [3 /*break*/,
|
|
169
|
-
case
|
|
99
|
+
return [3 /*break*/, 10];
|
|
100
|
+
case 10: return [2 /*return*/, headers];
|
|
170
101
|
}
|
|
171
102
|
});
|
|
172
103
|
});
|
|
@@ -203,14 +134,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
203
134
|
switch (operationType) {
|
|
204
135
|
case 'query':
|
|
205
136
|
case 'mutation':
|
|
206
|
-
this.
|
|
207
|
-
var cancellableToken = this._api.getCancellableToken();
|
|
208
|
-
var initParams = {
|
|
209
|
-
cancellableToken: cancellableToken,
|
|
210
|
-
withCredentials: this._options.withCredentials,
|
|
211
|
-
};
|
|
212
|
-
var responsePromise = this._graphql({ query: query, variables: variables, authMode: authMode }, headers, initParams, customUserAgentDetails);
|
|
213
|
-
this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
|
|
137
|
+
var responsePromise = this._graphql({ query: query, variables: variables, authMode: authMode }, headers, customUserAgentDetails);
|
|
214
138
|
return responsePromise;
|
|
215
139
|
case 'subscription':
|
|
216
140
|
return this._graphqlSubscribe({ query: query, variables: variables, authMode: authMode }, headers, customUserAgentDetails);
|
|
@@ -218,59 +142,49 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
218
142
|
throw new Error("invalid operation type: " + operationType);
|
|
219
143
|
}
|
|
220
144
|
};
|
|
221
|
-
InternalGraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders,
|
|
145
|
+
InternalGraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders, customUserAgentDetails) {
|
|
222
146
|
var query = _a.query, variables = _a.variables, authMode = _a.authMode;
|
|
223
147
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
224
|
-
if (initParams === void 0) { initParams = {}; }
|
|
225
148
|
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
-
var _b, region, appSyncGraphqlEndpoint,
|
|
227
|
-
var
|
|
228
|
-
return __generator(this, function (
|
|
229
|
-
switch (
|
|
149
|
+
var config, _b, region, appSyncGraphqlEndpoint, customGraphqlEndpoint, customEndpointRegion, headers, _c, _d, _e, _f, _g, body, endpoint, error, response, err_1, errors;
|
|
150
|
+
var _h;
|
|
151
|
+
return __generator(this, function (_j) {
|
|
152
|
+
switch (_j.label) {
|
|
230
153
|
case 0:
|
|
231
|
-
|
|
232
|
-
_b =
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
154
|
+
config = Amplify.getConfig();
|
|
155
|
+
_b = config.API.AppSync, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint;
|
|
156
|
+
customGraphqlEndpoint = null;
|
|
157
|
+
customEndpointRegion = null;
|
|
158
|
+
_c = [{}];
|
|
159
|
+
_d = !customGraphqlEndpoint;
|
|
160
|
+
if (!_d) return [3 /*break*/, 2];
|
|
161
|
+
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders, customUserAgentDetails)];
|
|
237
162
|
case 1:
|
|
238
|
-
|
|
239
|
-
|
|
163
|
+
_d = (_j.sent());
|
|
164
|
+
_j.label = 2;
|
|
240
165
|
case 2:
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (!
|
|
166
|
+
_e = [__assign.apply(void 0, _c.concat([(_d)]))];
|
|
167
|
+
_f = customGraphqlEndpoint;
|
|
168
|
+
if (!_f) return [3 /*break*/, 6];
|
|
244
169
|
if (!customEndpointRegion) return [3 /*break*/, 4];
|
|
245
|
-
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
|
|
170
|
+
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders, customUserAgentDetails)];
|
|
246
171
|
case 3:
|
|
247
|
-
|
|
172
|
+
_g = _j.sent();
|
|
248
173
|
return [3 /*break*/, 5];
|
|
249
174
|
case 4:
|
|
250
|
-
|
|
251
|
-
|
|
175
|
+
_g = { Authorization: null };
|
|
176
|
+
_j.label = 5;
|
|
252
177
|
case 5:
|
|
253
|
-
|
|
254
|
-
|
|
178
|
+
_f = (_g);
|
|
179
|
+
_j.label = 6;
|
|
255
180
|
case 6:
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
headers = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _j.concat([(_l.sent())])), additionalHeaders]), (!customGraphqlEndpoint && (_k = {},
|
|
260
|
-
_k[USER_AGENT_HEADER] = getAmplifyUserAgent(customUserAgentDetails),
|
|
261
|
-
_k))]);
|
|
181
|
+
headers = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _e.concat([(_f)])), additionalHeaders]), (!customGraphqlEndpoint && (_h = {},
|
|
182
|
+
_h[USER_AGENT_HEADER] = getAmplifyUserAgent(customUserAgentDetails),
|
|
183
|
+
_h))]);
|
|
262
184
|
body = {
|
|
263
185
|
query: print(query),
|
|
264
186
|
variables: variables,
|
|
265
187
|
};
|
|
266
|
-
init = Object.assign({
|
|
267
|
-
headers: headers,
|
|
268
|
-
body: body,
|
|
269
|
-
signerServiceInfo: {
|
|
270
|
-
service: !customGraphqlEndpoint ? 'appsync' : 'execute-api',
|
|
271
|
-
region: !customGraphqlEndpoint ? region : customEndpointRegion,
|
|
272
|
-
},
|
|
273
|
-
}, initParams);
|
|
274
188
|
endpoint = customGraphqlEndpoint || appSyncGraphqlEndpoint;
|
|
275
189
|
if (!endpoint) {
|
|
276
190
|
error = new GraphQLError('No graphql endpoint provided.');
|
|
@@ -279,27 +193,26 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
279
193
|
errors: [error],
|
|
280
194
|
};
|
|
281
195
|
}
|
|
282
|
-
|
|
196
|
+
_j.label = 7;
|
|
197
|
+
case 7:
|
|
198
|
+
_j.trys.push([7, 9, , 10]);
|
|
199
|
+
return [4 /*yield*/, post(endpoint, {
|
|
200
|
+
headers: headers,
|
|
201
|
+
body: body,
|
|
202
|
+
region: region,
|
|
203
|
+
serviceName: 'appsync',
|
|
204
|
+
})];
|
|
283
205
|
case 8:
|
|
284
|
-
|
|
285
|
-
return [
|
|
206
|
+
response = _j.sent();
|
|
207
|
+
return [3 /*break*/, 10];
|
|
286
208
|
case 9:
|
|
287
|
-
|
|
288
|
-
return [3 /*break*/, 11];
|
|
289
|
-
case 10:
|
|
290
|
-
err_1 = _l.sent();
|
|
291
|
-
// If the exception is because user intentionally
|
|
292
|
-
// cancelled the request, do not modify the exception
|
|
293
|
-
// so that clients can identify the exception correctly.
|
|
294
|
-
if (this._api.isCancel(err_1)) {
|
|
295
|
-
throw err_1;
|
|
296
|
-
}
|
|
209
|
+
err_1 = _j.sent();
|
|
297
210
|
response = {
|
|
298
211
|
data: {},
|
|
299
212
|
errors: [new GraphQLError(err_1.message, null, null, null, null, err_1)],
|
|
300
213
|
};
|
|
301
|
-
return [3 /*break*/,
|
|
302
|
-
case
|
|
214
|
+
return [3 /*break*/, 10];
|
|
215
|
+
case 10:
|
|
303
216
|
errors = response.errors;
|
|
304
217
|
if (errors && errors.length) {
|
|
305
218
|
throw response;
|
|
@@ -309,90 +222,23 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
309
222
|
});
|
|
310
223
|
});
|
|
311
224
|
};
|
|
312
|
-
InternalGraphQLAPIClass.prototype.createInstanceIfNotCreated = function () {
|
|
313
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
314
|
-
return __generator(this, function (_a) {
|
|
315
|
-
switch (_a.label) {
|
|
316
|
-
case 0:
|
|
317
|
-
if (!!this._api) return [3 /*break*/, 2];
|
|
318
|
-
return [4 /*yield*/, this.createInstance()];
|
|
319
|
-
case 1:
|
|
320
|
-
_a.sent();
|
|
321
|
-
_a.label = 2;
|
|
322
|
-
case 2: return [2 /*return*/];
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
};
|
|
327
|
-
/**
|
|
328
|
-
* Checks to see if an error thrown is from an api request cancellation
|
|
329
|
-
* @param {any} error - Any error
|
|
330
|
-
* @return {boolean} - A boolean indicating if the error was from an api request cancellation
|
|
331
|
-
*/
|
|
332
|
-
InternalGraphQLAPIClass.prototype.isCancel = function (error) {
|
|
333
|
-
return this._api.isCancel(error);
|
|
334
|
-
};
|
|
335
|
-
/**
|
|
336
|
-
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
337
|
-
* @param {any} request - request to cancel
|
|
338
|
-
* @return {boolean} - A boolean indicating if the request was cancelled
|
|
339
|
-
*/
|
|
340
|
-
InternalGraphQLAPIClass.prototype.cancel = function (request, message) {
|
|
341
|
-
return this._api.cancel(request, message);
|
|
342
|
-
};
|
|
343
|
-
/**
|
|
344
|
-
* Check if the request has a corresponding cancel token in the WeakMap.
|
|
345
|
-
* @params request - The request promise
|
|
346
|
-
* @return if the request has a corresponding cancel token.
|
|
347
|
-
*/
|
|
348
|
-
InternalGraphQLAPIClass.prototype.hasCancelToken = function (request) {
|
|
349
|
-
return this._api.hasCancelToken(request);
|
|
350
|
-
};
|
|
351
225
|
InternalGraphQLAPIClass.prototype._graphqlSubscribe = function (_a, additionalHeaders, customUserAgentDetails) {
|
|
352
226
|
var query = _a.query, variables = _a.variables, defaultAuthenticationType = _a.authMode, authToken = _a.authToken;
|
|
353
227
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
354
|
-
var _b
|
|
355
|
-
var
|
|
356
|
-
if (
|
|
357
|
-
|
|
358
|
-
provider: INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
|
|
359
|
-
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
360
|
-
authenticationType: authenticationType,
|
|
361
|
-
apiKey: apiKey,
|
|
362
|
-
query: print(query),
|
|
363
|
-
region: region,
|
|
364
|
-
variables: variables,
|
|
365
|
-
graphql_headers: graphql_headers,
|
|
366
|
-
additionalHeaders: additionalHeaders,
|
|
367
|
-
authToken: authToken,
|
|
368
|
-
}, customUserAgentDetails);
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
logger.debug('No pubsub module applied for subscription');
|
|
372
|
-
throw new Error('No pubsub module applied for subscription');
|
|
228
|
+
var _b;
|
|
229
|
+
var AppSync = ((_b = Amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).AppSync;
|
|
230
|
+
if (!this.appSyncRealTime) {
|
|
231
|
+
this.appSyncRealTime = new AWSAppSyncRealTimeProvider();
|
|
373
232
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
return this.Credentials.get()
|
|
381
|
-
.then(function (credentials) {
|
|
382
|
-
if (!credentials)
|
|
383
|
-
return false;
|
|
384
|
-
var cred = _this.Credentials.shear(credentials);
|
|
385
|
-
logger.debug('set credentials for api', cred);
|
|
386
|
-
return true;
|
|
387
|
-
})
|
|
388
|
-
.catch(function (err) {
|
|
389
|
-
logger.warn('ensure credentials error', err);
|
|
390
|
-
return false;
|
|
233
|
+
return this.appSyncRealTime.subscribe({
|
|
234
|
+
query: print(query),
|
|
235
|
+
variables: variables,
|
|
236
|
+
appSyncGraphqlEndpoint: AppSync.endpoint,
|
|
237
|
+
region: AppSync.region,
|
|
238
|
+
authenticationType: AppSync.defaultAuthMode,
|
|
391
239
|
});
|
|
392
240
|
};
|
|
393
241
|
return InternalGraphQLAPIClass;
|
|
394
242
|
}());
|
|
395
243
|
export { InternalGraphQLAPIClass };
|
|
396
244
|
export var InternalGraphQLAPI = new InternalGraphQLAPIClass(null);
|
|
397
|
-
Amplify.register(InternalGraphQLAPI);
|
|
398
|
-
//# sourceMappingURL=InternalGraphQLAPI.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { GraphQLOptionsV6, GraphQLResponseV6 } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Invokes graphql operations against a graphql service, providing correct input and
|
|
4
|
+
* output types if Amplify-generated graphql from a recent version of the CLI/codegen
|
|
5
|
+
* are used *or* correct typing is provided via the type argument.
|
|
6
|
+
*
|
|
7
|
+
* Amplify-generated "branded" graphql queries will look similar to this:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* //
|
|
11
|
+
* // |-- branding
|
|
12
|
+
* // v
|
|
13
|
+
* export const getModel = `...` as GeneratedQuery<
|
|
14
|
+
* GetModelQueryVariables,
|
|
15
|
+
* GetModelQuery
|
|
16
|
+
* >;
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* If this branding is not in your generated graphql, update to a newer version of
|
|
20
|
+
* CLI/codegen and regenerate your graphql using `amplify codegen`.
|
|
21
|
+
*
|
|
22
|
+
* ## Using Amplify-generated graphql
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import * as queries from './graphql/queries';
|
|
26
|
+
*
|
|
27
|
+
* //
|
|
28
|
+
* // |-- correctly typed graphql response containing a Widget
|
|
29
|
+
* // v
|
|
30
|
+
* const queryResult = await graphql({
|
|
31
|
+
* query: queries.getWidget,
|
|
32
|
+
* variables: {
|
|
33
|
+
* id: "abc", // <-- type hinted/enforced
|
|
34
|
+
* },
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* //
|
|
38
|
+
* // |-- a correctly typed Widget
|
|
39
|
+
* // v
|
|
40
|
+
* const fetchedWidget = queryResult.data?.getWidget!;
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* ## Custom input + result types
|
|
44
|
+
*
|
|
45
|
+
* To provide input types (`variables`) and result types:
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* type GetById_NameOnly = {
|
|
49
|
+
* variables: {
|
|
50
|
+
* id: string
|
|
51
|
+
* },
|
|
52
|
+
* result: Promise<{
|
|
53
|
+
* data: { getWidget: { name: string } }
|
|
54
|
+
* }>
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* //
|
|
58
|
+
* // |-- type is GetById_NameOnly["result"]
|
|
59
|
+
* // v
|
|
60
|
+
* const result = graphql<GetById_NameOnly>({
|
|
61
|
+
* query: "...",
|
|
62
|
+
* variables: { id: "abc" } // <-- type of GetById_NameOnly["variables"]
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* ## Custom result type only
|
|
67
|
+
*
|
|
68
|
+
* To specify result types only, use a type that is *not* in the `{variables, result}` shape:
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* type MyResultType = Promise<{
|
|
72
|
+
* data: {
|
|
73
|
+
* getWidget: { name: string }
|
|
74
|
+
* }
|
|
75
|
+
* }>
|
|
76
|
+
*
|
|
77
|
+
* //
|
|
78
|
+
* // |-- type is MyResultType
|
|
79
|
+
* // v
|
|
80
|
+
* const result = graphql<MyResultType>({query: "..."});
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @param options
|
|
84
|
+
* @param additionalHeaders
|
|
85
|
+
*/
|
|
86
|
+
export declare function graphql<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
|
|
87
|
+
[key: string]: string;
|
|
88
|
+
}): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
89
|
+
export { GraphQLOptionsV6, GraphQLResponseV6 };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { GraphQLAPI } from '../GraphQLAPI';
|
|
4
|
+
/**
|
|
5
|
+
* Invokes graphql operations against a graphql service, providing correct input and
|
|
6
|
+
* output types if Amplify-generated graphql from a recent version of the CLI/codegen
|
|
7
|
+
* are used *or* correct typing is provided via the type argument.
|
|
8
|
+
*
|
|
9
|
+
* Amplify-generated "branded" graphql queries will look similar to this:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* //
|
|
13
|
+
* // |-- branding
|
|
14
|
+
* // v
|
|
15
|
+
* export const getModel = `...` as GeneratedQuery<
|
|
16
|
+
* GetModelQueryVariables,
|
|
17
|
+
* GetModelQuery
|
|
18
|
+
* >;
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* If this branding is not in your generated graphql, update to a newer version of
|
|
22
|
+
* CLI/codegen and regenerate your graphql using `amplify codegen`.
|
|
23
|
+
*
|
|
24
|
+
* ## Using Amplify-generated graphql
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* import * as queries from './graphql/queries';
|
|
28
|
+
*
|
|
29
|
+
* //
|
|
30
|
+
* // |-- correctly typed graphql response containing a Widget
|
|
31
|
+
* // v
|
|
32
|
+
* const queryResult = await graphql({
|
|
33
|
+
* query: queries.getWidget,
|
|
34
|
+
* variables: {
|
|
35
|
+
* id: "abc", // <-- type hinted/enforced
|
|
36
|
+
* },
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* //
|
|
40
|
+
* // |-- a correctly typed Widget
|
|
41
|
+
* // v
|
|
42
|
+
* const fetchedWidget = queryResult.data?.getWidget!;
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* ## Custom input + result types
|
|
46
|
+
*
|
|
47
|
+
* To provide input types (`variables`) and result types:
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* type GetById_NameOnly = {
|
|
51
|
+
* variables: {
|
|
52
|
+
* id: string
|
|
53
|
+
* },
|
|
54
|
+
* result: Promise<{
|
|
55
|
+
* data: { getWidget: { name: string } }
|
|
56
|
+
* }>
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* //
|
|
60
|
+
* // |-- type is GetById_NameOnly["result"]
|
|
61
|
+
* // v
|
|
62
|
+
* const result = graphql<GetById_NameOnly>({
|
|
63
|
+
* query: "...",
|
|
64
|
+
* variables: { id: "abc" } // <-- type of GetById_NameOnly["variables"]
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* ## Custom result type only
|
|
69
|
+
*
|
|
70
|
+
* To specify result types only, use a type that is *not* in the `{variables, result}` shape:
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* type MyResultType = Promise<{
|
|
74
|
+
* data: {
|
|
75
|
+
* getWidget: { name: string }
|
|
76
|
+
* }
|
|
77
|
+
* }>
|
|
78
|
+
*
|
|
79
|
+
* //
|
|
80
|
+
* // |-- type is MyResultType
|
|
81
|
+
* // v
|
|
82
|
+
* const result = graphql<MyResultType>({query: "..."});
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @param options
|
|
86
|
+
* @param additionalHeaders
|
|
87
|
+
*/
|
|
88
|
+
export function graphql(options, additionalHeaders) {
|
|
89
|
+
/**
|
|
90
|
+
* The correctness of these typings depends on correct string branding or overrides.
|
|
91
|
+
* Neither of these can actually be validated at runtime. Hence, we don't perform
|
|
92
|
+
* any validation or type-guarding here.
|
|
93
|
+
*/
|
|
94
|
+
var result = GraphQLAPI.graphql(options, additionalHeaders);
|
|
95
|
+
return result;
|
|
96
|
+
}
|