@aws-amplify/api-graphql 3.3.2-unstable.f47d472.1 → 3.4.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/internals/package.json +8 -0
- package/lib/GraphQLAPI.d.ts +5 -61
- package/lib/GraphQLAPI.js +9 -370
- package/lib/GraphQLAPI.js.map +1 -1
- package/lib/internals/InternalGraphQLAPI.d.ts +81 -0
- package/lib/internals/InternalGraphQLAPI.js +400 -0
- package/lib/internals/InternalGraphQLAPI.js.map +1 -0
- package/lib/internals/index.d.ts +1 -0
- package/lib/internals/index.js +8 -0
- package/lib/internals/index.js.map +1 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.js.map +1 -1
- package/lib-esm/GraphQLAPI.d.ts +5 -61
- package/lib-esm/GraphQLAPI.js +11 -372
- package/lib-esm/GraphQLAPI.js.map +1 -1
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +81 -0
- package/lib-esm/internals/InternalGraphQLAPI.js +398 -0
- package/lib-esm/internals/InternalGraphQLAPI.js.map +1 -0
- package/lib-esm/internals/index.d.ts +1 -0
- package/lib-esm/internals/index.js +4 -0
- package/lib-esm/internals/index.js.map +1 -0
- package/lib-esm/types/index.d.ts +3 -0
- package/lib-esm/types/index.js.map +1 -1
- package/package.json +10 -9
- package/src/GraphQLAPI.ts +7 -411
- package/src/internals/InternalGraphQLAPI.ts +449 -0
- package/src/internals/index.ts +6 -0
- package/src/types/index.ts +6 -2
package/lib-esm/GraphQLAPI.js
CHANGED
|
@@ -1,187 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { Amplify, ConsoleLogger as Logger, Credentials, getAmplifyUserAgent, INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER, } from '@aws-amplify/core';
|
|
6
|
-
import { PubSub } from '@aws-amplify/pubsub';
|
|
7
|
-
import { Auth } from '@aws-amplify/auth';
|
|
8
|
-
import { Cache } from '@aws-amplify/cache';
|
|
9
|
-
import { GraphQLAuthError, } from './types';
|
|
10
|
-
import { RestClient } from '@aws-amplify/api-rest';
|
|
11
|
-
var USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
12
|
-
var logger = new Logger('GraphQLAPI');
|
|
13
|
-
export var graphqlOperation = function (query, variables, authToken, userAgentSuffix) {
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { Amplify } from '@aws-amplify/core';
|
|
3
|
+
import { InternalGraphQLAPIClass } from './internals';
|
|
4
|
+
export var graphqlOperation = function (query, variables, authToken) {
|
|
14
5
|
if (variables === void 0) { variables = {}; }
|
|
15
6
|
return ({
|
|
16
7
|
query: query,
|
|
17
8
|
variables: variables,
|
|
18
9
|
authToken: authToken,
|
|
19
|
-
userAgentSuffix: userAgentSuffix,
|
|
20
10
|
});
|
|
21
11
|
};
|
|
22
12
|
/**
|
|
23
13
|
* Export Cloud Logic APIs
|
|
24
14
|
*/
|
|
25
|
-
var GraphQLAPIClass = /** @class */ (function () {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
function GraphQLAPIClass(options) {
|
|
31
|
-
this._api = null;
|
|
32
|
-
this.Auth = Auth;
|
|
33
|
-
this.Cache = Cache;
|
|
34
|
-
this.Credentials = Credentials;
|
|
35
|
-
this._options = options;
|
|
36
|
-
logger.debug('API Options', this._options);
|
|
15
|
+
var GraphQLAPIClass = /** @class */ (function (_super) {
|
|
16
|
+
__extends(GraphQLAPIClass, _super);
|
|
17
|
+
function GraphQLAPIClass() {
|
|
18
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
37
19
|
}
|
|
38
20
|
GraphQLAPIClass.prototype.getModuleName = function () {
|
|
39
21
|
return 'GraphQLAPI';
|
|
40
22
|
};
|
|
41
|
-
/**
|
|
42
|
-
* Configure API
|
|
43
|
-
* @param {Object} config - Configuration of the API
|
|
44
|
-
* @return {Object} - The current configuration
|
|
45
|
-
*/
|
|
46
|
-
GraphQLAPIClass.prototype.configure = function (options) {
|
|
47
|
-
var _a = options || {}, _b = _a.API, API = _b === void 0 ? {} : _b, otherOptions = __rest(_a, ["API"]);
|
|
48
|
-
var opt = __assign(__assign({}, otherOptions), API);
|
|
49
|
-
logger.debug('configure GraphQL API', { opt: opt });
|
|
50
|
-
if (opt['aws_project_region']) {
|
|
51
|
-
opt = Object.assign({}, opt, {
|
|
52
|
-
region: opt['aws_project_region'],
|
|
53
|
-
header: {},
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
if (typeof opt.graphql_headers !== 'undefined' &&
|
|
57
|
-
typeof opt.graphql_headers !== 'function') {
|
|
58
|
-
logger.warn('graphql_headers should be a function');
|
|
59
|
-
opt.graphql_headers = undefined;
|
|
60
|
-
}
|
|
61
|
-
this._options = Object.assign({}, this._options, opt);
|
|
62
|
-
this.createInstance();
|
|
63
|
-
return this._options;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Create an instance of API for the library
|
|
67
|
-
* @return - A promise of true if Success
|
|
68
|
-
*/
|
|
69
|
-
GraphQLAPIClass.prototype.createInstance = function () {
|
|
70
|
-
logger.debug('create Rest instance');
|
|
71
|
-
if (this._options) {
|
|
72
|
-
this._api = new RestClient(this._options);
|
|
73
|
-
// Share instance Credentials with client for SSR
|
|
74
|
-
this._api.Credentials = this.Credentials;
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
return Promise.reject('API not configured');
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
GraphQLAPIClass.prototype._headerBasedAuth = function (defaultAuthenticationType, additionalHeaders) {
|
|
82
|
-
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
83
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
-
var _a, aws_appsync_authenticationType, apiKey, authenticationType, headers, _b, credentialsOK, token, federatedInfo, currentUser, e_1, session, e_2;
|
|
85
|
-
return __generator(this, function (_c) {
|
|
86
|
-
switch (_c.label) {
|
|
87
|
-
case 0:
|
|
88
|
-
_a = this._options, aws_appsync_authenticationType = _a.aws_appsync_authenticationType, apiKey = _a.aws_appsync_apiKey;
|
|
89
|
-
authenticationType = defaultAuthenticationType || aws_appsync_authenticationType || 'AWS_IAM';
|
|
90
|
-
headers = {};
|
|
91
|
-
_b = authenticationType;
|
|
92
|
-
switch (_b) {
|
|
93
|
-
case 'API_KEY': return [3 /*break*/, 1];
|
|
94
|
-
case 'AWS_IAM': return [3 /*break*/, 2];
|
|
95
|
-
case 'OPENID_CONNECT': return [3 /*break*/, 4];
|
|
96
|
-
case 'AMAZON_COGNITO_USER_POOLS': return [3 /*break*/, 11];
|
|
97
|
-
case 'AWS_LAMBDA': return [3 /*break*/, 15];
|
|
98
|
-
}
|
|
99
|
-
return [3 /*break*/, 16];
|
|
100
|
-
case 1:
|
|
101
|
-
if (!apiKey) {
|
|
102
|
-
throw new Error(GraphQLAuthError.NO_API_KEY);
|
|
103
|
-
}
|
|
104
|
-
headers = {
|
|
105
|
-
Authorization: null,
|
|
106
|
-
'X-Api-Key': apiKey,
|
|
107
|
-
};
|
|
108
|
-
return [3 /*break*/, 17];
|
|
109
|
-
case 2: return [4 /*yield*/, this._ensureCredentials()];
|
|
110
|
-
case 3:
|
|
111
|
-
credentialsOK = _c.sent();
|
|
112
|
-
if (!credentialsOK) {
|
|
113
|
-
throw new Error(GraphQLAuthError.NO_CREDENTIALS);
|
|
114
|
-
}
|
|
115
|
-
return [3 /*break*/, 17];
|
|
116
|
-
case 4:
|
|
117
|
-
_c.trys.push([4, 9, , 10]);
|
|
118
|
-
token = void 0;
|
|
119
|
-
return [4 /*yield*/, Cache.getItem('federatedInfo')];
|
|
120
|
-
case 5:
|
|
121
|
-
federatedInfo = _c.sent();
|
|
122
|
-
if (!federatedInfo) return [3 /*break*/, 6];
|
|
123
|
-
token = federatedInfo.token;
|
|
124
|
-
return [3 /*break*/, 8];
|
|
125
|
-
case 6: return [4 /*yield*/, Auth.currentAuthenticatedUser()];
|
|
126
|
-
case 7:
|
|
127
|
-
currentUser = _c.sent();
|
|
128
|
-
if (currentUser) {
|
|
129
|
-
token = currentUser.token;
|
|
130
|
-
}
|
|
131
|
-
_c.label = 8;
|
|
132
|
-
case 8:
|
|
133
|
-
if (!token) {
|
|
134
|
-
throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);
|
|
135
|
-
}
|
|
136
|
-
headers = {
|
|
137
|
-
Authorization: token,
|
|
138
|
-
};
|
|
139
|
-
return [3 /*break*/, 10];
|
|
140
|
-
case 9:
|
|
141
|
-
e_1 = _c.sent();
|
|
142
|
-
throw new Error(GraphQLAuthError.NO_CURRENT_USER);
|
|
143
|
-
case 10: return [3 /*break*/, 17];
|
|
144
|
-
case 11:
|
|
145
|
-
_c.trys.push([11, 13, , 14]);
|
|
146
|
-
return [4 /*yield*/, this.Auth.currentSession()];
|
|
147
|
-
case 12:
|
|
148
|
-
session = _c.sent();
|
|
149
|
-
headers = {
|
|
150
|
-
Authorization: session.getAccessToken().getJwtToken(),
|
|
151
|
-
};
|
|
152
|
-
return [3 /*break*/, 14];
|
|
153
|
-
case 13:
|
|
154
|
-
e_2 = _c.sent();
|
|
155
|
-
throw new Error(GraphQLAuthError.NO_CURRENT_USER);
|
|
156
|
-
case 14: return [3 /*break*/, 17];
|
|
157
|
-
case 15:
|
|
158
|
-
if (!additionalHeaders.Authorization) {
|
|
159
|
-
throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);
|
|
160
|
-
}
|
|
161
|
-
headers = {
|
|
162
|
-
Authorization: additionalHeaders.Authorization,
|
|
163
|
-
};
|
|
164
|
-
return [3 /*break*/, 17];
|
|
165
|
-
case 16:
|
|
166
|
-
headers = {
|
|
167
|
-
Authorization: null,
|
|
168
|
-
};
|
|
169
|
-
return [3 /*break*/, 17];
|
|
170
|
-
case 17: return [2 /*return*/, headers];
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* to get the operation type
|
|
177
|
-
* @param operation
|
|
178
|
-
*/
|
|
179
|
-
GraphQLAPIClass.prototype.getGraphqlOperationType = function (operation) {
|
|
180
|
-
var doc = parse(operation);
|
|
181
|
-
var definitions = doc.definitions;
|
|
182
|
-
var _a = __read(definitions, 1), operationType = _a[0].operation;
|
|
183
|
-
return operationType;
|
|
184
|
-
};
|
|
185
23
|
/**
|
|
186
24
|
* Executes a GraphQL operation
|
|
187
25
|
*
|
|
@@ -189,210 +27,11 @@ var GraphQLAPIClass = /** @class */ (function () {
|
|
|
189
27
|
* @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
|
|
190
28
|
* @returns An Observable if the query is a subscription query, else a promise of the graphql result.
|
|
191
29
|
*/
|
|
192
|
-
GraphQLAPIClass.prototype.graphql = function (
|
|
193
|
-
|
|
194
|
-
var query = typeof paramQuery === 'string'
|
|
195
|
-
? parse(paramQuery)
|
|
196
|
-
: parse(print(paramQuery));
|
|
197
|
-
var _c = __read(query.definitions.filter(function (def) { return def.kind === 'OperationDefinition'; }), 1), _d = _c[0], operationDef = _d === void 0 ? {} : _d;
|
|
198
|
-
var operationType = operationDef.operation;
|
|
199
|
-
var headers = additionalHeaders || {};
|
|
200
|
-
// if an authorization header is set, have the explicit authToken take precedence
|
|
201
|
-
if (authToken) {
|
|
202
|
-
headers.Authorization = authToken;
|
|
203
|
-
}
|
|
204
|
-
switch (operationType) {
|
|
205
|
-
case 'query':
|
|
206
|
-
case 'mutation':
|
|
207
|
-
this.createInstanceIfNotCreated();
|
|
208
|
-
var cancellableToken = this._api.getCancellableToken();
|
|
209
|
-
var initParams = {
|
|
210
|
-
cancellableToken: cancellableToken,
|
|
211
|
-
withCredentials: this._options.withCredentials,
|
|
212
|
-
};
|
|
213
|
-
var responsePromise = this._graphql({ query: query, variables: variables, authMode: authMode, userAgentSuffix: userAgentSuffix }, headers, initParams);
|
|
214
|
-
this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
|
|
215
|
-
return responsePromise;
|
|
216
|
-
case 'subscription':
|
|
217
|
-
return this._graphqlSubscribe({ query: query, variables: variables, authMode: authMode }, headers);
|
|
218
|
-
default:
|
|
219
|
-
throw new Error("invalid operation type: " + operationType);
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
GraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders, initParams) {
|
|
223
|
-
var query = _a.query, variables = _a.variables, authMode = _a.authMode, userAgentSuffix = _a.userAgentSuffix;
|
|
224
|
-
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
225
|
-
if (initParams === void 0) { initParams = {}; }
|
|
226
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
-
var _b, region, appSyncGraphqlEndpoint, _c, graphql_headers, customGraphqlEndpoint, customEndpointRegion, headers, _d, _e, _f, _g, _h, _j, body, init, endpoint, error, response, err_1, errors;
|
|
228
|
-
var _k;
|
|
229
|
-
return __generator(this, function (_l) {
|
|
230
|
-
switch (_l.label) {
|
|
231
|
-
case 0:
|
|
232
|
-
this.createInstanceIfNotCreated();
|
|
233
|
-
_b = this._options, region = _b.aws_appsync_region, appSyncGraphqlEndpoint = _b.aws_appsync_graphqlEndpoint, _c = _b.graphql_headers, graphql_headers = _c === void 0 ? function () { return ({}); } : _c, customGraphqlEndpoint = _b.graphql_endpoint, customEndpointRegion = _b.graphql_endpoint_iam_region;
|
|
234
|
-
_d = [{}];
|
|
235
|
-
_e = !customGraphqlEndpoint;
|
|
236
|
-
if (!_e) return [3 /*break*/, 2];
|
|
237
|
-
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
|
|
238
|
-
case 1:
|
|
239
|
-
_e = (_l.sent());
|
|
240
|
-
_l.label = 2;
|
|
241
|
-
case 2:
|
|
242
|
-
_f = [__assign.apply(void 0, _d.concat([(_e)]))];
|
|
243
|
-
_g = customGraphqlEndpoint;
|
|
244
|
-
if (!_g) return [3 /*break*/, 6];
|
|
245
|
-
if (!customEndpointRegion) return [3 /*break*/, 4];
|
|
246
|
-
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
|
|
247
|
-
case 3:
|
|
248
|
-
_h = _l.sent();
|
|
249
|
-
return [3 /*break*/, 5];
|
|
250
|
-
case 4:
|
|
251
|
-
_h = { Authorization: null };
|
|
252
|
-
_l.label = 5;
|
|
253
|
-
case 5:
|
|
254
|
-
_g = (_h);
|
|
255
|
-
_l.label = 6;
|
|
256
|
-
case 6:
|
|
257
|
-
_j = [__assign.apply(void 0, _f.concat([(_g)]))];
|
|
258
|
-
return [4 /*yield*/, graphql_headers({ query: query, variables: variables })];
|
|
259
|
-
case 7:
|
|
260
|
-
headers = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _j.concat([(_l.sent())])), additionalHeaders]), (!customGraphqlEndpoint && (_k = {},
|
|
261
|
-
_k[USER_AGENT_HEADER] = getAmplifyUserAgent(userAgentSuffix),
|
|
262
|
-
_k))]);
|
|
263
|
-
body = {
|
|
264
|
-
query: print(query),
|
|
265
|
-
variables: variables,
|
|
266
|
-
};
|
|
267
|
-
init = Object.assign({
|
|
268
|
-
headers: headers,
|
|
269
|
-
body: body,
|
|
270
|
-
signerServiceInfo: {
|
|
271
|
-
service: !customGraphqlEndpoint ? 'appsync' : 'execute-api',
|
|
272
|
-
region: !customGraphqlEndpoint ? region : customEndpointRegion,
|
|
273
|
-
},
|
|
274
|
-
}, initParams);
|
|
275
|
-
endpoint = customGraphqlEndpoint || appSyncGraphqlEndpoint;
|
|
276
|
-
if (!endpoint) {
|
|
277
|
-
error = new GraphQLError('No graphql endpoint provided.');
|
|
278
|
-
throw {
|
|
279
|
-
data: {},
|
|
280
|
-
errors: [error],
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
_l.label = 8;
|
|
284
|
-
case 8:
|
|
285
|
-
_l.trys.push([8, 10, , 11]);
|
|
286
|
-
return [4 /*yield*/, this._api.post(endpoint, init)];
|
|
287
|
-
case 9:
|
|
288
|
-
response = _l.sent();
|
|
289
|
-
return [3 /*break*/, 11];
|
|
290
|
-
case 10:
|
|
291
|
-
err_1 = _l.sent();
|
|
292
|
-
// If the exception is because user intentionally
|
|
293
|
-
// cancelled the request, do not modify the exception
|
|
294
|
-
// so that clients can identify the exception correctly.
|
|
295
|
-
if (this._api.isCancel(err_1)) {
|
|
296
|
-
throw err_1;
|
|
297
|
-
}
|
|
298
|
-
response = {
|
|
299
|
-
data: {},
|
|
300
|
-
errors: [new GraphQLError(err_1.message, null, null, null, null, err_1)],
|
|
301
|
-
};
|
|
302
|
-
return [3 /*break*/, 11];
|
|
303
|
-
case 11:
|
|
304
|
-
errors = response.errors;
|
|
305
|
-
if (errors && errors.length) {
|
|
306
|
-
throw response;
|
|
307
|
-
}
|
|
308
|
-
return [2 /*return*/, response];
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
};
|
|
313
|
-
GraphQLAPIClass.prototype.createInstanceIfNotCreated = function () {
|
|
314
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
315
|
-
return __generator(this, function (_a) {
|
|
316
|
-
switch (_a.label) {
|
|
317
|
-
case 0:
|
|
318
|
-
if (!!this._api) return [3 /*break*/, 2];
|
|
319
|
-
return [4 /*yield*/, this.createInstance()];
|
|
320
|
-
case 1:
|
|
321
|
-
_a.sent();
|
|
322
|
-
_a.label = 2;
|
|
323
|
-
case 2: return [2 /*return*/];
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
};
|
|
328
|
-
/**
|
|
329
|
-
* Checks to see if an error thrown is from an api request cancellation
|
|
330
|
-
* @param {any} error - Any error
|
|
331
|
-
* @return {boolean} - A boolean indicating if the error was from an api request cancellation
|
|
332
|
-
*/
|
|
333
|
-
GraphQLAPIClass.prototype.isCancel = function (error) {
|
|
334
|
-
return this._api.isCancel(error);
|
|
335
|
-
};
|
|
336
|
-
/**
|
|
337
|
-
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
338
|
-
* @param {any} request - request to cancel
|
|
339
|
-
* @return {boolean} - A boolean indicating if the request was cancelled
|
|
340
|
-
*/
|
|
341
|
-
GraphQLAPIClass.prototype.cancel = function (request, message) {
|
|
342
|
-
return this._api.cancel(request, message);
|
|
343
|
-
};
|
|
344
|
-
/**
|
|
345
|
-
* Check if the request has a corresponding cancel token in the WeakMap.
|
|
346
|
-
* @params request - The request promise
|
|
347
|
-
* @return if the request has a corresponding cancel token.
|
|
348
|
-
*/
|
|
349
|
-
GraphQLAPIClass.prototype.hasCancelToken = function (request) {
|
|
350
|
-
return this._api.hasCancelToken(request);
|
|
351
|
-
};
|
|
352
|
-
GraphQLAPIClass.prototype._graphqlSubscribe = function (_a, additionalHeaders) {
|
|
353
|
-
var query = _a.query, variables = _a.variables, defaultAuthenticationType = _a.authMode, authToken = _a.authToken;
|
|
354
|
-
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
355
|
-
var _b = this._options, region = _b.aws_appsync_region, appSyncGraphqlEndpoint = _b.aws_appsync_graphqlEndpoint, aws_appsync_authenticationType = _b.aws_appsync_authenticationType, apiKey = _b.aws_appsync_apiKey, _c = _b.graphql_headers, graphql_headers = _c === void 0 ? function () { return ({}); } : _c;
|
|
356
|
-
var authenticationType = defaultAuthenticationType || aws_appsync_authenticationType || 'AWS_IAM';
|
|
357
|
-
if (PubSub && typeof PubSub.subscribe === 'function') {
|
|
358
|
-
return PubSub.subscribe('', {
|
|
359
|
-
provider: INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
|
|
360
|
-
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
361
|
-
authenticationType: authenticationType,
|
|
362
|
-
apiKey: apiKey,
|
|
363
|
-
query: print(query),
|
|
364
|
-
region: region,
|
|
365
|
-
variables: variables,
|
|
366
|
-
graphql_headers: graphql_headers,
|
|
367
|
-
additionalHeaders: additionalHeaders,
|
|
368
|
-
authToken: authToken,
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
logger.debug('No pubsub module applied for subscription');
|
|
373
|
-
throw new Error('No pubsub module applied for subscription');
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
/**
|
|
377
|
-
* @private
|
|
378
|
-
*/
|
|
379
|
-
GraphQLAPIClass.prototype._ensureCredentials = function () {
|
|
380
|
-
var _this = this;
|
|
381
|
-
return this.Credentials.get()
|
|
382
|
-
.then(function (credentials) {
|
|
383
|
-
if (!credentials)
|
|
384
|
-
return false;
|
|
385
|
-
var cred = _this.Credentials.shear(credentials);
|
|
386
|
-
logger.debug('set credentials for api', cred);
|
|
387
|
-
return true;
|
|
388
|
-
})
|
|
389
|
-
.catch(function (err) {
|
|
390
|
-
logger.warn('ensure credentials error', err);
|
|
391
|
-
return false;
|
|
392
|
-
});
|
|
30
|
+
GraphQLAPIClass.prototype.graphql = function (options, additionalHeaders) {
|
|
31
|
+
return _super.prototype.graphql.call(this, options, additionalHeaders);
|
|
393
32
|
};
|
|
394
33
|
return GraphQLAPIClass;
|
|
395
|
-
}());
|
|
34
|
+
}(InternalGraphQLAPIClass));
|
|
396
35
|
export { GraphQLAPIClass };
|
|
397
36
|
export var GraphQLAPI = new GraphQLAPIClass(null);
|
|
398
37
|
Amplify.register(GraphQLAPI);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphQLAPI.js","sourceRoot":"","sources":["../src/GraphQLAPI.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"GraphQLAPI.js","sourceRoot":"","sources":["../src/GraphQLAPI.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAGtD,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAC/B,KAAK,EACL,SAAc,EACd,SAAkB;IADlB,0BAAA,EAAA,cAAc;IAEV,OAAA,CAAC;QACL,KAAK,OAAA;QACL,SAAS,WAAA;QACT,SAAS,WAAA;KACT,CAAC;AAJG,CAIH,CAAC;AAEH;;GAEG;AACH;IAAqC,mCAAuB;IAA5D;;IAkBA,CAAC;IAjBO,uCAAa,GAApB;QACC,OAAO,YAAY,CAAC;IACrB,CAAC;IAED;;;;;;OAMG;IACH,iCAAO,GAAP,UACC,OAAuB,EACvB,iBAA6C;QAE7C,OAAO,iBAAM,OAAO,YAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAClD,CAAC;IACF,sBAAC;AAAD,CAAC,AAlBD,CAAqC,uBAAuB,GAkB3D;;AAED,MAAM,CAAC,IAAM,UAAU,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;AACpD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { OperationTypeNode } from 'graphql';
|
|
2
|
+
import Observable from 'zen-observable-ts';
|
|
3
|
+
import { CustomUserAgentDetails } from '@aws-amplify/core';
|
|
4
|
+
import { GraphQLOptions, GraphQLResult, GraphQLOperation } from '../types';
|
|
5
|
+
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string) => {
|
|
6
|
+
query: any;
|
|
7
|
+
variables: {};
|
|
8
|
+
authToken: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Export Cloud Logic APIs
|
|
12
|
+
*/
|
|
13
|
+
export declare class InternalGraphQLAPIClass {
|
|
14
|
+
/**
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
private _options;
|
|
18
|
+
private _api;
|
|
19
|
+
Auth: import("@aws-amplify/auth/lib-esm/Auth").AuthClass;
|
|
20
|
+
Cache: import("@aws-amplify/cache/lib-esm/types").ICache;
|
|
21
|
+
Credentials: import("@aws-amplify/core").CredentialsClass;
|
|
22
|
+
/**
|
|
23
|
+
* Initialize GraphQL API with AWS configuration
|
|
24
|
+
* @param {Object} options - Configuration object for API
|
|
25
|
+
*/
|
|
26
|
+
constructor(options: any);
|
|
27
|
+
getModuleName(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Configure API
|
|
30
|
+
* @param {Object} config - Configuration of the API
|
|
31
|
+
* @return {Object} - The current configuration
|
|
32
|
+
*/
|
|
33
|
+
configure(options: any): any;
|
|
34
|
+
/**
|
|
35
|
+
* Create an instance of API for the library
|
|
36
|
+
* @return - A promise of true if Success
|
|
37
|
+
*/
|
|
38
|
+
createInstance(): true | Promise<never>;
|
|
39
|
+
private _headerBasedAuth;
|
|
40
|
+
/**
|
|
41
|
+
* to get the operation type
|
|
42
|
+
* @param operation
|
|
43
|
+
*/
|
|
44
|
+
getGraphqlOperationType(operation: GraphQLOperation): OperationTypeNode;
|
|
45
|
+
/**
|
|
46
|
+
* Executes a GraphQL operation
|
|
47
|
+
*
|
|
48
|
+
* @param options - GraphQL Options
|
|
49
|
+
* @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
|
|
50
|
+
* @returns An Observable if the query is a subscription query, else a promise of the graphql result.
|
|
51
|
+
*/
|
|
52
|
+
graphql<T = any>({ query: paramQuery, variables, authMode, authToken }: GraphQLOptions, additionalHeaders?: {
|
|
53
|
+
[key: string]: string;
|
|
54
|
+
}, customUserAgentDetails?: CustomUserAgentDetails): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
|
|
55
|
+
private _graphql;
|
|
56
|
+
createInstanceIfNotCreated(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Checks to see if an error thrown is from an api request cancellation
|
|
59
|
+
* @param {any} error - Any error
|
|
60
|
+
* @return {boolean} - A boolean indicating if the error was from an api request cancellation
|
|
61
|
+
*/
|
|
62
|
+
isCancel(error: any): any;
|
|
63
|
+
/**
|
|
64
|
+
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
65
|
+
* @param {any} request - request to cancel
|
|
66
|
+
* @return {boolean} - A boolean indicating if the request was cancelled
|
|
67
|
+
*/
|
|
68
|
+
cancel(request: Promise<any>, message?: string): any;
|
|
69
|
+
/**
|
|
70
|
+
* Check if the request has a corresponding cancel token in the WeakMap.
|
|
71
|
+
* @params request - The request promise
|
|
72
|
+
* @return if the request has a corresponding cancel token.
|
|
73
|
+
*/
|
|
74
|
+
hasCancelToken(request: Promise<any>): any;
|
|
75
|
+
private _graphqlSubscribe;
|
|
76
|
+
/**
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
_ensureCredentials(): any;
|
|
80
|
+
}
|
|
81
|
+
export declare const InternalGraphQLAPI: InternalGraphQLAPIClass;
|