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