@aws-amplify/api-graphql 4.6.6 → 4.6.7-graphql-multi-client.4f8e7a9.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/dist/cjs/internals/InternalGraphQLAPI.js +13 -13
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/cjs/internals/generateClient.js +28 -16
- package/dist/cjs/internals/generateClient.js.map +1 -1
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +11 -1
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -1
- package/dist/cjs/internals/v6.js +32 -2
- package/dist/cjs/internals/v6.js.map +1 -1
- package/dist/cjs/server/generateClient.js +4 -6
- package/dist/cjs/server/generateClient.js.map +1 -1
- package/dist/cjs/types/index.js +5 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.mjs +13 -13
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/dist/esm/internals/generateClient.d.ts +1 -1
- package/dist/esm/internals/generateClient.mjs +29 -17
- package/dist/esm/internals/generateClient.mjs.map +1 -1
- package/dist/esm/internals/index.d.ts +1 -0
- 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/types.d.ts +23 -4
- package/dist/esm/internals/v6.mjs +32 -2
- package/dist/esm/internals/v6.mjs.map +1 -1
- package/dist/esm/server/generateClient.d.ts +1 -1
- package/dist/esm/server/generateClient.mjs +4 -6
- package/dist/esm/server/generateClient.mjs.map +1 -1
- package/dist/esm/types/index.d.ts +59 -15
- package/dist/esm/types/index.mjs +5 -1
- package/dist/esm/types/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/internals/InternalGraphQLAPI.ts +33 -13
- package/src/internals/generateClient.ts +42 -19
- package/src/internals/index.ts +1 -0
- package/src/internals/server/generateClientWithAmplifyInstance.ts +21 -4
- package/src/internals/types.ts +38 -7
- package/src/internals/v6.ts +40 -4
- package/src/server/generateClient.ts +22 -13
- package/src/types/index.ts +113 -32
|
@@ -56,7 +56,7 @@ class InternalGraphQLAPIClass {
|
|
|
56
56
|
* @param [additionalHeaders] - headers to merge in after any `libraryConfigHeaders` set in the config
|
|
57
57
|
* @returns An Observable if the query is a subscription query, else a promise of the graphql result.
|
|
58
58
|
*/
|
|
59
|
-
graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken }, additionalHeaders, customUserAgentDetails) {
|
|
59
|
+
graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken, endpoint, apiKey, }, additionalHeaders, customUserAgentDetails) {
|
|
60
60
|
const query = typeof paramQuery === 'string'
|
|
61
61
|
? parse(paramQuery)
|
|
62
62
|
: parse(print(paramQuery));
|
|
@@ -69,13 +69,13 @@ class InternalGraphQLAPIClass {
|
|
|
69
69
|
const abortController = new AbortController();
|
|
70
70
|
let responsePromise;
|
|
71
71
|
if (isAmplifyInstance(amplify)) {
|
|
72
|
-
responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);
|
|
72
|
+
responsePromise = this._graphql(amplify, { query, variables, authMode, apiKey, endpoint }, headers, abortController, customUserAgentDetails, authToken);
|
|
73
73
|
}
|
|
74
74
|
else {
|
|
75
75
|
// NOTE: this wrapper function must be await-able so the Amplify server context manager can
|
|
76
76
|
// destroy the context only after it completes
|
|
77
77
|
const wrapper = async (amplifyInstance) => {
|
|
78
|
-
const result = await this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);
|
|
78
|
+
const result = await this._graphql(amplifyInstance, { query, variables, authMode, apiKey, endpoint }, headers, abortController, customUserAgentDetails, authToken);
|
|
79
79
|
return result;
|
|
80
80
|
};
|
|
81
81
|
responsePromise = amplify(wrapper);
|
|
@@ -84,14 +84,14 @@ class InternalGraphQLAPIClass {
|
|
|
84
84
|
return responsePromise;
|
|
85
85
|
}
|
|
86
86
|
case 'subscription':
|
|
87
|
-
return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails, authToken);
|
|
87
|
+
return this._graphqlSubscribe(amplify, { query, variables, authMode, apiKey, endpoint }, headers, customUserAgentDetails, authToken);
|
|
88
88
|
default:
|
|
89
89
|
throw new Error(`invalid operation type: ${operationType}`);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
async _graphql(amplify, { query, variables, authMode:
|
|
92
|
+
async _graphql(amplify, { query, variables, authMode: authModeOverride, endpoint: endpointOverride, apiKey: apiKeyOverride, }, additionalHeaders = {}, abortController, customUserAgentDetails, authToken) {
|
|
93
93
|
const { apiKey, region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, defaultAuthMode, } = resolveConfig(amplify);
|
|
94
|
-
const initialAuthMode =
|
|
94
|
+
const initialAuthMode = authModeOverride || defaultAuthMode || 'iam';
|
|
95
95
|
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
96
96
|
const authMode = initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
97
97
|
/**
|
|
@@ -111,7 +111,7 @@ class InternalGraphQLAPIClass {
|
|
|
111
111
|
if (typeof additionalHeaders === 'function') {
|
|
112
112
|
const requestOptions = {
|
|
113
113
|
method: 'POST',
|
|
114
|
-
url: new AmplifyUrl(customEndpoint || appSyncGraphqlEndpoint || '').toString(),
|
|
114
|
+
url: new AmplifyUrl(endpointOverride || customEndpoint || appSyncGraphqlEndpoint || '').toString(),
|
|
115
115
|
queryString: print(query),
|
|
116
116
|
};
|
|
117
117
|
additionalCustomHeaders = await additionalHeaders(requestOptions);
|
|
@@ -126,7 +126,7 @@ class InternalGraphQLAPIClass {
|
|
|
126
126
|
Authorization: authToken,
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
const authHeaders = await headerBasedAuth(amplify, authMode, apiKey, additionalCustomHeaders);
|
|
129
|
+
const authHeaders = await headerBasedAuth(amplify, authMode, apiKeyOverride ?? apiKey, additionalCustomHeaders);
|
|
130
130
|
const headers = {
|
|
131
131
|
...(!customEndpoint && authHeaders),
|
|
132
132
|
/**
|
|
@@ -174,7 +174,7 @@ class InternalGraphQLAPIClass {
|
|
|
174
174
|
region: !customEndpointRegion ? region : customEndpointRegion,
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
|
-
const endpoint = customEndpoint || appSyncGraphqlEndpoint;
|
|
177
|
+
const endpoint = endpointOverride || customEndpoint || appSyncGraphqlEndpoint;
|
|
178
178
|
if (!endpoint) {
|
|
179
179
|
throw createGraphQLResultWithError(new GraphQLApiError(NO_ENDPOINT));
|
|
180
180
|
}
|
|
@@ -222,9 +222,9 @@ class InternalGraphQLAPIClass {
|
|
|
222
222
|
cancel(request, message) {
|
|
223
223
|
return this._api.cancelREST(request, message);
|
|
224
224
|
}
|
|
225
|
-
_graphqlSubscribe(amplify, { query, variables, authMode:
|
|
225
|
+
_graphqlSubscribe(amplify, { query, variables, authMode: authModeOverride, apiKey: apiKeyOverride, endpoint, }, additionalHeaders = {}, customUserAgentDetails, authToken) {
|
|
226
226
|
const config = resolveConfig(amplify);
|
|
227
|
-
const initialAuthMode =
|
|
227
|
+
const initialAuthMode = authModeOverride || config?.defaultAuthMode || 'iam';
|
|
228
228
|
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
229
229
|
const authMode = initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
230
230
|
/**
|
|
@@ -240,10 +240,10 @@ class InternalGraphQLAPIClass {
|
|
|
240
240
|
.subscribe({
|
|
241
241
|
query: print(query),
|
|
242
242
|
variables,
|
|
243
|
-
appSyncGraphqlEndpoint: config?.endpoint,
|
|
243
|
+
appSyncGraphqlEndpoint: endpoint ?? config?.endpoint,
|
|
244
244
|
region: config?.region,
|
|
245
245
|
authenticationType: authMode,
|
|
246
|
-
apiKey: config?.apiKey,
|
|
246
|
+
apiKey: apiKeyOverride ?? config?.apiKey,
|
|
247
247
|
additionalHeaders,
|
|
248
248
|
authToken,
|
|
249
249
|
libraryConfigHeaders,
|
|
@@ -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 { 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_ENDPOINT } from '../utils/errors/constants';\nimport { GraphQLApiError, createGraphQLResultWithError } from '../utils/errors';\nimport { isGraphQLResponseWithErrors } from './utils/runtimeTypeGuards/isGraphQLResponseWithErrors';\nimport { headerBasedAuth } from './graphqlAuth';\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 /**\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 { apiKey, region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, defaultAuthMode, } = resolveConfig(amplify);\n const initialAuthMode = explicitAuthMode || defaultAuthMode || 'iam';\n // identityPool is an alias for iam. TODO: remove 'iam' in v7\n const authMode = initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;\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 const authHeaders = await headerBasedAuth(amplify, authMode, apiKey, additionalCustomHeaders);\n const headers = {\n ...(!customEndpoint && authHeaders),\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 && (customEndpointRegion ? authHeaders : {})) || {}),\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 // \t// // See the inline doc of the REST `post()` API for possible errors to be thrown.\n // \t// // As these errors are catastrophic they should be caught and handled by GraphQL\n // \t// // 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: explicitAuthMode }, additionalHeaders = {}, customUserAgentDetails, authToken) {\n const config = resolveConfig(amplify);\n const initialAuthMode = explicitAuthMode || config?.defaultAuthMode || 'iam';\n // identityPool is an alias for iam. TODO: remove 'iam' in v7\n const authMode = initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;\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,\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;AAaA,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,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;AACA;AACA;AACA;AACA,IAAI,uBAAuB,CAAC,SAAS,EAAE;AACvC,QAAQ,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;AACrC,QAAQ,MAAM,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC;AAC5C,QAAQ,MAAM,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,GAAG,WAAW,CAAC;AAC3D,QAAQ,OAAO,aAAa,CAAC;AAC7B,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,GAAG,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,iBAAiB,EAAE,sBAAsB,EAAE;AAC5H,QAAQ,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AC;AAC/B,YAAY,SAAS;AACrB,YAAY,sBAAsB,EAAE,MAAM,EAAE,QAAQ;AACpD,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,kBAAkB,EAAE,QAAQ;AACxC,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
|
+
{"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_ENDPOINT } from '../utils/errors/constants';\nimport { GraphQLApiError, createGraphQLResultWithError } from '../utils/errors';\nimport { isGraphQLResponseWithErrors } from './utils/runtimeTypeGuards/isGraphQLResponseWithErrors';\nimport { headerBasedAuth } from './graphqlAuth';\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 /**\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, endpoint, apiKey, }, 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, apiKey, endpoint }, 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, apiKey, endpoint }, 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, apiKey, endpoint }, headers, customUserAgentDetails, authToken);\n default:\n throw new Error(`invalid operation type: ${operationType}`);\n }\n }\n async _graphql(amplify, { query, variables, authMode: authModeOverride, endpoint: endpointOverride, apiKey: apiKeyOverride, }, additionalHeaders = {}, abortController, customUserAgentDetails, authToken) {\n const { apiKey, region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, defaultAuthMode, } = resolveConfig(amplify);\n const initialAuthMode = authModeOverride || defaultAuthMode || 'iam';\n // identityPool is an alias for iam. TODO: remove 'iam' in v7\n const authMode = initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;\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(endpointOverride || 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 const authHeaders = await headerBasedAuth(amplify, authMode, apiKeyOverride ?? apiKey, additionalCustomHeaders);\n const headers = {\n ...(!customEndpoint && authHeaders),\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 && (customEndpointRegion ? authHeaders : {})) || {}),\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 = endpointOverride || customEndpoint || appSyncGraphqlEndpoint;\n if (!endpoint) {\n throw createGraphQLResultWithError(new GraphQLApiError(NO_ENDPOINT));\n }\n let response;\n try {\n // \t// // See the inline doc of the REST `post()` API for possible errors to be thrown.\n // \t// // As these errors are catastrophic they should be caught and handled by GraphQL\n // \t// // 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: authModeOverride, apiKey: apiKeyOverride, endpoint, }, additionalHeaders = {}, customUserAgentDetails, authToken) {\n const config = resolveConfig(amplify);\n const initialAuthMode = authModeOverride || config?.defaultAuthMode || 'iam';\n // identityPool is an alias for iam. TODO: remove 'iam' in v7\n const authMode = initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;\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: endpoint ?? config?.endpoint,\n region: config?.region,\n authenticationType: authMode,\n apiKey: apiKeyOverride ?? 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;AAaA,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,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,oBAAo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,CAAC;AACpB,SAAS,CAAC,CAAC,CAAC;AACZ,KAAK;AACL,CAAC;AACW,MAAC,kBAAkB,GAAG,IAAI,uBAAuB;;;;"}
|
|
@@ -9,4 +9,4 @@ import { ClientGenerationParams } from './types';
|
|
|
9
9
|
* @param params
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
|
-
export declare function generateClient<T extends Record<any, any> = never>(params: ClientGenerationParams): V6Client<T>;
|
|
12
|
+
export declare function generateClient<T extends Record<any, any> = never, WithCustomEndpoint extends boolean = false, WithApiKey extends boolean = false>(params: ClientGenerationParams<WithCustomEndpoint, WithApiKey>): V6Client<T, WithCustomEndpoint, WithApiKey>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hub } from '@aws-amplify/core';
|
|
2
2
|
import { addSchemaToClient } from '@aws-amplify/data-schema/runtime';
|
|
3
|
-
import { __amplify, __authMode, __authToken, __headers, getInternals } from '../types/index.mjs';
|
|
3
|
+
import { __amplify, __authMode, __authToken, __apiKey, __endpoint, __headers, getInternals } from '../types/index.mjs';
|
|
4
4
|
import { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs';
|
|
5
5
|
import { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs';
|
|
6
6
|
import { graphql, cancel, isCancelError } from './v6.mjs';
|
|
@@ -21,6 +21,8 @@ function generateClient(params) {
|
|
|
21
21
|
[__amplify]: params.amplify,
|
|
22
22
|
[__authMode]: params.authMode,
|
|
23
23
|
[__authToken]: params.authToken,
|
|
24
|
+
[__apiKey]: 'apiKey' in params ? params.apiKey : undefined,
|
|
25
|
+
[__endpoint]: 'endpoint' in params ? params.endpoint : undefined,
|
|
24
26
|
[__headers]: params.headers,
|
|
25
27
|
graphql,
|
|
26
28
|
cancel,
|
|
@@ -32,23 +34,33 @@ function generateClient(params) {
|
|
|
32
34
|
subscriptions: emptyProperty,
|
|
33
35
|
};
|
|
34
36
|
const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
+
if (client[__endpoint]) {
|
|
38
|
+
if (!client[__authMode]) {
|
|
39
|
+
throw new Error('generateClient() requires an explicit `authMode` when `endpoint` is provided.');
|
|
40
|
+
}
|
|
41
|
+
if (client[__authMode] === 'apiKey' && !client[__apiKey]) {
|
|
42
|
+
throw new Error("generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.");
|
|
43
|
+
}
|
|
37
44
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
if (!client[__endpoint]) {
|
|
46
|
+
if (isApiGraphQLConfig(apiGraphqlConfig)) {
|
|
47
|
+
addSchemaToClient(client, apiGraphqlConfig, getInternals);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
|
|
51
|
+
//
|
|
52
|
+
// Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in
|
|
53
|
+
// different source files, script bundlers may randomly arrange their orders in the production
|
|
54
|
+
// bundle.
|
|
55
|
+
//
|
|
56
|
+
// With the current implementation, the `client.models` instance created by `generateClient()`
|
|
57
|
+
// will be rebuilt on every `Amplify.configure()` call that's provided with a valid GraphQL
|
|
58
|
+
// provider configuration.
|
|
59
|
+
//
|
|
60
|
+
// TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints
|
|
61
|
+
// configuration.
|
|
62
|
+
generateModelsPropertyOnAmplifyConfigure(client);
|
|
63
|
+
}
|
|
52
64
|
}
|
|
53
65
|
return client;
|
|
54
66
|
}
|
|
@@ -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 { addSchemaToClient, } from '@aws-amplify/data-schema/runtime';\nimport { __amplify, __authMode, __authToken, __headers, getInternals, } from '../types';\nimport { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig';\nimport { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig';\nimport { cancel, graphql, isCancelError } from './v6';\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
|
|
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 { addSchemaToClient, } from '@aws-amplify/data-schema/runtime';\nimport { __amplify, __apiKey, __authMode, __authToken, __endpoint, __headers, getInternals, } from '../types';\nimport { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig';\nimport { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig';\nimport { cancel, graphql, isCancelError } from './v6';\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 [__apiKey]: 'apiKey' in params ? params.apiKey : undefined,\n [__endpoint]: 'endpoint' in params ? params.endpoint : undefined,\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 (client[__endpoint]) {\n if (!client[__authMode]) {\n throw new Error('generateClient() requires an explicit `authMode` when `endpoint` is provided.');\n }\n if (client[__authMode] === 'apiKey' && !client[__apiKey]) {\n throw new Error(\"generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.\");\n }\n }\n if (!client[__endpoint]) {\n if (isApiGraphQLConfig(apiGraphqlConfig)) {\n addSchemaToClient(client, apiGraphqlConfig, getInternals);\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 }\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 addSchemaToClient(clientRef, apiGraphQLConfig, getInternals);\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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rI,SAAS;AACT,KAAK;AACL,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;AAC7B,QAAQ,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;AAClD,YAAY,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC;AACtE,SAAS;AACT,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,wCAAwC,CAAC,MAAM,CAAC,CAAC;AAC7D,SAAS;AACT,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD,MAAM,wCAAwC,GAAG,CAAC,SAAS,KAAK;AAChE,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,IAAI;AACpC,QAAQ,IAAI,CAAC,kCAAkC,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;AACpE,YAAY,OAAO;AACnB,SAAS;AACT,QAAQ,MAAM,gBAAgB,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC;AACrE,QAAQ,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;AAClD,YAAY,iBAAiB,CAAC,SAAS,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC;AACzE,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;;;;"}
|
|
@@ -10,4 +10,4 @@ import { CommonPublicClientOptions, ServerClientGenerationParams, V6ClientSSRCoo
|
|
|
10
10
|
* @param params
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
|
-
export declare function generateClientWithAmplifyInstance<T extends Record<any, any> = never, ClientType extends V6ClientSSRRequest<T> | V6ClientSSRCookies<T> = V6ClientSSRCookies<T>>(params: ServerClientGenerationParams & CommonPublicClientOptions): ClientType;
|
|
13
|
+
export declare function generateClientWithAmplifyInstance<T extends Record<any, any> = never, ClientType extends V6ClientSSRRequest<T, any, any> | V6ClientSSRCookies<T, any, any> = V6ClientSSRCookies<T, any, any>>(params: ServerClientGenerationParams & CommonPublicClientOptions<any, any>): ClientType;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { addSchemaToClientWithInstance } from '@aws-amplify/data-schema/runtime';
|
|
2
|
-
import { __amplify, __authMode, __authToken, __headers, getInternals } from '../../types/index.mjs';
|
|
2
|
+
import { __amplify, __authMode, __authToken, __apiKey, __endpoint, __headers, getInternals } from '../../types/index.mjs';
|
|
3
3
|
import { isApiGraphQLConfig } from '../utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs';
|
|
4
4
|
import '../InternalGraphQLAPI.mjs';
|
|
5
5
|
import { graphql, cancel, isCancelError } from '../v6.mjs';
|
|
@@ -23,13 +23,23 @@ function generateClientWithAmplifyInstance(params) {
|
|
|
23
23
|
[__amplify]: params.amplify,
|
|
24
24
|
[__authMode]: params.authMode,
|
|
25
25
|
[__authToken]: params.authToken,
|
|
26
|
+
[__apiKey]: 'apiKey' in params ? params.apiKey : undefined,
|
|
27
|
+
[__endpoint]: 'endpoint' in params ? params.endpoint : undefined,
|
|
26
28
|
[__headers]: params.headers,
|
|
27
29
|
graphql,
|
|
28
30
|
cancel,
|
|
29
31
|
isCancelError,
|
|
30
32
|
};
|
|
31
33
|
const apiGraphqlConfig = params.config?.API?.GraphQL;
|
|
32
|
-
if (
|
|
34
|
+
if (client[__endpoint]) {
|
|
35
|
+
if (!client[__authMode]) {
|
|
36
|
+
throw new Error('generateClient() requires an explicit `authMode` when `endpoint` is provided.');
|
|
37
|
+
}
|
|
38
|
+
if (client[__authMode] === 'apiKey' && !client[__apiKey]) {
|
|
39
|
+
throw new Error("generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!client[__endpoint] && isApiGraphQLConfig(apiGraphqlConfig)) {
|
|
33
43
|
addSchemaToClientWithInstance(client, params, getInternals);
|
|
34
44
|
}
|
|
35
45
|
return client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateClientWithAmplifyInstance.mjs","sources":["../../../../src/internals/server/generateClientWithAmplifyInstance.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { addSchemaToClientWithInstance } from '@aws-amplify/data-schema/runtime';\nimport { __amplify, __authMode, __authToken, __headers, getInternals, } from '../../types';\nimport { isApiGraphQLConfig } from '../utils/runtimeTypeGuards/isApiGraphQLProviderConfig';\nimport { cancel, graphql, isCancelError } from '..';\n/**\n * @private\n *\n * Used internally by `adapter-nextjs` package.\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 generateClientWithAmplifyInstance(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 };\n const apiGraphqlConfig = params.config?.API?.GraphQL;\n if (isApiGraphQLConfig(apiGraphqlConfig)) {\n addSchemaToClientWithInstance(client, params, getInternals);\n }\n return client;\n}\n"],"names":[],"mappings":";;;;;;;AAAA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iCAAiC,CAAC,MAAM,EAAE;AAC1D,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;AACd,QAAQ,aAAa;AACrB,KAAK,CAAC;AACN,IAAI,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC;AACzD,IAAI,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"generateClientWithAmplifyInstance.mjs","sources":["../../../../src/internals/server/generateClientWithAmplifyInstance.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { addSchemaToClientWithInstance } from '@aws-amplify/data-schema/runtime';\nimport { __amplify, __apiKey, __authMode, __authToken, __endpoint, __headers, getInternals, } from '../../types';\nimport { isApiGraphQLConfig } from '../utils/runtimeTypeGuards/isApiGraphQLProviderConfig';\nimport { cancel, graphql, isCancelError } from '..';\n/**\n * @private\n *\n * Used internally by `adapter-nextjs` package.\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 generateClientWithAmplifyInstance(params) {\n const client = {\n [__amplify]: params.amplify,\n [__authMode]: params.authMode,\n [__authToken]: params.authToken,\n [__apiKey]: 'apiKey' in params ? params.apiKey : undefined,\n [__endpoint]: 'endpoint' in params ? params.endpoint : undefined,\n [__headers]: params.headers,\n graphql,\n cancel,\n isCancelError,\n };\n const apiGraphqlConfig = params.config?.API?.GraphQL;\n if (client[__endpoint]) {\n if (!client[__authMode]) {\n throw new Error('generateClient() requires an explicit `authMode` when `endpoint` is provided.');\n }\n if (client[__authMode] === 'apiKey' && !client[__apiKey]) {\n throw new Error(\"generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.\");\n }\n }\n if (!client[__endpoint] && isApiGraphQLConfig(apiGraphqlConfig)) {\n addSchemaToClientWithInstance(client, params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IAAI,OAAO,MAAM,CAAC;AAClB;;;;"}
|
|
@@ -6,14 +6,33 @@ import { CustomHeaders } from '@aws-amplify/data-schema/runtime';
|
|
|
6
6
|
*
|
|
7
7
|
* The knobs available for configuring `generateClient` internally.
|
|
8
8
|
*/
|
|
9
|
-
export type ClientGenerationParams = {
|
|
9
|
+
export type ClientGenerationParams<WithCustomEndpoint extends boolean, WithApiKey extends boolean> = {
|
|
10
10
|
amplify: AmplifyClassV6;
|
|
11
|
-
} & CommonPublicClientOptions
|
|
11
|
+
} & CommonPublicClientOptions<WithCustomEndpoint, WithApiKey>;
|
|
12
12
|
/**
|
|
13
13
|
* Common options that can be used on public `generateClient()` interfaces.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export type CommonPublicClientOptions<WithCustomEndpoint extends boolean, WithApiKey extends boolean> = WithCustomEndpoint extends true ? WithApiKey extends true ? {
|
|
16
|
+
endpoint: string;
|
|
17
|
+
authMode: 'apiKey';
|
|
18
|
+
apiKey: string;
|
|
19
|
+
authToken?: string;
|
|
20
|
+
headers?: CustomHeaders;
|
|
21
|
+
} | {
|
|
22
|
+
endpoint: string;
|
|
23
|
+
apiKey: string;
|
|
24
|
+
authMode: Exclude<GraphQLAuthMode, 'apiKey'>;
|
|
25
|
+
authToken?: string;
|
|
26
|
+
headers?: CustomHeaders;
|
|
27
|
+
} : {
|
|
28
|
+
endpoint: string;
|
|
29
|
+
authMode: Exclude<GraphQLAuthMode, 'apiKey'>;
|
|
30
|
+
apiKey?: never;
|
|
31
|
+
authToken?: string;
|
|
32
|
+
headers?: CustomHeaders;
|
|
33
|
+
} : {
|
|
34
|
+
endpoint?: never;
|
|
16
35
|
authMode?: GraphQLAuthMode;
|
|
17
36
|
authToken?: string;
|
|
18
37
|
headers?: CustomHeaders;
|
|
19
|
-
}
|
|
38
|
+
};
|
|
@@ -88,8 +88,35 @@ import { getInternals } from '../types/index.mjs';
|
|
|
88
88
|
function graphql(options, additionalHeaders) {
|
|
89
89
|
// inject client-level auth
|
|
90
90
|
const internals = getInternals(this);
|
|
91
|
-
|
|
91
|
+
/**
|
|
92
|
+
* The custom `endpoint` specific to the client
|
|
93
|
+
*/
|
|
94
|
+
const clientEndpoint = internals.endpoint;
|
|
95
|
+
/**
|
|
96
|
+
* The `authMode` specific to the client.
|
|
97
|
+
*/
|
|
98
|
+
const clientAuthMode = internals.authMode;
|
|
99
|
+
/**
|
|
100
|
+
* The `apiKey` specific to the client.
|
|
101
|
+
*/
|
|
102
|
+
const clientApiKey = internals.apiKey;
|
|
103
|
+
/**
|
|
104
|
+
* The most specific `authMode` wins. Setting an `endpoint` value without also
|
|
105
|
+
* setting an `authMode` value is invalid. This helps to prevent customers apps
|
|
106
|
+
* from unexpectedly sending auth details to endpoints the auth details do not
|
|
107
|
+
* belong to.
|
|
108
|
+
*
|
|
109
|
+
* This is especially pronounced for `apiKey`. When both an `endpoint` *and*
|
|
110
|
+
* `authMode: 'apiKey'` are provided, an explicit `apiKey` override is required
|
|
111
|
+
* to prevent inadvertent sending of an API's `apiKey` to an endpoint is does
|
|
112
|
+
* not belong to.
|
|
113
|
+
*/
|
|
114
|
+
options.authMode = options.authMode || clientAuthMode;
|
|
115
|
+
options.apiKey = options.apiKey ?? clientApiKey;
|
|
92
116
|
options.authToken = options.authToken || internals.authToken;
|
|
117
|
+
if (clientEndpoint && options.authMode === 'apiKey' && !options.apiKey) {
|
|
118
|
+
throw new Error("graphql() requires an explicit `apiKey` for a custom `endpoint` when `authMode = 'apiKey'`.");
|
|
119
|
+
}
|
|
93
120
|
const headers = additionalHeaders || internals.headers;
|
|
94
121
|
/**
|
|
95
122
|
* The correctness of these typings depends on correct string branding or overrides.
|
|
@@ -98,7 +125,10 @@ function graphql(options, additionalHeaders) {
|
|
|
98
125
|
*/
|
|
99
126
|
const result = GraphQLAPI.graphql(
|
|
100
127
|
// TODO: move V6Client back into this package?
|
|
101
|
-
internals.amplify,
|
|
128
|
+
internals.amplify, {
|
|
129
|
+
...options,
|
|
130
|
+
endpoint: clientEndpoint,
|
|
131
|
+
}, headers);
|
|
102
132
|
return result;
|
|
103
133
|
}
|
|
104
134
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v6.mjs","sources":["../../../src/internals/v6.ts"],"sourcesContent":["import { GraphQLAPI } from '../GraphQLAPI';\nimport { getInternals, } from '../types';\n/**\n * Invokes graphql operations against a graphql service, providing correct input and\n * output types if Amplify-generated graphql from a recent version of the CLI/codegen\n * are used *or* correct typing is provided via the type argument.\n *\n * Amplify-generated \"branded\" graphql queries will look similar to this:\n *\n * ```ts\n * //\n * // |-- branding\n * // v\n * export const getModel = `...` as GeneratedQuery<\n * \tGetModelQueryVariables,\n * \tGetModelQuery\n * >;\n * ```\n *\n * If this branding is not in your generated graphql, update to a newer version of\n * CLI/codegen and regenerate your graphql using `amplify codegen`.\n *\n * ## Using Amplify-generated graphql\n *\n * ```ts\n * import * as queries from './graphql/queries';\n *\n * //\n * // |-- correctly typed graphql response containing a Widget\n * // v\n * const queryResult = await graphql({\n * \tquery: queries.getWidget,\n * \tvariables: {\n * \t\tid: \"abc\", // <-- type hinted/enforced\n * \t},\n * });\n *\n * //\n * // |-- a correctly typed Widget\n * // v\n * const fetchedWidget = queryResult.data?.getWidget!;\n * ```\n *\n * ## Custom input + result types\n *\n * To provide input types (`variables`) and result types:\n *\n * ```ts\n * type GetById_NameOnly = {\n * \tvariables: {\n * \t\tid: string\n * \t},\n * \tresult: Promise<{\n * \t\tdata: { getWidget: { name: string } }\n * \t}>\n * }\n *\n * //\n * // |-- type is GetById_NameOnly[\"result\"]\n * // v\n * const result = graphql<GetById_NameOnly>({\n * \tquery: \"...\",\n * \tvariables: { id: \"abc\" } // <-- type of GetById_NameOnly[\"variables\"]\n * });\n * ```\n *\n * ## Custom result type only\n *\n * To specify result types only, use a type that is *not* in the `{variables, result}` shape:\n *\n * ```ts\n * type MyResultType = Promise<{\n * \tdata: {\n * \t\tgetWidget: { name: string }\n * \t}\n * }>\n *\n * //\n * // |-- type is MyResultType\n * // v\n * const result = graphql<MyResultType>({query: \"...\"});\n * ```\n *\n * @param options\n * @param additionalHeaders\n */\nexport function graphql(options, additionalHeaders) {\n // inject client-level auth\n const internals = getInternals(this);\n options.authMode = options.authMode ||
|
|
1
|
+
{"version":3,"file":"v6.mjs","sources":["../../../src/internals/v6.ts"],"sourcesContent":["import { GraphQLAPI } from '../GraphQLAPI';\nimport { getInternals, } from '../types';\n/**\n * Invokes graphql operations against a graphql service, providing correct input and\n * output types if Amplify-generated graphql from a recent version of the CLI/codegen\n * are used *or* correct typing is provided via the type argument.\n *\n * Amplify-generated \"branded\" graphql queries will look similar to this:\n *\n * ```ts\n * //\n * // |-- branding\n * // v\n * export const getModel = `...` as GeneratedQuery<\n * \tGetModelQueryVariables,\n * \tGetModelQuery\n * >;\n * ```\n *\n * If this branding is not in your generated graphql, update to a newer version of\n * CLI/codegen and regenerate your graphql using `amplify codegen`.\n *\n * ## Using Amplify-generated graphql\n *\n * ```ts\n * import * as queries from './graphql/queries';\n *\n * //\n * // |-- correctly typed graphql response containing a Widget\n * // v\n * const queryResult = await graphql({\n * \tquery: queries.getWidget,\n * \tvariables: {\n * \t\tid: \"abc\", // <-- type hinted/enforced\n * \t},\n * });\n *\n * //\n * // |-- a correctly typed Widget\n * // v\n * const fetchedWidget = queryResult.data?.getWidget!;\n * ```\n *\n * ## Custom input + result types\n *\n * To provide input types (`variables`) and result types:\n *\n * ```ts\n * type GetById_NameOnly = {\n * \tvariables: {\n * \t\tid: string\n * \t},\n * \tresult: Promise<{\n * \t\tdata: { getWidget: { name: string } }\n * \t}>\n * }\n *\n * //\n * // |-- type is GetById_NameOnly[\"result\"]\n * // v\n * const result = graphql<GetById_NameOnly>({\n * \tquery: \"...\",\n * \tvariables: { id: \"abc\" } // <-- type of GetById_NameOnly[\"variables\"]\n * });\n * ```\n *\n * ## Custom result type only\n *\n * To specify result types only, use a type that is *not* in the `{variables, result}` shape:\n *\n * ```ts\n * type MyResultType = Promise<{\n * \tdata: {\n * \t\tgetWidget: { name: string }\n * \t}\n * }>\n *\n * //\n * // |-- type is MyResultType\n * // v\n * const result = graphql<MyResultType>({query: \"...\"});\n * ```\n *\n * @param options\n * @param additionalHeaders\n */\nexport function graphql(options, additionalHeaders) {\n // inject client-level auth\n const internals = getInternals(this);\n /**\n * The custom `endpoint` specific to the client\n */\n const clientEndpoint = internals.endpoint;\n /**\n * The `authMode` specific to the client.\n */\n const clientAuthMode = internals.authMode;\n /**\n * The `apiKey` specific to the client.\n */\n const clientApiKey = internals.apiKey;\n /**\n * The most specific `authMode` wins. Setting an `endpoint` value without also\n * setting an `authMode` value is invalid. This helps to prevent customers apps\n * from unexpectedly sending auth details to endpoints the auth details do not\n * belong to.\n *\n * This is especially pronounced for `apiKey`. When both an `endpoint` *and*\n * `authMode: 'apiKey'` are provided, an explicit `apiKey` override is required\n * to prevent inadvertent sending of an API's `apiKey` to an endpoint is does\n * not belong to.\n */\n options.authMode = options.authMode || clientAuthMode;\n options.apiKey = options.apiKey ?? clientApiKey;\n options.authToken = options.authToken || internals.authToken;\n if (clientEndpoint && options.authMode === 'apiKey' && !options.apiKey) {\n throw new Error(\"graphql() requires an explicit `apiKey` for a custom `endpoint` when `authMode = 'apiKey'`.\");\n }\n const headers = additionalHeaders || internals.headers;\n /**\n * The correctness of these typings depends on correct string branding or overrides.\n * Neither of these can actually be validated at runtime. Hence, we don't perform\n * any validation or type-guarding here.\n */\n const result = GraphQLAPI.graphql(\n // TODO: move V6Client back into this package?\n internals.amplify, {\n ...options,\n endpoint: clientEndpoint,\n }, headers);\n return result;\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 */\nexport function cancel(promise, message) {\n return GraphQLAPI.cancel(promise, message);\n}\n/**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @returns - A boolean indicating if the error was from an api request cancellation\n */\nexport function isCancelError(error) {\n return GraphQLAPI.isCancelError(error);\n}\n"],"names":[],"mappings":";;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,OAAO,CAAC,OAAO,EAAE,iBAAiB,EAAE;AACpD;AACA,IAAI,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;AACzC;AACA;AACA;AACA,IAAI,MAAM,cAAc,GAAG,SAAS,CAAC,QAAQ,CAAC;AAC9C;AACA;AACA;AACA,IAAI,MAAM,cAAc,GAAG,SAAS,CAAC,QAAQ,CAAC;AAC9C;AACA;AACA;AACA,IAAI,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,cAAc,CAAC;AAC1D,IAAI,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,YAAY,CAAC;AACpD,IAAI,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC;AACjE,IAAI,IAAI,cAAc,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;AAC5E,QAAQ,MAAM,IAAI,KAAK,CAAC,6FAA6F,CAAC,CAAC;AACvH,KAAK;AACL,IAAI,MAAM,OAAO,GAAG,iBAAiB,IAAI,SAAS,CAAC,OAAO,CAAC;AAC3D;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO;AACrC;AACA,IAAI,SAAS,CAAC,OAAO,EAAE;AACvB,QAAQ,GAAG,OAAO;AAClB,QAAQ,QAAQ,EAAE,cAAc;AAChC,KAAK,EAAE,OAAO,CAAC,CAAC;AAChB,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD;AACA;AACA;AACA;AACA;AACO,SAAS,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE;AACzC,IAAI,OAAO,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC;AACD;AACA;AACA;AACA;AACA;AACO,SAAS,aAAa,CAAC,KAAK,EAAE;AACrC,IAAI,OAAO,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAC3C;;;;"}
|
|
@@ -15,4 +15,4 @@ import { GenerateServerClientParams, V6ClientSSRRequest } from '../types';
|
|
|
15
15
|
* }),
|
|
16
16
|
* });
|
|
17
17
|
*/
|
|
18
|
-
export declare function generateClient<T extends Record<any, any> = never
|
|
18
|
+
export declare function generateClient<T extends Record<any, any> = never, WithCustomEndpoint extends boolean = false, WithApiKey extends boolean = false>(options: GenerateServerClientParams<WithCustomEndpoint, WithApiKey>): V6ClientSSRRequest<T, WithCustomEndpoint, WithApiKey>;
|
|
@@ -20,20 +20,18 @@ import { __amplify } from '../types/index.mjs';
|
|
|
20
20
|
* }),
|
|
21
21
|
* });
|
|
22
22
|
*/
|
|
23
|
-
function generateClient(
|
|
23
|
+
function generateClient(options) {
|
|
24
24
|
// passing `null` instance because each (future model) method must retrieve a valid instance
|
|
25
25
|
// from server context
|
|
26
26
|
const client = generateClientWithAmplifyInstance({
|
|
27
27
|
amplify: null,
|
|
28
|
-
|
|
29
|
-
authMode,
|
|
30
|
-
authToken,
|
|
28
|
+
...options,
|
|
31
29
|
});
|
|
32
30
|
// TODO: improve this and the next type
|
|
33
31
|
const prevGraphql = client.graphql;
|
|
34
|
-
const wrappedGraphql = (contextSpec,
|
|
32
|
+
const wrappedGraphql = (contextSpec, innerOptions, additionalHeaders) => {
|
|
35
33
|
const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;
|
|
36
|
-
return prevGraphql.call({ [__amplify]: amplifyInstance },
|
|
34
|
+
return prevGraphql.call({ [__amplify]: amplifyInstance }, innerOptions, additionalHeaders);
|
|
37
35
|
};
|
|
38
36
|
client.graphql = wrappedGraphql;
|
|
39
37
|
return client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateClient.mjs","sources":["../../../src/server/generateClient.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { getAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-core';\nimport { generateClientWithAmplifyInstance } from '../internals/server';\nimport { __amplify, } from '../types';\n/**\n * Generates an GraphQL API client that works with Amplify server context.\n *\n * @example\n * import config from './amplifyconfiguration.json';\n * import { listPosts } from './graphql/queries';\n *\n * const client = generateServerClient({ config });\n *\n * const result = await runWithAmplifyServerContext({\n * nextServerContext: { request, response },\n * operation: (contextSpec) => client.graphql(contextSpec, {\n * query: listPosts,\n * }),\n * });\n */\nexport function generateClient(
|
|
1
|
+
{"version":3,"file":"generateClient.mjs","sources":["../../../src/server/generateClient.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { getAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-core';\nimport { generateClientWithAmplifyInstance } from '../internals/server';\nimport { __amplify, } from '../types';\n/**\n * Generates an GraphQL API client that works with Amplify server context.\n *\n * @example\n * import config from './amplifyconfiguration.json';\n * import { listPosts } from './graphql/queries';\n *\n * const client = generateServerClient({ config });\n *\n * const result = await runWithAmplifyServerContext({\n * nextServerContext: { request, response },\n * operation: (contextSpec) => client.graphql(contextSpec, {\n * query: listPosts,\n * }),\n * });\n */\nexport function generateClient(options) {\n // passing `null` instance because each (future model) method must retrieve a valid instance\n // from server context\n const client = generateClientWithAmplifyInstance({\n amplify: null,\n ...options,\n });\n // TODO: improve this and the next type\n const prevGraphql = client.graphql;\n const wrappedGraphql = (contextSpec, innerOptions, additionalHeaders) => {\n const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;\n return prevGraphql.call({ [__amplify]: amplifyInstance }, innerOptions, additionalHeaders);\n };\n client.graphql = wrappedGraphql;\n return client;\n}\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,OAAO,EAAE;AACxC;AACA;AACA,IAAI,MAAM,MAAM,GAAG,iCAAiC,CAAC;AACrD,QAAQ,OAAO,EAAE,IAAI;AACrB,QAAQ,GAAG,OAAO;AAClB,KAAK,CAAC,CAAC;AACP;AACA,IAAI,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;AACvC,IAAI,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,iBAAiB,KAAK;AAC7E,QAAQ,MAAM,eAAe,GAAG,uBAAuB,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC;AAC7E,QAAQ,OAAO,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,GAAG,eAAe,EAAE,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC;AACnG,KAAK,CAAC;AACN,IAAI,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC;AACpC,IAAI,OAAO,MAAM,CAAC;AAClB;;;;"}
|