@aws-amplify/api-graphql 4.6.7-graphql-multi-client.e61d28d.0 → 4.6.7-graphql-multi-client.27123f5.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.
@@ -237,12 +237,13 @@ class InternalGraphQLAPIClass {
237
237
  */
238
238
  const { headers: libraryConfigHeaders } = (0, utils_2.resolveLibraryOptions)(amplify);
239
239
  const appSyncGraphqlEndpoint = endpoint ?? config?.endpoint;
240
- if (!appSyncGraphqlEndpoint) {
241
- throw new Error('Endpoint missing from subscription query. An endpoint must either be configured or provided at the call site.');
242
- }
243
- const realtimeProvider = this.appSyncRealTime.get(appSyncGraphqlEndpoint) ??
244
- new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();
245
- this.appSyncRealTime.set(appSyncGraphqlEndpoint, realtimeProvider);
240
+ // TODO: This could probably be an exception. But, lots of tests rely on
241
+ // attempting to connect to nowhere. So, I'm treating as the opposite of
242
+ // a Chesterton's fence for now. (A fence I shouldn't build, because I don't
243
+ // know why somethings depends on its absence!)
244
+ const memoKey = appSyncGraphqlEndpoint ?? 'none';
245
+ const realtimeProvider = this.appSyncRealTime.get(memoKey) ?? new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();
246
+ this.appSyncRealTime.set(memoKey, realtimeProvider);
246
247
  return realtimeProvider
247
248
  .subscribe({
248
249
  query: (0, graphql_1.print)(query),
@@ -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 graphqlAuth_1 = require(\"./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 */\nclass InternalGraphQLAPIClass {\n constructor() {\n /**\n * @private\n */\n this.appSyncRealTime = new Map();\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 /**\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, endpoint, apiKey, }, 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, 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, } = (0, utils_2.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 } = (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(endpointOverride || 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 const authHeaders = await (0, graphqlAuth_1.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: (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 = endpointOverride || 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 // \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 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: authModeOverride, apiKey: apiKeyOverride, endpoint, }, additionalHeaders = {}, customUserAgentDetails, authToken) {\n const config = (0, utils_2.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 } = (0, utils_2.resolveLibraryOptions)(amplify);\n const appSyncGraphqlEndpoint = endpoint ?? config?.endpoint;\n if (!appSyncGraphqlEndpoint) {\n throw new Error('Endpoint missing from subscription query. An endpoint must either be configured or provided at the call site.');\n }\n const realtimeProvider = this.appSyncRealTime.get(appSyncGraphqlEndpoint) ??\n new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();\n this.appSyncRealTime.set(appSyncGraphqlEndpoint, realtimeProvider);\n return realtimeProvider\n .subscribe({\n query: (0, graphql_1.print)(query),\n variables,\n appSyncGraphqlEndpoint,\n region: config?.region,\n authenticationType: authMode,\n apiKey: apiKeyOverride ?? 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,uDAAu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,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC,IAAI;AAC9C,YAAY,IAAI,CAAC,CAAC,MAAM,EAAE;AAC1B,gBAAgB,MAAM,IAAI,oBAAoB,CAAC,0BAA0B,EAAE,CAAC,CAAC,CAAC;AAC9E,aAAa;AACb,YAAY,MAAM,CAAC,CAAC;AACpB,SAAS,CAAC,CAAC,CAAC;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 graphqlAuth_1 = require(\"./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 */\nclass InternalGraphQLAPIClass {\n constructor() {\n /**\n * @private\n */\n this.appSyncRealTime = new Map();\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 /**\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, endpoint, apiKey, }, 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, 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, } = (0, utils_2.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 } = (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(endpointOverride || 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 const authHeaders = await (0, graphqlAuth_1.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: (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 = endpointOverride || 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 // \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 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: authModeOverride, apiKey: apiKeyOverride, endpoint, }, additionalHeaders = {}, customUserAgentDetails, authToken) {\n const config = (0, utils_2.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 } = (0, utils_2.resolveLibraryOptions)(amplify);\n const appSyncGraphqlEndpoint = endpoint ?? config?.endpoint;\n // TODO: This could probably be an exception. But, lots of tests rely on\n // attempting to connect to nowhere. So, I'm treating as the opposite of\n // a Chesterton's fence for now. (A fence I shouldn't build, because I don't\n // know why somethings depends on its absence!)\n const memoKey = appSyncGraphqlEndpoint ?? 'none';\n const realtimeProvider = this.appSyncRealTime.get(memoKey) ?? new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();\n this.appSyncRealTime.set(memoKey, realtimeProvider);\n return realtimeProvider\n .subscribe({\n query: (0, graphql_1.print)(query),\n variables,\n appSyncGraphqlEndpoint,\n region: config?.region,\n authenticationType: authMode,\n apiKey: apiKeyOverride ?? 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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E,QAAQ,CAAC;AACpE;AACA;AACA;AACA;AACA,QAAQ,MAAM,OAAO,GAAG,sBAAsB,IAAI,MAAM,CAAC;AACzD,QAAQ,MAAM,gBAAgB,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,4BAA4B,CAAC,0BAA0B,EAAE,CAAC;AACpI,QAAQ,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;AAC5D,QAAQ,OAAO,gBAAgB;AAC/B,aAAa,SAAS,CAAC;AACvB,YAAY,KAAK,EAAE,IAAI,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;AAC9C,YAAY,SAAS;AACrB,YAAY,sBAAsB;AAClC,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,kBAAkB,EAAE,QAAQ;AACxC,YAAY,MAAM,EAAE,cAAc,IAAI,MAAM,EAAE,MAAM;AACpD,YAAY,iBAAiB;AAC7B,YAAY,SAAS;AACrB,YAAY,oBAAoB;AAChC,SAAS,EAAE,sBAAsB,CAAC;AAClC,aAAa,IAAI,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC,IAAI;AAC9C,YAAY,IAAI,CAAC,CAAC,MAAM,EAAE;AAC1B,gBAAgB,MAAM,IAAI,oBAAoB,CAAC,0BAA0B,EAAE,CAAC,CAAC,CAAC;AAC9E,aAAa;AACb,YAAY,MAAM,CAAC,CAAC;AACpB,SAAS,CAAC,CAAC,CAAC;AACZ,KAAK;AACL,CAAC;AACD,OAAO,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;AAC1D,OAAO,CAAC,kBAAkB,GAAG,IAAI,uBAAuB,EAAE;;"}
@@ -237,12 +237,13 @@ class InternalGraphQLAPIClass {
237
237
  */
238
238
  const { headers: libraryConfigHeaders } = resolveLibraryOptions(amplify);
239
239
  const appSyncGraphqlEndpoint = endpoint ?? config?.endpoint;
240
- if (!appSyncGraphqlEndpoint) {
241
- throw new Error('Endpoint missing from subscription query. An endpoint must either be configured or provided at the call site.');
242
- }
243
- const realtimeProvider = this.appSyncRealTime.get(appSyncGraphqlEndpoint) ??
244
- new AWSAppSyncRealTimeProvider();
245
- this.appSyncRealTime.set(appSyncGraphqlEndpoint, realtimeProvider);
240
+ // TODO: This could probably be an exception. But, lots of tests rely on
241
+ // attempting to connect to nowhere. So, I'm treating as the opposite of
242
+ // a Chesterton's fence for now. (A fence I shouldn't build, because I don't
243
+ // know why somethings depends on its absence!)
244
+ const memoKey = appSyncGraphqlEndpoint ?? 'none';
245
+ const realtimeProvider = this.appSyncRealTime.get(memoKey) ?? new AWSAppSyncRealTimeProvider();
246
+ this.appSyncRealTime.set(memoKey, realtimeProvider);
246
247
  return realtimeProvider
247
248
  .subscribe({
248
249
  query: print(query),
@@ -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 Map();\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 const appSyncGraphqlEndpoint = endpoint ?? config?.endpoint;\n if (!appSyncGraphqlEndpoint) {\n throw new Error('Endpoint missing from subscription query. An endpoint must either be configured or provided at the call site.');\n }\n const realtimeProvider = this.appSyncRealTime.get(appSyncGraphqlEndpoint) ??\n new AWSAppSyncRealTimeProvider();\n this.appSyncRealTime.set(appSyncGraphqlEndpoint, realtimeProvider);\n return realtimeProvider\n .subscribe({\n query: print(query),\n variables,\n appSyncGraphqlEndpoint,\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,GAAG,EAAE,CAAC;AACzC,QAAQ,IAAI,CAAC,IAAI,GAAG;AACpB,YAAY,IAA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vB,YAAY,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;AAC/B,YAAY,SAAS;AACrB,YAAY,sBAAsB;AAClC,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,kBAAkB,EAAE,QAAQ;AACxC,YAAY,MAAM,EAAE,cAAc,IAAI,MAAM,EAAE,MAAM;AACpD,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 Map();\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 const appSyncGraphqlEndpoint = endpoint ?? config?.endpoint;\n // TODO: This could probably be an exception. But, lots of tests rely on\n // attempting to connect to nowhere. So, I'm treating as the opposite of\n // a Chesterton's fence for now. (A fence I shouldn't build, because I don't\n // know why somethings depends on its absence!)\n const memoKey = appSyncGraphqlEndpoint ?? 'none';\n const realtimeProvider = this.appSyncRealTime.get(memoKey) ?? new AWSAppSyncRealTimeProvider();\n this.appSyncRealTime.set(memoKey, realtimeProvider);\n return realtimeProvider\n .subscribe({\n query: print(query),\n variables,\n appSyncGraphqlEndpoint,\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;A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,EAAE,gBAAgB,CAAC,CAAC;AAC5D,QAAQ,OAAO,gBAAgB;AAC/B,aAAa,SAAS,CAAC;AACvB,YAAY,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;AAC/B,YAAY,SAAS;AACrB,YAAY,sBAAsB;AAClC,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,kBAAkB,EAAE,QAAQ;AACxC,YAAY,MAAM,EAAE,cAAc,IAAI,MAAM,EAAE,MAAM;AACpD,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.6.7-graphql-multi-client.e61d28d.0+e61d28d",
3
+ "version": "4.6.7-graphql-multi-client.27123f5.0+27123f5",
4
4
  "description": "Api-graphql category of aws-amplify",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -84,8 +84,8 @@
84
84
  "server"
85
85
  ],
86
86
  "dependencies": {
87
- "@aws-amplify/api-rest": "4.0.64-graphql-multi-client.e61d28d.0+e61d28d",
88
- "@aws-amplify/core": "6.7.4-graphql-multi-client.e61d28d.0+e61d28d",
87
+ "@aws-amplify/api-rest": "4.0.64-graphql-multi-client.27123f5.0+27123f5",
88
+ "@aws-amplify/core": "6.7.4-graphql-multi-client.27123f5.0+27123f5",
89
89
  "@aws-amplify/data-schema": "^1.7.0",
90
90
  "@aws-sdk/types": "3.387.0",
91
91
  "graphql": "15.8.0",
@@ -101,5 +101,5 @@
101
101
  "limit": "91.7 kB"
102
102
  }
103
103
  ],
104
- "gitHead": "e61d28d6575aec0a0ff5fd5255022a0fdb301229"
104
+ "gitHead": "27123f53648289529d58f8075117282d1bfda03b"
105
105
  }
@@ -386,17 +386,14 @@ export class InternalGraphQLAPIClass {
386
386
 
387
387
  const appSyncGraphqlEndpoint = endpoint ?? config?.endpoint;
388
388
 
389
- if (!appSyncGraphqlEndpoint) {
390
- throw new Error(
391
- 'Endpoint missing from subscription query. An endpoint must either be configured or provided at the call site.',
392
- );
393
- }
394
-
389
+ // TODO: This could probably be an exception. But, lots of tests rely on
390
+ // attempting to connect to nowhere. So, I'm treating as the opposite of
391
+ // a Chesterton's fence for now. (A fence I shouldn't build, because I don't
392
+ // know why somethings depends on its absence!)
393
+ const memoKey = appSyncGraphqlEndpoint ?? 'none';
395
394
  const realtimeProvider =
396
- this.appSyncRealTime.get(appSyncGraphqlEndpoint!) ??
397
- new AWSAppSyncRealTimeProvider();
398
-
399
- this.appSyncRealTime.set(appSyncGraphqlEndpoint, realtimeProvider);
395
+ this.appSyncRealTime.get(memoKey) ?? new AWSAppSyncRealTimeProvider();
396
+ this.appSyncRealTime.set(memoKey, realtimeProvider);
400
397
 
401
398
  return realtimeProvider
402
399
  .subscribe(