@aws-amplify/api-graphql 4.0.31-data-schema-v-0-18.4f27733.0 → 4.0.31-unstable.8fb751a.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 +8 -3
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +3 -1
- package/dist/esm/internals/InternalGraphQLAPI.mjs +8 -3
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/package.json +5 -5
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +4 -2
- package/src/internals/InternalGraphQLAPI.ts +12 -3
|
@@ -145,7 +145,9 @@ class InternalGraphQLAPIClass {
|
|
|
145
145
|
}
|
|
146
146
|
async _graphql(amplify, { query, variables, authMode: explicitAuthMode }, additionalHeaders = {}, abortController, customUserAgentDetails, authToken) {
|
|
147
147
|
const { region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, defaultAuthMode, } = (0, utils_2.resolveConfig)(amplify);
|
|
148
|
-
const
|
|
148
|
+
const initialAuthMode = explicitAuthMode || defaultAuthMode || 'iam';
|
|
149
|
+
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
150
|
+
const authMode = initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
149
151
|
/**
|
|
150
152
|
* Retrieve library options from Amplify configuration.
|
|
151
153
|
* `customHeaders` here are from the Amplify configuration options,
|
|
@@ -279,8 +281,11 @@ class InternalGraphQLAPIClass {
|
|
|
279
281
|
cancel(request, message) {
|
|
280
282
|
return this._api.cancelREST(request, message);
|
|
281
283
|
}
|
|
282
|
-
_graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails, authToken) {
|
|
284
|
+
_graphqlSubscribe(amplify, { query, variables, authMode: explicitAuthMode }, additionalHeaders = {}, customUserAgentDetails, authToken) {
|
|
283
285
|
const config = (0, utils_2.resolveConfig)(amplify);
|
|
286
|
+
const initialAuthMode = explicitAuthMode || config?.defaultAuthMode || 'iam';
|
|
287
|
+
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
288
|
+
const authMode = initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
284
289
|
/**
|
|
285
290
|
* Retrieve library options from Amplify configuration.
|
|
286
291
|
* `libraryConfigHeaders` are from the Amplify configuration options,
|
|
@@ -296,7 +301,7 @@ class InternalGraphQLAPIClass {
|
|
|
296
301
|
variables,
|
|
297
302
|
appSyncGraphqlEndpoint: config?.endpoint,
|
|
298
303
|
region: config?.region,
|
|
299
|
-
authenticationType: authMode
|
|
304
|
+
authenticationType: authMode,
|
|
300
305
|
apiKey: config?.apiKey,
|
|
301
306
|
additionalHeaders,
|
|
302
307
|
authToken,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InternalGraphQLAPI.js","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.InternalGraphQLAPI = exports.InternalGraphQLAPIClass = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst graphql_1 = require(\"graphql\");\nconst rxjs_1 = require(\"rxjs\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst api_rest_1 = require(\"@aws-amplify/api-rest\");\nconst internals_1 = require(\"@aws-amplify/api-rest/internals\");\nconst AWSAppSyncRealTimeProvider_1 = require(\"../Providers/AWSAppSyncRealTimeProvider\");\nconst utils_2 = require(\"../utils\");\nconst repackageAuthError_1 = require(\"../utils/errors/repackageAuthError\");\nconst constants_1 = require(\"../utils/errors/constants\");\nconst errors_1 = require(\"../utils/errors\");\nconst isGraphQLResponseWithErrors_1 = require(\"./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 */\nclass InternalGraphQLAPIClass {\n constructor() {\n /**\n * @private\n */\n this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();\n this._api = {\n post: internals_1.post,\n cancelREST: internals_1.cancel,\n isCancelErrorREST: api_rest_1.isCancelError,\n updateRequestToBeCancellable: internals_1.updateRequestToBeCancellable,\n };\n }\n getModuleName() {\n return 'InternalGraphQLAPI';\n }\n async _headerBasedAuth(amplify, authMode, additionalHeaders = {}) {\n const { apiKey } = (0, utils_2.resolveConfig)(amplify);\n let headers = {};\n switch (authMode) {\n case 'apiKey':\n if (!apiKey) {\n throw new errors_1.GraphQLApiError(constants_1.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 errors_1.GraphQLApiError(constants_1.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 errors_1.GraphQLApiError({\n ...constants_1.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 errors_1.GraphQLApiError(constants_1.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 errors_1.GraphQLApiError(constants_1.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 = (0, graphql_1.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 ? (0, graphql_1.parse)(paramQuery)\n : (0, graphql_1.parse)((0, graphql_1.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, } = (0, utils_2.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 } = (0, utils_2.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 utils_1.AmplifyUrl(customEndpoint || appSyncGraphqlEndpoint || '').toString(),\n queryString: (0, graphql_1.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: (0, graphql_1.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]: (0, utils_1.getAmplifyUserAgent)(customUserAgentDetails),\n }),\n };\n const body = {\n query: (0, graphql_1.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 (0, errors_1.createGraphQLResultWithError)(new errors_1.GraphQLApiError(constants_1.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 utils_1.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 = (0, errors_1.createGraphQLResultWithError)(error);\n }\n if ((0, isGraphQLResponseWithErrors_1.isGraphQLResponseWithErrors)(response)) {\n throw (0, repackageAuthError_1.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 = (0, utils_2.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 } = (0, utils_2.resolveLibraryOptions)(amplify);\n return this.appSyncRealTime\n .subscribe({\n query: (0, graphql_1.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((0, rxjs_1.catchError)(e => {\n if (e.errors) {\n throw (0, repackageAuthError_1.repackageUnauthorizedError)(e);\n }\n throw e;\n }));\n }\n}\nexports.InternalGraphQLAPIClass = InternalGraphQLAPIClass;\nexports.InternalGraphQLAPI = new InternalGraphQLAPIClass();\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,uBAAuB,GAAG,KAAK,CAAC,CAAC;AACtE;AACA;AACA,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACrC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,UAAU,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AACpD,MAAM,WAAW,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAC;AAC/D,MAAM,4BAA4B,GAAG,OAAO,CAAC,yCAAyC,CAAC,CAAC;AACxF,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,MAAM,oBAAoB,GAAG,OAAO,CAAC,oCAAoC,CAAC,CAAC;AAC3E,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACzD,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC5C,MAAM,6BAA6B,GAAG,OAAO,CAAC,uDAAuD,CAAC,CAAC;AACvG,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC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AC;AACZ,KAAK;AACL,CAAC;AACD,OAAO,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;AAC1D,OAAO,CAAC,kBAAkB,GAAG,IAAI,uBAAuB,EAAE;;"}
|
|
1
|
+
{"version":3,"file":"InternalGraphQLAPI.js","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.InternalGraphQLAPI = exports.InternalGraphQLAPIClass = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst graphql_1 = require(\"graphql\");\nconst rxjs_1 = require(\"rxjs\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst api_rest_1 = require(\"@aws-amplify/api-rest\");\nconst internals_1 = require(\"@aws-amplify/api-rest/internals\");\nconst AWSAppSyncRealTimeProvider_1 = require(\"../Providers/AWSAppSyncRealTimeProvider\");\nconst utils_2 = require(\"../utils\");\nconst repackageAuthError_1 = require(\"../utils/errors/repackageAuthError\");\nconst constants_1 = require(\"../utils/errors/constants\");\nconst errors_1 = require(\"../utils/errors\");\nconst isGraphQLResponseWithErrors_1 = require(\"./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 */\nclass InternalGraphQLAPIClass {\n constructor() {\n /**\n * @private\n */\n this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();\n this._api = {\n post: internals_1.post,\n cancelREST: internals_1.cancel,\n isCancelErrorREST: api_rest_1.isCancelError,\n updateRequestToBeCancellable: internals_1.updateRequestToBeCancellable,\n };\n }\n getModuleName() {\n return 'InternalGraphQLAPI';\n }\n async _headerBasedAuth(amplify, authMode, additionalHeaders = {}) {\n const { apiKey } = (0, utils_2.resolveConfig)(amplify);\n let headers = {};\n switch (authMode) {\n case 'apiKey':\n if (!apiKey) {\n throw new errors_1.GraphQLApiError(constants_1.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 errors_1.GraphQLApiError(constants_1.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 errors_1.GraphQLApiError({\n ...constants_1.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 errors_1.GraphQLApiError(constants_1.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 errors_1.GraphQLApiError(constants_1.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 = (0, graphql_1.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 ? (0, graphql_1.parse)(paramQuery)\n : (0, graphql_1.parse)((0, graphql_1.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, } = (0, utils_2.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 } = (0, utils_2.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 utils_1.AmplifyUrl(customEndpoint || appSyncGraphqlEndpoint || '').toString(),\n queryString: (0, graphql_1.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: (0, graphql_1.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]: (0, utils_1.getAmplifyUserAgent)(customUserAgentDetails),\n }),\n };\n const body = {\n query: (0, graphql_1.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 (0, errors_1.createGraphQLResultWithError)(new errors_1.GraphQLApiError(constants_1.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 utils_1.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 = (0, errors_1.createGraphQLResultWithError)(error);\n }\n if ((0, isGraphQLResponseWithErrors_1.isGraphQLResponseWithErrors)(response)) {\n throw (0, repackageAuthError_1.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 = (0, utils_2.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 } = (0, utils_2.resolveLibraryOptions)(amplify);\n return this.appSyncRealTime\n .subscribe({\n query: (0, graphql_1.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((0, rxjs_1.catchError)(e => {\n if (e.errors) {\n throw (0, repackageAuthError_1.repackageUnauthorizedError)(e);\n }\n throw e;\n }));\n }\n}\nexports.InternalGraphQLAPIClass = InternalGraphQLAPIClass;\nexports.InternalGraphQLAPI = new InternalGraphQLAPIClass();\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,uBAAuB,GAAG,KAAK,CAAC,CAAC;AACtE;AACA;AACA,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACrC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,UAAU,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AACpD,MAAM,WAAW,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAC;AAC/D,MAAM,4BAA4B,GAAG,OAAO,CAAC,yCAAyC,CAAC,CAAC;AACxF,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,MAAM,oBAAoB,GAAG,OAAO,CAAC,oCAAoC,CAAC,CAAC;AAC3E,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACzD,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC5C,MAAM,6BAA6B,GAAG,OAAO,CAAC,uDAAuD,CAAC,CAAC;AACvG,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;AACA,MAAM,uBAAuB,CAAC;AAC9B,IAAI,WAAW,GAAG;AAClB;AACA;AACA;AACA,QAAQ,IAAI,CAAC,eAAe,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pB,SAAS,CAAC,CAAC,CAAC;AACZ,KAAK;AACL,CAAC;AACD,OAAO,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;AAC1D,OAAO,CAAC,kBAAkB,GAAG,IAAI,uBAAuB,EAAE;;"}
|
|
@@ -3,6 +3,7 @@ import { CustomUserAgentDetails, DocumentType, GraphQLAuthMode } from '@aws-ampl
|
|
|
3
3
|
import { CustomHeaders } from '@aws-amplify/data-schema/runtime';
|
|
4
4
|
import { PubSubContentObserver } from '../../types/PubSub';
|
|
5
5
|
import { SUBSCRIPTION_STATUS } from '../constants';
|
|
6
|
+
type ResolvedGraphQLAuthModes = Exclude<GraphQLAuthMode, 'identityPool'>;
|
|
6
7
|
export interface ObserverQuery {
|
|
7
8
|
observer: PubSubContentObserver;
|
|
8
9
|
query: string;
|
|
@@ -14,7 +15,7 @@ export interface ObserverQuery {
|
|
|
14
15
|
}
|
|
15
16
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
16
17
|
appSyncGraphqlEndpoint?: string;
|
|
17
|
-
authenticationType?:
|
|
18
|
+
authenticationType?: ResolvedGraphQLAuthModes;
|
|
18
19
|
query?: string;
|
|
19
20
|
variables?: Record<string, DocumentType>;
|
|
20
21
|
apiKey?: string;
|
|
@@ -63,3 +64,4 @@ export declare class AWSAppSyncRealTimeProvider {
|
|
|
63
64
|
private _awsRealTimeIAMHeader;
|
|
64
65
|
private _customAuthHeader;
|
|
65
66
|
}
|
|
67
|
+
export {};
|
|
@@ -145,7 +145,9 @@ class InternalGraphQLAPIClass {
|
|
|
145
145
|
}
|
|
146
146
|
async _graphql(amplify, { query, variables, authMode: explicitAuthMode }, additionalHeaders = {}, abortController, customUserAgentDetails, authToken) {
|
|
147
147
|
const { region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, defaultAuthMode, } = resolveConfig(amplify);
|
|
148
|
-
const
|
|
148
|
+
const initialAuthMode = explicitAuthMode || defaultAuthMode || 'iam';
|
|
149
|
+
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
150
|
+
const authMode = initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
149
151
|
/**
|
|
150
152
|
* Retrieve library options from Amplify configuration.
|
|
151
153
|
* `customHeaders` here are from the Amplify configuration options,
|
|
@@ -279,8 +281,11 @@ class InternalGraphQLAPIClass {
|
|
|
279
281
|
cancel(request, message) {
|
|
280
282
|
return this._api.cancelREST(request, message);
|
|
281
283
|
}
|
|
282
|
-
_graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails, authToken) {
|
|
284
|
+
_graphqlSubscribe(amplify, { query, variables, authMode: explicitAuthMode }, additionalHeaders = {}, customUserAgentDetails, authToken) {
|
|
283
285
|
const config = resolveConfig(amplify);
|
|
286
|
+
const initialAuthMode = explicitAuthMode || config?.defaultAuthMode || 'iam';
|
|
287
|
+
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
288
|
+
const authMode = initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
284
289
|
/**
|
|
285
290
|
* Retrieve library options from Amplify configuration.
|
|
286
291
|
* `libraryConfigHeaders` are from the Amplify configuration options,
|
|
@@ -296,7 +301,7 @@ class InternalGraphQLAPIClass {
|
|
|
296
301
|
variables,
|
|
297
302
|
appSyncGraphqlEndpoint: config?.endpoint,
|
|
298
303
|
region: config?.region,
|
|
299
|
-
authenticationType: authMode
|
|
304
|
+
authenticationType: authMode,
|
|
300
305
|
apiKey: config?.apiKey,
|
|
301
306
|
additionalHeaders,
|
|
302
307
|
authToken,
|
|
@@ -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_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,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,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAClD,QAAQ,IAAI,OAAO,GAAG,EAAE,CAAC;AACzB,QAAQ,QAAQ,QAAQ;AACxB,YAAY,KAAK,QAAQ;AACzB,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"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 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 // 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: 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;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,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,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,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;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api-graphql",
|
|
3
|
-
"version": "4.0.31-
|
|
3
|
+
"version": "4.0.31-unstable.8fb751a.0+8fb751a",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -84,9 +84,9 @@
|
|
|
84
84
|
"server"
|
|
85
85
|
],
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@aws-amplify/api-rest": "4.0.29-
|
|
88
|
-
"@aws-amplify/core": "6.0.29-
|
|
89
|
-
"@aws-amplify/data-schema": "^0.
|
|
87
|
+
"@aws-amplify/api-rest": "4.0.29-unstable.8fb751a.0+8fb751a",
|
|
88
|
+
"@aws-amplify/core": "6.0.29-unstable.8fb751a.0+8fb751a",
|
|
89
|
+
"@aws-amplify/data-schema": "^1.0.0",
|
|
90
90
|
"@aws-sdk/types": "3.387.0",
|
|
91
91
|
"graphql": "15.8.0",
|
|
92
92
|
"rxjs": "^7.8.1",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"limit": "91.7 kB"
|
|
102
102
|
}
|
|
103
103
|
],
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "8fb751ad0f7ae9102cb5ae7935ccd6436bb7dbb0"
|
|
105
105
|
}
|
|
@@ -61,6 +61,8 @@ const dispatchApiEvent = (payload: HubPayload) => {
|
|
|
61
61
|
Hub.dispatch('api', payload, 'PubSub', AMPLIFY_SYMBOL);
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
+
// resolved/actual AuthMode values. identityPool gets resolves to IAM upstream in InternalGraphQLAPI._graphqlSubscribe
|
|
65
|
+
type ResolvedGraphQLAuthModes = Exclude<GraphQLAuthMode, 'identityPool'>;
|
|
64
66
|
export interface ObserverQuery {
|
|
65
67
|
observer: PubSubContentObserver;
|
|
66
68
|
query: string;
|
|
@@ -96,7 +98,7 @@ interface ParsedMessagePayload {
|
|
|
96
98
|
|
|
97
99
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
98
100
|
appSyncGraphqlEndpoint?: string;
|
|
99
|
-
authenticationType?:
|
|
101
|
+
authenticationType?: ResolvedGraphQLAuthModes;
|
|
100
102
|
query?: string;
|
|
101
103
|
variables?: Record<string, DocumentType>;
|
|
102
104
|
apiKey?: string;
|
|
@@ -935,7 +937,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
935
937
|
Record<string, unknown> | undefined
|
|
936
938
|
> {
|
|
937
939
|
const headerHandler: {
|
|
938
|
-
[key in
|
|
940
|
+
[key in ResolvedGraphQLAuthModes]: (
|
|
939
941
|
arg0: AWSAppSyncRealTimeAuthInput,
|
|
940
942
|
) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
941
943
|
} = {
|
|
@@ -259,7 +259,10 @@ export class InternalGraphQLAPIClass {
|
|
|
259
259
|
defaultAuthMode,
|
|
260
260
|
} = resolveConfig(amplify);
|
|
261
261
|
|
|
262
|
-
const
|
|
262
|
+
const initialAuthMode = explicitAuthMode || defaultAuthMode || 'iam';
|
|
263
|
+
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
264
|
+
const authMode =
|
|
265
|
+
initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
263
266
|
|
|
264
267
|
/**
|
|
265
268
|
* Retrieve library options from Amplify configuration.
|
|
@@ -425,13 +428,19 @@ export class InternalGraphQLAPIClass {
|
|
|
425
428
|
|
|
426
429
|
private _graphqlSubscribe(
|
|
427
430
|
amplify: AmplifyClassV6,
|
|
428
|
-
{ query, variables, authMode }: GraphQLOptions,
|
|
431
|
+
{ query, variables, authMode: explicitAuthMode }: GraphQLOptions,
|
|
429
432
|
additionalHeaders: CustomHeaders = {},
|
|
430
433
|
customUserAgentDetails?: CustomUserAgentDetails,
|
|
431
434
|
authToken?: string,
|
|
432
435
|
): Observable<any> {
|
|
433
436
|
const config = resolveConfig(amplify);
|
|
434
437
|
|
|
438
|
+
const initialAuthMode =
|
|
439
|
+
explicitAuthMode || config?.defaultAuthMode || 'iam';
|
|
440
|
+
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
441
|
+
const authMode =
|
|
442
|
+
initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
443
|
+
|
|
435
444
|
/**
|
|
436
445
|
* Retrieve library options from Amplify configuration.
|
|
437
446
|
* `libraryConfigHeaders` are from the Amplify configuration options,
|
|
@@ -449,7 +458,7 @@ export class InternalGraphQLAPIClass {
|
|
|
449
458
|
variables,
|
|
450
459
|
appSyncGraphqlEndpoint: config?.endpoint,
|
|
451
460
|
region: config?.region,
|
|
452
|
-
authenticationType: authMode
|
|
461
|
+
authenticationType: authMode,
|
|
453
462
|
apiKey: config?.apiKey,
|
|
454
463
|
additionalHeaders,
|
|
455
464
|
authToken,
|