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