@aws-amplify/api-graphql 4.0.23 → 4.0.24-unstable.873a6f4.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.
Files changed (50) hide show
  1. package/dist/cjs/internals/APIClient.js +13 -0
  2. package/dist/cjs/internals/APIClient.js.map +1 -1
  3. package/dist/cjs/internals/InternalGraphQLAPI.js +36 -38
  4. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
  5. package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js +15 -0
  6. package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js.map +1 -0
  7. package/dist/cjs/utils/errors/constants.js +47 -0
  8. package/dist/cjs/utils/errors/constants.js.map +1 -0
  9. package/dist/cjs/utils/errors/createGraphQLResultWithError.js +15 -0
  10. package/dist/cjs/utils/errors/createGraphQLResultWithError.js.map +1 -0
  11. package/dist/cjs/utils/errors/index.js +3 -1
  12. package/dist/cjs/utils/errors/index.js.map +1 -1
  13. package/dist/cjs/utils/errors/repackageAuthError.js +6 -6
  14. package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -1
  15. package/dist/cjs/utils/resolveOwnerFields.js +4 -1
  16. package/dist/cjs/utils/resolveOwnerFields.js.map +1 -1
  17. package/dist/esm/internals/APIClient.mjs +13 -0
  18. package/dist/esm/internals/APIClient.mjs.map +1 -1
  19. package/dist/esm/internals/InternalGraphQLAPI.mjs +40 -40
  20. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  21. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.d.ts +2 -0
  22. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs +12 -0
  23. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs.map +1 -0
  24. package/dist/esm/types/index.d.ts +2 -1
  25. package/dist/esm/utils/errors/constants.d.ts +7 -0
  26. package/dist/esm/utils/errors/constants.mjs +46 -0
  27. package/dist/esm/utils/errors/constants.mjs.map +1 -0
  28. package/dist/esm/utils/errors/createGraphQLResultWithError.d.ts +2 -0
  29. package/dist/esm/utils/errors/createGraphQLResultWithError.mjs +13 -0
  30. package/dist/esm/utils/errors/createGraphQLResultWithError.mjs.map +1 -0
  31. package/dist/esm/utils/errors/index.d.ts +1 -0
  32. package/dist/esm/utils/errors/index.mjs +1 -0
  33. package/dist/esm/utils/errors/index.mjs.map +1 -1
  34. package/dist/esm/utils/errors/repackageAuthError.d.ts +3 -7
  35. package/dist/esm/utils/errors/repackageAuthError.mjs +5 -5
  36. package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -1
  37. package/dist/esm/utils/resolveConfig.mjs +1 -0
  38. package/dist/esm/utils/resolveConfig.mjs.map +1 -1
  39. package/dist/esm/utils/resolveOwnerFields.mjs +4 -1
  40. package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -1
  41. package/package.json +5 -5
  42. package/src/internals/APIClient.ts +19 -0
  43. package/src/internals/InternalGraphQLAPI.ts +50 -56
  44. package/src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts +15 -0
  45. package/src/types/index.ts +2 -0
  46. package/src/utils/errors/constants.ts +56 -0
  47. package/src/utils/errors/createGraphQLResultWithError.ts +15 -0
  48. package/src/utils/errors/index.ts +1 -0
  49. package/src/utils/errors/repackageAuthError.ts +8 -10
  50. package/src/utils/resolveOwnerFields.ts +4 -1
@@ -1,13 +1,17 @@
1
- import { parse, print, GraphQLError } from 'graphql';
1
+ import { parse, print } from 'graphql';
2
2
  import { catchError } from 'rxjs';
3
3
  import { AmplifyUrl, getAmplifyUserAgent } from '@aws-amplify/core/internals/utils';
4
4
  import { isCancelError } from '@aws-amplify/api-rest';
5
5
  import { post, cancel, updateRequestToBeCancellable } from '@aws-amplify/api-rest/internals';
6
6
  import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider/index.mjs';
7
- import { GraphQLAuthError } from '../types/index.mjs';
8
7
  import { resolveConfig } from '../utils/resolveConfig.mjs';
9
8
  import { resolveLibraryOptions } from '../utils/resolveLibraryOptions.mjs';
10
- import { repackageUnauthError } from '../utils/errors/repackageAuthError.mjs';
9
+ import { repackageUnauthorizedError } from '../utils/errors/repackageAuthError.mjs';
10
+ import { NO_AUTH_TOKEN_HEADER, NO_SIGNED_IN_USER, NO_VALID_AUTH_TOKEN, NO_VALID_CREDENTIALS, NO_API_KEY, NO_ENDPOINT } from '../utils/errors/constants.mjs';
11
+ import { GraphQLApiError } from '../utils/errors/GraphQLApiError.mjs';
12
+ import '../utils/errors/validation.mjs';
13
+ import { createGraphQLResultWithError } from '../utils/errors/createGraphQLResultWithError.mjs';
14
+ import { isGraphQLResponseWithErrors } from './utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs';
11
15
 
12
16
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
13
17
  // SPDX-License-Identifier: Apache-2.0
@@ -40,7 +44,7 @@ class InternalGraphQLAPIClass {
40
44
  switch (authMode) {
41
45
  case 'apiKey':
42
46
  if (!apiKey) {
43
- throw new Error(GraphQLAuthError.NO_API_KEY);
47
+ throw new GraphQLApiError(NO_API_KEY);
44
48
  }
45
49
  headers = {
46
50
  'X-Api-Key': apiKey,
@@ -49,29 +53,38 @@ class InternalGraphQLAPIClass {
49
53
  case 'iam': {
50
54
  const session = await amplify.Auth.fetchAuthSession();
51
55
  if (session.credentials === undefined) {
52
- throw new Error(GraphQLAuthError.NO_CREDENTIALS);
56
+ throw new GraphQLApiError(NO_VALID_CREDENTIALS);
53
57
  }
54
58
  break;
55
59
  }
56
60
  case 'oidc':
57
- case 'userPool':
61
+ case 'userPool': {
62
+ let token;
58
63
  try {
59
- const token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();
60
- if (!token) {
61
- throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);
62
- }
63
- headers = {
64
- Authorization: token,
65
- };
64
+ token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();
66
65
  }
67
66
  catch (e) {
68
- throw new Error(GraphQLAuthError.NO_CURRENT_USER);
67
+ // fetchAuthSession failed
68
+ throw new GraphQLApiError({
69
+ ...NO_SIGNED_IN_USER,
70
+ underlyingError: e,
71
+ });
72
+ }
73
+ // `fetchAuthSession()` succeeded but didn't return `tokens`.
74
+ // This may happen when unauthenticated access is enabled and there is
75
+ // no user signed in.
76
+ if (!token) {
77
+ throw new GraphQLApiError(NO_VALID_AUTH_TOKEN);
69
78
  }
79
+ headers = {
80
+ Authorization: token,
81
+ };
70
82
  break;
83
+ }
71
84
  case 'lambda':
72
85
  if (typeof additionalHeaders === 'object' &&
73
86
  !additionalHeaders.Authorization) {
74
- throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);
87
+ throw new GraphQLApiError(NO_AUTH_TOKEN_HEADER);
75
88
  }
76
89
  headers = {
77
90
  Authorization: additionalHeaders.Authorization,
@@ -220,16 +233,13 @@ class InternalGraphQLAPIClass {
220
233
  }
221
234
  const endpoint = customEndpoint || appSyncGraphqlEndpoint;
222
235
  if (!endpoint) {
223
- const error = new GraphQLError('No graphql endpoint provided.');
224
- // TODO(Eslint): refactor this to throw an Error instead of a plain object
225
- // eslint-disable-next-line no-throw-literal
226
- throw {
227
- data: {},
228
- errors: [error],
229
- };
236
+ throw createGraphQLResultWithError(new GraphQLApiError(NO_ENDPOINT));
230
237
  }
231
238
  let response;
232
239
  try {
240
+ // See the inline doc of the REST `post()` API for possible errors to be thrown.
241
+ // As these errors are catastrophic they should be caught and handled by GraphQL
242
+ // API consumers.
233
243
  const { body: responseBody } = await this._api.post(amplify, {
234
244
  url: new AmplifyUrl(endpoint),
235
245
  options: {
@@ -240,26 +250,16 @@ class InternalGraphQLAPIClass {
240
250
  },
241
251
  abortController,
242
252
  });
243
- const result = await responseBody.json();
244
- response = result;
253
+ response = await responseBody.json();
245
254
  }
246
- catch (err) {
247
- // If the exception is because user intentionally
248
- // cancelled the request, do not modify the exception
249
- // so that clients can identify the exception correctly.
250
- if (this.isCancelError(err)) {
251
- throw err;
255
+ catch (error) {
256
+ if (this.isCancelError(error)) {
257
+ throw error;
252
258
  }
253
- response = {
254
- data: {},
255
- errors: [
256
- new GraphQLError(err.message, null, null, null, null, err),
257
- ],
258
- };
259
+ response = createGraphQLResultWithError(error);
259
260
  }
260
- const { errors } = response;
261
- if (errors && errors.length) {
262
- throw repackageUnauthError(response);
261
+ if (isGraphQLResponseWithErrors(response)) {
262
+ throw repackageUnauthorizedError(response);
263
263
  }
264
264
  return response;
265
265
  }
@@ -304,7 +304,7 @@ class InternalGraphQLAPIClass {
304
304
  }, customUserAgentDetails)
305
305
  .pipe(catchError(e => {
306
306
  if (e.errors) {
307
- throw repackageUnauthError(e);
307
+ throw repackageUnauthorizedError(e);
308
308
  }
309
309
  throw e;
310
310
  }));
@@ -1 +1 @@
1
- {"version":3,"file":"InternalGraphQLAPI.mjs","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { 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;AACF;AACA;AACA;AACO,MAAM,uBAAuB,CAAC;AACrC,IAAI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;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,GAAG;AAC1B,oBAAoB,WAAW,EAAE,MAAM;AACvC,iBAAiB,CAA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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,2 @@
1
+ import { GraphQLResult } from '../../../types';
2
+ export declare function isGraphQLResponseWithErrors(response: unknown): response is GraphQLResult;
@@ -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,2 @@
1
+ import { GraphQLResult } from '../../types';
2
+ export declare const createGraphQLResultWithError: <T>(error: Error) => GraphQLResult<T>;
@@ -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 { AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
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
- * unauth error. If it does, it changes the error message to include instructions
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 repackageUnauthError<T extends ErrorObject>(content: T): T;
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
- * unauth error. If it does, it changes the error message to include instructions
5
+ * Unauthorized error. If it does, it changes the error message to include instructions
6
6
  * for the app developer.
7
7
  */
8
- function repackageUnauthError(content) {
8
+ function repackageUnauthorizedError(content) {
9
9
  if (content.errors && Array.isArray(content.errors)) {
10
10
  content.errors.forEach(e => {
11
- if (isUnauthError(e)) {
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 isUnauthError(error) {
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 { repackageUnauthError };
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 * unauth error. If it does, it changes the error message to include instructions\n * for the app developer.\n */\nexport function repackageUnauthError(content) {\n if (content.errors && Array.isArray(content.errors)) {\n content.errors.forEach(e => {\n if (isUnauthError(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 isUnauthError(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,oBAAoB,CAAC,OAAO,EAAE;AAC9C,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,aAAa,CAAC,CAAC,CAAC,EAAE;AAClC,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,aAAa,CAAC,KAAK,EAAE;AAC9B;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;;;;"}
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":";;;;;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;;;;"}
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;;;;"}
@@ -12,7 +12,10 @@ function resolveOwnerFields(model) {
12
12
  if (rule.allow === 'owner') {
13
13
  ownerFields.add(rule.ownerField || 'owner');
14
14
  }
15
- else if (rule.allow === 'groups') {
15
+ else if (rule.allow === 'groups' && rule.groupsField !== undefined) {
16
+ // only valid for dynamic group(s)
17
+ // static group auth will have an array of predefined groups in the attribute, groups: string[]
18
+ // but `groupsField` will be undefined
16
19
  ownerFields.add(rule.groupsField);
17
20
  }
18
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolveOwnerFields.mjs","sources":["../../../src/utils/resolveOwnerFields.ts"],"sourcesContent":["/**\n * Given an introspection schema model, returns all owner fields.\n *\n * @param model Model from an introspection schema\n * @returns List of owner field names\n */\nexport function resolveOwnerFields(model) {\n const ownerFields = new Set();\n for (const attr of model.attributes || []) {\n if (isAuthAttribute(attr)) {\n for (const rule of attr.properties.rules) {\n if (rule.allow === 'owner') {\n ownerFields.add(rule.ownerField || 'owner');\n }\n else if (rule.allow === 'groups') {\n ownerFields.add(rule.groupsField);\n }\n }\n }\n }\n return Array.from(ownerFields);\n}\n/**\n * Type guard that identifies an auth attribute with an attached rules list that\n * specifies an `allow` attribute at a minimum.\n *\n * @param attribute Any object. Ideally a model introspection schema model attribute\n * @returns True if given object is an auth attribute\n */\nfunction isAuthAttribute(attribute) {\n if (attribute?.type === 'auth') {\n if (typeof attribute?.properties === 'object') {\n if (Array.isArray(attribute?.properties?.rules)) {\n return (attribute?.properties?.rules).every(rule => !!rule.allow);\n }\n }\n }\n return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,KAAK,EAAE;AAC1C,IAAI,MAAM,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;AAClC,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE;AAC/C,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;AACnC,YAAY,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;AACtD,gBAAgB,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;AAC5C,oBAAoB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,OAAO,CAAC,CAAC;AAChE,iBAAiB;AACjB,qBAAqB,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE;AAClD,oBAAoB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACtD,iBAAiB;AACjB,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,CAAC,SAAS,EAAE;AACpC,IAAI,IAAI,SAAS,EAAE,IAAI,KAAK,MAAM,EAAE;AACpC,QAAQ,IAAI,OAAO,SAAS,EAAE,UAAU,KAAK,QAAQ,EAAE;AACvD,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE;AAC7D,gBAAgB,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClF,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB;;;;"}
1
+ {"version":3,"file":"resolveOwnerFields.mjs","sources":["../../../src/utils/resolveOwnerFields.ts"],"sourcesContent":["/**\n * Given an introspection schema model, returns all owner fields.\n *\n * @param model Model from an introspection schema\n * @returns List of owner field names\n */\nexport function resolveOwnerFields(model) {\n const ownerFields = new Set();\n for (const attr of model.attributes || []) {\n if (isAuthAttribute(attr)) {\n for (const rule of attr.properties.rules) {\n if (rule.allow === 'owner') {\n ownerFields.add(rule.ownerField || 'owner');\n }\n else if (rule.allow === 'groups' && rule.groupsField !== undefined) {\n // only valid for dynamic group(s)\n // static group auth will have an array of predefined groups in the attribute, groups: string[]\n // but `groupsField` will be undefined\n ownerFields.add(rule.groupsField);\n }\n }\n }\n }\n return Array.from(ownerFields);\n}\n/**\n * Type guard that identifies an auth attribute with an attached rules list that\n * specifies an `allow` attribute at a minimum.\n *\n * @param attribute Any object. Ideally a model introspection schema model attribute\n * @returns True if given object is an auth attribute\n */\nfunction isAuthAttribute(attribute) {\n if (attribute?.type === 'auth') {\n if (typeof attribute?.properties === 'object') {\n if (Array.isArray(attribute?.properties?.rules)) {\n return (attribute?.properties?.rules).every(rule => !!rule.allow);\n }\n }\n }\n return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;A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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/api-graphql",
3
- "version": "4.0.23",
3
+ "version": "4.0.24-unstable.873a6f4.0+873a6f4",
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.23",
89
- "@aws-amplify/core": "6.0.23",
90
- "@aws-amplify/data-schema-types": "^0.7.11",
88
+ "@aws-amplify/api-rest": "4.0.24-unstable.873a6f4.0+873a6f4",
89
+ "@aws-amplify/core": "6.0.24-unstable.873a6f4.0+873a6f4",
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": "6c46368559f4c3229024d10c18aabb34c58efe68"
105
+ "gitHead": "873a6f47b24b6f8c97bf3af001db70f204f67daa"
106
106
  }
@@ -732,6 +732,15 @@ export function generateGraphQLDocument(
732
732
  graphQLArguments ??
733
733
  (graphQLArguments = {
734
734
  filter: `Model${name}FilterInput`,
735
+ sortDirection: 'ModelSortDirection',
736
+ ...[primaryKeyFieldName, ...sortKeyFieldNames].reduce(
737
+ (acc: Record<string, any>, fieldName) => {
738
+ acc[fieldName] = `${fields[fieldName].type}`;
739
+
740
+ return acc;
741
+ },
742
+ [],
743
+ ),
735
744
  limit: 'Int',
736
745
  nextToken: 'String',
737
746
  });
@@ -745,6 +754,7 @@ export function generateGraphQLDocument(
745
754
  (graphQLArguments = {
746
755
  ...indexQueryArgs!,
747
756
  filter: `Model${name}FilterInput`,
757
+ sortDirection: 'ModelSortDirection',
748
758
  limit: 'Int',
749
759
  nextToken: 'String',
750
760
  });
@@ -858,6 +868,10 @@ export function buildGraphQLVariables(
858
868
  if (arg?.filter) {
859
869
  variables.filter = arg.filter;
860
870
  }
871
+ if (arg?.sortDirection) {
872
+ variables.sortDirection = arg.sortDirection;
873
+ variables[primaryKeyFieldName] = arg[primaryKeyFieldName];
874
+ }
861
875
  if (arg?.nextToken) {
862
876
  variables.nextToken = arg.nextToken;
863
877
  }
@@ -877,6 +891,11 @@ export function buildGraphQLVariables(
877
891
  if (arg?.filter) {
878
892
  variables.filter = arg.filter;
879
893
  }
894
+
895
+ if (arg?.sortDirection) {
896
+ variables.sortDirection = arg.sortDirection;
897
+ }
898
+
880
899
  if (arg?.nextToken) {
881
900
  variables.nextToken = arg.nextToken;
882
901
  }