@aws-amplify/api-graphql 4.0.17 → 4.0.18-experimental-lerna-test.d2b0b08.55
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/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +40 -31
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/dist/cjs/internals/APIClient.js +145 -54
- package/dist/cjs/internals/APIClient.js.map +1 -1
- package/dist/cjs/internals/InternalGraphQLAPI.js +41 -42
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/cjs/internals/generateClient.js +15 -5
- package/dist/cjs/internals/generateClient.js.map +1 -1
- package/dist/cjs/internals/generateCustomOperationsProperty.js +50 -0
- package/dist/cjs/internals/generateCustomOperationsProperty.js.map +1 -0
- package/dist/cjs/internals/operations/custom.js +356 -0
- package/dist/cjs/internals/operations/custom.js.map +1 -0
- package/dist/cjs/internals/operations/get.js +1 -1
- package/dist/cjs/internals/operations/get.js.map +1 -1
- package/dist/cjs/internals/operations/indexQuery.js +1 -1
- package/dist/cjs/internals/operations/indexQuery.js.map +1 -1
- package/dist/cjs/internals/operations/list.js +2 -2
- package/dist/cjs/internals/operations/list.js.map +1 -1
- package/dist/cjs/internals/operations/subscription.js +1 -1
- package/dist/cjs/internals/operations/subscription.js.map +1 -1
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +12 -2
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -1
- package/dist/cjs/internals/server/generateModelsProperty.js +1 -1
- package/dist/cjs/internals/server/generateModelsProperty.js.map +1 -1
- package/dist/cjs/internals/utils/clientProperties/generateEnumsProperty.js.map +1 -0
- package/dist/cjs/internals/utils/{generateModelsProperty.js → clientProperties/generateModelsProperty.js} +7 -7
- package/dist/cjs/internals/utils/clientProperties/generateModelsProperty.js.map +1 -0
- package/dist/cjs/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.js.map +1 -0
- package/dist/cjs/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.js.map +1 -0
- package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js +15 -0
- package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js.map +1 -0
- package/dist/cjs/internals/v6.js +0 -2
- package/dist/cjs/internals/v6.js.map +1 -1
- package/dist/cjs/utils/errors/constants.js +47 -0
- package/dist/cjs/utils/errors/constants.js.map +1 -0
- package/dist/cjs/utils/errors/createGraphQLResultWithError.js +15 -0
- package/dist/cjs/utils/errors/createGraphQLResultWithError.js.map +1 -0
- package/dist/cjs/utils/errors/index.js +3 -1
- package/dist/cjs/utils/errors/index.js.map +1 -1
- package/dist/cjs/utils/errors/repackageAuthError.js +7 -7
- package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -1
- package/dist/cjs/utils/resolveOwnerFields.js +6 -0
- package/dist/cjs/utils/resolveOwnerFields.js.map +1 -1
- package/dist/esm/GraphQLAPI.d.ts +2 -2
- package/dist/esm/GraphQLAPI.mjs.map +1 -1
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +8 -8
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +40 -31
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
- package/dist/esm/internals/APIClient.d.ts +10 -9
- package/dist/esm/internals/APIClient.mjs +144 -54
- package/dist/esm/internals/APIClient.mjs.map +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.mjs +45 -44
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/dist/esm/internals/generateClient.mjs +15 -5
- package/dist/esm/internals/generateClient.mjs.map +1 -1
- package/dist/esm/internals/generateCustomOperationsProperty.d.ts +9 -0
- package/dist/esm/internals/generateCustomOperationsProperty.mjs +45 -0
- package/dist/esm/internals/generateCustomOperationsProperty.mjs.map +1 -0
- package/dist/esm/internals/operations/custom.d.ts +63 -0
- package/dist/esm/internals/operations/custom.mjs +354 -0
- package/dist/esm/internals/operations/custom.mjs.map +1 -0
- package/dist/esm/internals/operations/get.d.ts +1 -1
- package/dist/esm/internals/operations/get.mjs +1 -1
- package/dist/esm/internals/operations/get.mjs.map +1 -1
- package/dist/esm/internals/operations/indexQuery.d.ts +3 -3
- package/dist/esm/internals/operations/indexQuery.mjs +1 -1
- package/dist/esm/internals/operations/indexQuery.mjs.map +1 -1
- package/dist/esm/internals/operations/list.d.ts +1 -1
- package/dist/esm/internals/operations/list.mjs +2 -2
- package/dist/esm/internals/operations/list.mjs.map +1 -1
- package/dist/esm/internals/operations/subscription.d.ts +1 -1
- package/dist/esm/internals/operations/subscription.mjs +1 -1
- package/dist/esm/internals/operations/subscription.mjs.map +1 -1
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.d.ts +1 -1
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs +12 -2
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -1
- package/dist/esm/internals/server/generateModelsProperty.d.ts +3 -3
- package/dist/esm/internals/server/generateModelsProperty.mjs +1 -1
- package/dist/esm/internals/server/generateModelsProperty.mjs.map +1 -1
- package/dist/esm/internals/types.d.ts +2 -2
- package/dist/esm/internals/utils/clientProperties/generateEnumsProperty.mjs.map +1 -0
- package/dist/esm/internals/utils/{generateModelsProperty.d.ts → clientProperties/generateModelsProperty.d.ts} +2 -2
- package/dist/esm/internals/utils/{generateModelsProperty.mjs → clientProperties/generateModelsProperty.mjs} +7 -7
- package/dist/esm/internals/utils/clientProperties/generateModelsProperty.mjs.map +1 -0
- package/dist/esm/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs.map +1 -0
- package/dist/esm/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs.map +1 -0
- package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.d.ts +2 -0
- package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs +12 -0
- package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs.map +1 -0
- package/dist/esm/internals/v6.d.ts +1 -1
- package/dist/esm/internals/v6.mjs +0 -2
- package/dist/esm/internals/v6.mjs.map +1 -1
- package/dist/esm/types/index.d.ts +43 -35
- package/dist/esm/utils/ConnectionStateMonitor.d.ts +2 -2
- package/dist/esm/utils/ConnectionStateMonitor.mjs.map +1 -1
- package/dist/esm/utils/ReachabilityMonitor/index.native.mjs.map +1 -1
- package/dist/esm/utils/errors/constants.d.ts +7 -0
- package/dist/esm/utils/errors/constants.mjs +46 -0
- package/dist/esm/utils/errors/constants.mjs.map +1 -0
- package/dist/esm/utils/errors/createGraphQLResultWithError.d.ts +2 -0
- package/dist/esm/utils/errors/createGraphQLResultWithError.mjs +13 -0
- package/dist/esm/utils/errors/createGraphQLResultWithError.mjs.map +1 -0
- package/dist/esm/utils/errors/index.d.ts +1 -0
- package/dist/esm/utils/errors/index.mjs +1 -0
- package/dist/esm/utils/errors/index.mjs.map +1 -1
- package/dist/esm/utils/errors/repackageAuthError.d.ts +3 -7
- package/dist/esm/utils/errors/repackageAuthError.mjs +6 -6
- package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -1
- package/dist/esm/utils/findIndexByFields.d.ts +1 -1
- package/dist/esm/utils/resolveConfig.mjs +1 -0
- package/dist/esm/utils/resolveConfig.mjs.map +1 -1
- package/dist/esm/utils/resolveOwnerFields.mjs +6 -0
- package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -1
- package/package.json +8 -7
- package/src/GraphQLAPI.ts +4 -3
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +84 -64
- package/src/internals/APIClient.ts +242 -104
- package/src/internals/InternalGraphQLAPI.ts +65 -75
- package/src/internals/clientUtils.ts +1 -1
- package/src/internals/generateClient.ts +43 -6
- package/src/internals/generateCustomOperationsProperty.ts +112 -0
- package/src/internals/operations/custom.ts +492 -0
- package/src/internals/operations/get.ts +10 -9
- package/src/internals/operations/indexQuery.ts +13 -12
- package/src/internals/operations/list.ts +11 -15
- package/src/internals/operations/observeQuery.ts +3 -1
- package/src/internals/operations/subscription.ts +14 -10
- package/src/internals/server/generateClientWithAmplifyInstance.ts +26 -7
- package/src/internals/server/generateModelsProperty.ts +12 -6
- package/src/internals/types.ts +2 -2
- package/src/internals/utils/{generateEnumsProperty.ts → clientProperties/generateEnumsProperty.ts} +7 -6
- package/src/internals/utils/{generateModelsProperty.ts → clientProperties/generateModelsProperty.ts} +11 -10
- package/src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts +15 -0
- package/src/internals/v6.ts +6 -4
- package/src/server/generateClient.ts +4 -1
- package/src/types/PubSub.ts +1 -0
- package/src/types/index.ts +61 -45
- package/src/utils/ConnectionStateMonitor.ts +8 -3
- package/src/utils/ReachabilityMonitor/index.native.ts +1 -1
- package/src/utils/ReachabilityMonitor/index.ts +1 -0
- package/src/utils/ReconnectionMonitor.ts +1 -0
- package/src/utils/errors/constants.ts +56 -0
- package/src/utils/errors/createGraphQLResultWithError.ts +15 -0
- package/src/utils/errors/index.ts +1 -0
- package/src/utils/errors/repackageAuthError.ts +11 -14
- package/src/utils/findIndexByFields.ts +1 -1
- package/src/utils/resolveConfig.ts +1 -0
- package/src/utils/resolveLibraryOptions.ts +1 -0
- package/src/utils/resolveOwnerFields.ts +19 -7
- package/src/utils/resolvePKFields.ts +1 -0
- package/dist/cjs/internals/utils/generateEnumsProperty.js.map +0 -1
- package/dist/cjs/internals/utils/generateModelsProperty.js.map +0 -1
- package/dist/cjs/internals/utils/isApiGraphQLProviderConfig.js.map +0 -1
- package/dist/cjs/internals/utils/isConfigureEventWithResourceConfig.js.map +0 -1
- package/dist/esm/internals/utils/generateEnumsProperty.mjs.map +0 -1
- package/dist/esm/internals/utils/generateModelsProperty.mjs.map +0 -1
- package/dist/esm/internals/utils/isApiGraphQLProviderConfig.mjs.map +0 -1
- package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.mjs.map +0 -1
- /package/dist/cjs/internals/utils/{generateEnumsProperty.js → clientProperties/generateEnumsProperty.js} +0 -0
- /package/dist/cjs/internals/utils/{isApiGraphQLProviderConfig.js → runtimeTypeGuards/isApiGraphQLProviderConfig.js} +0 -0
- /package/dist/cjs/internals/utils/{isConfigureEventWithResourceConfig.js → runtimeTypeGuards/isConfigureEventWithResourceConfig.js} +0 -0
- /package/dist/esm/internals/utils/{generateEnumsProperty.d.ts → clientProperties/generateEnumsProperty.d.ts} +0 -0
- /package/dist/esm/internals/utils/{generateEnumsProperty.mjs → clientProperties/generateEnumsProperty.mjs} +0 -0
- /package/dist/esm/internals/utils/{isApiGraphQLProviderConfig.d.ts → runtimeTypeGuards/isApiGraphQLProviderConfig.d.ts} +0 -0
- /package/dist/esm/internals/utils/{isApiGraphQLProviderConfig.mjs → runtimeTypeGuards/isApiGraphQLProviderConfig.mjs} +0 -0
- /package/dist/esm/internals/utils/{isConfigureEventWithResourceConfig.d.ts → runtimeTypeGuards/isConfigureEventWithResourceConfig.d.ts} +0 -0
- /package/dist/esm/internals/utils/{isConfigureEventWithResourceConfig.mjs → runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs} +0 -0
- /package/src/internals/utils/{isApiGraphQLProviderConfig.ts → runtimeTypeGuards/isApiGraphQLProviderConfig.ts} +0 -0
- /package/src/internals/utils/{isConfigureEventWithResourceConfig.ts → runtimeTypeGuards/isConfigureEventWithResourceConfig.ts} +0 -0
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { parse, print
|
|
1
|
+
import { parse, print } from 'graphql';
|
|
2
2
|
import { catchError } from 'rxjs';
|
|
3
|
-
import { ConsoleLogger } from '@aws-amplify/core';
|
|
4
3
|
import { AmplifyUrl, getAmplifyUserAgent } from '@aws-amplify/core/internals/utils';
|
|
5
|
-
import { GraphQLAuthError } from '../types/index.mjs';
|
|
6
4
|
import { isCancelError } from '@aws-amplify/api-rest';
|
|
7
5
|
import { post, cancel, updateRequestToBeCancellable } from '@aws-amplify/api-rest/internals';
|
|
8
6
|
import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider/index.mjs';
|
|
9
7
|
import { resolveConfig } from '../utils/resolveConfig.mjs';
|
|
10
8
|
import { resolveLibraryOptions } from '../utils/resolveLibraryOptions.mjs';
|
|
11
|
-
import {
|
|
9
|
+
import { repackageUnauthorizedError } from '../utils/errors/repackageAuthError.mjs';
|
|
10
|
+
import { NO_AUTH_TOKEN_HEADER, NO_SIGNED_IN_USER, NO_VALID_AUTH_TOKEN, NO_VALID_CREDENTIALS, NO_API_KEY, NO_ENDPOINT } from '../utils/errors/constants.mjs';
|
|
11
|
+
import { GraphQLApiError } from '../utils/errors/GraphQLApiError.mjs';
|
|
12
|
+
import '../utils/errors/validation.mjs';
|
|
13
|
+
import { createGraphQLResultWithError } from '../utils/errors/createGraphQLResultWithError.mjs';
|
|
14
|
+
import { isGraphQLResponseWithErrors } from './utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs';
|
|
12
15
|
|
|
13
16
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
14
17
|
// SPDX-License-Identifier: Apache-2.0
|
|
15
18
|
const USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
16
|
-
new ConsoleLogger('GraphQLAPI');
|
|
17
19
|
const isAmplifyInstance = (amplify) => {
|
|
18
20
|
return typeof amplify !== 'function';
|
|
19
21
|
};
|
|
@@ -37,43 +39,52 @@ class InternalGraphQLAPIClass {
|
|
|
37
39
|
return 'InternalGraphQLAPI';
|
|
38
40
|
}
|
|
39
41
|
async _headerBasedAuth(amplify, authMode, additionalHeaders = {}) {
|
|
40
|
-
const {
|
|
42
|
+
const { apiKey } = resolveConfig(amplify);
|
|
41
43
|
let headers = {};
|
|
42
44
|
switch (authMode) {
|
|
43
45
|
case 'apiKey':
|
|
44
46
|
if (!apiKey) {
|
|
45
|
-
throw new
|
|
47
|
+
throw new GraphQLApiError(NO_API_KEY);
|
|
46
48
|
}
|
|
47
49
|
headers = {
|
|
48
50
|
'X-Api-Key': apiKey,
|
|
49
51
|
};
|
|
50
52
|
break;
|
|
51
|
-
case 'iam':
|
|
53
|
+
case 'iam': {
|
|
52
54
|
const session = await amplify.Auth.fetchAuthSession();
|
|
53
55
|
if (session.credentials === undefined) {
|
|
54
|
-
throw new
|
|
56
|
+
throw new GraphQLApiError(NO_VALID_CREDENTIALS);
|
|
55
57
|
}
|
|
56
58
|
break;
|
|
59
|
+
}
|
|
57
60
|
case 'oidc':
|
|
58
|
-
case 'userPool':
|
|
61
|
+
case 'userPool': {
|
|
62
|
+
let token;
|
|
59
63
|
try {
|
|
60
|
-
let token;
|
|
61
64
|
token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();
|
|
62
|
-
if (!token) {
|
|
63
|
-
throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);
|
|
64
|
-
}
|
|
65
|
-
headers = {
|
|
66
|
-
Authorization: token,
|
|
67
|
-
};
|
|
68
65
|
}
|
|
69
66
|
catch (e) {
|
|
70
|
-
|
|
67
|
+
// fetchAuthSession failed
|
|
68
|
+
throw new GraphQLApiError({
|
|
69
|
+
...NO_SIGNED_IN_USER,
|
|
70
|
+
underlyingError: e,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
// `fetchAuthSession()` succeeded but didn't return `tokens`.
|
|
74
|
+
// This may happen when unauthenticated access is enabled and there is
|
|
75
|
+
// no user signed in.
|
|
76
|
+
if (!token) {
|
|
77
|
+
throw new GraphQLApiError(NO_VALID_AUTH_TOKEN);
|
|
71
78
|
}
|
|
79
|
+
headers = {
|
|
80
|
+
Authorization: token,
|
|
81
|
+
};
|
|
72
82
|
break;
|
|
83
|
+
}
|
|
73
84
|
case 'lambda':
|
|
74
85
|
if (typeof additionalHeaders === 'object' &&
|
|
75
86
|
!additionalHeaders.Authorization) {
|
|
76
|
-
throw new
|
|
87
|
+
throw new GraphQLApiError(NO_AUTH_TOKEN_HEADER);
|
|
77
88
|
}
|
|
78
89
|
headers = {
|
|
79
90
|
Authorization: additionalHeaders.Authorization,
|
|
@@ -108,7 +119,7 @@ class InternalGraphQLAPIClass {
|
|
|
108
119
|
const headers = additionalHeaders || {};
|
|
109
120
|
switch (operationType) {
|
|
110
121
|
case 'query':
|
|
111
|
-
case 'mutation':
|
|
122
|
+
case 'mutation': {
|
|
112
123
|
const abortController = new AbortController();
|
|
113
124
|
let responsePromise;
|
|
114
125
|
if (isAmplifyInstance(amplify)) {
|
|
@@ -125,6 +136,7 @@ class InternalGraphQLAPIClass {
|
|
|
125
136
|
}
|
|
126
137
|
this._api.updateRequestToBeCancellable(responsePromise, abortController);
|
|
127
138
|
return responsePromise;
|
|
139
|
+
}
|
|
128
140
|
case 'subscription':
|
|
129
141
|
return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails, authToken);
|
|
130
142
|
default:
|
|
@@ -132,7 +144,7 @@ class InternalGraphQLAPIClass {
|
|
|
132
144
|
}
|
|
133
145
|
}
|
|
134
146
|
async _graphql(amplify, { query, variables, authMode: explicitAuthMode }, additionalHeaders = {}, abortController, customUserAgentDetails, authToken) {
|
|
135
|
-
const { region
|
|
147
|
+
const { region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, defaultAuthMode, } = resolveConfig(amplify);
|
|
136
148
|
const authMode = explicitAuthMode || defaultAuthMode || 'iam';
|
|
137
149
|
/**
|
|
138
150
|
* Retrieve library options from Amplify configuration.
|
|
@@ -221,14 +233,13 @@ class InternalGraphQLAPIClass {
|
|
|
221
233
|
}
|
|
222
234
|
const endpoint = customEndpoint || appSyncGraphqlEndpoint;
|
|
223
235
|
if (!endpoint) {
|
|
224
|
-
|
|
225
|
-
throw {
|
|
226
|
-
data: {},
|
|
227
|
-
errors: [error],
|
|
228
|
-
};
|
|
236
|
+
throw createGraphQLResultWithError(new GraphQLApiError(NO_ENDPOINT));
|
|
229
237
|
}
|
|
230
238
|
let response;
|
|
231
239
|
try {
|
|
240
|
+
// See the inline doc of the REST `post()` API for possible errors to be thrown.
|
|
241
|
+
// As these errors are catastrophic they should be caught and handled by GraphQL
|
|
242
|
+
// API consumers.
|
|
232
243
|
const { body: responseBody } = await this._api.post(amplify, {
|
|
233
244
|
url: new AmplifyUrl(endpoint),
|
|
234
245
|
options: {
|
|
@@ -239,26 +250,16 @@ class InternalGraphQLAPIClass {
|
|
|
239
250
|
},
|
|
240
251
|
abortController,
|
|
241
252
|
});
|
|
242
|
-
|
|
243
|
-
response = result;
|
|
253
|
+
response = await responseBody.json();
|
|
244
254
|
}
|
|
245
|
-
catch (
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
// so that clients can identify the exception correctly.
|
|
249
|
-
if (this.isCancelError(err)) {
|
|
250
|
-
throw err;
|
|
255
|
+
catch (error) {
|
|
256
|
+
if (this.isCancelError(error)) {
|
|
257
|
+
throw error;
|
|
251
258
|
}
|
|
252
|
-
response =
|
|
253
|
-
data: {},
|
|
254
|
-
errors: [
|
|
255
|
-
new GraphQLError(err.message, null, null, null, null, err),
|
|
256
|
-
],
|
|
257
|
-
};
|
|
259
|
+
response = createGraphQLResultWithError(error);
|
|
258
260
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
throw repackageUnauthError(response);
|
|
261
|
+
if (isGraphQLResponseWithErrors(response)) {
|
|
262
|
+
throw repackageUnauthorizedError(response);
|
|
262
263
|
}
|
|
263
264
|
return response;
|
|
264
265
|
}
|
|
@@ -303,7 +304,7 @@ class InternalGraphQLAPIClass {
|
|
|
303
304
|
}, customUserAgentDetails)
|
|
304
305
|
.pipe(catchError(e => {
|
|
305
306
|
if (e.errors) {
|
|
306
|
-
throw
|
|
307
|
+
throw repackageUnauthorizedError(e);
|
|
307
308
|
}
|
|
308
309
|
throw e;
|
|
309
310
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InternalGraphQLAPI.mjs","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { print, parse, GraphQLError, } from 'graphql';\nimport { catchError } from 'rxjs';\nimport { ConsoleLogger } from '@aws-amplify/core';\nimport { getAmplifyUserAgent, AmplifyUrl, } from '@aws-amplify/core/internals/utils';\nimport { GraphQLAuthError, } from '../types';\nimport { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';\nimport { post, cancel as cancelREST, updateRequestToBeCancellable, } from '@aws-amplify/api-rest/internals';\nimport { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';\nimport { resolveConfig, resolveLibraryOptions } from '../utils';\nimport { repackageUnauthError } from '../utils/errors/repackageAuthError';\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst logger = new ConsoleLogger('GraphQLAPI');\nconst isAmplifyInstance = (amplify) => {\n return typeof amplify !== 'function';\n};\n/**\n * Export Cloud Logic APIs\n */\nexport class InternalGraphQLAPIClass {\n constructor() {\n /**\n * @private\n */\n this.appSyncRealTime = new AWSAppSyncRealTimeProvider();\n this._api = {\n post,\n cancelREST,\n isCancelErrorREST,\n updateRequestToBeCancellable,\n };\n }\n getModuleName() {\n return 'InternalGraphQLAPI';\n }\n async _headerBasedAuth(amplify, authMode, additionalHeaders = {}) {\n const { region: region, endpoint: appSyncGraphqlEndpoint, apiKey, } = resolveConfig(amplify);\n let headers = {};\n switch (authMode) {\n case 'apiKey':\n if (!apiKey) {\n throw new Error(GraphQLAuthError.NO_API_KEY);\n }\n headers = {\n 'X-Api-Key': apiKey,\n };\n break;\n case 'iam':\n const session = await amplify.Auth.fetchAuthSession();\n if (session.credentials === undefined) {\n throw new Error(GraphQLAuthError.NO_CREDENTIALS);\n }\n break;\n case 'oidc':\n case 'userPool':\n try {\n let token;\n token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();\n if (!token) {\n throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);\n }\n headers = {\n Authorization: token,\n };\n }\n catch (e) {\n throw new Error(GraphQLAuthError.NO_CURRENT_USER);\n }\n break;\n case 'lambda':\n if (typeof additionalHeaders === 'object' &&\n !additionalHeaders.Authorization) {\n throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);\n }\n headers = {\n Authorization: additionalHeaders.Authorization,\n };\n break;\n case 'none':\n break;\n default:\n break;\n }\n return headers;\n }\n /**\n * to get the operation type\n * @param operation\n */\n getGraphqlOperationType(operation) {\n const doc = parse(operation);\n const definitions = doc.definitions;\n const [{ operation: operationType }] = definitions;\n return operationType;\n }\n /**\n * Executes a GraphQL operation\n *\n * @param options - GraphQL Options\n * @param [additionalHeaders] - headers to merge in after any `libraryConfigHeaders` set in the config\n * @returns An Observable if the query is a subscription query, else a promise of the graphql result.\n */\n graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken }, additionalHeaders, customUserAgentDetails) {\n const query = typeof paramQuery === 'string'\n ? parse(paramQuery)\n : parse(print(paramQuery));\n const [operationDef = {}] = query.definitions.filter(def => def.kind === 'OperationDefinition');\n const { operation: operationType } = operationDef;\n const headers = additionalHeaders || {};\n switch (operationType) {\n case 'query':\n case 'mutation':\n const abortController = new AbortController();\n let responsePromise;\n if (isAmplifyInstance(amplify)) {\n responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n }\n else {\n // NOTE: this wrapper function must be await-able so the Amplify server context manager can\n // destroy the context only after it completes\n const wrapper = async (amplifyInstance) => {\n const result = await this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n return result;\n };\n responsePromise = amplify(wrapper);\n }\n this._api.updateRequestToBeCancellable(responsePromise, abortController);\n return responsePromise;\n case 'subscription':\n return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails, authToken);\n default:\n throw new Error(`invalid operation type: ${operationType}`);\n }\n }\n async _graphql(amplify, { query, variables, authMode: explicitAuthMode }, additionalHeaders = {}, abortController, customUserAgentDetails, authToken) {\n const { region: region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, defaultAuthMode, } = resolveConfig(amplify);\n const authMode = explicitAuthMode || defaultAuthMode || 'iam';\n /**\n * Retrieve library options from Amplify configuration.\n * `customHeaders` here are from the Amplify configuration options,\n * and are for non-AppSync endpoints only. These are *not* the same as\n * `additionalHeaders`, which are custom headers that are either 1)\n * included when configuring the API client or 2) passed along with\n * individual requests.\n */\n const { headers: customHeaders, withCredentials } = resolveLibraryOptions(amplify);\n /**\n * Client or request-specific custom headers that may or may not be\n * returned by a function:\n */\n let additionalCustomHeaders;\n if (typeof additionalHeaders === 'function') {\n const requestOptions = {\n method: 'POST',\n url: new AmplifyUrl(customEndpoint || appSyncGraphqlEndpoint || '').toString(),\n queryString: print(query),\n };\n additionalCustomHeaders = await additionalHeaders(requestOptions);\n }\n else {\n additionalCustomHeaders = additionalHeaders;\n }\n // if an authorization header is set, have the explicit authToken take precedence\n if (authToken) {\n additionalCustomHeaders = {\n ...additionalCustomHeaders,\n Authorization: authToken,\n };\n }\n // TODO: Figure what we need to do to remove `!`'s.\n const headers = {\n ...(!customEndpoint &&\n (await this._headerBasedAuth(amplify, authMode, additionalCustomHeaders))),\n /**\n * Custom endpoint headers.\n * If there is both a custom endpoint and custom region present, we get the headers.\n * If there is a custom endpoint but no region, we return an empty object.\n * If neither are present, we return an empty object.\n */\n ...((customEndpoint &&\n (customEndpointRegion\n ? await this._headerBasedAuth(amplify, authMode, additionalCustomHeaders)\n : {})) ||\n {}),\n // Custom headers included in Amplify configuration options:\n ...(customHeaders &&\n (await customHeaders({\n query: print(query),\n variables,\n }))),\n // Custom headers from individual requests or API client configuration:\n ...additionalCustomHeaders,\n // User agent headers:\n ...(!customEndpoint && {\n [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),\n }),\n };\n const body = {\n query: print(query),\n variables: variables || null,\n };\n let signingServiceInfo;\n /**\n * We do not send the signing service info to the REST API under the\n * following conditions (i.e. it will not sign the request):\n * - there is a custom endpoint but no region\n * - the auth mode is `none`, or `apiKey`\n * - the auth mode is a type other than the types listed below\n */\n if ((customEndpoint && !customEndpointRegion) ||\n (authMode !== 'oidc' &&\n authMode !== 'userPool' &&\n authMode !== 'iam' &&\n authMode !== 'lambda')) {\n signingServiceInfo = undefined;\n }\n else {\n signingServiceInfo = {\n service: !customEndpointRegion ? 'appsync' : 'execute-api',\n region: !customEndpointRegion ? region : customEndpointRegion,\n };\n }\n const endpoint = customEndpoint || appSyncGraphqlEndpoint;\n if (!endpoint) {\n const error = new GraphQLError('No graphql endpoint provided.');\n throw {\n data: {},\n errors: [error],\n };\n }\n let response;\n try {\n const { body: responseBody } = await this._api.post(amplify, {\n url: new AmplifyUrl(endpoint),\n options: {\n headers,\n body,\n signingServiceInfo,\n withCredentials,\n },\n abortController,\n });\n const result = await responseBody.json();\n response = result;\n }\n catch (err) {\n // If the exception is because user intentionally\n // cancelled the request, do not modify the exception\n // so that clients can identify the exception correctly.\n if (this.isCancelError(err)) {\n throw err;\n }\n response = {\n data: {},\n errors: [\n new GraphQLError(err.message, null, null, null, null, err),\n ],\n };\n }\n const { errors } = response;\n if (errors && errors.length) {\n throw repackageUnauthError(response);\n }\n return response;\n }\n /**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @return {boolean} - A boolean indicating if the error was from an api request cancellation\n */\n isCancelError(error) {\n return this._api.isCancelErrorREST(error);\n }\n /**\n * Cancels an inflight request. Only applicable for graphql queries and mutations\n * @param {any} request - request to cancel\n * @returns - A boolean indicating if the request was cancelled\n */\n cancel(request, message) {\n return this._api.cancelREST(request, message);\n }\n _graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails, authToken) {\n const config = resolveConfig(amplify);\n /**\n * Retrieve library options from Amplify configuration.\n * `libraryConfigHeaders` are from the Amplify configuration options,\n * and will not be overwritten by other custom headers. These are *not*\n * the same as `additionalHeaders`, which are custom headers that are\n * either 1)included when configuring the API client or 2) passed along\n * with individual requests.\n */\n const { headers: libraryConfigHeaders } = resolveLibraryOptions(amplify);\n return this.appSyncRealTime\n .subscribe({\n query: print(query),\n variables,\n appSyncGraphqlEndpoint: config?.endpoint,\n region: config?.region,\n authenticationType: authMode || config?.defaultAuthMode,\n apiKey: config?.apiKey,\n additionalHeaders,\n authToken,\n libraryConfigHeaders,\n }, customUserAgentDetails)\n .pipe(catchError(e => {\n if (e.errors) {\n throw repackageUnauthError(e);\n }\n throw e;\n }));\n }\n}\nexport const InternalGraphQLAPI = new InternalGraphQLAPIClass();\n"],"names":["cancelREST","isCancelErrorREST"],"mappings":";;;;;;;;;;;;AAAA;AACA;AAWA,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC9B,IAAI,aAAa,CAAC,YAAY,EAAE;AAC/C,MAAM,iBAAiB,GAAG,CAAC,OAAO,KAAK;AACvC,IAAI,OAAO,OAAO,OAAO,KAAK,UAAU,CAAC;AACzC,CAAC,CAAC;AACF;AACA;AACA;AACO,MAAM,uBAAuB,CAAC;AACrC,IAAI,WAAW,GAAG;AAClB;AACA;AACA;AACA,QAAQ,IAAI,CAAC,eAAe,GAAG,IAAI,0BAA0B,EAAE,CAAC;AAChE,QAAQ,IAAI,CAAC,IAAI,GAAG;AACpB,YAAY,IAAI;AAChB,wBAAYA,MAAU;AACtB,+BAAYC,aAAiB;AAC7B,YAAY,4BAA4B;AACxC,SAAS,CAAC;AACV,KAAK;AACL,IAAI,aAAa,GAAG;AACpB,QAAQ,OAAO,oBAAoB,CAAC;AACpC,KAAK;AACL,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,GAAG,EAAE,EAAE;AACtE,QAAQ,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,GAAG,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;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,SAAS;AACrB,YAAY,oBAAoB;AAChC,SAAS,EAAE,sBAAsB,CAAC;AAClC,aAAa,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI;AAClC,YAAY,IAAI,CAAC,CAAC,MAAM,EAAE;AAC1B,gBAAgB,MAAM,oBAAoB,CAAC,CAAC,CAAC,CAAC;AAC9C,aAAa;AACb,YAAY,MAAM,CAAC,CAAC;AACpB,SAAS,CAAC,CAAC,CAAC;AACZ,KAAK;AACL,CAAC;AACW,MAAC,kBAAkB,GAAG,IAAI,uBAAuB;;;;"}
|
|
1
|
+
{"version":3,"file":"InternalGraphQLAPI.mjs","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { parse, print, } from 'graphql';\nimport { catchError } from 'rxjs';\nimport { AmplifyUrl, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils';\nimport { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';\nimport { cancel as cancelREST, post, updateRequestToBeCancellable, } from '@aws-amplify/api-rest/internals';\nimport { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';\nimport { resolveConfig, resolveLibraryOptions } from '../utils';\nimport { repackageUnauthorizedError } from '../utils/errors/repackageAuthError';\nimport { NO_API_KEY, NO_AUTH_TOKEN_HEADER, NO_ENDPOINT, NO_SIGNED_IN_USER, NO_VALID_AUTH_TOKEN, NO_VALID_CREDENTIALS, } from '../utils/errors/constants';\nimport { GraphQLApiError, createGraphQLResultWithError } from '../utils/errors';\nimport { isGraphQLResponseWithErrors } from './utils/runtimeTypeGuards/isGraphQLResponseWithErrors';\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst isAmplifyInstance = (amplify) => {\n return typeof amplify !== 'function';\n};\n/**\n * Export Cloud Logic APIs\n */\nexport class InternalGraphQLAPIClass {\n constructor() {\n /**\n * @private\n */\n this.appSyncRealTime = new AWSAppSyncRealTimeProvider();\n this._api = {\n post,\n cancelREST,\n isCancelErrorREST,\n updateRequestToBeCancellable,\n };\n }\n getModuleName() {\n return 'InternalGraphQLAPI';\n }\n async _headerBasedAuth(amplify, authMode, additionalHeaders = {}) {\n const { apiKey } = resolveConfig(amplify);\n let headers = {};\n switch (authMode) {\n case 'apiKey':\n if (!apiKey) {\n throw new GraphQLApiError(NO_API_KEY);\n }\n headers = {\n 'X-Api-Key': apiKey,\n };\n break;\n case 'iam': {\n const session = await amplify.Auth.fetchAuthSession();\n if (session.credentials === undefined) {\n throw new GraphQLApiError(NO_VALID_CREDENTIALS);\n }\n break;\n }\n case 'oidc':\n case 'userPool': {\n let token;\n try {\n token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();\n }\n catch (e) {\n // fetchAuthSession failed\n throw new GraphQLApiError({\n ...NO_SIGNED_IN_USER,\n underlyingError: e,\n });\n }\n // `fetchAuthSession()` succeeded but didn't return `tokens`.\n // This may happen when unauthenticated access is enabled and there is\n // no user signed in.\n if (!token) {\n throw new GraphQLApiError(NO_VALID_AUTH_TOKEN);\n }\n headers = {\n Authorization: token,\n };\n break;\n }\n case 'lambda':\n if (typeof additionalHeaders === 'object' &&\n !additionalHeaders.Authorization) {\n throw new GraphQLApiError(NO_AUTH_TOKEN_HEADER);\n }\n headers = {\n Authorization: additionalHeaders.Authorization,\n };\n break;\n case 'none':\n break;\n default:\n break;\n }\n return headers;\n }\n /**\n * to get the operation type\n * @param operation\n */\n getGraphqlOperationType(operation) {\n const doc = parse(operation);\n const definitions = doc.definitions;\n const [{ operation: operationType }] = definitions;\n return operationType;\n }\n /**\n * Executes a GraphQL operation\n *\n * @param options - GraphQL Options\n * @param [additionalHeaders] - headers to merge in after any `libraryConfigHeaders` set in the config\n * @returns An Observable if the query is a subscription query, else a promise of the graphql result.\n */\n graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken }, additionalHeaders, customUserAgentDetails) {\n const query = typeof paramQuery === 'string'\n ? parse(paramQuery)\n : parse(print(paramQuery));\n const [operationDef = {}] = query.definitions.filter(def => def.kind === 'OperationDefinition');\n const { operation: operationType } = operationDef;\n const headers = additionalHeaders || {};\n switch (operationType) {\n case 'query':\n case 'mutation': {\n const abortController = new AbortController();\n let responsePromise;\n if (isAmplifyInstance(amplify)) {\n responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n }\n else {\n // NOTE: this wrapper function must be await-able so the Amplify server context manager can\n // destroy the context only after it completes\n const wrapper = async (amplifyInstance) => {\n const result = await this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n return result;\n };\n responsePromise = amplify(wrapper);\n }\n this._api.updateRequestToBeCancellable(responsePromise, abortController);\n return responsePromise;\n }\n case 'subscription':\n return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails, authToken);\n default:\n throw new Error(`invalid operation type: ${operationType}`);\n }\n }\n async _graphql(amplify, { query, variables, authMode: explicitAuthMode }, additionalHeaders = {}, abortController, customUserAgentDetails, authToken) {\n const { region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, defaultAuthMode, } = resolveConfig(amplify);\n const authMode = explicitAuthMode || defaultAuthMode || 'iam';\n /**\n * Retrieve library options from Amplify configuration.\n * `customHeaders` here are from the Amplify configuration options,\n * and are for non-AppSync endpoints only. These are *not* the same as\n * `additionalHeaders`, which are custom headers that are either 1)\n * included when configuring the API client or 2) passed along with\n * individual requests.\n */\n const { headers: customHeaders, withCredentials } = resolveLibraryOptions(amplify);\n /**\n * Client or request-specific custom headers that may or may not be\n * returned by a function:\n */\n let additionalCustomHeaders;\n if (typeof additionalHeaders === 'function') {\n const requestOptions = {\n method: 'POST',\n url: new AmplifyUrl(customEndpoint || appSyncGraphqlEndpoint || '').toString(),\n queryString: print(query),\n };\n additionalCustomHeaders = await additionalHeaders(requestOptions);\n }\n else {\n additionalCustomHeaders = additionalHeaders;\n }\n // if an authorization header is set, have the explicit authToken take precedence\n if (authToken) {\n additionalCustomHeaders = {\n ...additionalCustomHeaders,\n Authorization: authToken,\n };\n }\n // TODO: Figure what we need to do to remove `!`'s.\n const headers = {\n ...(!customEndpoint &&\n (await this._headerBasedAuth(amplify, authMode, additionalCustomHeaders))),\n /**\n * Custom endpoint headers.\n * If there is both a custom endpoint and custom region present, we get the headers.\n * If there is a custom endpoint but no region, we return an empty object.\n * If neither are present, we return an empty object.\n */\n ...((customEndpoint &&\n (customEndpointRegion\n ? await this._headerBasedAuth(amplify, authMode, additionalCustomHeaders)\n : {})) ||\n {}),\n // Custom headers included in Amplify configuration options:\n ...(customHeaders &&\n (await customHeaders({\n query: print(query),\n variables,\n }))),\n // Custom headers from individual requests or API client configuration:\n ...additionalCustomHeaders,\n // User agent headers:\n ...(!customEndpoint && {\n [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),\n }),\n };\n const body = {\n query: print(query),\n variables: variables || null,\n };\n let signingServiceInfo;\n /**\n * We do not send the signing service info to the REST API under the\n * following conditions (i.e. it will not sign the request):\n * - there is a custom endpoint but no region\n * - the auth mode is `none`, or `apiKey`\n * - the auth mode is a type other than the types listed below\n */\n if ((customEndpoint && !customEndpointRegion) ||\n (authMode !== 'oidc' &&\n authMode !== 'userPool' &&\n authMode !== 'iam' &&\n authMode !== 'lambda')) {\n signingServiceInfo = undefined;\n }\n else {\n signingServiceInfo = {\n service: !customEndpointRegion ? 'appsync' : 'execute-api',\n region: !customEndpointRegion ? region : customEndpointRegion,\n };\n }\n const endpoint = customEndpoint || appSyncGraphqlEndpoint;\n if (!endpoint) {\n throw createGraphQLResultWithError(new GraphQLApiError(NO_ENDPOINT));\n }\n let response;\n try {\n // See the inline doc of the REST `post()` API for possible errors to be thrown.\n // As these errors are catastrophic they should be caught and handled by GraphQL\n // API consumers.\n const { body: responseBody } = await this._api.post(amplify, {\n url: new AmplifyUrl(endpoint),\n options: {\n headers,\n body,\n signingServiceInfo,\n withCredentials,\n },\n abortController,\n });\n response = await responseBody.json();\n }\n catch (error) {\n if (this.isCancelError(error)) {\n throw error;\n }\n response = createGraphQLResultWithError(error);\n }\n if (isGraphQLResponseWithErrors(response)) {\n throw repackageUnauthorizedError(response);\n }\n return response;\n }\n /**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @return {boolean} - A boolean indicating if the error was from an api request cancellation\n */\n isCancelError(error) {\n return this._api.isCancelErrorREST(error);\n }\n /**\n * Cancels an inflight request. Only applicable for graphql queries and mutations\n * @param {any} request - request to cancel\n * @returns - A boolean indicating if the request was cancelled\n */\n cancel(request, message) {\n return this._api.cancelREST(request, message);\n }\n _graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails, authToken) {\n const config = resolveConfig(amplify);\n /**\n * Retrieve library options from Amplify configuration.\n * `libraryConfigHeaders` are from the Amplify configuration options,\n * and will not be overwritten by other custom headers. These are *not*\n * the same as `additionalHeaders`, which are custom headers that are\n * either 1)included when configuring the API client or 2) passed along\n * with individual requests.\n */\n const { headers: libraryConfigHeaders } = resolveLibraryOptions(amplify);\n return this.appSyncRealTime\n .subscribe({\n query: print(query),\n variables,\n appSyncGraphqlEndpoint: config?.endpoint,\n region: config?.region,\n authenticationType: authMode || config?.defaultAuthMode,\n apiKey: config?.apiKey,\n additionalHeaders,\n authToken,\n libraryConfigHeaders,\n }, customUserAgentDetails)\n .pipe(catchError(e => {\n if (e.errors) {\n throw repackageUnauthorizedError(e);\n }\n throw e;\n }));\n }\n}\nexport const InternalGraphQLAPI = new InternalGraphQLAPIClass();\n"],"names":["cancelREST","isCancelErrorREST"],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AAYA,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC7C,MAAM,iBAAiB,GAAG,CAAC,OAAO,KAAK;AACvC,IAAI,OAAO,OAAO,OAAO,KAAK,UAAU,CAAC;AACzC,CAAC,CAAC;AACF;AACA;AACA;AACO,MAAM,uBAA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Y,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,kBAAkB,EAAE,QAAQ,IAAI,MAAM,EAAE,eAAe;AACnE,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,iBAAiB;AAC7B,YAAY,SAAS;AACrB,YAAY,oBAAoB;AAChC,SAAS,EAAE,sBAAsB,CAAC;AAClC,aAAa,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI;AAClC,YAAY,IAAI,CAAC,CAAC,MAAM,EAAE;AAC1B,gBAAgB,MAAM,0BAA0B,CAAC,CAAC,CAAC,CAAC;AACpD,aAAa;AACb,YAAY,MAAM,CAAC,CAAC;AACpB,SAAS,CAAC,CAAC,CAAC;AACZ,KAAK;AACL,CAAC;AACW,MAAC,kBAAkB,GAAG,IAAI,uBAAuB;;;;"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Hub } from '@aws-amplify/core';
|
|
2
|
-
import { graphql, cancel, isCancelError } from './v6.mjs';
|
|
3
|
-
import { generateEnumsProperty } from './utils/generateEnumsProperty.mjs';
|
|
4
|
-
import { generateModelsProperty } from './utils/generateModelsProperty.mjs';
|
|
5
|
-
import { isApiGraphQLConfig } from './utils/isApiGraphQLProviderConfig.mjs';
|
|
6
2
|
import { __amplify, __authMode, __authToken, __headers } from '../types/index.mjs';
|
|
7
|
-
import {
|
|
3
|
+
import { graphql, cancel, isCancelError } from './v6.mjs';
|
|
4
|
+
import { generateEnumsProperty } from './utils/clientProperties/generateEnumsProperty.mjs';
|
|
5
|
+
import { generateModelsProperty } from './utils/clientProperties/generateModelsProperty.mjs';
|
|
6
|
+
import { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs';
|
|
7
|
+
import { generateCustomQueriesProperty, generateCustomMutationsProperty, generateCustomSubscriptionsProperty } from './generateCustomOperationsProperty.mjs';
|
|
8
|
+
import { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs';
|
|
8
9
|
|
|
9
10
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
10
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -28,11 +29,17 @@ function generateClient(params) {
|
|
|
28
29
|
isCancelError,
|
|
29
30
|
models: emptyProperty,
|
|
30
31
|
enums: emptyProperty,
|
|
32
|
+
queries: emptyProperty,
|
|
33
|
+
mutations: emptyProperty,
|
|
34
|
+
subscriptions: emptyProperty,
|
|
31
35
|
};
|
|
32
36
|
const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
|
|
33
37
|
if (isApiGraphQLConfig(apiGraphqlConfig)) {
|
|
34
38
|
client.models = generateModelsProperty(client, apiGraphqlConfig);
|
|
35
39
|
client.enums = generateEnumsProperty(apiGraphqlConfig);
|
|
40
|
+
client.queries = generateCustomQueriesProperty(client, apiGraphqlConfig);
|
|
41
|
+
client.mutations = generateCustomMutationsProperty(client, apiGraphqlConfig);
|
|
42
|
+
client.subscriptions = generateCustomSubscriptionsProperty(client, apiGraphqlConfig);
|
|
36
43
|
}
|
|
37
44
|
else {
|
|
38
45
|
// This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
|
|
@@ -60,6 +67,9 @@ const generateModelsPropertyOnAmplifyConfigure = (clientRef) => {
|
|
|
60
67
|
if (isApiGraphQLConfig(apiGraphQLConfig)) {
|
|
61
68
|
clientRef.models = generateModelsProperty(clientRef, apiGraphQLConfig);
|
|
62
69
|
clientRef.enums = generateEnumsProperty(apiGraphQLConfig);
|
|
70
|
+
clientRef.queries = generateCustomQueriesProperty(clientRef, apiGraphQLConfig);
|
|
71
|
+
clientRef.mutations = generateCustomMutationsProperty(clientRef, apiGraphQLConfig);
|
|
72
|
+
clientRef.subscriptions = generateCustomSubscriptionsProperty(clientRef, apiGraphQLConfig);
|
|
63
73
|
}
|
|
64
74
|
});
|
|
65
75
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateClient.mjs","sources":["../../../src/internals/generateClient.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Hub } from '@aws-amplify/core';\nimport {
|
|
1
|
+
{"version":3,"file":"generateClient.mjs","sources":["../../../src/internals/generateClient.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Hub } from '@aws-amplify/core';\nimport { __amplify, __authMode, __authToken, __headers, } from '../types';\nimport { cancel, graphql, isCancelError } from './v6';\nimport { generateEnumsProperty } from './utils/clientProperties/generateEnumsProperty';\nimport { generateModelsProperty } from './utils/clientProperties/generateModelsProperty';\nimport { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig';\nimport { generateCustomMutationsProperty, generateCustomQueriesProperty, generateCustomSubscriptionsProperty, } from './generateCustomOperationsProperty';\nimport { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig';\n/**\n * @private\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nexport function generateClient(params) {\n const client = {\n [__amplify]: params.amplify,\n [__authMode]: params.authMode,\n [__authToken]: params.authToken,\n [__headers]: params.headers,\n graphql,\n cancel,\n isCancelError,\n models: emptyProperty,\n enums: emptyProperty,\n queries: emptyProperty,\n mutations: emptyProperty,\n subscriptions: emptyProperty,\n };\n const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;\n if (isApiGraphQLConfig(apiGraphqlConfig)) {\n client.models = generateModelsProperty(client, apiGraphqlConfig);\n client.enums = generateEnumsProperty(apiGraphqlConfig);\n client.queries = generateCustomQueriesProperty(client, apiGraphqlConfig);\n client.mutations = generateCustomMutationsProperty(client, apiGraphqlConfig);\n client.subscriptions = generateCustomSubscriptionsProperty(client, apiGraphqlConfig);\n }\n else {\n // This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.\n //\n // Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in\n // different source files, script bundlers may randomly arrange their orders in the production\n // bundle.\n //\n // With the current implementation, the `client.models` instance created by `generateClient()`\n // will be rebuilt on every `Amplify.configure()` call that's provided with a valid GraphQL\n // provider configuration.\n //\n // TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints\n // configuration.\n generateModelsPropertyOnAmplifyConfigure(client);\n }\n return client;\n}\nconst generateModelsPropertyOnAmplifyConfigure = (clientRef) => {\n Hub.listen('core', coreEvent => {\n if (!isConfigureEventWithResourceConfig(coreEvent.payload)) {\n return;\n }\n const apiGraphQLConfig = coreEvent.payload.data.API?.GraphQL;\n if (isApiGraphQLConfig(apiGraphQLConfig)) {\n clientRef.models = generateModelsProperty(clientRef, apiGraphQLConfig);\n clientRef.enums = generateEnumsProperty(apiGraphQLConfig);\n clientRef.queries = generateCustomQueriesProperty(clientRef, apiGraphQLConfig);\n clientRef.mutations = generateCustomMutationsProperty(clientRef, apiGraphQLConfig);\n clientRef.subscriptions = generateCustomSubscriptionsProperty(clientRef, apiGraphQLConfig);\n }\n });\n};\nconst emptyProperty = new Proxy({}, {\n get() {\n throw new Error('Client could not be generated. This is likely due to `Amplify.configure()` not being called prior to `generateClient()` or because the configuration passed to `Amplify.configure()` is missing GraphQL provider configuration.');\n },\n});\n"],"names":[],"mappings":";;;;;;;;;AAAA;AACA;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,MAAM,EAAE;AACvC,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ;AACrC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS;AACvC,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,OAAO;AACf,QAAQ,MAAM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C;AACrE,QAAQ,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;AAClD,YAAY,SAAS,CAAC,MAAM,GAAG,sBAAsB,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACnF,YAAY,SAAS,CAAC,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;AACtE,YAAY,SAAS,CAAC,OAAO,GAAG,6BAA6B,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAC3F,YAAY,SAAS,CAAC,SAAS,GAAG,+BAA+B,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAC/F,YAAY,SAAS,CAAC,aAAa,GAAG,mCAAmC,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACvG,SAAS;AACT,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE;AACpC,IAAI,GAAG,GAAG;AACV,QAAQ,MAAM,IAAI,KAAK,CAAC,iOAAiO,CAAC,CAAC;AAC3P,KAAK;AACL,CAAC,CAAC;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CustomMutations, CustomQueries } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import { GraphQLProviderConfig } from '@aws-amplify/core/internals/utils';
|
|
3
|
+
import { V6Client } from '../types';
|
|
4
|
+
type OpTypes = 'queries' | 'mutations' | 'subscriptions';
|
|
5
|
+
export declare function generateCustomOperationsProperty<T extends Record<any, any>, OpType extends OpTypes>(client: V6Client<Record<string, any>>, config: GraphQLProviderConfig['GraphQL'], operationsType: OpType): OpType extends 'queries' ? CustomQueries<T> : CustomMutations<T>;
|
|
6
|
+
export declare function generateCustomMutationsProperty<T extends Record<any, any>>(client: V6Client<Record<string, any>>, config: GraphQLProviderConfig['GraphQL']): CustomMutations<T>;
|
|
7
|
+
export declare function generateCustomQueriesProperty<T extends Record<any, any>>(client: V6Client<Record<string, any>>, config: GraphQLProviderConfig['GraphQL']): CustomQueries<T>;
|
|
8
|
+
export declare function generateCustomSubscriptionsProperty<T extends Record<any, any>>(client: V6Client<Record<string, any>>, config: GraphQLProviderConfig['GraphQL']): CustomMutations<T>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { __amplify } from '../types/index.mjs';
|
|
2
|
+
import { customOpFactory } from './operations/custom.mjs';
|
|
3
|
+
|
|
4
|
+
const operationTypeMap = {
|
|
5
|
+
queries: 'query',
|
|
6
|
+
mutations: 'mutation',
|
|
7
|
+
subscriptions: 'subscription',
|
|
8
|
+
};
|
|
9
|
+
function generateCustomOperationsProperty(client, config, operationsType) {
|
|
10
|
+
// some bundlers end up with `Amplify.configure` being called *after* generate client.
|
|
11
|
+
// if that occurs, we need to *not error* while we wait. handling for late configuration
|
|
12
|
+
// occurs in `generateClient()`. we do not need to subscribe to Hub events here.
|
|
13
|
+
if (!config) {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
const modelIntrospection = config.modelIntrospection;
|
|
17
|
+
// model intro schema might be absent if there's not actually a configured GraphQL API
|
|
18
|
+
if (!modelIntrospection) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
// custom operations will be absent from model intro schema if no custom ops
|
|
22
|
+
// are present on the source schema.
|
|
23
|
+
const operations = modelIntrospection[operationsType];
|
|
24
|
+
if (!operations) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
const ops = {};
|
|
28
|
+
const useContext = client[__amplify] === null;
|
|
29
|
+
for (const operation of Object.values(operations)) {
|
|
30
|
+
ops[operation.name] = customOpFactory(client, modelIntrospection, operationTypeMap[operationsType], operation, useContext);
|
|
31
|
+
}
|
|
32
|
+
return ops;
|
|
33
|
+
}
|
|
34
|
+
function generateCustomMutationsProperty(client, config) {
|
|
35
|
+
return generateCustomOperationsProperty(client, config, 'mutations');
|
|
36
|
+
}
|
|
37
|
+
function generateCustomQueriesProperty(client, config) {
|
|
38
|
+
return generateCustomOperationsProperty(client, config, 'queries');
|
|
39
|
+
}
|
|
40
|
+
function generateCustomSubscriptionsProperty(client, config) {
|
|
41
|
+
return generateCustomOperationsProperty(client, config, 'subscriptions');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { generateCustomMutationsProperty, generateCustomOperationsProperty, generateCustomQueriesProperty, generateCustomSubscriptionsProperty };
|
|
45
|
+
//# sourceMappingURL=generateCustomOperationsProperty.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateCustomOperationsProperty.mjs","sources":["../../../src/internals/generateCustomOperationsProperty.ts"],"sourcesContent":["import { __amplify } from '../types';\nimport { customOpFactory } from './operations/custom';\nconst operationTypeMap = {\n queries: 'query',\n mutations: 'mutation',\n subscriptions: 'subscription',\n};\nexport function generateCustomOperationsProperty(client, config, operationsType) {\n // some bundlers end up with `Amplify.configure` being called *after* generate client.\n // if that occurs, we need to *not error* while we wait. handling for late configuration\n // occurs in `generateClient()`. we do not need to subscribe to Hub events here.\n if (!config) {\n return {};\n }\n const modelIntrospection = config.modelIntrospection;\n // model intro schema might be absent if there's not actually a configured GraphQL API\n if (!modelIntrospection) {\n return {};\n }\n // custom operations will be absent from model intro schema if no custom ops\n // are present on the source schema.\n const operations = modelIntrospection[operationsType];\n if (!operations) {\n return {};\n }\n const ops = {};\n const useContext = client[__amplify] === null;\n for (const operation of Object.values(operations)) {\n ops[operation.name] = customOpFactory(client, modelIntrospection, operationTypeMap[operationsType], operation, useContext);\n }\n return ops;\n}\nexport function generateCustomMutationsProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'mutations');\n}\nexport function generateCustomQueriesProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'queries');\n}\nexport function generateCustomSubscriptionsProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'subscriptions');\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,gBAAgB,GAAG;AACzB,IAAI,OAAO,EAAE,OAAO;AACpB,IAAI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AM,EAAE;AACpE,IAAI,OAAO,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;AAC7E;;;;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
2
|
+
import { CustomOperation, ModelIntrospectionSchema } from '@aws-amplify/core/internals/utils';
|
|
3
|
+
import { AuthModeParams, ClientWithModels, ListArgs, QueryArgs } from '../../types';
|
|
4
|
+
type CustomOperationOptions = AuthModeParams & ListArgs;
|
|
5
|
+
type OpArgs = [AmplifyServer.ContextSpec, QueryArgs, CustomOperationOptions] | [AmplifyServer.ContextSpec, CustomOperationOptions] | [QueryArgs, CustomOperationOptions] | [CustomOperationOptions];
|
|
6
|
+
/**
|
|
7
|
+
* Builds an operation function, embedded with all client and context data, that
|
|
8
|
+
* can be attached to a client as a custom query or mutation.
|
|
9
|
+
*
|
|
10
|
+
* If we have this source schema:
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* a.schema({
|
|
14
|
+
* echo: a.query()
|
|
15
|
+
* .arguments({input: a.string().required()})
|
|
16
|
+
* .returns(a.string())
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Our model intro schema will contain an entry like this:
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* {
|
|
24
|
+
* queries: {
|
|
25
|
+
* echo: {
|
|
26
|
+
* name: "echo",
|
|
27
|
+
* isArray: false,
|
|
28
|
+
* type: 'String',
|
|
29
|
+
* isRequired: false,
|
|
30
|
+
* arguments: {
|
|
31
|
+
* input: {
|
|
32
|
+
* name: 'input',
|
|
33
|
+
* isArray: false,
|
|
34
|
+
* type: String,
|
|
35
|
+
* isRequired: true
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* The `echo` object is used to build the `echo' method that goes here:
|
|
44
|
+
*
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const client = generateClent()
|
|
47
|
+
* const { data } = await client.queries.echo({input: 'a string'});
|
|
48
|
+
* // ^
|
|
49
|
+
* // |
|
|
50
|
+
* // +-- This one right here.
|
|
51
|
+
* //
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
*
|
|
55
|
+
* @param client The client to run graphql queries through.
|
|
56
|
+
* @param modelIntrospection The model introspection schema the op comes from.
|
|
57
|
+
* @param operationType The broad category of graphql operation.
|
|
58
|
+
* @param operation The operation definition from the introspection schema.
|
|
59
|
+
* @param useContext Whether the function needs to accept an SSR context.
|
|
60
|
+
* @returns The operation function to attach to query, mutations, etc.
|
|
61
|
+
*/
|
|
62
|
+
export declare function customOpFactory(client: ClientWithModels, modelIntrospection: ModelIntrospectionSchema, operationType: 'query' | 'mutation' | 'subscription', operation: CustomOperation, useContext: boolean): (...args: OpArgs) => Promise<any> | import("rxjs").Observable<any>;
|
|
63
|
+
export {};
|