@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.
- package/lib/GraphQLAPI.d.ts +1 -1
- package/lib/GraphQLAPI.js +25 -30
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +468 -584
- package/lib/Providers/constants.js +4 -5
- package/lib/index.js +5 -6
- package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib/internals/InternalGraphQLAPI.js +203 -263
- package/lib/internals/index.d.ts +0 -1
- package/lib/internals/index.js +5 -8
- package/lib/internals/v6.js +3 -4
- package/lib/tsconfig.tsbuildinfo +6798 -1
- package/lib/types/PubSub.d.ts +2 -2
- package/lib/types/PubSub.js +2 -3
- package/lib/types/index.d.ts +39 -28
- package/lib/types/index.js +3 -4
- package/lib/utils/ConnectionStateMonitor.d.ts +3 -3
- package/lib/utils/ConnectionStateMonitor.js +51 -65
- package/lib/utils/ReachabilityMonitor/index.d.ts +1 -1
- package/lib/utils/ReachabilityMonitor/index.js +2 -4
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -1
- package/lib/utils/ReachabilityMonitor/index.native.js +4 -8
- package/lib/utils/ReconnectionMonitor.js +21 -26
- package/lib/utils/errors/APIError.js +7 -12
- package/lib/utils/errors/assertValidationError.js +4 -5
- package/lib/utils/errors/index.js +4 -5
- package/lib/utils/errors/validation.js +6 -8
- package/lib/utils/index.js +2 -3
- package/lib/utils/resolveConfig.d.ts +1 -1
- package/lib/utils/resolveConfig.js +10 -13
- package/lib/utils/resolveLibraryOptions.d.ts +1 -1
- package/lib/utils/resolveLibraryOptions.js +4 -7
- package/lib-esm/GraphQLAPI.d.ts +1 -1
- package/lib-esm/GraphQLAPI.js +25 -29
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +459 -575
- package/lib-esm/Providers/constants.js +10 -10
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib-esm/internals/InternalGraphQLAPI.js +197 -256
- package/lib-esm/internals/index.d.ts +0 -1
- package/lib-esm/internals/index.js +0 -1
- package/lib-esm/internals/v6.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +6798 -1
- package/lib-esm/types/PubSub.d.ts +2 -2
- package/lib-esm/types/index.d.ts +39 -28
- package/lib-esm/types/index.js +1 -1
- package/lib-esm/utils/ConnectionStateMonitor.d.ts +3 -3
- package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
- package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.js +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +1 -3
- package/lib-esm/utils/ReconnectionMonitor.js +19 -24
- package/lib-esm/utils/errors/APIError.js +6 -11
- package/lib-esm/utils/errors/assertValidationError.js +2 -2
- package/lib-esm/utils/errors/validation.js +5 -6
- package/lib-esm/utils/resolveConfig.d.ts +1 -1
- package/lib-esm/utils/resolveConfig.js +8 -9
- package/lib-esm/utils/resolveLibraryOptions.d.ts +1 -1
- package/lib-esm/utils/resolveLibraryOptions.js +4 -5
- package/package.json +6 -12
- package/src/GraphQLAPI.ts +6 -1
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +6 -5
- package/src/internals/InternalGraphQLAPI.ts +7 -8
- package/src/internals/index.ts +0 -1
- package/src/types/index.ts +39 -15
- package/lib/internals/APIClient.d.ts +0 -101
- package/lib/internals/APIClient.js +0 -443
- package/lib/internals/generateClient.d.ts +0 -12
- package/lib/internals/generateClient.js +0 -30
- package/lib/internals/generateModelsProperty.d.ts +0 -4
- package/lib/internals/generateModelsProperty.js +0 -169
- package/lib/internals/types.d.ts +0 -10
- package/lib/internals/types.js +0 -2
- package/lib/utils/resolveOwnerFields.d.ts +0 -12
- package/lib/utils/resolveOwnerFields.js +0 -63
- package/lib-esm/internals/APIClient.d.ts +0 -101
- package/lib-esm/internals/APIClient.js +0 -432
- package/lib-esm/internals/generateClient.d.ts +0 -12
- package/lib-esm/internals/generateClient.js +0 -26
- package/lib-esm/internals/generateModelsProperty.d.ts +0 -4
- package/lib-esm/internals/generateModelsProperty.js +0 -165
- package/lib-esm/internals/types.d.ts +0 -10
- package/lib-esm/internals/types.js +0 -1
- package/lib-esm/utils/resolveOwnerFields.d.ts +0 -12
- package/lib-esm/utils/resolveOwnerFields.js +0 -59
- package/src/internals/APIClient.ts +0 -583
- package/src/internals/generateClient.ts +0 -30
- package/src/internals/generateModelsProperty.ts +0 -192
- package/src/internals/types.ts +0 -15
- 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
|
|
5
|
-
export
|
|
6
|
-
export
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
+
constructor(options) {
|
|
37
30
|
this._api = {
|
|
38
|
-
post
|
|
39
|
-
cancelREST
|
|
40
|
-
isCancelErrorREST
|
|
41
|
-
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
|
-
|
|
39
|
+
getModuleName() {
|
|
47
40
|
return 'InternalGraphQLAPI';
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
136
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
152
|
-
|
|
124
|
+
const abortController = new AbortController();
|
|
125
|
+
let responsePromise;
|
|
153
126
|
if (isAmplifyInstance(amplify)) {
|
|
154
|
-
responsePromise = this._graphql(amplify, { query
|
|
127
|
+
responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails);
|
|
155
128
|
}
|
|
156
129
|
else {
|
|
157
|
-
|
|
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,
|
|
133
|
+
this._api.updateRequestToBeCancellable(responsePromise, abortController);
|
|
163
134
|
return responsePromise;
|
|
164
135
|
case 'subscription':
|
|
165
|
-
return this._graphqlSubscribe(amplify, { query
|
|
136
|
+
return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails);
|
|
166
137
|
default:
|
|
167
|
-
throw new Error(
|
|
138
|
+
throw new Error(`invalid operation type: ${operationType}`);
|
|
168
139
|
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
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
|
-
|
|
252
|
+
cancel(request, message) {
|
|
308
253
|
return this._api.cancelREST(request, message);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
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
|
|
320
|
-
appSyncGraphqlEndpoint: config
|
|
321
|
-
region: config
|
|
322
|
-
authenticationType:
|
|
323
|
-
apiKey: config
|
|
324
|
-
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
|
-
|
|
328
|
-
|
|
329
|
-
export { InternalGraphQLAPIClass };
|
|
330
|
-
export var InternalGraphQLAPI = new InternalGraphQLAPIClass(null);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
export const InternalGraphQLAPI = new InternalGraphQLAPIClass(null);
|
package/lib-esm/internals/v6.js
CHANGED
|
@@ -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
|
-
|
|
95
|
+
const result = GraphQLAPI.graphql(this[__amplify], options, additionalHeaders);
|
|
96
96
|
return result;
|
|
97
97
|
}
|
|
98
98
|
/**
|