@aws-amplify/api-graphql 4.0.1-console-preview.d745d43.0 → 4.0.1-mjs-test.20ead30.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.
Files changed (155) hide show
  1. package/dist/cjs/GraphQLAPI.js +52 -0
  2. package/dist/cjs/GraphQLAPI.js.map +1 -0
  3. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +693 -0
  4. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -0
  5. package/{lib → dist/cjs}/Providers/constants.js +8 -8
  6. package/dist/cjs/Providers/constants.js.map +1 -0
  7. package/dist/cjs/index.js +15 -0
  8. package/dist/cjs/index.js.map +1 -0
  9. package/dist/cjs/internals/InternalGraphQLAPI.js +274 -0
  10. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -0
  11. package/dist/cjs/internals/index.js +14 -0
  12. package/dist/cjs/internals/index.js.map +1 -0
  13. package/{lib → dist/cjs}/internals/v6.js +7 -4
  14. package/dist/cjs/internals/v6.js.map +1 -0
  15. package/{lib → dist/cjs}/types/PubSub.js +6 -6
  16. package/dist/cjs/types/PubSub.js.map +1 -0
  17. package/{lib → dist/cjs}/types/index.js +7 -5
  18. package/dist/cjs/types/index.js.map +1 -0
  19. package/dist/cjs/utils/ConnectionStateMonitor.js +134 -0
  20. package/dist/cjs/utils/ConnectionStateMonitor.js.map +1 -0
  21. package/dist/cjs/utils/ReachabilityMonitor/index.js +10 -0
  22. package/dist/cjs/utils/ReachabilityMonitor/index.js.map +1 -0
  23. package/dist/cjs/utils/ReachabilityMonitor/index.native.js +12 -0
  24. package/dist/cjs/utils/ReachabilityMonitor/index.native.js.map +1 -0
  25. package/{lib → dist/cjs}/utils/ReconnectionMonitor.js +24 -25
  26. package/dist/cjs/utils/ReconnectionMonitor.js.map +1 -0
  27. package/dist/cjs/utils/errors/APIError.js +21 -0
  28. package/dist/cjs/utils/errors/APIError.js.map +1 -0
  29. package/dist/cjs/utils/errors/assertValidationError.js +19 -0
  30. package/dist/cjs/utils/errors/assertValidationError.js.map +1 -0
  31. package/dist/cjs/utils/errors/index.js +14 -0
  32. package/dist/cjs/utils/errors/index.js.map +1 -0
  33. package/{lib → dist/cjs}/utils/errors/validation.js +9 -7
  34. package/dist/cjs/utils/errors/validation.js.map +1 -0
  35. package/dist/cjs/utils/index.js +11 -0
  36. package/dist/cjs/utils/index.js.map +1 -0
  37. package/dist/cjs/utils/resolveConfig.js +26 -0
  38. package/dist/cjs/utils/resolveConfig.js.map +1 -0
  39. package/dist/cjs/utils/resolveLibraryOptions.js +16 -0
  40. package/dist/cjs/utils/resolveLibraryOptions.js.map +1 -0
  41. package/{lib-esm → dist/esm}/GraphQLAPI.d.ts +2 -2
  42. package/dist/esm/GraphQLAPI.mjs +50 -0
  43. package/dist/esm/GraphQLAPI.mjs.map +1 -0
  44. package/{lib → dist/esm}/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
  45. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +691 -0
  46. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -0
  47. package/{lib-esm/Providers/constants.js → dist/esm/Providers/constants.mjs} +18 -14
  48. package/dist/esm/Providers/constants.mjs.map +1 -0
  49. package/dist/esm/index.mjs +5 -0
  50. package/dist/esm/index.mjs.map +1 -0
  51. package/{lib → dist/esm}/internals/InternalGraphQLAPI.d.ts +2 -2
  52. package/dist/esm/internals/InternalGraphQLAPI.mjs +272 -0
  53. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -0
  54. package/dist/esm/internals/index.mjs +3 -0
  55. package/dist/esm/internals/index.mjs.map +1 -0
  56. package/{lib-esm/internals/v6.js → dist/esm/internals/v6.mjs} +10 -6
  57. package/dist/esm/internals/v6.mjs.map +1 -0
  58. package/{lib → dist/esm}/types/PubSub.d.ts +2 -2
  59. package/{lib-esm/types/PubSub.js → dist/esm/types/PubSub.mjs} +5 -2
  60. package/dist/esm/types/PubSub.mjs.map +1 -0
  61. package/{lib-esm → dist/esm}/types/index.d.ts +45 -25
  62. package/{lib-esm/types/index.js → dist/esm/types/index.mjs} +7 -3
  63. package/dist/esm/types/index.mjs.map +1 -0
  64. package/{lib-esm → dist/esm}/utils/ConnectionStateMonitor.d.ts +3 -3
  65. package/{lib-esm/utils/ConnectionStateMonitor.js → dist/esm/utils/ConnectionStateMonitor.mjs} +56 -66
  66. package/dist/esm/utils/ConnectionStateMonitor.mjs.map +1 -0
  67. package/dist/esm/utils/ReachabilityMonitor/index.d.ts +1 -0
  68. package/{lib-esm/utils/ReachabilityMonitor/index.js → dist/esm/utils/ReachabilityMonitor/index.mjs} +6 -2
  69. package/dist/esm/utils/ReachabilityMonitor/index.mjs.map +1 -0
  70. package/dist/esm/utils/ReachabilityMonitor/index.native.d.ts +1 -0
  71. package/dist/esm/utils/ReachabilityMonitor/index.native.mjs +9 -0
  72. package/dist/esm/utils/ReachabilityMonitor/index.native.mjs.map +1 -0
  73. package/{lib-esm/utils/ReconnectionMonitor.js → dist/esm/utils/ReconnectionMonitor.mjs} +25 -26
  74. package/dist/esm/utils/ReconnectionMonitor.mjs.map +1 -0
  75. package/dist/esm/utils/errors/APIError.mjs +19 -0
  76. package/dist/esm/utils/errors/APIError.mjs.map +1 -0
  77. package/dist/esm/utils/errors/assertValidationError.mjs +17 -0
  78. package/dist/esm/utils/errors/assertValidationError.mjs.map +1 -0
  79. package/dist/esm/utils/errors/index.mjs +4 -0
  80. package/dist/esm/utils/errors/index.mjs.map +1 -0
  81. package/{lib-esm/utils/errors/validation.js → dist/esm/utils/errors/validation.mjs} +9 -7
  82. package/dist/esm/utils/errors/validation.mjs.map +1 -0
  83. package/dist/esm/utils/index.mjs +3 -0
  84. package/dist/esm/utils/index.mjs.map +1 -0
  85. package/{lib → dist/esm}/utils/resolveConfig.d.ts +1 -1
  86. package/dist/esm/utils/resolveConfig.mjs +26 -0
  87. package/dist/esm/utils/resolveConfig.mjs.map +1 -0
  88. package/{lib-esm → dist/esm}/utils/resolveLibraryOptions.d.ts +2 -2
  89. package/dist/esm/utils/resolveLibraryOptions.mjs +13 -0
  90. package/dist/esm/utils/resolveLibraryOptions.mjs.map +1 -0
  91. package/internals/package.json +4 -4
  92. package/package.json +48 -26
  93. package/src/GraphQLAPI.ts +2 -2
  94. package/src/internals/InternalGraphQLAPI.ts +35 -10
  95. package/src/types/index.ts +51 -9
  96. package/lib/GraphQLAPI.d.ts +0 -38
  97. package/lib/GraphQLAPI.js +0 -57
  98. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +0 -805
  99. package/lib/Providers/constants.d.ts +0 -95
  100. package/lib/index.d.ts +0 -3
  101. package/lib/index.js +0 -12
  102. package/lib/internals/InternalGraphQLAPI.js +0 -316
  103. package/lib/internals/index.d.ts +0 -2
  104. package/lib/internals/index.js +0 -11
  105. package/lib/internals/v6.d.ts +0 -101
  106. package/lib/tsconfig.tsbuildinfo +0 -6638
  107. package/lib/types/index.d.ts +0 -289
  108. package/lib/utils/ConnectionStateMonitor.d.ts +0 -41
  109. package/lib/utils/ConnectionStateMonitor.js +0 -144
  110. package/lib/utils/ReachabilityMonitor/index.d.ts +0 -1
  111. package/lib/utils/ReachabilityMonitor/index.js +0 -6
  112. package/lib/utils/ReachabilityMonitor/index.native.d.ts +0 -1
  113. package/lib/utils/ReachabilityMonitor/index.native.js +0 -10
  114. package/lib/utils/ReconnectionMonitor.d.ts +0 -29
  115. package/lib/utils/errors/APIError.d.ts +0 -7
  116. package/lib/utils/errors/APIError.js +0 -22
  117. package/lib/utils/errors/assertValidationError.d.ts +0 -5
  118. package/lib/utils/errors/assertValidationError.js +0 -16
  119. package/lib/utils/errors/index.d.ts +0 -3
  120. package/lib/utils/errors/index.js +0 -11
  121. package/lib/utils/errors/validation.d.ts +0 -7
  122. package/lib/utils/index.d.ts +0 -2
  123. package/lib/utils/index.js +0 -8
  124. package/lib/utils/resolveConfig.js +0 -23
  125. package/lib/utils/resolveLibraryOptions.d.ts +0 -11
  126. package/lib/utils/resolveLibraryOptions.js +0 -13
  127. package/lib-esm/GraphQLAPI.js +0 -55
  128. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -64
  129. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +0 -803
  130. package/lib-esm/index.js +0 -5
  131. package/lib-esm/internals/InternalGraphQLAPI.d.ts +0 -58
  132. package/lib-esm/internals/InternalGraphQLAPI.js +0 -314
  133. package/lib-esm/internals/index.js +0 -4
  134. package/lib-esm/tsconfig.tsbuildinfo +0 -6638
  135. package/lib-esm/types/PubSub.d.ts +0 -27
  136. package/lib-esm/utils/ReachabilityMonitor/index.d.ts +0 -1
  137. package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +0 -1
  138. package/lib-esm/utils/ReachabilityMonitor/index.native.js +0 -7
  139. package/lib-esm/utils/errors/APIError.js +0 -20
  140. package/lib-esm/utils/errors/assertValidationError.js +0 -13
  141. package/lib-esm/utils/errors/index.js +0 -5
  142. package/lib-esm/utils/index.js +0 -4
  143. package/lib-esm/utils/resolveConfig.d.ts +0 -12
  144. package/lib-esm/utils/resolveConfig.js +0 -21
  145. package/lib-esm/utils/resolveLibraryOptions.js +0 -11
  146. /package/{lib-esm → dist/esm}/Providers/constants.d.ts +0 -0
  147. /package/{lib-esm → dist/esm}/index.d.ts +0 -0
  148. /package/{lib-esm → dist/esm}/internals/index.d.ts +0 -0
  149. /package/{lib-esm → dist/esm}/internals/v6.d.ts +0 -0
  150. /package/{lib-esm → dist/esm}/utils/ReconnectionMonitor.d.ts +0 -0
  151. /package/{lib-esm → dist/esm}/utils/errors/APIError.d.ts +0 -0
  152. /package/{lib-esm → dist/esm}/utils/errors/assertValidationError.d.ts +0 -0
  153. /package/{lib-esm → dist/esm}/utils/errors/index.d.ts +0 -0
  154. /package/{lib-esm → dist/esm}/utils/errors/validation.d.ts +0 -0
  155. /package/{lib-esm → dist/esm}/utils/index.d.ts +0 -0
package/lib-esm/index.js DELETED
@@ -1,5 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- export { GraphQLAPI, GraphQLAPIClass, graphqlOperation } from './GraphQLAPI';
4
- export * from './types';
5
- export { CONNECTION_STATE_CHANGE } from './Providers/constants';
@@ -1,58 +0,0 @@
1
- import { OperationTypeNode } from 'graphql';
2
- import { Observable } from 'rxjs';
3
- import { AmplifyClassV6 } from '@aws-amplify/core';
4
- import { CustomUserAgentDetails } from '@aws-amplify/core/internals/utils';
5
- import { GraphQLResult, GraphQLOperation, GraphQLOptions } from '../types';
6
- export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string | undefined) => {
7
- query: any;
8
- variables: {};
9
- authToken: string | undefined;
10
- };
11
- /**
12
- * Export Cloud Logic APIs
13
- */
14
- export declare class InternalGraphQLAPIClass {
15
- /**
16
- * @private
17
- */
18
- private _options;
19
- private appSyncRealTime;
20
- private _api;
21
- /**
22
- * Initialize GraphQL API with AWS configuration
23
- * @param {Object} options - Configuration object for API
24
- */
25
- constructor(options: any);
26
- getModuleName(): string;
27
- private _headerBasedAuth;
28
- /**
29
- * to get the operation type
30
- * @param operation
31
- */
32
- getGraphqlOperationType(operation: GraphQLOperation): OperationTypeNode;
33
- /**
34
- * Executes a GraphQL operation
35
- *
36
- * @param options - GraphQL Options
37
- * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
38
- * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
39
- */
40
- graphql<T = any>(amplify: AmplifyClassV6, { query: paramQuery, variables, authMode, authToken }: GraphQLOptions, additionalHeaders?: {
41
- [key: string]: string;
42
- }, customUserAgentDetails?: CustomUserAgentDetails): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
43
- private _graphql;
44
- /**
45
- * Checks to see if an error thrown is from an api request cancellation
46
- * @param {any} error - Any error
47
- * @return {boolean} - A boolean indicating if the error was from an api request cancellation
48
- */
49
- isCancelError(error: any): boolean;
50
- /**
51
- * Cancels an inflight request. Only applicable for graphql queries and mutations
52
- * @param {any} request - request to cancel
53
- * @returns - A boolean indicating if the request was cancelled
54
- */
55
- cancel(request: Promise<any>, message?: string): boolean;
56
- private _graphqlSubscribe;
57
- }
58
- export declare const InternalGraphQLAPI: InternalGraphQLAPIClass;
@@ -1,314 +0,0 @@
1
- import { __assign, __awaiter, __generator, __read } from "tslib";
2
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- // SPDX-License-Identifier: Apache-2.0
4
- import { print, parse, GraphQLError, } from 'graphql';
5
- import { ConsoleLogger } from '@aws-amplify/core';
6
- import { getAmplifyUserAgent, AmplifyUrl, } from '@aws-amplify/core/internals/utils';
7
- import { GraphQLAuthError, } from '../types';
8
- import { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';
9
- import { post, cancel as cancelREST, updateRequestToBeCancellable, } from '@aws-amplify/api-rest/internals';
10
- import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
11
- import { resolveConfig, resolveLibraryOptions } from '../utils';
12
- var USER_AGENT_HEADER = 'x-amz-user-agent';
13
- var logger = new ConsoleLogger('GraphQLAPI');
14
- export var graphqlOperation = function (query, variables, authToken) {
15
- if (variables === void 0) { variables = {}; }
16
- return ({
17
- query: query,
18
- variables: variables,
19
- authToken: authToken,
20
- });
21
- };
22
- /**
23
- * Export Cloud Logic APIs
24
- */
25
- var InternalGraphQLAPIClass = /** @class */ (function () {
26
- /**
27
- * Initialize GraphQL API with AWS configuration
28
- * @param {Object} options - Configuration object for API
29
- */
30
- function InternalGraphQLAPIClass(options) {
31
- this._api = {
32
- post: post,
33
- cancelREST: cancelREST,
34
- isCancelErrorREST: isCancelErrorREST,
35
- updateRequestToBeCancellable: updateRequestToBeCancellable,
36
- };
37
- this._options = options;
38
- logger.debug('API Options', this._options);
39
- }
40
- InternalGraphQLAPIClass.prototype.getModuleName = function () {
41
- return 'InternalGraphQLAPI';
42
- };
43
- InternalGraphQLAPIClass.prototype._headerBasedAuth = function (amplify, authMode, additionalHeaders) {
44
- if (additionalHeaders === void 0) { additionalHeaders = {}; }
45
- var _a;
46
- return __awaiter(this, void 0, void 0, function () {
47
- var config, _b, region, appSyncGraphqlEndpoint, apiKey, defaultAuthMode, authenticationType, headers, _c, session, token, e_1;
48
- return __generator(this, function (_d) {
49
- switch (_d.label) {
50
- case 0:
51
- config = amplify.getConfig();
52
- _b = resolveConfig(amplify), region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, apiKey = _b.apiKey, defaultAuthMode = _b.defaultAuthMode;
53
- authenticationType = authMode || defaultAuthMode || 'iam';
54
- headers = {};
55
- _c = authenticationType;
56
- switch (_c) {
57
- case 'apiKey': return [3 /*break*/, 1];
58
- case 'iam': return [3 /*break*/, 2];
59
- case 'oidc': return [3 /*break*/, 4];
60
- case 'userPool': return [3 /*break*/, 4];
61
- case 'lambda': return [3 /*break*/, 8];
62
- case 'none': return [3 /*break*/, 9];
63
- }
64
- return [3 /*break*/, 10];
65
- case 1:
66
- if (!apiKey) {
67
- throw new Error(GraphQLAuthError.NO_API_KEY);
68
- }
69
- headers = {
70
- 'X-Api-Key': apiKey,
71
- };
72
- return [3 /*break*/, 11];
73
- case 2: return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
74
- case 3:
75
- session = _d.sent();
76
- if (session.credentials === undefined) {
77
- throw new Error(GraphQLAuthError.NO_CREDENTIALS);
78
- }
79
- return [3 /*break*/, 11];
80
- case 4:
81
- _d.trys.push([4, 6, , 7]);
82
- token = void 0;
83
- return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
84
- case 5:
85
- token = (_a = (_d.sent()).tokens) === null || _a === void 0 ? void 0 : _a.accessToken.toString();
86
- if (!token) {
87
- throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);
88
- }
89
- headers = {
90
- Authorization: token,
91
- };
92
- return [3 /*break*/, 7];
93
- case 6:
94
- e_1 = _d.sent();
95
- throw new Error(GraphQLAuthError.NO_CURRENT_USER);
96
- case 7: return [3 /*break*/, 11];
97
- case 8:
98
- if (!additionalHeaders.Authorization) {
99
- throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);
100
- }
101
- headers = {
102
- Authorization: additionalHeaders.Authorization,
103
- };
104
- return [3 /*break*/, 11];
105
- case 9: return [3 /*break*/, 11];
106
- case 10: return [3 /*break*/, 11];
107
- case 11: return [2 /*return*/, headers];
108
- }
109
- });
110
- });
111
- };
112
- /**
113
- * to get the operation type
114
- * @param operation
115
- */
116
- InternalGraphQLAPIClass.prototype.getGraphqlOperationType = function (operation) {
117
- var doc = parse(operation);
118
- var definitions = doc.definitions;
119
- var _a = __read(definitions, 1), operationType = _a[0].operation;
120
- return operationType;
121
- };
122
- /**
123
- * Executes a GraphQL operation
124
- *
125
- * @param options - GraphQL Options
126
- * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
127
- * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
128
- */
129
- InternalGraphQLAPIClass.prototype.graphql = function (amplify, _a, additionalHeaders, customUserAgentDetails) {
130
- var paramQuery = _a.query, _b = _a.variables, variables = _b === void 0 ? {} : _b, authMode = _a.authMode, authToken = _a.authToken;
131
- var query = typeof paramQuery === 'string'
132
- ? parse(paramQuery)
133
- : parse(print(paramQuery));
134
- var _c = __read(query.definitions.filter(function (def) { return def.kind === 'OperationDefinition'; }), 1), _d = _c[0], operationDef = _d === void 0 ? {} : _d;
135
- var operationType = operationDef.operation;
136
- var headers = additionalHeaders || {};
137
- // if an authorization header is set, have the explicit authToken take precedence
138
- if (authToken) {
139
- headers.Authorization = authToken;
140
- }
141
- switch (operationType) {
142
- case 'query':
143
- case 'mutation':
144
- var abortController = new AbortController();
145
- var responsePromise = this._graphql(amplify, { query: query, variables: variables, authMode: authMode }, headers, abortController, customUserAgentDetails);
146
- this._api.updateRequestToBeCancellable(responsePromise, abortController);
147
- return responsePromise;
148
- case 'subscription':
149
- return this._graphqlSubscribe(amplify, { query: query, variables: variables, authMode: authMode }, headers, customUserAgentDetails);
150
- default:
151
- throw new Error("invalid operation type: " + operationType);
152
- }
153
- };
154
- InternalGraphQLAPIClass.prototype._graphql = function (amplify, _a, additionalHeaders, abortController, customUserAgentDetails) {
155
- var query = _a.query, variables = _a.variables, authMode = _a.authMode;
156
- if (additionalHeaders === void 0) { additionalHeaders = {}; }
157
- return __awaiter(this, void 0, void 0, function () {
158
- var _b, region, appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, _c, customHeaders, withCredentials, headers, _d, _e, _f, _g, _h, _j, _k, body, signingServiceInfo, endpoint, error, response, responseBody, result, err_1, errors;
159
- var _l;
160
- return __generator(this, function (_m) {
161
- switch (_m.label) {
162
- case 0:
163
- _b = resolveConfig(amplify), region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, customEndpoint = _b.customEndpoint, customEndpointRegion = _b.customEndpointRegion;
164
- _c = resolveLibraryOptions(amplify), customHeaders = _c.headers, withCredentials = _c.withCredentials;
165
- _d = [{}];
166
- _e = !customEndpoint;
167
- if (!_e) return [3 /*break*/, 2];
168
- return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
169
- case 1:
170
- _e = (_m.sent());
171
- _m.label = 2;
172
- case 2:
173
- _f = [__assign.apply(void 0, _d.concat([(_e)]))];
174
- _g = customEndpoint;
175
- if (!_g) return [3 /*break*/, 6];
176
- if (!customEndpointRegion) return [3 /*break*/, 4];
177
- return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
178
- case 3:
179
- _h = _m.sent();
180
- return [3 /*break*/, 5];
181
- case 4:
182
- _h = {};
183
- _m.label = 5;
184
- case 5:
185
- _g = (_h);
186
- _m.label = 6;
187
- case 6:
188
- _j = [__assign.apply(void 0, _f.concat([((_g) ||
189
- {})]))];
190
- _k = customHeaders;
191
- if (!_k) return [3 /*break*/, 8];
192
- return [4 /*yield*/, customHeaders({
193
- query: print(query),
194
- variables: variables,
195
- })];
196
- case 7:
197
- _k = (_m.sent());
198
- _m.label = 8;
199
- case 8:
200
- headers = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _j.concat([(_k)])), additionalHeaders]), (!customEndpoint && (_l = {},
201
- _l[USER_AGENT_HEADER] = getAmplifyUserAgent(customUserAgentDetails),
202
- _l))]);
203
- body = {
204
- query: print(query),
205
- variables: variables || null,
206
- };
207
- /**
208
- * We do not send the signing service info to the REST API under the
209
- * following conditions (i.e. it will not sign the request):
210
- * - there is a custom endpoint but no region
211
- * - the auth mode is `none`, or `apiKey`
212
- * - the auth mode is a type other than the types listed below
213
- */
214
- if ((customEndpoint && !customEndpointRegion) ||
215
- (authMode !== 'oidc' &&
216
- authMode !== 'userPool' &&
217
- authMode !== 'iam' &&
218
- authMode !== 'lambda')) {
219
- signingServiceInfo = null;
220
- }
221
- else {
222
- signingServiceInfo = {
223
- service: !customEndpointRegion ? 'appsync' : 'execute-api',
224
- region: !customEndpointRegion ? region : customEndpointRegion,
225
- };
226
- }
227
- endpoint = customEndpoint || appSyncGraphqlEndpoint;
228
- if (!endpoint) {
229
- error = new GraphQLError('No graphql endpoint provided.');
230
- throw {
231
- data: {},
232
- errors: [error],
233
- };
234
- }
235
- _m.label = 9;
236
- case 9:
237
- _m.trys.push([9, 12, , 13]);
238
- return [4 /*yield*/, this._api.post({
239
- url: new AmplifyUrl(endpoint),
240
- options: {
241
- headers: headers,
242
- body: body,
243
- signingServiceInfo: signingServiceInfo,
244
- withCredentials: withCredentials,
245
- },
246
- abortController: abortController,
247
- })];
248
- case 10:
249
- responseBody = (_m.sent()).body;
250
- return [4 /*yield*/, responseBody.json()];
251
- case 11:
252
- result = _m.sent();
253
- response = result;
254
- return [3 /*break*/, 13];
255
- case 12:
256
- err_1 = _m.sent();
257
- // If the exception is because user intentionally
258
- // cancelled the request, do not modify the exception
259
- // so that clients can identify the exception correctly.
260
- if (this.isCancelError(err_1)) {
261
- throw err_1;
262
- }
263
- response = {
264
- data: {},
265
- errors: [new GraphQLError(err_1.message, null, null, null, null, err_1)],
266
- };
267
- return [3 /*break*/, 13];
268
- case 13:
269
- errors = response.errors;
270
- if (errors && errors.length) {
271
- throw response;
272
- }
273
- return [2 /*return*/, response];
274
- }
275
- });
276
- });
277
- };
278
- /**
279
- * Checks to see if an error thrown is from an api request cancellation
280
- * @param {any} error - Any error
281
- * @return {boolean} - A boolean indicating if the error was from an api request cancellation
282
- */
283
- InternalGraphQLAPIClass.prototype.isCancelError = function (error) {
284
- return this._api.isCancelErrorREST(error);
285
- };
286
- /**
287
- * Cancels an inflight request. Only applicable for graphql queries and mutations
288
- * @param {any} request - request to cancel
289
- * @returns - A boolean indicating if the request was cancelled
290
- */
291
- InternalGraphQLAPIClass.prototype.cancel = function (request, message) {
292
- return this._api.cancelREST(request, message);
293
- };
294
- InternalGraphQLAPIClass.prototype._graphqlSubscribe = function (amplify, _a, additionalHeaders, customUserAgentDetails) {
295
- var query = _a.query, variables = _a.variables, authMode = _a.authMode;
296
- if (additionalHeaders === void 0) { additionalHeaders = {}; }
297
- var config = resolveConfig(amplify);
298
- if (!this.appSyncRealTime) {
299
- this.appSyncRealTime = new AWSAppSyncRealTimeProvider();
300
- }
301
- return this.appSyncRealTime.subscribe({
302
- query: print(query),
303
- variables: variables,
304
- appSyncGraphqlEndpoint: config === null || config === void 0 ? void 0 : config.endpoint,
305
- region: config === null || config === void 0 ? void 0 : config.region,
306
- authenticationType: config === null || config === void 0 ? void 0 : config.defaultAuthMode,
307
- apiKey: config === null || config === void 0 ? void 0 : config.apiKey,
308
- additionalHeaders: additionalHeaders,
309
- }, customUserAgentDetails);
310
- };
311
- return InternalGraphQLAPIClass;
312
- }());
313
- export { InternalGraphQLAPIClass };
314
- export var InternalGraphQLAPI = new InternalGraphQLAPIClass(null);
@@ -1,4 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- export { InternalGraphQLAPI, InternalGraphQLAPIClass, } from './InternalGraphQLAPI';
4
- export { graphql, cancel, isCancelError } from './v6';