@aws-amplify/api-graphql 4.0.21 → 4.0.22-unstable.1aafa48.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 (98) hide show
  1. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +40 -31
  2. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
  3. package/dist/cjs/internals/APIClient.js +34 -19
  4. package/dist/cjs/internals/APIClient.js.map +1 -1
  5. package/dist/cjs/internals/InternalGraphQLAPI.js +10 -9
  6. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
  7. package/dist/cjs/internals/generateClient.js +1 -1
  8. package/dist/cjs/internals/generateClient.js.map +1 -1
  9. package/dist/cjs/internals/operations/custom.js +2 -2
  10. package/dist/cjs/internals/operations/custom.js.map +1 -1
  11. package/dist/cjs/internals/operations/list.js +1 -1
  12. package/dist/cjs/internals/operations/list.js.map +1 -1
  13. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +1 -1
  14. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -1
  15. package/dist/cjs/internals/server/generateModelsProperty.js +1 -1
  16. package/dist/cjs/internals/server/generateModelsProperty.js.map +1 -1
  17. package/dist/cjs/internals/v6.js +0 -2
  18. package/dist/cjs/internals/v6.js.map +1 -1
  19. package/dist/cjs/utils/errors/repackageAuthError.js +1 -1
  20. package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -1
  21. package/dist/esm/GraphQLAPI.d.ts +2 -2
  22. package/dist/esm/GraphQLAPI.mjs.map +1 -1
  23. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +8 -8
  24. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +40 -31
  25. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
  26. package/dist/esm/internals/APIClient.d.ts +5 -6
  27. package/dist/esm/internals/APIClient.mjs +34 -19
  28. package/dist/esm/internals/APIClient.mjs.map +1 -1
  29. package/dist/esm/internals/InternalGraphQLAPI.d.ts +1 -1
  30. package/dist/esm/internals/InternalGraphQLAPI.mjs +10 -9
  31. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  32. package/dist/esm/internals/generateClient.mjs +1 -1
  33. package/dist/esm/internals/generateClient.mjs.map +1 -1
  34. package/dist/esm/internals/generateCustomOperationsProperty.d.ts +2 -2
  35. package/dist/esm/internals/operations/custom.d.ts +1 -1
  36. package/dist/esm/internals/operations/custom.mjs +2 -2
  37. package/dist/esm/internals/operations/custom.mjs.map +1 -1
  38. package/dist/esm/internals/operations/get.d.ts +1 -1
  39. package/dist/esm/internals/operations/get.mjs.map +1 -1
  40. package/dist/esm/internals/operations/indexQuery.d.ts +3 -3
  41. package/dist/esm/internals/operations/indexQuery.mjs.map +1 -1
  42. package/dist/esm/internals/operations/list.d.ts +1 -1
  43. package/dist/esm/internals/operations/list.mjs +1 -1
  44. package/dist/esm/internals/operations/list.mjs.map +1 -1
  45. package/dist/esm/internals/operations/subscription.d.ts +1 -1
  46. package/dist/esm/internals/operations/subscription.mjs.map +1 -1
  47. package/dist/esm/internals/server/generateClientWithAmplifyInstance.d.ts +1 -1
  48. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs +1 -1
  49. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -1
  50. package/dist/esm/internals/server/generateModelsProperty.d.ts +1 -2
  51. package/dist/esm/internals/server/generateModelsProperty.mjs +1 -1
  52. package/dist/esm/internals/server/generateModelsProperty.mjs.map +1 -1
  53. package/dist/esm/internals/types.d.ts +2 -2
  54. package/dist/esm/internals/utils/clientProperties/generateModelsProperty.d.ts +1 -1
  55. package/dist/esm/internals/v6.d.ts +1 -1
  56. package/dist/esm/internals/v6.mjs +0 -2
  57. package/dist/esm/internals/v6.mjs.map +1 -1
  58. package/dist/esm/types/index.d.ts +33 -35
  59. package/dist/esm/utils/ConnectionStateMonitor.d.ts +2 -2
  60. package/dist/esm/utils/ConnectionStateMonitor.mjs.map +1 -1
  61. package/dist/esm/utils/ReachabilityMonitor/index.native.mjs.map +1 -1
  62. package/dist/esm/utils/errors/repackageAuthError.d.ts +2 -2
  63. package/dist/esm/utils/errors/repackageAuthError.mjs +1 -1
  64. package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -1
  65. package/dist/esm/utils/findIndexByFields.d.ts +1 -1
  66. package/package.json +6 -5
  67. package/src/GraphQLAPI.ts +4 -3
  68. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +84 -64
  69. package/src/internals/APIClient.ts +59 -27
  70. package/src/internals/InternalGraphQLAPI.ts +26 -30
  71. package/src/internals/clientUtils.ts +1 -1
  72. package/src/internals/generateClient.ts +12 -10
  73. package/src/internals/generateCustomOperationsProperty.ts +7 -6
  74. package/src/internals/operations/custom.ts +16 -13
  75. package/src/internals/operations/get.ts +9 -8
  76. package/src/internals/operations/indexQuery.ts +12 -11
  77. package/src/internals/operations/list.ts +11 -15
  78. package/src/internals/operations/observeQuery.ts +3 -1
  79. package/src/internals/operations/subscription.ts +12 -10
  80. package/src/internals/server/generateClientWithAmplifyInstance.ts +7 -7
  81. package/src/internals/server/generateModelsProperty.ts +7 -4
  82. package/src/internals/types.ts +2 -2
  83. package/src/internals/utils/clientProperties/generateEnumsProperty.ts +7 -6
  84. package/src/internals/utils/clientProperties/generateModelsProperty.ts +7 -6
  85. package/src/internals/v6.ts +6 -4
  86. package/src/server/generateClient.ts +4 -1
  87. package/src/types/PubSub.ts +1 -0
  88. package/src/types/index.ts +49 -47
  89. package/src/utils/ConnectionStateMonitor.ts +8 -3
  90. package/src/utils/ReachabilityMonitor/index.native.ts +1 -1
  91. package/src/utils/ReachabilityMonitor/index.ts +1 -0
  92. package/src/utils/ReconnectionMonitor.ts +1 -0
  93. package/src/utils/errors/repackageAuthError.ts +6 -7
  94. package/src/utils/findIndexByFields.ts +1 -1
  95. package/src/utils/resolveConfig.ts +1 -0
  96. package/src/utils/resolveLibraryOptions.ts +1 -0
  97. package/src/utils/resolveOwnerFields.ts +7 -5
  98. package/src/utils/resolvePKFields.ts +1 -0
@@ -1,15 +1,18 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { resolveOwnerFields } from '../utils/resolveOwnerFields';
4
3
  import {
4
+ AssociationBelongsTo,
5
+ AssociationHasOne,
5
6
  GraphQLAuthMode,
6
- ModelIntrospectionSchema,
7
7
  ModelFieldType,
8
+ ModelIntrospectionSchema,
8
9
  NonModelFieldType,
9
10
  SchemaModel,
10
- AssociationHasOne,
11
- AssociationBelongsTo,
11
+ SchemaNonModel,
12
12
  } from '@aws-amplify/core/internals/utils';
13
+ import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
14
+ import { CustomHeaders } from '@aws-amplify/data-schema-types';
15
+
13
16
  import {
14
17
  AuthModeParams,
15
18
  ClientWithModels,
@@ -21,18 +24,17 @@ import {
21
24
  __authToken,
22
25
  __headers,
23
26
  } from '../types';
24
- import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
25
- import { CustomHeaders } from '@aws-amplify/data-schema-types';
26
- import { SchemaNonModel } from '@aws-amplify/core/dist/esm/singleton/API/types';
27
+ import { resolveOwnerFields } from '../utils/resolveOwnerFields';
28
+
27
29
  import type { IndexMeta } from './operations/indexQuery';
28
30
 
29
- type LazyLoadOptions = {
31
+ interface LazyLoadOptions {
30
32
  authMode?: GraphQLAuthMode;
31
33
  authToken?: string | undefined;
32
34
  limit?: number | undefined;
33
35
  nextToken?: string | undefined | null;
34
36
  headers?: CustomHeaders | undefined;
35
- };
37
+ }
36
38
 
37
39
  const connectionType = {
38
40
  HAS_ONE: 'HAS_ONE',
@@ -54,9 +56,11 @@ export const flattenItems = (obj: Record<string, any>): Record<string, any> => {
54
56
  res[prop] = value.items.map((item: Record<string, any>) =>
55
57
  flattenItems(item),
56
58
  );
59
+
57
60
  return;
58
61
  }
59
62
  res[prop] = flattenItems(value);
63
+
60
64
  return;
61
65
  }
62
66
 
@@ -109,15 +113,17 @@ export function initializeModel(
109
113
  connectionFields = modelField.association.associatedWith;
110
114
  }
111
115
 
112
- let targetNames: string[] = [];
116
+ const targetNames: string[] = [];
113
117
  if (modelField.association && 'targetNames' in modelField.association) {
114
- targetNames = modelField.association.targetNames;
118
+ targetNames.push(...modelField.association.targetNames);
115
119
  }
116
120
 
117
121
  switch (relationType) {
118
122
  case connectionType.HAS_ONE:
119
- case connectionType.BELONGS_TO:
123
+ case connectionType.BELONGS_TO: {
120
124
  const sortKeyValues = relatedModelSKFieldNames.reduce(
125
+ // TODO(Eslint): is this implementation correct?
126
+ // eslint-disable-next-line array-callback-return
121
127
  (acc: Record<string, any>, curVal) => {
122
128
  if (record[curVal]) {
123
129
  return (acc[curVal] = record[curVal]);
@@ -146,6 +152,7 @@ export function initializeModel(
146
152
  },
147
153
  );
148
154
  }
155
+
149
156
  return undefined;
150
157
  };
151
158
  } else {
@@ -166,12 +173,14 @@ export function initializeModel(
166
173
  },
167
174
  );
168
175
  }
176
+
169
177
  return undefined;
170
178
  };
171
179
  }
172
180
 
173
181
  break;
174
- case connectionType.HAS_MANY:
182
+ }
183
+ case connectionType.HAS_MANY: {
175
184
  const parentPk = introModel.primaryKeyInfo.primaryKeyFieldName;
176
185
  const parentSK = introModel.primaryKeyInfo.sortKeyFieldNames;
177
186
 
@@ -214,6 +223,7 @@ export function initializeModel(
214
223
  authToken: options?.authToken || authToken,
215
224
  });
216
225
  }
226
+
217
227
  return [];
218
228
  };
219
229
  } else {
@@ -231,6 +241,7 @@ export function initializeModel(
231
241
  authToken: options?.authToken || authToken,
232
242
  });
233
243
  }
244
+
234
245
  return [];
235
246
  };
236
247
  }
@@ -264,6 +275,7 @@ export function initializeModel(
264
275
  authToken: options?.authToken || authToken,
265
276
  });
266
277
  }
278
+
267
279
  return [];
268
280
  };
269
281
  } else {
@@ -281,11 +293,13 @@ export function initializeModel(
281
293
  authToken: options?.authToken || authToken,
282
294
  });
283
295
  }
296
+
284
297
  return [];
285
298
  };
286
299
  }
287
300
 
288
301
  break;
302
+ }
289
303
  default:
290
304
  break;
291
305
  }
@@ -309,9 +323,6 @@ export const graphQLOperationsInfo = {
309
323
  } as const;
310
324
  export type ModelOperation = keyof typeof graphQLOperationsInfo;
311
325
 
312
- type OperationPrefix =
313
- (typeof graphQLOperationsInfo)[ModelOperation]['operationPrefix'];
314
-
315
326
  const SELECTION_SET_WILDCARD = '*';
316
327
 
317
328
  export function defaultSelectionSetForNonModelWithIR(
@@ -346,6 +357,7 @@ export function defaultSelectionSetForNonModelWithIR(
346
357
  pair: (string | Record<string, unknown>)[] | undefined,
347
358
  ): pair is (string | Record<string, unknown>)[] => pair !== undefined,
348
359
  );
360
+
349
361
  return Object.fromEntries(mappedFields);
350
362
  }
351
363
 
@@ -365,6 +377,8 @@ function defaultSelectionSetForModel(modelDefinition: SchemaModel): string[] {
365
377
  return `${name}.${SELECTION_SET_WILDCARD}`;
366
378
  }
367
379
  }
380
+
381
+ return undefined;
368
382
  })
369
383
  .filter(Boolean);
370
384
 
@@ -460,10 +474,13 @@ export function customSelectionSetToIR(
460
474
  }
461
475
 
462
476
  if (nested === SELECTION_SET_WILDCARD) {
463
- const relatedModelDefinition = modelIntrospection.models[relatedModel];
477
+ const nestedRelatedModelDefinition =
478
+ modelIntrospection.models[relatedModel];
464
479
 
465
480
  result = {
466
- [fieldName]: modelsDefaultSelectionSetIR(relatedModelDefinition),
481
+ [fieldName]: modelsDefaultSelectionSetIR(
482
+ nestedRelatedModelDefinition,
483
+ ),
467
484
  };
468
485
  } else {
469
486
  result = {
@@ -527,6 +544,7 @@ const modelsDefaultSelectionSetIR = (relatedModelDefinition: SchemaModel) => {
527
544
  const reduced = defaultSelectionSet.reduce(
528
545
  (acc: Record<string, any>, curVal) => {
529
546
  acc[curVal] = FIELD_IR;
547
+
530
548
  return acc;
531
549
  },
532
550
  {},
@@ -594,9 +612,12 @@ function deepMergeSelectionSetObjects<T extends Record<string, any>>(
594
612
 
595
613
  for (const key in source) {
596
614
  // This verification avoids 'Prototype Pollution' issue
597
- if (!source.hasOwnProperty(key)) continue;
615
+ if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
598
616
 
599
- if (target.hasOwnProperty(key) && isObject(target[key])) {
617
+ if (
618
+ Object.prototype.hasOwnProperty.call(target, key) &&
619
+ isObject(target[key])
620
+ ) {
600
621
  deepMergeSelectionSetObjects(source[key], target[key]);
601
622
  } else {
602
623
  target[key] = source[key];
@@ -659,6 +680,7 @@ export function generateGraphQLDocument(
659
680
  const skQueryArgs = sk.reduce((acc: Record<string, any>, fieldName) => {
660
681
  const fieldType = fields[fieldName].type;
661
682
  acc[fieldName] = `Model${fieldType}KeyConditionInput`;
683
+
662
684
  return acc;
663
685
  }, {});
664
686
 
@@ -694,6 +716,8 @@ export function generateGraphQLDocument(
694
716
  }${name}Input!`,
695
717
  });
696
718
  graphQLOperationType ?? (graphQLOperationType = 'mutation');
719
+ // TODO(Eslint): this this case clause correct without the break statement?
720
+ // eslint-disable-next-line no-fallthrough
697
721
  case 'READ':
698
722
  graphQLArguments ??
699
723
  (graphQLArguments = isCustomPrimaryKey
@@ -709,6 +733,8 @@ export function generateGraphQLDocument(
709
733
  [primaryKeyFieldName]: `${fields[primaryKeyFieldName].type}!`,
710
734
  });
711
735
  graphQLSelectionSet ?? (graphQLSelectionSet = selectionSetFields);
736
+ // TODO(Eslint): this this case clause correct without the break statement?
737
+ // eslint-disable-next-line no-fallthrough
712
738
  case 'LIST':
713
739
  graphQLArguments ??
714
740
  (graphQLArguments = {
@@ -719,6 +745,8 @@ export function generateGraphQLDocument(
719
745
  graphQLOperationType ?? (graphQLOperationType = 'query');
720
746
  graphQLSelectionSet ??
721
747
  (graphQLSelectionSet = `items { ${selectionSetFields} } nextToken __typename`);
748
+ // TODO(Eslint): this this case clause correct without the break statement?
749
+ // eslint-disable-next-line no-fallthrough
722
750
  case 'INDEX_QUERY':
723
751
  graphQLArguments ??
724
752
  (graphQLArguments = {
@@ -730,6 +758,8 @@ export function generateGraphQLDocument(
730
758
  graphQLOperationType ?? (graphQLOperationType = 'query');
731
759
  graphQLSelectionSet ??
732
760
  (graphQLSelectionSet = `items { ${selectionSetFields} } nextToken __typename`);
761
+ // TODO(Eslint): this this case clause correct without the break statement?
762
+ // eslint-disable-next-line no-fallthrough
733
763
  case 'ONCREATE':
734
764
  case 'ONUPDATE':
735
765
  case 'ONDELETE':
@@ -750,13 +780,13 @@ export function generateGraphQLDocument(
750
780
  const graphQLDocument = `${graphQLOperationType}${
751
781
  graphQLArguments
752
782
  ? `(${Object.entries(graphQLArguments).map(
753
- ([fieldName, type]) => `\$${fieldName}: ${type}`,
783
+ ([fieldName, type]) => `$${fieldName}: ${type}`,
754
784
  )})`
755
785
  : ''
756
786
  } { ${graphQLFieldName}${
757
787
  graphQLArguments
758
788
  ? `(${Object.keys(graphQLArguments).map(
759
- fieldName => `${fieldName}: \$${fieldName}`,
789
+ fieldName => `${fieldName}: $${fieldName}`,
760
790
  )})`
761
791
  : ''
762
792
  } { ${graphQLSelectionSet} } }`;
@@ -842,7 +872,7 @@ export function buildGraphQLVariables(
842
872
  variables.limit = arg.limit;
843
873
  }
844
874
  break;
845
- case 'INDEX_QUERY':
875
+ case 'INDEX_QUERY': {
846
876
  const { pk, sk = [] } = indexMeta!;
847
877
 
848
878
  variables[pk] = arg![pk];
@@ -861,6 +891,7 @@ export function buildGraphQLVariables(
861
891
  variables.limit = arg.limit;
862
892
  }
863
893
  break;
894
+ }
864
895
  case 'ONCREATE':
865
896
  case 'ONUPDATE':
866
897
  case 'ONDELETE':
@@ -873,9 +904,10 @@ export function buildGraphQLVariables(
873
904
  'Internal error: Attempted to build variables for observeQuery. Please report this error.',
874
905
  );
875
906
  break;
876
- default:
907
+ default: {
877
908
  const exhaustiveCheck: never = operation;
878
909
  throw new Error(`Unhandled operation case: ${exhaustiveCheck}`);
910
+ }
879
911
  }
880
912
 
881
913
  return variables;
@@ -969,9 +1001,9 @@ export function authModeParams(
969
1001
 
970
1002
  /**
971
1003
  * Retrieves custom headers from either the client or request options.
972
- * @param {client} V6Client | V6ClientSSRRequest | V6ClientSSRCookies - for extracting client headers
973
- * @param {requestHeaders} [CustomHeaders] - request headers
974
- * @returns {CustomHeaders} - custom headers
1004
+ * @param client V6Client | V6ClientSSRRequest | V6ClientSSRCookies - for extracting client headers
1005
+ * @param requestHeaders {@link CustomHeaders} - request headers
1006
+ * @returns custom headers as {@link CustomHeaders}
975
1007
  */
976
1008
  export function getCustomHeaders(
977
1009
  client: V6Client | ClientWithModels,
@@ -2,41 +2,40 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import {
4
4
  DocumentNode,
5
- OperationDefinitionNode,
6
- print,
7
- parse,
8
5
  GraphQLError,
6
+ OperationDefinitionNode,
9
7
  OperationTypeNode,
8
+ parse,
9
+ print,
10
10
  } from 'graphql';
11
11
  import { Observable, catchError } from 'rxjs';
12
- import { AmplifyClassV6, ConsoleLogger } from '@aws-amplify/core';
12
+ import { AmplifyClassV6 } from '@aws-amplify/core';
13
13
  import {
14
- GraphQLAuthMode,
14
+ AmplifyUrl,
15
15
  CustomUserAgentDetails,
16
+ GraphQLAuthMode,
16
17
  getAmplifyUserAgent,
17
- AmplifyUrl,
18
18
  } from '@aws-amplify/core/internals/utils';
19
- import {
20
- GraphQLAuthError,
21
- GraphQLResult,
22
- GraphQLOperation,
23
- GraphQLOptions,
24
- } from '../types';
25
19
  import { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';
26
20
  import {
27
- post,
28
21
  cancel as cancelREST,
22
+ post,
29
23
  updateRequestToBeCancellable,
30
24
  } from '@aws-amplify/api-rest/internals';
31
- import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
32
25
  import { CustomHeaders, RequestOptions } from '@aws-amplify/data-schema-types';
26
+
27
+ import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
28
+ import {
29
+ GraphQLAuthError,
30
+ GraphQLOperation,
31
+ GraphQLOptions,
32
+ GraphQLResult,
33
+ } from '../types';
33
34
  import { resolveConfig, resolveLibraryOptions } from '../utils';
34
35
  import { repackageUnauthError } from '../utils/errors/repackageAuthError';
35
36
 
36
37
  const USER_AGENT_HEADER = 'x-amz-user-agent';
37
38
 
38
- const logger = new ConsoleLogger('GraphQLAPI');
39
-
40
39
  const isAmplifyInstance = (
41
40
  amplify:
42
41
  | AmplifyClassV6
@@ -70,11 +69,7 @@ export class InternalGraphQLAPIClass {
70
69
  authMode: GraphQLAuthMode,
71
70
  additionalHeaders: Record<string, string> = {},
72
71
  ) {
73
- const {
74
- region: region,
75
- endpoint: appSyncGraphqlEndpoint,
76
- apiKey,
77
- } = resolveConfig(amplify);
72
+ const { apiKey } = resolveConfig(amplify);
78
73
 
79
74
  let headers = {};
80
75
 
@@ -87,18 +82,17 @@ export class InternalGraphQLAPIClass {
87
82
  'X-Api-Key': apiKey,
88
83
  };
89
84
  break;
90
- case 'iam':
85
+ case 'iam': {
91
86
  const session = await amplify.Auth.fetchAuthSession();
92
87
  if (session.credentials === undefined) {
93
88
  throw new Error(GraphQLAuthError.NO_CREDENTIALS);
94
89
  }
95
90
  break;
91
+ }
96
92
  case 'oidc':
97
93
  case 'userPool':
98
94
  try {
99
- let token;
100
-
101
- token = (
95
+ const token = (
102
96
  await amplify.Auth.fetchAuthSession()
103
97
  ).tokens?.accessToken.toString();
104
98
 
@@ -139,8 +133,7 @@ export class InternalGraphQLAPIClass {
139
133
  */
140
134
  getGraphqlOperationType(operation: GraphQLOperation): OperationTypeNode {
141
135
  const doc = parse(operation);
142
- const definitions =
143
- doc.definitions as ReadonlyArray<OperationDefinitionNode>;
136
+ const definitions = doc.definitions as readonly OperationDefinitionNode[];
144
137
  const [{ operation: operationType }] = definitions;
145
138
 
146
139
  return operationType;
@@ -176,7 +169,7 @@ export class InternalGraphQLAPIClass {
176
169
 
177
170
  switch (operationType) {
178
171
  case 'query':
179
- case 'mutation':
172
+ case 'mutation': {
180
173
  const abortController = new AbortController();
181
174
 
182
175
  let responsePromise: Promise<GraphQLResult<T>>;
@@ -215,7 +208,9 @@ export class InternalGraphQLAPIClass {
215
208
  responsePromise,
216
209
  abortController,
217
210
  );
211
+
218
212
  return responsePromise;
213
+ }
219
214
  case 'subscription':
220
215
  return this._graphqlSubscribe(
221
216
  amplify as AmplifyClassV6,
@@ -238,7 +233,7 @@ export class InternalGraphQLAPIClass {
238
233
  authToken?: string,
239
234
  ): Promise<GraphQLResult<T>> {
240
235
  const {
241
- region: region,
236
+ region,
242
237
  endpoint: appSyncGraphqlEndpoint,
243
238
  customEndpoint,
244
239
  customEndpointRegion,
@@ -356,7 +351,8 @@ export class InternalGraphQLAPIClass {
356
351
 
357
352
  if (!endpoint) {
358
353
  const error = new GraphQLError('No graphql endpoint provided.');
359
-
354
+ // TODO(Eslint): refactor this to throw an Error instead of a plain object
355
+ // eslint-disable-next-line no-throw-literal
360
356
  throw {
361
357
  data: {},
362
358
  errors: [error],
@@ -2,8 +2,8 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type {
5
- SchemaModel,
6
5
  ModelAttribute,
6
+ SchemaModel,
7
7
  SecondaryIndexAttribute,
8
8
  } from '@aws-amplify/core/internals/utils';
9
9
 
@@ -1,20 +1,13 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Hub } from '@aws-amplify/core';
4
- import { graphql, cancel, isCancelError } from './v6';
5
4
  import {
5
+ CustomMutations,
6
+ CustomQueries,
6
7
  EnumTypes,
7
8
  ModelTypes,
8
- CustomQueries,
9
- CustomMutations,
10
9
  } from '@aws-amplify/data-schema-types';
11
- import { generateEnumsProperty } from './utils/clientProperties/generateEnumsProperty';
12
- import { generateModelsProperty } from './utils/clientProperties/generateModelsProperty';
13
- import { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig';
14
- import {
15
- generateCustomQueriesProperty,
16
- generateCustomMutationsProperty,
17
- } from './generateCustomOperationsProperty';
10
+
18
11
  import {
19
12
  V6Client,
20
13
  __amplify,
@@ -22,6 +15,15 @@ import {
22
15
  __authToken,
23
16
  __headers,
24
17
  } from '../types';
18
+
19
+ import { cancel, graphql, isCancelError } from './v6';
20
+ import { generateEnumsProperty } from './utils/clientProperties/generateEnumsProperty';
21
+ import { generateModelsProperty } from './utils/clientProperties/generateModelsProperty';
22
+ import { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig';
23
+ import {
24
+ generateCustomMutationsProperty,
25
+ generateCustomQueriesProperty,
26
+ } from './generateCustomOperationsProperty';
25
27
  import { ClientGenerationParams } from './types';
26
28
  import { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig';
27
29
 
@@ -1,14 +1,15 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { CustomQueries, CustomMutations } from '@aws-amplify/data-schema-types';
4
- import { V6Client, __authMode, __authToken, __amplify } from '../types';
5
-
6
- import { customOpFactory } from './operations/custom';
3
+ import { CustomMutations, CustomQueries } from '@aws-amplify/data-schema-types';
7
4
  import {
8
- ModelIntrospectionSchema,
9
5
  GraphQLProviderConfig,
6
+ ModelIntrospectionSchema,
10
7
  } from '@aws-amplify/core/internals/utils';
11
8
 
9
+ import { V6Client, __amplify } from '../types';
10
+
11
+ import { customOpFactory } from './operations/custom';
12
+
12
13
  type OpTypes = 'queries' | 'mutations';
13
14
 
14
15
  type CustomOpsProperty<
@@ -59,7 +60,7 @@ export function generateCustomOperationsProperty<
59
60
  modelIntrospection,
60
61
  operationTypeMap[operationsType],
61
62
  operation,
62
- useContext
63
+ useContext,
63
64
  );
64
65
  }
65
66
 
@@ -2,13 +2,18 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
4
4
  import {
5
- initializeModel,
6
- flattenItems,
5
+ CustomOperation,
6
+ ModelIntrospectionSchema,
7
+ } from '@aws-amplify/core/internals/utils';
8
+
9
+ import {
7
10
  authModeParams,
8
- getCustomHeaders,
11
+ defaultSelectionSetForNonModelWithIR,
12
+ flattenItems,
9
13
  generateSelectionSet,
14
+ getCustomHeaders,
15
+ initializeModel,
10
16
  selectionSetIRToString,
11
- defaultSelectionSetForNonModelWithIR,
12
17
  } from '../APIClient';
13
18
  import {
14
19
  AuthModeParams,
@@ -20,13 +25,6 @@ import {
20
25
  V6Client,
21
26
  V6ClientSSRRequest,
22
27
  } from '../../types';
23
- import {
24
- ModelIntrospectionSchema,
25
- SchemaModel,
26
- SchemaNonModel,
27
- CustomOperation,
28
- CustomOperationArgument,
29
- } from '@aws-amplify/core/internals/utils';
30
28
 
31
29
  /**
32
30
  * Builds an operation function, embedded with all client and context data, that
@@ -168,9 +166,11 @@ function outerArguments(operation: CustomOperation): string {
168
166
  const finalType = v.isArray
169
167
  ? `[${baseType}]${v.isArrayNullable ? '' : '!'}`
170
168
  : baseType;
169
+
171
170
  return `$${k}: ${finalType}`;
172
171
  })
173
172
  .join(', ');
173
+
174
174
  return args.length > 0 ? `(${args})` : '';
175
175
  }
176
176
 
@@ -194,9 +194,10 @@ function outerArguments(operation: CustomOperation): string {
194
194
  * @returns "outer" arguments string
195
195
  */
196
196
  function innerArguments(operation: CustomOperation): string {
197
- const args = Object.entries(operation.arguments)
198
- .map(([k, v]) => `${k}: $${k}`)
197
+ const args = Object.keys(operation.arguments)
198
+ .map(k => `${k}: $${k}`)
199
199
  .join(', ');
200
+
200
201
  return args.length > 0 ? `(${args})` : '';
201
202
  }
202
203
 
@@ -234,6 +235,7 @@ function operationSelectionSet(
234
235
  return '';
235
236
  } else if (hasStringField(operation.type, 'nonModel')) {
236
237
  const nonModel = modelIntrospection.nonModels[operation.type.nonModel];
238
+
237
239
  return `{${selectionSetIRToString(
238
240
  defaultSelectionSetForNonModelWithIR(nonModel, modelIntrospection),
239
241
  )}}`;
@@ -266,6 +268,7 @@ function operationVariables(
266
268
  throw new Error(`${operation.name} requires arguments '${argDef.name}'`);
267
269
  }
268
270
  }
271
+
269
272
  return variables;
270
273
  }
271
274
 
@@ -2,13 +2,18 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
4
4
  import {
5
- initializeModel,
6
- generateGraphQLDocument,
5
+ ModelIntrospectionSchema,
6
+ SchemaModel,
7
+ } from '@aws-amplify/core/internals/utils';
8
+
9
+ import {
10
+ ModelOperation,
11
+ authModeParams,
7
12
  buildGraphQLVariables,
8
13
  flattenItems,
9
- authModeParams,
10
- ModelOperation,
14
+ generateGraphQLDocument,
11
15
  getCustomHeaders,
16
+ initializeModel,
12
17
  } from '../APIClient';
13
18
  import {
14
19
  AuthModeParams,
@@ -20,10 +25,6 @@ import {
20
25
  V6Client,
21
26
  V6ClientSSRRequest,
22
27
  } from '../../types';
23
- import {
24
- ModelIntrospectionSchema,
25
- SchemaModel,
26
- } from '@aws-amplify/core/internals/utils';
27
28
 
28
29
  export function getFactory(
29
30
  client: ClientWithModels,
@@ -2,31 +2,32 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
4
4
  import {
5
- initializeModel,
6
- generateGraphQLDocument,
5
+ ModelIntrospectionSchema,
6
+ SchemaModel,
7
+ } from '@aws-amplify/core/internals/utils';
8
+
9
+ import {
10
+ authModeParams,
7
11
  buildGraphQLVariables,
8
12
  flattenItems,
9
- authModeParams,
13
+ generateGraphQLDocument,
10
14
  getCustomHeaders,
15
+ initializeModel,
11
16
  } from '../APIClient';
12
17
  import {
13
18
  AuthModeParams,
14
19
  ClientWithModels,
15
- ListArgs,
16
- V6ClientSSRRequest,
17
20
  GraphQLResult,
21
+ ListArgs,
18
22
  QueryArgs,
23
+ V6ClientSSRRequest,
19
24
  } from '../../types';
20
- import {
21
- ModelIntrospectionSchema,
22
- SchemaModel,
23
- } from '@aws-amplify/core/internals/utils';
24
25
 
25
- export type IndexMeta = {
26
+ export interface IndexMeta {
26
27
  queryField: string;
27
28
  pk: string;
28
29
  sk?: string[];
29
- };
30
+ }
30
31
 
31
32
  export function indexQueryFactory(
32
33
  client: ClientWithModels,