@aws-amplify/api-graphql 4.0.26 → 4.0.27
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/APIClient.js +14 -0
- package/dist/cjs/internals/APIClient.js.map +1 -1
- package/dist/cjs/internals/InternalGraphQLAPI.js +36 -38
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js +15 -0
- package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js.map +1 -0
- package/dist/cjs/utils/errors/constants.js +47 -0
- package/dist/cjs/utils/errors/constants.js.map +1 -0
- package/dist/cjs/utils/errors/createGraphQLResultWithError.js +15 -0
- package/dist/cjs/utils/errors/createGraphQLResultWithError.js.map +1 -0
- package/dist/cjs/utils/errors/index.js +3 -1
- package/dist/cjs/utils/errors/index.js.map +1 -1
- package/dist/cjs/utils/errors/repackageAuthError.js +6 -6
- package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -1
- package/dist/esm/internals/APIClient.mjs +14 -0
- package/dist/esm/internals/APIClient.mjs.map +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.mjs +40 -40
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.d.ts +2 -0
- package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs +12 -0
- package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs.map +1 -0
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/utils/errors/constants.d.ts +7 -0
- package/dist/esm/utils/errors/constants.mjs +46 -0
- package/dist/esm/utils/errors/constants.mjs.map +1 -0
- package/dist/esm/utils/errors/createGraphQLResultWithError.d.ts +2 -0
- package/dist/esm/utils/errors/createGraphQLResultWithError.mjs +13 -0
- package/dist/esm/utils/errors/createGraphQLResultWithError.mjs.map +1 -0
- package/dist/esm/utils/errors/index.d.ts +1 -0
- package/dist/esm/utils/errors/index.mjs +1 -0
- package/dist/esm/utils/errors/index.mjs.map +1 -1
- package/dist/esm/utils/errors/repackageAuthError.d.ts +3 -7
- package/dist/esm/utils/errors/repackageAuthError.mjs +5 -5
- package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -1
- package/dist/esm/utils/resolveConfig.mjs +1 -0
- package/dist/esm/utils/resolveConfig.mjs.map +1 -1
- package/package.json +5 -5
- package/src/internals/APIClient.ts +20 -0
- package/src/internals/InternalGraphQLAPI.ts +50 -56
- package/src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts +15 -0
- package/src/types/index.ts +2 -0
- package/src/utils/errors/constants.ts +56 -0
- package/src/utils/errors/createGraphQLResultWithError.ts +15 -0
- package/src/utils/errors/index.ts +1 -0
- package/src/utils/errors/repackageAuthError.ts +8 -10
|
@@ -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 { GraphQLError, 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 { GraphQLAuthError, } from '../types';\nimport { resolveConfig, resolveLibraryOptions } from '../utils';\nimport { repackageUnauthError } from '../utils/errors/repackageAuthError';\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 Error(GraphQLAuthError.NO_API_KEY);\n }\n headers = {\n 'X-Api-Key': apiKey,\n };\n break;\n case 'iam': {\n const session = await amplify.Auth.fetchAuthSession();\n if (session.credentials === undefined) {\n throw new Error(GraphQLAuthError.NO_CREDENTIALS);\n }\n break;\n }\n case 'oidc':\n case 'userPool':\n try {\n const token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();\n if (!token) {\n throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);\n }\n headers = {\n Authorization: token,\n };\n }\n catch (e) {\n throw new Error(GraphQLAuthError.NO_CURRENT_USER);\n }\n break;\n case 'lambda':\n if (typeof additionalHeaders === 'object' &&\n !additionalHeaders.Authorization) {\n throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);\n }\n headers = {\n Authorization: additionalHeaders.Authorization,\n };\n break;\n case 'none':\n break;\n default:\n break;\n }\n return headers;\n }\n /**\n * to get the operation type\n * @param operation\n */\n getGraphqlOperationType(operation) {\n const doc = parse(operation);\n const definitions = doc.definitions;\n const [{ operation: operationType }] = definitions;\n return operationType;\n }\n /**\n * Executes a GraphQL operation\n *\n * @param options - GraphQL Options\n * @param [additionalHeaders] - headers to merge in after any `libraryConfigHeaders` set in the config\n * @returns An Observable if the query is a subscription query, else a promise of the graphql result.\n */\n graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken }, additionalHeaders, customUserAgentDetails) {\n const query = typeof paramQuery === 'string'\n ? parse(paramQuery)\n : parse(print(paramQuery));\n const [operationDef = {}] = query.definitions.filter(def => def.kind === 'OperationDefinition');\n const { operation: operationType } = operationDef;\n const headers = additionalHeaders || {};\n switch (operationType) {\n case 'query':\n case 'mutation': {\n const abortController = new AbortController();\n let responsePromise;\n if (isAmplifyInstance(amplify)) {\n responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n }\n else {\n // NOTE: this wrapper function must be await-able so the Amplify server context manager can\n // destroy the context only after it completes\n const wrapper = async (amplifyInstance) => {\n const result = await this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n return result;\n };\n responsePromise = amplify(wrapper);\n }\n this._api.updateRequestToBeCancellable(responsePromise, abortController);\n return responsePromise;\n }\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 const error = new GraphQLError('No graphql endpoint provided.');\n // TODO(Eslint): refactor this to throw an Error instead of a plain object\n // eslint-disable-next-line no-throw-literal\n throw {\n data: {},\n errors: [error],\n };\n }\n let response;\n try {\n const { body: responseBody } = await this._api.post(amplify, {\n url: new AmplifyUrl(endpoint),\n options: {\n headers,\n body,\n signingServiceInfo,\n withCredentials,\n },\n abortController,\n });\n const result = await responseBody.json();\n response = result;\n }\n catch (err) {\n // If the exception is because user intentionally\n // cancelled the request, do not modify the exception\n // so that clients can identify the exception correctly.\n if (this.isCancelError(err)) {\n throw err;\n }\n response = {\n data: {},\n errors: [\n new GraphQLError(err.message, null, null, null, null, err),\n ],\n };\n }\n const { errors } = response;\n if (errors && errors.length) {\n throw repackageUnauthError(response);\n }\n return response;\n }\n /**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @return {boolean} - A boolean indicating if the error was from an api request cancellation\n */\n isCancelError(error) {\n return this._api.isCancelErrorREST(error);\n }\n /**\n * Cancels an inflight request. Only applicable for graphql queries and mutations\n * @param {any} request - request to cancel\n * @returns - A boolean indicating if the request was cancelled\n */\n cancel(request, message) {\n return this._api.cancelREST(request, message);\n }\n _graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails, authToken) {\n const config = resolveConfig(amplify);\n /**\n * Retrieve library options from Amplify configuration.\n * `libraryConfigHeaders` are from the Amplify configuration options,\n * and will not be overwritten by other custom headers. These are *not*\n * the same as `additionalHeaders`, which are custom headers that are\n * either 1)included when configuring the API client or 2) passed along\n * with individual requests.\n */\n const { headers: libraryConfigHeaders } = resolveLibraryOptions(amplify);\n return this.appSyncRealTime\n .subscribe({\n query: print(query),\n variables,\n appSyncGraphqlEndpoint: config?.endpoint,\n region: config?.region,\n authenticationType: authMode || config?.defaultAuthMode,\n apiKey: config?.apiKey,\n additionalHeaders,\n authToken,\n libraryConfigHeaders,\n }, customUserAgentDetails)\n .pipe(catchError(e => {\n if (e.errors) {\n throw repackageUnauthError(e);\n }\n throw e;\n }));\n }\n}\nexport const InternalGraphQLAPI = new InternalGraphQLAPIClass();\n"],"names":["cancelREST","isCancelErrorREST"],"mappings":";;;;;;;;;;;AAAA;AACA;AAUA,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC7C,MAAM,iBAAiB,GAAG,CAAC,OAAO,KAAK;AACvC,IAAI,OAAO,OAAO,OAAO,KAAK,UAAU,CAAC;AACzC,CAAC,CAAC;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AM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;AACjF,QAAQ,OAAO,IAAI,CAAC,eAAe;AACnC,aAAa,SAAS,CAAC;AACvB,YAAY,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;AAC/B,YAAY,SAAS;AACrB,YAAY,sBAAsB,EAAE,MAAM,EAAE,QAAQ;AACpD,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,kBAAkB,EAAE,QAAQ,IAAI,MAAM,EAAE,eAAe;AACnE,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,iBAAiB;AAC7B,YAAY,SAAS;AACrB,YAAY,oBAAoB;AAChC,SAAS,EAAE,sBAAsB,CAAC;AAClC,aAAa,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI;AAClC,YAAY,IAAI,CAAC,CAAC,MAAM,EAAE;AAC1B,gBAAgB,MAAM,oBAAoB,CAAC,CAAC,CAAC,CAAC;AAC9C,aAAa;AACb,YAAY,MAAM,CAAC,CAAC;AACpB,SAAS,CAAC,CAAC,CAAC;AACZ,KAAK;AACL,CAAC;AACW,MAAC,kBAAkB,GAAG,IAAI,uBAAuB;;;;"}
|
|
1
|
+
{"version":3,"file":"InternalGraphQLAPI.mjs","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { parse, print, } from 'graphql';\nimport { catchError } from 'rxjs';\nimport { AmplifyUrl, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils';\nimport { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';\nimport { cancel as cancelREST, post, updateRequestToBeCancellable, } from '@aws-amplify/api-rest/internals';\nimport { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';\nimport { resolveConfig, resolveLibraryOptions } from '../utils';\nimport { repackageUnauthorizedError } from '../utils/errors/repackageAuthError';\nimport { NO_API_KEY, NO_AUTH_TOKEN_HEADER, NO_ENDPOINT, NO_SIGNED_IN_USER, NO_VALID_AUTH_TOKEN, NO_VALID_CREDENTIALS, } from '../utils/errors/constants';\nimport { GraphQLApiError, createGraphQLResultWithError } from '../utils/errors';\nimport { isGraphQLResponseWithErrors } from './utils/runtimeTypeGuards/isGraphQLResponseWithErrors';\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst isAmplifyInstance = (amplify) => {\n return typeof amplify !== 'function';\n};\n/**\n * Export Cloud Logic APIs\n */\nexport class InternalGraphQLAPIClass {\n constructor() {\n /**\n * @private\n */\n this.appSyncRealTime = new AWSAppSyncRealTimeProvider();\n this._api = {\n post,\n cancelREST,\n isCancelErrorREST,\n updateRequestToBeCancellable,\n };\n }\n getModuleName() {\n return 'InternalGraphQLAPI';\n }\n async _headerBasedAuth(amplify, authMode, additionalHeaders = {}) {\n const { apiKey } = resolveConfig(amplify);\n let headers = {};\n switch (authMode) {\n case 'apiKey':\n if (!apiKey) {\n throw new GraphQLApiError(NO_API_KEY);\n }\n headers = {\n 'X-Api-Key': apiKey,\n };\n break;\n case 'iam': {\n const session = await amplify.Auth.fetchAuthSession();\n if (session.credentials === undefined) {\n throw new GraphQLApiError(NO_VALID_CREDENTIALS);\n }\n break;\n }\n case 'oidc':\n case 'userPool': {\n let token;\n try {\n token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();\n }\n catch (e) {\n // fetchAuthSession failed\n throw new GraphQLApiError({\n ...NO_SIGNED_IN_USER,\n underlyingError: e,\n });\n }\n // `fetchAuthSession()` succeeded but didn't return `tokens`.\n // This may happen when unauthenticated access is enabled and there is\n // no user signed in.\n if (!token) {\n throw new GraphQLApiError(NO_VALID_AUTH_TOKEN);\n }\n headers = {\n Authorization: token,\n };\n break;\n }\n case 'lambda':\n if (typeof additionalHeaders === 'object' &&\n !additionalHeaders.Authorization) {\n throw new GraphQLApiError(NO_AUTH_TOKEN_HEADER);\n }\n headers = {\n Authorization: additionalHeaders.Authorization,\n };\n break;\n case 'none':\n break;\n default:\n break;\n }\n return headers;\n }\n /**\n * to get the operation type\n * @param operation\n */\n getGraphqlOperationType(operation) {\n const doc = parse(operation);\n const definitions = doc.definitions;\n const [{ operation: operationType }] = definitions;\n return operationType;\n }\n /**\n * Executes a GraphQL operation\n *\n * @param options - GraphQL Options\n * @param [additionalHeaders] - headers to merge in after any `libraryConfigHeaders` set in the config\n * @returns An Observable if the query is a subscription query, else a promise of the graphql result.\n */\n graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken }, additionalHeaders, customUserAgentDetails) {\n const query = typeof paramQuery === 'string'\n ? parse(paramQuery)\n : parse(print(paramQuery));\n const [operationDef = {}] = query.definitions.filter(def => def.kind === 'OperationDefinition');\n const { operation: operationType } = operationDef;\n const headers = additionalHeaders || {};\n switch (operationType) {\n case 'query':\n case 'mutation': {\n const abortController = new AbortController();\n let responsePromise;\n if (isAmplifyInstance(amplify)) {\n responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n }\n else {\n // NOTE: this wrapper function must be await-able so the Amplify server context manager can\n // destroy the context only after it completes\n const wrapper = async (amplifyInstance) => {\n const result = await this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails, authToken);\n return result;\n };\n responsePromise = amplify(wrapper);\n }\n this._api.updateRequestToBeCancellable(responsePromise, abortController);\n return responsePromise;\n }\n case 'subscription':\n return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails, authToken);\n default:\n throw new Error(`invalid operation type: ${operationType}`);\n }\n }\n async _graphql(amplify, { query, variables, authMode: explicitAuthMode }, additionalHeaders = {}, abortController, customUserAgentDetails, authToken) {\n const { region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, defaultAuthMode, } = resolveConfig(amplify);\n const authMode = explicitAuthMode || defaultAuthMode || 'iam';\n /**\n * Retrieve library options from Amplify configuration.\n * `customHeaders` here are from the Amplify configuration options,\n * and are for non-AppSync endpoints only. These are *not* the same as\n * `additionalHeaders`, which are custom headers that are either 1)\n * included when configuring the API client or 2) passed along with\n * individual requests.\n */\n const { headers: customHeaders, withCredentials } = resolveLibraryOptions(amplify);\n /**\n * Client or request-specific custom headers that may or may not be\n * returned by a function:\n */\n let additionalCustomHeaders;\n if (typeof additionalHeaders === 'function') {\n const requestOptions = {\n method: 'POST',\n url: new AmplifyUrl(customEndpoint || appSyncGraphqlEndpoint || '').toString(),\n queryString: print(query),\n };\n additionalCustomHeaders = await additionalHeaders(requestOptions);\n }\n else {\n additionalCustomHeaders = additionalHeaders;\n }\n // if an authorization header is set, have the explicit authToken take precedence\n if (authToken) {\n additionalCustomHeaders = {\n ...additionalCustomHeaders,\n Authorization: authToken,\n };\n }\n // TODO: Figure what we need to do to remove `!`'s.\n const headers = {\n ...(!customEndpoint &&\n (await this._headerBasedAuth(amplify, authMode, additionalCustomHeaders))),\n /**\n * Custom endpoint headers.\n * If there is both a custom endpoint and custom region present, we get the headers.\n * If there is a custom endpoint but no region, we return an empty object.\n * If neither are present, we return an empty object.\n */\n ...((customEndpoint &&\n (customEndpointRegion\n ? await this._headerBasedAuth(amplify, authMode, additionalCustomHeaders)\n : {})) ||\n {}),\n // Custom headers included in Amplify configuration options:\n ...(customHeaders &&\n (await customHeaders({\n query: print(query),\n variables,\n }))),\n // Custom headers from individual requests or API client configuration:\n ...additionalCustomHeaders,\n // User agent headers:\n ...(!customEndpoint && {\n [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),\n }),\n };\n const body = {\n query: print(query),\n variables: variables || null,\n };\n let signingServiceInfo;\n /**\n * We do not send the signing service info to the REST API under the\n * following conditions (i.e. it will not sign the request):\n * - there is a custom endpoint but no region\n * - the auth mode is `none`, or `apiKey`\n * - the auth mode is a type other than the types listed below\n */\n if ((customEndpoint && !customEndpointRegion) ||\n (authMode !== 'oidc' &&\n authMode !== 'userPool' &&\n authMode !== 'iam' &&\n authMode !== 'lambda')) {\n signingServiceInfo = undefined;\n }\n else {\n signingServiceInfo = {\n service: !customEndpointRegion ? 'appsync' : 'execute-api',\n region: !customEndpointRegion ? region : customEndpointRegion,\n };\n }\n const endpoint = customEndpoint || appSyncGraphqlEndpoint;\n if (!endpoint) {\n throw createGraphQLResultWithError(new GraphQLApiError(NO_ENDPOINT));\n }\n let response;\n try {\n // See the inline doc of the REST `post()` API for possible errors to be thrown.\n // As these errors are catastrophic they should be caught and handled by GraphQL\n // API consumers.\n const { body: responseBody } = await this._api.post(amplify, {\n url: new AmplifyUrl(endpoint),\n options: {\n headers,\n body,\n signingServiceInfo,\n withCredentials,\n },\n abortController,\n });\n response = await responseBody.json();\n }\n catch (error) {\n if (this.isCancelError(error)) {\n throw error;\n }\n response = createGraphQLResultWithError(error);\n }\n if (isGraphQLResponseWithErrors(response)) {\n throw repackageUnauthorizedError(response);\n }\n return response;\n }\n /**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @return {boolean} - A boolean indicating if the error was from an api request cancellation\n */\n isCancelError(error) {\n return this._api.isCancelErrorREST(error);\n }\n /**\n * Cancels an inflight request. Only applicable for graphql queries and mutations\n * @param {any} request - request to cancel\n * @returns - A boolean indicating if the request was cancelled\n */\n cancel(request, message) {\n return this._api.cancelREST(request, message);\n }\n _graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails, authToken) {\n const config = resolveConfig(amplify);\n /**\n * Retrieve library options from Amplify configuration.\n * `libraryConfigHeaders` are from the Amplify configuration options,\n * and will not be overwritten by other custom headers. These are *not*\n * the same as `additionalHeaders`, which are custom headers that are\n * either 1)included when configuring the API client or 2) passed along\n * with individual requests.\n */\n const { headers: libraryConfigHeaders } = resolveLibraryOptions(amplify);\n return this.appSyncRealTime\n .subscribe({\n query: print(query),\n variables,\n appSyncGraphqlEndpoint: config?.endpoint,\n region: config?.region,\n authenticationType: authMode || config?.defaultAuthMode,\n apiKey: config?.apiKey,\n additionalHeaders,\n authToken,\n libraryConfigHeaders,\n }, customUserAgentDetails)\n .pipe(catchError(e => {\n if (e.errors) {\n throw repackageUnauthorizedError(e);\n }\n throw e;\n }));\n }\n}\nexport const InternalGraphQLAPI = new InternalGraphQLAPIClass();\n"],"names":["cancelREST","isCancelErrorREST"],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AAYA,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC7C,MAAM,iBAAiB,GAAG,CAAC,OAAO,KAAK;AACvC,IAAI,OAAO,OAAO,OAAO,KAAK,UAAU,CAAC;AACzC,CAAC,CAAC;AACF;AACA;AACA;AACO,MAAM,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,gBAAgB,IAAI,CAAC,MAAM,EAAE;AAC7B,oBAAoB,MAAM,IAAI,eAAe,CAAC,UAAU,CAAC,CAAC;AAC1D,iBAAiB;AACjB,gBAAgB,OAAO,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K;AACL,IAAI,iBAAiB,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,iBAAiB,GAAG,EAAE,EAAE,sBAAsB,EAAE,SAAS,EAAE;AAC1H,QAAQ,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;AACjF,QAAQ,OAAO,IAAI,CAAC,eAAe;AACnC,aAAa,SAAS,CAAC;AACvB,YAAY,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;AAC/B,YAAY,SAAS;AACrB,YAAY,sBAAsB,EAAE,MAAM,EAAE,QAAQ;AACpD,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,kBAAkB,EAAE,QAAQ,IAAI,MAAM,EAAE,eAAe;AACnE,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,iBAAiB;AAC7B,YAAY,SAAS;AACrB,YAAY,oBAAoB;AAChC,SAAS,EAAE,sBAAsB,CAAC;AAClC,aAAa,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI;AAClC,YAAY,IAAI,CAAC,CAAC,MAAM,EAAE;AAC1B,gBAAgB,MAAM,0BAA0B,CAAC,CAAC,CAAC,CAAC;AACpD,aAAa;AACb,YAAY,MAAM,CAAC,CAAC;AACpB,SAAS,CAAC,CAAC,CAAC;AACZ,KAAK;AACL,CAAC;AACW,MAAC,kBAAkB,GAAG,IAAI,uBAAuB;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
function isGraphQLResponseWithErrors(response) {
|
|
4
|
+
if (!response) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const r = response;
|
|
8
|
+
return Array.isArray(r.errors) && r.errors.length > 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { isGraphQLResponseWithErrors };
|
|
12
|
+
//# sourceMappingURL=isGraphQLResponseWithErrors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isGraphQLResponseWithErrors.mjs","sources":["../../../../../src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport function isGraphQLResponseWithErrors(response) {\n if (!response) {\n return false;\n }\n const r = response;\n return Array.isArray(r.errors) && r.errors.length > 0;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACO,SAAS,2BAA2B,CAAC,QAAQ,EAAE;AACtD,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC;AACvB,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AAC1D;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
|
|
2
|
-
import { CustomHeaders, CustomMutations, CustomQueries, CustomSubscriptions, EnumTypes, ModelTypes } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import { CustomHeaders, CustomMutations, CustomQueries, CustomSubscriptions, EnumTypes, ModelSortDirection, ModelTypes } from '@aws-amplify/data-schema-types';
|
|
3
3
|
import { DocumentNode, GraphQLError, Source } from 'graphql';
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
5
|
import { DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
@@ -338,6 +338,7 @@ export type QueryArgs = Record<string, unknown>;
|
|
|
338
338
|
export interface ListArgs extends Record<string, unknown> {
|
|
339
339
|
selectionSet?: string[];
|
|
340
340
|
filter?: Record<string, unknown>;
|
|
341
|
+
sortDirection?: ModelSortDirection;
|
|
341
342
|
headers?: CustomHeaders;
|
|
342
343
|
}
|
|
343
344
|
export interface AuthModeParams extends Record<string, unknown> {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
export declare const NO_API_KEY: AmplifyErrorParams;
|
|
3
|
+
export declare const NO_VALID_CREDENTIALS: AmplifyErrorParams;
|
|
4
|
+
export declare const NO_VALID_AUTH_TOKEN: AmplifyErrorParams;
|
|
5
|
+
export declare const NO_SIGNED_IN_USER: AmplifyErrorParams;
|
|
6
|
+
export declare const NO_AUTH_TOKEN_HEADER: AmplifyErrorParams;
|
|
7
|
+
export declare const NO_ENDPOINT: AmplifyErrorParams;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { GraphQLAuthError } from '../../types/index.mjs';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
const NO_API_KEY = {
|
|
6
|
+
name: 'NoApiKey',
|
|
7
|
+
// ideal: No API key configured.
|
|
8
|
+
message: GraphQLAuthError.NO_API_KEY,
|
|
9
|
+
recoverySuggestion: 'The API request was made with `authMode: "apiKey"` but no API Key was passed into `Amplify.configure()`. Review if your API key is passed into the `Amplify.configure()` function.',
|
|
10
|
+
};
|
|
11
|
+
const NO_VALID_CREDENTIALS = {
|
|
12
|
+
name: 'NoCredentials',
|
|
13
|
+
// ideal: No auth credentials available.
|
|
14
|
+
message: GraphQLAuthError.NO_CREDENTIALS,
|
|
15
|
+
recoverySuggestion: `The API request was made with \`authMode: "iam"\` but no authentication credentials are available.
|
|
16
|
+
|
|
17
|
+
If you intended to make a request using an authenticated role, review if your user is signed in before making the request.
|
|
18
|
+
|
|
19
|
+
If you intend to make a request using an unauthenticated role or also known as "guest access", verify if "Auth.Cognito.allowGuestAccess" is set to "true" in the \`Amplify.configure()\` function.`,
|
|
20
|
+
};
|
|
21
|
+
const NO_VALID_AUTH_TOKEN = {
|
|
22
|
+
name: 'NoValidAuthTokens',
|
|
23
|
+
// ideal: No valid JWT auth token provided to make the API request..
|
|
24
|
+
message: GraphQLAuthError.NO_FEDERATED_JWT,
|
|
25
|
+
recoverySuggestion: 'If you intended to make an authenticated API request, review if the current user is signed in.',
|
|
26
|
+
};
|
|
27
|
+
const NO_SIGNED_IN_USER = {
|
|
28
|
+
name: 'NoSignedUser',
|
|
29
|
+
// ideal: Couldn't retrieve authentication credentials to make the API request.
|
|
30
|
+
message: GraphQLAuthError.NO_CURRENT_USER,
|
|
31
|
+
recoverySuggestion: 'Review the underlying exception field for more details. If you intended to make an authenticated API request, review if the current user is signed in.',
|
|
32
|
+
};
|
|
33
|
+
const NO_AUTH_TOKEN_HEADER = {
|
|
34
|
+
name: 'NoAuthorizationHeader',
|
|
35
|
+
// ideal: Authorization header not specified.
|
|
36
|
+
message: GraphQLAuthError.NO_AUTH_TOKEN,
|
|
37
|
+
recoverySuggestion: 'The API request was made with `authMode: "lambda"` but no `authToken` is set. Review if a valid authToken is passed into the request options or in the `Amplify.configure()` function.',
|
|
38
|
+
};
|
|
39
|
+
const NO_ENDPOINT = {
|
|
40
|
+
name: 'NoEndpoint',
|
|
41
|
+
message: 'No GraphQL endpoint configured in `Amplify.configure()`.',
|
|
42
|
+
recoverySuggestion: 'Review if the GraphQL API endpoint is set in the `Amplify.configure()` function.',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { NO_API_KEY, NO_AUTH_TOKEN_HEADER, NO_ENDPOINT, NO_SIGNED_IN_USER, NO_VALID_AUTH_TOKEN, NO_VALID_CREDENTIALS };
|
|
46
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","sources":["../../../../src/utils/errors/constants.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { GraphQLAuthError } from '../../types';\nexport const NO_API_KEY = {\n name: 'NoApiKey',\n // ideal: No API key configured.\n message: GraphQLAuthError.NO_API_KEY,\n recoverySuggestion: 'The API request was made with `authMode: \"apiKey\"` but no API Key was passed into `Amplify.configure()`. Review if your API key is passed into the `Amplify.configure()` function.',\n};\nexport const NO_VALID_CREDENTIALS = {\n name: 'NoCredentials',\n // ideal: No auth credentials available.\n message: GraphQLAuthError.NO_CREDENTIALS,\n recoverySuggestion: `The API request was made with \\`authMode: \"iam\"\\` but no authentication credentials are available.\n\nIf you intended to make a request using an authenticated role, review if your user is signed in before making the request.\n\nIf you intend to make a request using an unauthenticated role or also known as \"guest access\", verify if \"Auth.Cognito.allowGuestAccess\" is set to \"true\" in the \\`Amplify.configure()\\` function.`,\n};\nexport const NO_VALID_AUTH_TOKEN = {\n name: 'NoValidAuthTokens',\n // ideal: No valid JWT auth token provided to make the API request..\n message: GraphQLAuthError.NO_FEDERATED_JWT,\n recoverySuggestion: 'If you intended to make an authenticated API request, review if the current user is signed in.',\n};\nexport const NO_SIGNED_IN_USER = {\n name: 'NoSignedUser',\n // ideal: Couldn't retrieve authentication credentials to make the API request.\n message: GraphQLAuthError.NO_CURRENT_USER,\n recoverySuggestion: 'Review the underlying exception field for more details. If you intended to make an authenticated API request, review if the current user is signed in.',\n};\nexport const NO_AUTH_TOKEN_HEADER = {\n name: 'NoAuthorizationHeader',\n // ideal: Authorization header not specified.\n message: GraphQLAuthError.NO_AUTH_TOKEN,\n recoverySuggestion: 'The API request was made with `authMode: \"lambda\"` but no `authToken` is set. Review if a valid authToken is passed into the request options or in the `Amplify.configure()` function.',\n};\nexport const NO_ENDPOINT = {\n name: 'NoEndpoint',\n message: 'No GraphQL endpoint configured in `Amplify.configure()`.',\n recoverySuggestion: 'Review if the GraphQL API endpoint is set in the `Amplify.configure()` function.',\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,UAAU,GAAG;AAC1B,IAAI,IAAI,EAAE,UAAU;AACpB;AACA,IAAI,OAAO,EAAE,gBAAgB,CAAC,UAAU;AACxC,IAAI,kBAAkB,EAAE,oLAAoL;AAC5M,EAAE;AACU,MAAC,oBAAoB,GAAG;AACpC,IAAI,IAAI,EAAE,eAAe;AACzB;AACA,IAAI,OAAO,EAAE,gBAAgB,CAAC,cAAc;AAC5C,IAAI,kBAAkB,EAAE,CAAC;AACzB;AACA;AACA;AACA,kMAAkM,CAAC;AACnM,EAAE;AACU,MAAC,mBAAmB,GAAG;AACnC,IAAI,IAAI,EAAE,mBAAmB;AAC7B;AACA,IAAI,OAAO,EAAE,gBAAgB,CAAC,gBAAgB;AAC9C,IAAI,kBAAkB,EAAE,gGAAgG;AACxH,EAAE;AACU,MAAC,iBAAiB,GAAG;AACjC,IAAI,IAAI,EAAE,cAAc;AACxB;AACA,IAAI,OAAO,EAAE,gBAAgB,CAAC,eAAe;AAC7C,IAAI,kBAAkB,EAAE,wJAAwJ;AAChL,EAAE;AACU,MAAC,oBAAoB,GAAG;AACpC,IAAI,IAAI,EAAE,uBAAuB;AACjC;AACA,IAAI,OAAO,EAAE,gBAAgB,CAAC,aAAa;AAC3C,IAAI,kBAAkB,EAAE,wLAAwL;AAChN,EAAE;AACU,MAAC,WAAW,GAAG;AAC3B,IAAI,IAAI,EAAE,YAAY;AACtB,IAAI,OAAO,EAAE,0DAA0D;AACvE,IAAI,kBAAkB,EAAE,kFAAkF;AAC1G;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
const createGraphQLResultWithError = (error) => {
|
|
6
|
+
return {
|
|
7
|
+
data: {},
|
|
8
|
+
errors: [new GraphQLError(error.message, null, null, null, null, error)],
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { createGraphQLResultWithError };
|
|
13
|
+
//# sourceMappingURL=createGraphQLResultWithError.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGraphQLResultWithError.mjs","sources":["../../../../src/utils/errors/createGraphQLResultWithError.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { GraphQLError } from 'graphql';\nexport const createGraphQLResultWithError = (error) => {\n return {\n data: {},\n errors: [new GraphQLError(error.message, null, null, null, null, error)],\n };\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,4BAA4B,GAAG,CAAC,KAAK,KAAK;AACvD,IAAI,OAAO;AACX,QAAQ,IAAI,EAAE,EAAE;AAChB,QAAQ,MAAM,EAAE,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AAChF,KAAK,CAAC;AACN;;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { GraphQLApiError } from './GraphQLApiError';
|
|
2
2
|
export { assertValidationError } from './assertValidationError';
|
|
3
3
|
export { APIValidationErrorCode, validationErrorMap } from './validation';
|
|
4
|
+
export { createGraphQLResultWithError } from './createGraphQLResultWithError';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { GraphQLApiError } from './GraphQLApiError.mjs';
|
|
2
2
|
export { assertValidationError } from './assertValidationError.mjs';
|
|
3
3
|
export { APIValidationErrorCode, validationErrorMap } from './validation.mjs';
|
|
4
|
+
export { createGraphQLResultWithError } from './createGraphQLResultWithError.mjs';
|
|
4
5
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
interface ErrorObject {
|
|
3
|
-
errors: AmplifyErrorParams[];
|
|
4
|
-
}
|
|
1
|
+
import { GraphQLResult } from '../../types';
|
|
5
2
|
/**
|
|
6
3
|
* Checks to see if the given response or subscription message contains an
|
|
7
|
-
*
|
|
4
|
+
* Unauthorized error. If it does, it changes the error message to include instructions
|
|
8
5
|
* for the app developer.
|
|
9
6
|
*/
|
|
10
|
-
export declare function
|
|
11
|
-
export {};
|
|
7
|
+
export declare function repackageUnauthorizedError<T extends GraphQLResult<any>>(content: T): T;
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
/**
|
|
4
4
|
* Checks to see if the given response or subscription message contains an
|
|
5
|
-
*
|
|
5
|
+
* Unauthorized error. If it does, it changes the error message to include instructions
|
|
6
6
|
* for the app developer.
|
|
7
7
|
*/
|
|
8
|
-
function
|
|
8
|
+
function repackageUnauthorizedError(content) {
|
|
9
9
|
if (content.errors && Array.isArray(content.errors)) {
|
|
10
10
|
content.errors.forEach(e => {
|
|
11
|
-
if (
|
|
11
|
+
if (isUnauthorizedError(e)) {
|
|
12
12
|
e.message = 'Unauthorized';
|
|
13
13
|
e.recoverySuggestion =
|
|
14
14
|
`If you're calling an Amplify-generated API, make sure ` +
|
|
@@ -19,7 +19,7 @@ function repackageUnauthError(content) {
|
|
|
19
19
|
}
|
|
20
20
|
return content;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function isUnauthorizedError(error) {
|
|
23
23
|
// Error pattern corresponding to appsync calls
|
|
24
24
|
if (error?.originalError?.name?.startsWith('UnauthorizedException')) {
|
|
25
25
|
return true;
|
|
@@ -32,5 +32,5 @@ function isUnauthError(error) {
|
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export {
|
|
35
|
+
export { repackageUnauthorizedError };
|
|
36
36
|
//# sourceMappingURL=repackageAuthError.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repackageAuthError.mjs","sources":["../../../../src/utils/errors/repackageAuthError.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Checks to see if the given response or subscription message contains an\n *
|
|
1
|
+
{"version":3,"file":"repackageAuthError.mjs","sources":["../../../../src/utils/errors/repackageAuthError.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Checks to see if the given response or subscription message contains an\n * Unauthorized error. If it does, it changes the error message to include instructions\n * for the app developer.\n */\nexport function repackageUnauthorizedError(content) {\n if (content.errors && Array.isArray(content.errors)) {\n content.errors.forEach(e => {\n if (isUnauthorizedError(e)) {\n e.message = 'Unauthorized';\n e.recoverySuggestion =\n `If you're calling an Amplify-generated API, make sure ` +\n `to set the \"authMode\" in generateClient({ authMode: '...' }) to the backend authorization ` +\n `rule's auth provider ('apiKey', 'userPool', 'iam', 'oidc', 'lambda')`;\n }\n });\n }\n return content;\n}\nfunction isUnauthorizedError(error) {\n // Error pattern corresponding to appsync calls\n if (error?.originalError?.name?.startsWith('UnauthorizedException')) {\n return true;\n }\n // Error pattern corresponding to appsync subscriptions\n if (error.message?.startsWith('Connection failed:') &&\n error.message?.includes('Permission denied')) {\n return true;\n }\n return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,0BAA0B,CAAC,OAAO,EAAE;AACpD,IAAI,IAAI,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;AACzD,QAAQ,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI;AACpC,YAAY,IAAI,mBAAmB,CAAC,CAAC,CAAC,EAAE;AACxC,gBAAgB,CAAC,CAAC,OAAO,GAAG,cAAc,CAAC;AAC3C,gBAAgB,CAAC,CAAC,kBAAkB;AACpC,oBAAoB,CAAC,sDAAsD,CAAC;AAC5E,wBAAwB,CAAC,0FAA0F,CAAC;AACpH,wBAAwB,CAAC,oEAAoE,CAAC,CAAC;AAC/F,aAAa;AACb,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,OAAO,CAAC;AACnB,CAAC;AACD,SAAS,mBAAmB,CAAC,KAAK,EAAE;AACpC;AACA,IAAI,IAAI,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,CAAC,uBAAuB,CAAC,EAAE;AACzE,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL;AACA,IAAI,IAAI,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,oBAAoB,CAAC;AACvD,QAAQ,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAAE;AACtD,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB;;;;"}
|
|
@@ -2,6 +2,7 @@ import { ConsoleLogger } from '@aws-amplify/core';
|
|
|
2
2
|
import '@aws-amplify/core/internals/utils';
|
|
3
3
|
import { assertValidationError } from './errors/assertValidationError.mjs';
|
|
4
4
|
import { APIValidationErrorCode } from './errors/validation.mjs';
|
|
5
|
+
import 'graphql';
|
|
5
6
|
|
|
6
7
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
7
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveConfig.mjs","sources":["../../../src/utils/resolveConfig.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger } from '@aws-amplify/core';\nimport { APIValidationErrorCode, assertValidationError } from './errors';\nconst logger = new ConsoleLogger('GraphQLAPI resolveConfig');\n/**\n * @internal\n */\nexport const resolveConfig = (amplify) => {\n const config = amplify.getConfig();\n if (!config.API?.GraphQL) {\n logger.warn('The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().');\n }\n const { apiKey, customEndpoint, customEndpointRegion, defaultAuthMode, endpoint, region, } = config.API?.GraphQL ?? {};\n // TODO: re-enable when working in all test environments:\n // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);\n assertValidationError(!(!customEndpoint && customEndpointRegion), APIValidationErrorCode.NoCustomEndpoint);\n return {\n apiKey,\n customEndpoint,\n customEndpointRegion,\n defaultAuthMode,\n endpoint,\n region,\n };\n};\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolveConfig.mjs","sources":["../../../src/utils/resolveConfig.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger } from '@aws-amplify/core';\nimport { APIValidationErrorCode, assertValidationError } from './errors';\nconst logger = new ConsoleLogger('GraphQLAPI resolveConfig');\n/**\n * @internal\n */\nexport const resolveConfig = (amplify) => {\n const config = amplify.getConfig();\n if (!config.API?.GraphQL) {\n logger.warn('The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().');\n }\n const { apiKey, customEndpoint, customEndpointRegion, defaultAuthMode, endpoint, region, } = config.API?.GraphQL ?? {};\n // TODO: re-enable when working in all test environments:\n // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);\n assertValidationError(!(!customEndpoint && customEndpointRegion), APIValidationErrorCode.NoCustomEndpoint);\n return {\n apiKey,\n customEndpoint,\n customEndpointRegion,\n defaultAuthMode,\n endpoint,\n region,\n };\n};\n"],"names":[],"mappings":";;;;;;AAAA;AACA;AAGA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,0BAA0B,CAAC,CAAC;AAC7D;AACA;AACA;AACY,MAAC,aAAa,GAAG,CAAC,OAAO,KAAK;AAC1C,IAAI,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;AACvC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE;AAC9B,QAAQ,MAAM,CAAC,IAAI,CAAC,yHAAyH,CAAC,CAAC;AAC/I,KAAK;AACL,IAAI,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,oBAAoB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,EAAE,OAAO,IAAI,EAAE,CAAC;AAC3H;AACA;AACA,IAAI,qBAAqB,CAAC,EAAE,CAAC,cAAc,IAAI,oBAAoB,CAAC,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;AAC/G,IAAI,OAAO;AACX,QAAQ,MAAM;AACd,QAAQ,cAAc;AACtB,QAAQ,oBAAoB;AAC5B,QAAQ,eAAe;AACvB,QAAQ,QAAQ;AAChB,QAAQ,MAAM;AACd,KAAK,CAAC;AACN;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api-graphql",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.27",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -85,9 +85,9 @@
|
|
|
85
85
|
"server"
|
|
86
86
|
],
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@aws-amplify/api-rest": "4.0.
|
|
89
|
-
"@aws-amplify/core": "6.0.
|
|
90
|
-
"@aws-amplify/data-schema-types": "^0.7.
|
|
88
|
+
"@aws-amplify/api-rest": "4.0.27",
|
|
89
|
+
"@aws-amplify/core": "6.0.27",
|
|
90
|
+
"@aws-amplify/data-schema-types": "^0.7.14",
|
|
91
91
|
"@aws-sdk/types": "3.387.0",
|
|
92
92
|
"graphql": "15.8.0",
|
|
93
93
|
"rxjs": "^7.8.1",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"limit": "91.7 kB"
|
|
103
103
|
}
|
|
104
104
|
],
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "39ac7cccb432a3e920e1ed0378bf5fd1cc50c47a"
|
|
106
106
|
}
|
|
@@ -732,6 +732,16 @@ export function generateGraphQLDocument(
|
|
|
732
732
|
graphQLArguments ??
|
|
733
733
|
(graphQLArguments = {
|
|
734
734
|
filter: `Model${name}FilterInput`,
|
|
735
|
+
...(sortKeyFieldNames.length > 0
|
|
736
|
+
? [primaryKeyFieldName, ...sortKeyFieldNames].reduce(
|
|
737
|
+
(acc: Record<string, any>, fieldName) => {
|
|
738
|
+
acc[fieldName] = `${fields[fieldName].type}`;
|
|
739
|
+
|
|
740
|
+
return acc;
|
|
741
|
+
},
|
|
742
|
+
{ sortDirection: 'ModelSortDirection' },
|
|
743
|
+
)
|
|
744
|
+
: []),
|
|
735
745
|
limit: 'Int',
|
|
736
746
|
nextToken: 'String',
|
|
737
747
|
});
|
|
@@ -745,6 +755,7 @@ export function generateGraphQLDocument(
|
|
|
745
755
|
(graphQLArguments = {
|
|
746
756
|
...indexQueryArgs!,
|
|
747
757
|
filter: `Model${name}FilterInput`,
|
|
758
|
+
sortDirection: 'ModelSortDirection',
|
|
748
759
|
limit: 'Int',
|
|
749
760
|
nextToken: 'String',
|
|
750
761
|
});
|
|
@@ -858,6 +869,10 @@ export function buildGraphQLVariables(
|
|
|
858
869
|
if (arg?.filter) {
|
|
859
870
|
variables.filter = arg.filter;
|
|
860
871
|
}
|
|
872
|
+
if (arg?.sortDirection) {
|
|
873
|
+
variables.sortDirection = arg.sortDirection;
|
|
874
|
+
variables[primaryKeyFieldName] = arg[primaryKeyFieldName];
|
|
875
|
+
}
|
|
861
876
|
if (arg?.nextToken) {
|
|
862
877
|
variables.nextToken = arg.nextToken;
|
|
863
878
|
}
|
|
@@ -877,6 +892,11 @@ export function buildGraphQLVariables(
|
|
|
877
892
|
if (arg?.filter) {
|
|
878
893
|
variables.filter = arg.filter;
|
|
879
894
|
}
|
|
895
|
+
|
|
896
|
+
if (arg?.sortDirection) {
|
|
897
|
+
variables.sortDirection = arg.sortDirection;
|
|
898
|
+
}
|
|
899
|
+
|
|
880
900
|
if (arg?.nextToken) {
|
|
881
901
|
variables.nextToken = arg.nextToken;
|
|
882
902
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import {
|
|
4
4
|
DocumentNode,
|
|
5
|
-
GraphQLError,
|
|
6
5
|
OperationDefinitionNode,
|
|
7
6
|
OperationTypeNode,
|
|
8
7
|
parse,
|
|
@@ -25,14 +24,20 @@ import {
|
|
|
25
24
|
import { CustomHeaders, RequestOptions } from '@aws-amplify/data-schema-types';
|
|
26
25
|
|
|
27
26
|
import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
|
|
28
|
-
import {
|
|
29
|
-
GraphQLAuthError,
|
|
30
|
-
GraphQLOperation,
|
|
31
|
-
GraphQLOptions,
|
|
32
|
-
GraphQLResult,
|
|
33
|
-
} from '../types';
|
|
27
|
+
import { GraphQLOperation, GraphQLOptions, GraphQLResult } from '../types';
|
|
34
28
|
import { resolveConfig, resolveLibraryOptions } from '../utils';
|
|
35
|
-
import {
|
|
29
|
+
import { repackageUnauthorizedError } from '../utils/errors/repackageAuthError';
|
|
30
|
+
import {
|
|
31
|
+
NO_API_KEY,
|
|
32
|
+
NO_AUTH_TOKEN_HEADER,
|
|
33
|
+
NO_ENDPOINT,
|
|
34
|
+
NO_SIGNED_IN_USER,
|
|
35
|
+
NO_VALID_AUTH_TOKEN,
|
|
36
|
+
NO_VALID_CREDENTIALS,
|
|
37
|
+
} from '../utils/errors/constants';
|
|
38
|
+
import { GraphQLApiError, createGraphQLResultWithError } from '../utils/errors';
|
|
39
|
+
|
|
40
|
+
import { isGraphQLResponseWithErrors } from './utils/runtimeTypeGuards/isGraphQLResponseWithErrors';
|
|
36
41
|
|
|
37
42
|
const USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
38
43
|
|
|
@@ -76,7 +81,7 @@ export class InternalGraphQLAPIClass {
|
|
|
76
81
|
switch (authMode) {
|
|
77
82
|
case 'apiKey':
|
|
78
83
|
if (!apiKey) {
|
|
79
|
-
throw new
|
|
84
|
+
throw new GraphQLApiError(NO_API_KEY);
|
|
80
85
|
}
|
|
81
86
|
headers = {
|
|
82
87
|
'X-Api-Key': apiKey,
|
|
@@ -85,33 +90,44 @@ export class InternalGraphQLAPIClass {
|
|
|
85
90
|
case 'iam': {
|
|
86
91
|
const session = await amplify.Auth.fetchAuthSession();
|
|
87
92
|
if (session.credentials === undefined) {
|
|
88
|
-
throw new
|
|
93
|
+
throw new GraphQLApiError(NO_VALID_CREDENTIALS);
|
|
89
94
|
}
|
|
90
95
|
break;
|
|
91
96
|
}
|
|
92
97
|
case 'oidc':
|
|
93
|
-
case 'userPool':
|
|
98
|
+
case 'userPool': {
|
|
99
|
+
let token: string | undefined;
|
|
100
|
+
|
|
94
101
|
try {
|
|
95
|
-
|
|
102
|
+
token = (
|
|
96
103
|
await amplify.Auth.fetchAuthSession()
|
|
97
104
|
).tokens?.accessToken.toString();
|
|
98
|
-
|
|
99
|
-
if (!token) {
|
|
100
|
-
throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);
|
|
101
|
-
}
|
|
102
|
-
headers = {
|
|
103
|
-
Authorization: token,
|
|
104
|
-
};
|
|
105
105
|
} catch (e) {
|
|
106
|
-
|
|
106
|
+
// fetchAuthSession failed
|
|
107
|
+
throw new GraphQLApiError({
|
|
108
|
+
...NO_SIGNED_IN_USER,
|
|
109
|
+
underlyingError: e,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// `fetchAuthSession()` succeeded but didn't return `tokens`.
|
|
114
|
+
// This may happen when unauthenticated access is enabled and there is
|
|
115
|
+
// no user signed in.
|
|
116
|
+
if (!token) {
|
|
117
|
+
throw new GraphQLApiError(NO_VALID_AUTH_TOKEN);
|
|
107
118
|
}
|
|
119
|
+
|
|
120
|
+
headers = {
|
|
121
|
+
Authorization: token,
|
|
122
|
+
};
|
|
108
123
|
break;
|
|
124
|
+
}
|
|
109
125
|
case 'lambda':
|
|
110
126
|
if (
|
|
111
127
|
typeof additionalHeaders === 'object' &&
|
|
112
128
|
!additionalHeaders.Authorization
|
|
113
129
|
) {
|
|
114
|
-
throw new
|
|
130
|
+
throw new GraphQLApiError(NO_AUTH_TOKEN_HEADER);
|
|
115
131
|
}
|
|
116
132
|
|
|
117
133
|
headers = {
|
|
@@ -350,18 +366,15 @@ export class InternalGraphQLAPIClass {
|
|
|
350
366
|
const endpoint = customEndpoint || appSyncGraphqlEndpoint;
|
|
351
367
|
|
|
352
368
|
if (!endpoint) {
|
|
353
|
-
|
|
354
|
-
// TODO(Eslint): refactor this to throw an Error instead of a plain object
|
|
355
|
-
// eslint-disable-next-line no-throw-literal
|
|
356
|
-
throw {
|
|
357
|
-
data: {},
|
|
358
|
-
errors: [error],
|
|
359
|
-
};
|
|
369
|
+
throw createGraphQLResultWithError<T>(new GraphQLApiError(NO_ENDPOINT));
|
|
360
370
|
}
|
|
361
371
|
|
|
362
372
|
let response: any;
|
|
363
373
|
|
|
364
374
|
try {
|
|
375
|
+
// See the inline doc of the REST `post()` API for possible errors to be thrown.
|
|
376
|
+
// As these errors are catastrophic they should be caught and handled by GraphQL
|
|
377
|
+
// API consumers.
|
|
365
378
|
const { body: responseBody } = await this._api.post(amplify, {
|
|
366
379
|
url: new AmplifyUrl(endpoint),
|
|
367
380
|
options: {
|
|
@@ -373,39 +386,20 @@ export class InternalGraphQLAPIClass {
|
|
|
373
386
|
abortController,
|
|
374
387
|
});
|
|
375
388
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
// If the exception is because user intentionally
|
|
381
|
-
// cancelled the request, do not modify the exception
|
|
382
|
-
// so that clients can identify the exception correctly.
|
|
383
|
-
if (this.isCancelError(err)) {
|
|
384
|
-
throw err;
|
|
389
|
+
response = await responseBody.json();
|
|
390
|
+
} catch (error) {
|
|
391
|
+
if (this.isCancelError(error)) {
|
|
392
|
+
throw error;
|
|
385
393
|
}
|
|
386
394
|
|
|
387
|
-
response =
|
|
388
|
-
data: {},
|
|
389
|
-
errors: [
|
|
390
|
-
new GraphQLError(
|
|
391
|
-
(err as any).message,
|
|
392
|
-
null,
|
|
393
|
-
null,
|
|
394
|
-
null,
|
|
395
|
-
null,
|
|
396
|
-
err as any,
|
|
397
|
-
),
|
|
398
|
-
],
|
|
399
|
-
};
|
|
395
|
+
response = createGraphQLResultWithError<T>(error as any);
|
|
400
396
|
}
|
|
401
397
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
if (errors && errors.length) {
|
|
405
|
-
throw repackageUnauthError(response);
|
|
398
|
+
if (isGraphQLResponseWithErrors(response)) {
|
|
399
|
+
throw repackageUnauthorizedError(response);
|
|
406
400
|
}
|
|
407
401
|
|
|
408
|
-
return response
|
|
402
|
+
return response as unknown as GraphQLResult<T>;
|
|
409
403
|
}
|
|
410
404
|
|
|
411
405
|
/**
|
|
@@ -463,7 +457,7 @@ export class InternalGraphQLAPIClass {
|
|
|
463
457
|
.pipe(
|
|
464
458
|
catchError(e => {
|
|
465
459
|
if (e.errors) {
|
|
466
|
-
throw
|
|
460
|
+
throw repackageUnauthorizedError(e);
|
|
467
461
|
}
|
|
468
462
|
throw e;
|
|
469
463
|
}),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { GraphQLResult } from '../../../types';
|
|
5
|
+
|
|
6
|
+
export function isGraphQLResponseWithErrors(
|
|
7
|
+
response: unknown,
|
|
8
|
+
): response is GraphQLResult {
|
|
9
|
+
if (!response) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const r = response as GraphQLResult;
|
|
13
|
+
|
|
14
|
+
return Array.isArray(r.errors) && r.errors.length > 0;
|
|
15
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
CustomQueries,
|
|
8
8
|
CustomSubscriptions,
|
|
9
9
|
EnumTypes,
|
|
10
|
+
ModelSortDirection,
|
|
10
11
|
ModelTypes,
|
|
11
12
|
} from '@aws-amplify/data-schema-types';
|
|
12
13
|
import { DocumentNode, GraphQLError, Source } from 'graphql';
|
|
@@ -464,6 +465,7 @@ export type QueryArgs = Record<string, unknown>;
|
|
|
464
465
|
export interface ListArgs extends Record<string, unknown> {
|
|
465
466
|
selectionSet?: string[];
|
|
466
467
|
filter?: Record<string, unknown>;
|
|
468
|
+
sortDirection?: ModelSortDirection;
|
|
467
469
|
headers?: CustomHeaders;
|
|
468
470
|
}
|
|
469
471
|
|