@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.
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@aws-amplify/api-graphql/internals",
3
+ "types": "../lib-esm/internals/index.d.ts",
4
+ "main": "../lib/internals/index.js",
5
+ "module": "../lib-esm/internals/index.js",
6
+ "react-native": "../lib-esm/internals/index.js",
7
+ "sideEffects": false
8
+ }
@@ -1,47 +1,16 @@
1
- import { OperationTypeNode } from 'graphql';
1
+ import { GraphQLOptions, GraphQLResult } from './types';
2
+ import { InternalGraphQLAPIClass } from './internals';
2
3
  import Observable from 'zen-observable-ts';
3
- import { GraphQLOptions, GraphQLResult, GraphQLOperation } from './types';
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>({ query: paramQuery, variables, authMode, authToken, userAgentSuffix, }: GraphQLOptions, additionalHeaders?: {
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 pubsub_1 = require("@aws-amplify/pubsub");
9
- var auth_1 = require("@aws-amplify/auth");
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
- * Initialize GraphQL API with AWS configuration
30
- * @param {Object} options - Configuration object for API
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 (_a, additionalHeaders) {
195
- var paramQuery = _a.query, _b = _a.variables, variables = _b === void 0 ? {} : _b, authMode = _a.authMode, authToken = _a.authToken, userAgentSuffix = _a.userAgentSuffix;
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);
@@ -1 +1 @@
1
- {"version":3,"file":"GraphQLAPI.js","sourceRoot":"","sources":["../src/GraphQLAPI.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACrE,sCAAsC;AACtC,mCAOiB;AAEjB,0CAM2B;AAC3B,8CAA6C;AAC7C,0CAAyC;AACzC,4CAA2C;AAC3C,iCAKiB;AACjB,kDAAmD;AACnD,IAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAE7C,IAAM,MAAM,GAAG,IAAI,oBAAM,CAAC,YAAY,CAAC,CAAC;AAE3B,QAAA,gBAAgB,GAAG,UAC/B,KAAK,EACL,SAAc,EACd,SAAkB,EAClB,eAAwB;IAFxB,0BAAA,EAAA,cAAc;IAGV,OAAA,CAAC;QACL,KAAK,OAAA;QACL,SAAS,WAAA;QACT,SAAS,WAAA;QACT,eAAe,iBAAA;KACf,CAAC;AALG,CAKH,CAAC;AAEH;;GAEG;AACH;IAWC;;;OAGG;IACH,yBAAY,OAAO;QAVX,SAAI,GAAG,IAAI,CAAC;QAEpB,SAAI,GAAG,WAAI,CAAC;QACZ,UAAK,GAAG,aAAK,CAAC;QACd,gBAAW,GAAG,kBAAW,CAAC;QAOzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CA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BY,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;