@aws-amplify/api-graphql 4.0.1-console-preview.d745d43.0 → 4.0.1-mjs-test.6f5dab7.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
@@ -1,95 +0,0 @@
1
- export { AMPLIFY_SYMBOL } from '@aws-amplify/core/internals/utils';
2
- export declare const MAX_DELAY_MS = 5000;
3
- export declare const NON_RETRYABLE_CODES: number[];
4
- export declare const CONNECTION_STATE_CHANGE = "ConnectionStateChange";
5
- export declare enum MESSAGE_TYPES {
6
- /**
7
- * Client -> Server message.
8
- * This message type is the first message after handshake and this will initialize AWS AppSync RealTime communication
9
- */
10
- GQL_CONNECTION_INIT = "connection_init",
11
- /**
12
- * Server -> Client message
13
- * This message type is in case there is an issue with AWS AppSync RealTime when establishing connection
14
- */
15
- GQL_CONNECTION_ERROR = "connection_error",
16
- /**
17
- * Server -> Client message.
18
- * This message type is for the ack response from AWS AppSync RealTime for GQL_CONNECTION_INIT message
19
- */
20
- GQL_CONNECTION_ACK = "connection_ack",
21
- /**
22
- * Client -> Server message.
23
- * This message type is for register subscriptions with AWS AppSync RealTime
24
- */
25
- GQL_START = "start",
26
- /**
27
- * Server -> Client message.
28
- * This message type is for the ack response from AWS AppSync RealTime for GQL_START message
29
- */
30
- GQL_START_ACK = "start_ack",
31
- /**
32
- * Server -> Client message.
33
- * This message type is for subscription message from AWS AppSync RealTime
34
- */
35
- GQL_DATA = "data",
36
- /**
37
- * Server -> Client message.
38
- * This message type helps the client to know is still receiving messages from AWS AppSync RealTime
39
- */
40
- GQL_CONNECTION_KEEP_ALIVE = "ka",
41
- /**
42
- * Client -> Server message.
43
- * This message type is for unregister subscriptions with AWS AppSync RealTime
44
- */
45
- GQL_STOP = "stop",
46
- /**
47
- * Server -> Client message.
48
- * This message type is for the ack response from AWS AppSync RealTime for GQL_STOP message
49
- */
50
- GQL_COMPLETE = "complete",
51
- /**
52
- * Server -> Client message.
53
- * This message type is for sending error messages from AWS AppSync RealTime to the client
54
- */
55
- GQL_ERROR = "error"
56
- }
57
- export declare enum SUBSCRIPTION_STATUS {
58
- PENDING = 0,
59
- CONNECTED = 1,
60
- FAILED = 2
61
- }
62
- export declare enum SOCKET_STATUS {
63
- CLOSED = 0,
64
- READY = 1,
65
- CONNECTING = 2
66
- }
67
- export declare const AWS_APPSYNC_REALTIME_HEADERS: {
68
- accept: string;
69
- 'content-encoding': string;
70
- 'content-type': string;
71
- };
72
- /**
73
- * Time in milleseconds to wait for GQL_CONNECTION_INIT message
74
- */
75
- export declare const CONNECTION_INIT_TIMEOUT = 15000;
76
- /**
77
- * Time in milleseconds to wait for GQL_START_ACK message
78
- */
79
- export declare const START_ACK_TIMEOUT = 15000;
80
- /**
81
- * Default Time in milleseconds to wait for GQL_CONNECTION_KEEP_ALIVE message
82
- */
83
- export declare const DEFAULT_KEEP_ALIVE_TIMEOUT: number;
84
- /**
85
- * Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message
86
- */
87
- export declare const DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT: number;
88
- /**
89
- * Default delay time in milleseconds between when reconnect is triggered vs when it is attempted
90
- */
91
- export declare const RECONNECT_DELAY: number;
92
- /**
93
- * Default interval time in milleseconds between when reconnect is re-attempted
94
- */
95
- export declare const RECONNECT_INTERVAL: number;
package/lib/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { GraphQLAPI, GraphQLAPIClass, graphqlOperation } from './GraphQLAPI';
2
- export * from './types';
3
- export { CONNECTION_STATE_CHANGE } from './Providers/constants';
package/lib/index.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- // SPDX-License-Identifier: Apache-2.0
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- var tslib_1 = require("tslib");
6
- var GraphQLAPI_1 = require("./GraphQLAPI");
7
- exports.GraphQLAPI = GraphQLAPI_1.GraphQLAPI;
8
- exports.GraphQLAPIClass = GraphQLAPI_1.GraphQLAPIClass;
9
- exports.graphqlOperation = GraphQLAPI_1.graphqlOperation;
10
- tslib_1.__exportStar(require("./types"), exports);
11
- var constants_1 = require("./Providers/constants");
12
- exports.CONNECTION_STATE_CHANGE = constants_1.CONNECTION_STATE_CHANGE;
@@ -1,316 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- var core_1 = require("@aws-amplify/core");
8
- var utils_1 = require("@aws-amplify/core/internals/utils");
9
- var types_1 = require("../types");
10
- var api_rest_1 = require("@aws-amplify/api-rest");
11
- var internals_1 = require("@aws-amplify/api-rest/internals");
12
- var AWSAppSyncRealTimeProvider_1 = require("../Providers/AWSAppSyncRealTimeProvider");
13
- var utils_2 = require("../utils");
14
- var USER_AGENT_HEADER = 'x-amz-user-agent';
15
- var logger = new core_1.ConsoleLogger('GraphQLAPI');
16
- exports.graphqlOperation = function (query, variables, authToken) {
17
- if (variables === void 0) { variables = {}; }
18
- return ({
19
- query: query,
20
- variables: variables,
21
- authToken: authToken,
22
- });
23
- };
24
- /**
25
- * Export Cloud Logic APIs
26
- */
27
- var InternalGraphQLAPIClass = /** @class */ (function () {
28
- /**
29
- * Initialize GraphQL API with AWS configuration
30
- * @param {Object} options - Configuration object for API
31
- */
32
- function InternalGraphQLAPIClass(options) {
33
- this._api = {
34
- post: internals_1.post,
35
- cancelREST: internals_1.cancel,
36
- isCancelErrorREST: api_rest_1.isCancelError,
37
- updateRequestToBeCancellable: internals_1.updateRequestToBeCancellable,
38
- };
39
- this._options = options;
40
- logger.debug('API Options', this._options);
41
- }
42
- InternalGraphQLAPIClass.prototype.getModuleName = function () {
43
- return 'InternalGraphQLAPI';
44
- };
45
- InternalGraphQLAPIClass.prototype._headerBasedAuth = function (amplify, authMode, additionalHeaders) {
46
- if (additionalHeaders === void 0) { additionalHeaders = {}; }
47
- var _a;
48
- return tslib_1.__awaiter(this, void 0, void 0, function () {
49
- var config, _b, region, appSyncGraphqlEndpoint, apiKey, defaultAuthMode, authenticationType, headers, _c, session, token, e_1;
50
- return tslib_1.__generator(this, function (_d) {
51
- switch (_d.label) {
52
- case 0:
53
- config = amplify.getConfig();
54
- _b = utils_2.resolveConfig(amplify), region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, apiKey = _b.apiKey, defaultAuthMode = _b.defaultAuthMode;
55
- authenticationType = authMode || defaultAuthMode || 'iam';
56
- headers = {};
57
- _c = authenticationType;
58
- switch (_c) {
59
- case 'apiKey': return [3 /*break*/, 1];
60
- case 'iam': return [3 /*break*/, 2];
61
- case 'oidc': return [3 /*break*/, 4];
62
- case 'userPool': return [3 /*break*/, 4];
63
- case 'lambda': return [3 /*break*/, 8];
64
- case 'none': return [3 /*break*/, 9];
65
- }
66
- return [3 /*break*/, 10];
67
- case 1:
68
- if (!apiKey) {
69
- throw new Error(types_1.GraphQLAuthError.NO_API_KEY);
70
- }
71
- headers = {
72
- 'X-Api-Key': apiKey,
73
- };
74
- return [3 /*break*/, 11];
75
- case 2: return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
76
- case 3:
77
- session = _d.sent();
78
- if (session.credentials === undefined) {
79
- throw new Error(types_1.GraphQLAuthError.NO_CREDENTIALS);
80
- }
81
- return [3 /*break*/, 11];
82
- case 4:
83
- _d.trys.push([4, 6, , 7]);
84
- token = void 0;
85
- return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
86
- case 5:
87
- token = (_a = (_d.sent()).tokens) === null || _a === void 0 ? void 0 : _a.accessToken.toString();
88
- if (!token) {
89
- throw new Error(types_1.GraphQLAuthError.NO_FEDERATED_JWT);
90
- }
91
- headers = {
92
- Authorization: token,
93
- };
94
- return [3 /*break*/, 7];
95
- case 6:
96
- e_1 = _d.sent();
97
- throw new Error(types_1.GraphQLAuthError.NO_CURRENT_USER);
98
- case 7: return [3 /*break*/, 11];
99
- case 8:
100
- if (!additionalHeaders.Authorization) {
101
- throw new Error(types_1.GraphQLAuthError.NO_AUTH_TOKEN);
102
- }
103
- headers = {
104
- Authorization: additionalHeaders.Authorization,
105
- };
106
- return [3 /*break*/, 11];
107
- case 9: return [3 /*break*/, 11];
108
- case 10: return [3 /*break*/, 11];
109
- case 11: return [2 /*return*/, headers];
110
- }
111
- });
112
- });
113
- };
114
- /**
115
- * to get the operation type
116
- * @param operation
117
- */
118
- InternalGraphQLAPIClass.prototype.getGraphqlOperationType = function (operation) {
119
- var doc = graphql_1.parse(operation);
120
- var definitions = doc.definitions;
121
- var _a = tslib_1.__read(definitions, 1), operationType = _a[0].operation;
122
- return operationType;
123
- };
124
- /**
125
- * Executes a GraphQL operation
126
- *
127
- * @param options - GraphQL Options
128
- * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
129
- * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
130
- */
131
- InternalGraphQLAPIClass.prototype.graphql = function (amplify, _a, additionalHeaders, customUserAgentDetails) {
132
- var paramQuery = _a.query, _b = _a.variables, variables = _b === void 0 ? {} : _b, authMode = _a.authMode, authToken = _a.authToken;
133
- var query = typeof paramQuery === 'string'
134
- ? graphql_1.parse(paramQuery)
135
- : graphql_1.parse(graphql_1.print(paramQuery));
136
- var _c = tslib_1.__read(query.definitions.filter(function (def) { return def.kind === 'OperationDefinition'; }), 1), _d = _c[0], operationDef = _d === void 0 ? {} : _d;
137
- var operationType = operationDef.operation;
138
- var headers = additionalHeaders || {};
139
- // if an authorization header is set, have the explicit authToken take precedence
140
- if (authToken) {
141
- headers.Authorization = authToken;
142
- }
143
- switch (operationType) {
144
- case 'query':
145
- case 'mutation':
146
- var abortController = new AbortController();
147
- var responsePromise = this._graphql(amplify, { query: query, variables: variables, authMode: authMode }, headers, abortController, customUserAgentDetails);
148
- this._api.updateRequestToBeCancellable(responsePromise, abortController);
149
- return responsePromise;
150
- case 'subscription':
151
- return this._graphqlSubscribe(amplify, { query: query, variables: variables, authMode: authMode }, headers, customUserAgentDetails);
152
- default:
153
- throw new Error("invalid operation type: " + operationType);
154
- }
155
- };
156
- InternalGraphQLAPIClass.prototype._graphql = function (amplify, _a, additionalHeaders, abortController, customUserAgentDetails) {
157
- var query = _a.query, variables = _a.variables, authMode = _a.authMode;
158
- if (additionalHeaders === void 0) { additionalHeaders = {}; }
159
- return tslib_1.__awaiter(this, void 0, void 0, function () {
160
- 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;
161
- var _l;
162
- return tslib_1.__generator(this, function (_m) {
163
- switch (_m.label) {
164
- case 0:
165
- _b = utils_2.resolveConfig(amplify), region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, customEndpoint = _b.customEndpoint, customEndpointRegion = _b.customEndpointRegion;
166
- _c = utils_2.resolveLibraryOptions(amplify), customHeaders = _c.headers, withCredentials = _c.withCredentials;
167
- _d = [{}];
168
- _e = !customEndpoint;
169
- if (!_e) return [3 /*break*/, 2];
170
- return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
171
- case 1:
172
- _e = (_m.sent());
173
- _m.label = 2;
174
- case 2:
175
- _f = [tslib_1.__assign.apply(void 0, _d.concat([(_e)]))];
176
- _g = customEndpoint;
177
- if (!_g) return [3 /*break*/, 6];
178
- if (!customEndpointRegion) return [3 /*break*/, 4];
179
- return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
180
- case 3:
181
- _h = _m.sent();
182
- return [3 /*break*/, 5];
183
- case 4:
184
- _h = {};
185
- _m.label = 5;
186
- case 5:
187
- _g = (_h);
188
- _m.label = 6;
189
- case 6:
190
- _j = [tslib_1.__assign.apply(void 0, _f.concat([((_g) ||
191
- {})]))];
192
- _k = customHeaders;
193
- if (!_k) return [3 /*break*/, 8];
194
- return [4 /*yield*/, customHeaders({
195
- query: graphql_1.print(query),
196
- variables: variables,
197
- })];
198
- case 7:
199
- _k = (_m.sent());
200
- _m.label = 8;
201
- case 8:
202
- headers = tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0, _j.concat([(_k)])), additionalHeaders]), (!customEndpoint && (_l = {},
203
- _l[USER_AGENT_HEADER] = utils_1.getAmplifyUserAgent(customUserAgentDetails),
204
- _l))]);
205
- body = {
206
- query: graphql_1.print(query),
207
- variables: variables || null,
208
- };
209
- /**
210
- * We do not send the signing service info to the REST API under the
211
- * following conditions (i.e. it will not sign the request):
212
- * - there is a custom endpoint but no region
213
- * - the auth mode is `none`, or `apiKey`
214
- * - the auth mode is a type other than the types listed below
215
- */
216
- if ((customEndpoint && !customEndpointRegion) ||
217
- (authMode !== 'oidc' &&
218
- authMode !== 'userPool' &&
219
- authMode !== 'iam' &&
220
- authMode !== 'lambda')) {
221
- signingServiceInfo = null;
222
- }
223
- else {
224
- signingServiceInfo = {
225
- service: !customEndpointRegion ? 'appsync' : 'execute-api',
226
- region: !customEndpointRegion ? region : customEndpointRegion,
227
- };
228
- }
229
- endpoint = customEndpoint || appSyncGraphqlEndpoint;
230
- if (!endpoint) {
231
- error = new graphql_1.GraphQLError('No graphql endpoint provided.');
232
- throw {
233
- data: {},
234
- errors: [error],
235
- };
236
- }
237
- _m.label = 9;
238
- case 9:
239
- _m.trys.push([9, 12, , 13]);
240
- return [4 /*yield*/, this._api.post({
241
- url: new utils_1.AmplifyUrl(endpoint),
242
- options: {
243
- headers: headers,
244
- body: body,
245
- signingServiceInfo: signingServiceInfo,
246
- withCredentials: withCredentials,
247
- },
248
- abortController: abortController,
249
- })];
250
- case 10:
251
- responseBody = (_m.sent()).body;
252
- return [4 /*yield*/, responseBody.json()];
253
- case 11:
254
- result = _m.sent();
255
- response = result;
256
- return [3 /*break*/, 13];
257
- case 12:
258
- err_1 = _m.sent();
259
- // If the exception is because user intentionally
260
- // cancelled the request, do not modify the exception
261
- // so that clients can identify the exception correctly.
262
- if (this.isCancelError(err_1)) {
263
- throw err_1;
264
- }
265
- response = {
266
- data: {},
267
- errors: [new graphql_1.GraphQLError(err_1.message, null, null, null, null, err_1)],
268
- };
269
- return [3 /*break*/, 13];
270
- case 13:
271
- errors = response.errors;
272
- if (errors && errors.length) {
273
- throw response;
274
- }
275
- return [2 /*return*/, response];
276
- }
277
- });
278
- });
279
- };
280
- /**
281
- * Checks to see if an error thrown is from an api request cancellation
282
- * @param {any} error - Any error
283
- * @return {boolean} - A boolean indicating if the error was from an api request cancellation
284
- */
285
- InternalGraphQLAPIClass.prototype.isCancelError = function (error) {
286
- return this._api.isCancelErrorREST(error);
287
- };
288
- /**
289
- * Cancels an inflight request. Only applicable for graphql queries and mutations
290
- * @param {any} request - request to cancel
291
- * @returns - A boolean indicating if the request was cancelled
292
- */
293
- InternalGraphQLAPIClass.prototype.cancel = function (request, message) {
294
- return this._api.cancelREST(request, message);
295
- };
296
- InternalGraphQLAPIClass.prototype._graphqlSubscribe = function (amplify, _a, additionalHeaders, customUserAgentDetails) {
297
- var query = _a.query, variables = _a.variables, authMode = _a.authMode;
298
- if (additionalHeaders === void 0) { additionalHeaders = {}; }
299
- var config = utils_2.resolveConfig(amplify);
300
- if (!this.appSyncRealTime) {
301
- this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();
302
- }
303
- return this.appSyncRealTime.subscribe({
304
- query: graphql_1.print(query),
305
- variables: variables,
306
- appSyncGraphqlEndpoint: config === null || config === void 0 ? void 0 : config.endpoint,
307
- region: config === null || config === void 0 ? void 0 : config.region,
308
- authenticationType: config === null || config === void 0 ? void 0 : config.defaultAuthMode,
309
- apiKey: config === null || config === void 0 ? void 0 : config.apiKey,
310
- additionalHeaders: additionalHeaders,
311
- }, customUserAgentDetails);
312
- };
313
- return InternalGraphQLAPIClass;
314
- }());
315
- exports.InternalGraphQLAPIClass = InternalGraphQLAPIClass;
316
- exports.InternalGraphQLAPI = new InternalGraphQLAPIClass(null);
@@ -1,2 +0,0 @@
1
- export { InternalGraphQLAPI, InternalGraphQLAPIClass, } from './InternalGraphQLAPI';
2
- export { graphql, cancel, isCancelError } from './v6';
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
- // SPDX-License-Identifier: Apache-2.0
5
- var InternalGraphQLAPI_1 = require("./InternalGraphQLAPI");
6
- exports.InternalGraphQLAPI = InternalGraphQLAPI_1.InternalGraphQLAPI;
7
- exports.InternalGraphQLAPIClass = InternalGraphQLAPI_1.InternalGraphQLAPIClass;
8
- var v6_1 = require("./v6");
9
- exports.graphql = v6_1.graphql;
10
- exports.cancel = v6_1.cancel;
11
- exports.isCancelError = v6_1.isCancelError;
@@ -1,101 +0,0 @@
1
- import { V6Client, GraphQLOptionsV6, GraphQLResponseV6 } from '../types';
2
- /**
3
- * Invokes graphql operations against a graphql service, providing correct input and
4
- * output types if Amplify-generated graphql from a recent version of the CLI/codegen
5
- * are used *or* correct typing is provided via the type argument.
6
- *
7
- * Amplify-generated "branded" graphql queries will look similar to this:
8
- *
9
- * ```ts
10
- * //
11
- * // |-- branding
12
- * // v
13
- * export const getModel = `...` as GeneratedQuery<
14
- * GetModelQueryVariables,
15
- * GetModelQuery
16
- * >;
17
- * ```
18
- *
19
- * If this branding is not in your generated graphql, update to a newer version of
20
- * CLI/codegen and regenerate your graphql using `amplify codegen`.
21
- *
22
- * ## Using Amplify-generated graphql
23
- *
24
- * ```ts
25
- * import * as queries from './graphql/queries';
26
- *
27
- * //
28
- * // |-- correctly typed graphql response containing a Widget
29
- * // v
30
- * const queryResult = await graphql({
31
- * query: queries.getWidget,
32
- * variables: {
33
- * id: "abc", // <-- type hinted/enforced
34
- * },
35
- * });
36
- *
37
- * //
38
- * // |-- a correctly typed Widget
39
- * // v
40
- * const fetchedWidget = queryResult.data?.getWidget!;
41
- * ```
42
- *
43
- * ## Custom input + result types
44
- *
45
- * To provide input types (`variables`) and result types:
46
- *
47
- * ```ts
48
- * type GetById_NameOnly = {
49
- * variables: {
50
- * id: string
51
- * },
52
- * result: Promise<{
53
- * data: { getWidget: { name: string } }
54
- * }>
55
- * }
56
- *
57
- * //
58
- * // |-- type is GetById_NameOnly["result"]
59
- * // v
60
- * const result = graphql<GetById_NameOnly>({
61
- * query: "...",
62
- * variables: { id: "abc" } // <-- type of GetById_NameOnly["variables"]
63
- * });
64
- * ```
65
- *
66
- * ## Custom result type only
67
- *
68
- * To specify result types only, use a type that is *not* in the `{variables, result}` shape:
69
- *
70
- * ```ts
71
- * type MyResultType = Promise<{
72
- * data: {
73
- * getWidget: { name: string }
74
- * }
75
- * }>
76
- *
77
- * //
78
- * // |-- type is MyResultType
79
- * // v
80
- * const result = graphql<MyResultType>({query: "..."});
81
- * ```
82
- *
83
- * @param options
84
- * @param additionalHeaders
85
- */
86
- export declare function graphql<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(this: V6Client, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
87
- [key: string]: string;
88
- }): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
89
- /**
90
- * Cancels an inflight request. Only applicable for graphql queries and mutations
91
- * @param {any} request - request to cancel
92
- * @returns - A boolean indicating if the request was cancelled
93
- */
94
- export declare function cancel(this: V6Client, promise: Promise<any>, message?: string): boolean;
95
- /**
96
- * Checks to see if an error thrown is from an api request cancellation
97
- * @param {any} error - Any error
98
- * @returns - A boolean indicating if the error was from an api request cancellation
99
- */
100
- export declare function isCancelError(this: V6Client, error: any): boolean;
101
- export { GraphQLOptionsV6, GraphQLResponseV6 };