@aws-amplify/api-graphql 4.0.16 → 4.0.17-unstable.3d2803e.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 (46) hide show
  1. package/dist/cjs/internals/APIClient.js +0 -1
  2. package/dist/cjs/internals/APIClient.js.map +1 -1
  3. package/dist/cjs/internals/InternalGraphQLAPI.js +7 -2
  4. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
  5. package/dist/cjs/internals/generateClient.js +20 -18
  6. package/dist/cjs/internals/generateClient.js.map +1 -1
  7. package/dist/cjs/internals/utils/generateEnumsProperty.js +21 -0
  8. package/dist/cjs/internals/utils/generateEnumsProperty.js.map +1 -0
  9. package/dist/cjs/internals/{generateModelsProperty.js → utils/generateModelsProperty.js} +9 -9
  10. package/dist/cjs/internals/utils/generateModelsProperty.js.map +1 -0
  11. package/dist/cjs/internals/utils/isApiGraphQLProviderConfig.js +11 -0
  12. package/dist/cjs/internals/utils/isApiGraphQLProviderConfig.js.map +1 -0
  13. package/dist/cjs/internals/utils/isConfigureEventWithResourceConfig.js +11 -0
  14. package/dist/cjs/internals/utils/isConfigureEventWithResourceConfig.js.map +1 -0
  15. package/dist/esm/internals/APIClient.mjs +0 -1
  16. package/dist/esm/internals/APIClient.mjs.map +1 -1
  17. package/dist/esm/internals/InternalGraphQLAPI.mjs +7 -2
  18. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  19. package/dist/esm/internals/generateClient.mjs +20 -18
  20. package/dist/esm/internals/generateClient.mjs.map +1 -1
  21. package/dist/esm/internals/utils/generateEnumsProperty.d.ts +3 -0
  22. package/dist/esm/internals/utils/generateEnumsProperty.mjs +18 -0
  23. package/dist/esm/internals/utils/generateEnumsProperty.mjs.map +1 -0
  24. package/dist/esm/internals/utils/generateModelsProperty.d.ts +4 -0
  25. package/dist/esm/internals/{generateModelsProperty.mjs → utils/generateModelsProperty.mjs} +9 -9
  26. package/dist/esm/internals/utils/generateModelsProperty.mjs.map +1 -0
  27. package/dist/esm/internals/utils/isApiGraphQLProviderConfig.d.ts +2 -0
  28. package/dist/esm/internals/utils/isApiGraphQLProviderConfig.mjs +8 -0
  29. package/dist/esm/internals/utils/isApiGraphQLProviderConfig.mjs.map +1 -0
  30. package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.d.ts +8 -0
  31. package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.mjs +8 -0
  32. package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.mjs.map +1 -0
  33. package/dist/esm/types/index.d.ts +2 -1
  34. package/dist/esm/utils/resolveLibraryOptions.d.ts +4 -1
  35. package/package.json +5 -5
  36. package/src/internals/APIClient.ts +0 -2
  37. package/src/internals/InternalGraphQLAPI.ts +24 -19
  38. package/src/internals/generateClient.ts +23 -35
  39. package/src/internals/utils/generateEnumsProperty.ts +33 -0
  40. package/src/internals/{generateModelsProperty.ts → utils/generateModelsProperty.ts} +14 -12
  41. package/src/internals/utils/isApiGraphQLProviderConfig.ts +10 -0
  42. package/src/internals/utils/isConfigureEventWithResourceConfig.ts +13 -0
  43. package/src/types/index.ts +2 -1
  44. package/dist/cjs/internals/generateModelsProperty.js.map +0 -1
  45. package/dist/esm/internals/generateModelsProperty.d.ts +0 -4
  46. package/dist/esm/internals/generateModelsProperty.mjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/api-graphql",
3
- "version": "4.0.16",
3
+ "version": "4.0.17-unstable.3d2803e.0+3d2803e",
4
4
  "description": "Api-graphql category of aws-amplify",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -84,9 +84,9 @@
84
84
  "server"
85
85
  ],
86
86
  "dependencies": {
87
- "@aws-amplify/api-rest": "4.0.16",
88
- "@aws-amplify/core": "6.0.16",
89
- "@aws-amplify/data-schema-types": "^0.7.1",
87
+ "@aws-amplify/api-rest": "4.0.17-unstable.3d2803e.0+3d2803e",
88
+ "@aws-amplify/core": "6.0.17-unstable.3d2803e.0+3d2803e",
89
+ "@aws-amplify/data-schema-types": "^0.7.2",
90
90
  "@aws-sdk/types": "3.387.0",
91
91
  "graphql": "15.8.0",
92
92
  "rxjs": "^7.8.1",
@@ -101,5 +101,5 @@
101
101
  "limit": "91.7 kB"
102
102
  }
103
103
  ],
104
- "gitHead": "0e919f6e759cb94d03e119162b530b32d48f1357"
104
+ "gitHead": "3d2803eb859c37e52f1dc9459b79d628e0377d2e"
105
105
  }
@@ -579,8 +579,6 @@ export function generateGraphQLDocument(
579
579
  );
580
580
  }
581
581
 
582
- console.log('indexQueryArgs', indexQueryArgs!);
583
-
584
582
  let graphQLOperationType: 'mutation' | 'query' | 'subscription' | undefined;
585
583
  let graphQLSelectionSet: string | undefined;
586
584
  let graphQLArguments: Record<string, any> | undefined;
@@ -40,7 +40,7 @@ const logger = new ConsoleLogger('GraphQLAPI');
40
40
  const isAmplifyInstance = (
41
41
  amplify:
42
42
  | AmplifyClassV6
43
- | ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>)
43
+ | ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>),
44
44
  ): amplify is AmplifyClassV6 => {
45
45
  return typeof amplify !== 'function';
46
46
  };
@@ -68,7 +68,7 @@ export class InternalGraphQLAPIClass {
68
68
  private async _headerBasedAuth(
69
69
  amplify: AmplifyClassV6,
70
70
  authMode: GraphQLAuthMode,
71
- additionalHeaders: Record<string, string> = {}
71
+ additionalHeaders: Record<string, string> = {},
72
72
  ) {
73
73
  const {
74
74
  region: region,
@@ -159,7 +159,7 @@ export class InternalGraphQLAPIClass {
159
159
  | ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>),
160
160
  { query: paramQuery, variables = {}, authMode, authToken }: GraphQLOptions,
161
161
  additionalHeaders?: CustomHeaders,
162
- customUserAgentDetails?: CustomUserAgentDetails
162
+ customUserAgentDetails?: CustomUserAgentDetails,
163
163
  ): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>> {
164
164
  const query =
165
165
  typeof paramQuery === 'string'
@@ -167,7 +167,7 @@ export class InternalGraphQLAPIClass {
167
167
  : parse(print(paramQuery));
168
168
 
169
169
  const [operationDef = {}] = query.definitions.filter(
170
- def => def.kind === 'OperationDefinition'
170
+ def => def.kind === 'OperationDefinition',
171
171
  );
172
172
  const { operation: operationType } =
173
173
  operationDef as OperationDefinitionNode;
@@ -188,19 +188,24 @@ export class InternalGraphQLAPIClass {
188
188
  headers,
189
189
  abortController,
190
190
  customUserAgentDetails,
191
- authToken
191
+ authToken,
192
192
  );
193
193
  } else {
194
- const wrapper = (amplifyInstance: AmplifyClassV6) =>
195
- this._graphql<T>(
194
+ // NOTE: this wrapper function must be await-able so the Amplify server context manager can
195
+ // destroy the context only after it completes
196
+ const wrapper = async (amplifyInstance: AmplifyClassV6) => {
197
+ const result = await this._graphql<T>(
196
198
  amplifyInstance,
197
199
  { query, variables, authMode },
198
200
  headers,
199
201
  abortController,
200
202
  customUserAgentDetails,
201
- authToken
203
+ authToken,
202
204
  );
203
205
 
206
+ return result;
207
+ };
208
+
204
209
  responsePromise = amplify(wrapper) as unknown as Promise<
205
210
  GraphQLResult<T>
206
211
  >;
@@ -208,7 +213,7 @@ export class InternalGraphQLAPIClass {
208
213
 
209
214
  this._api.updateRequestToBeCancellable(
210
215
  responsePromise,
211
- abortController
216
+ abortController,
212
217
  );
213
218
  return responsePromise;
214
219
  case 'subscription':
@@ -217,7 +222,7 @@ export class InternalGraphQLAPIClass {
217
222
  { query, variables, authMode },
218
223
  headers,
219
224
  customUserAgentDetails,
220
- authToken
225
+ authToken,
221
226
  );
222
227
  default:
223
228
  throw new Error(`invalid operation type: ${operationType}`);
@@ -230,7 +235,7 @@ export class InternalGraphQLAPIClass {
230
235
  additionalHeaders: CustomHeaders = {},
231
236
  abortController: AbortController,
232
237
  customUserAgentDetails?: CustomUserAgentDetails,
233
- authToken?: string
238
+ authToken?: string,
234
239
  ): Promise<GraphQLResult<T>> {
235
240
  const {
236
241
  region: region,
@@ -263,7 +268,7 @@ export class InternalGraphQLAPIClass {
263
268
  const requestOptions: RequestOptions = {
264
269
  method: 'POST',
265
270
  url: new AmplifyUrl(
266
- customEndpoint || appSyncGraphqlEndpoint || ''
271
+ customEndpoint || appSyncGraphqlEndpoint || '',
267
272
  ).toString(),
268
273
  queryString: print(query as DocumentNode),
269
274
  };
@@ -287,7 +292,7 @@ export class InternalGraphQLAPIClass {
287
292
  (await this._headerBasedAuth(
288
293
  amplify,
289
294
  authMode!,
290
- additionalCustomHeaders
295
+ additionalCustomHeaders,
291
296
  ))),
292
297
  /**
293
298
  * Custom endpoint headers.
@@ -300,7 +305,7 @@ export class InternalGraphQLAPIClass {
300
305
  ? await this._headerBasedAuth(
301
306
  amplify,
302
307
  authMode!,
303
- additionalCustomHeaders
308
+ additionalCustomHeaders,
304
309
  )
305
310
  : {})) ||
306
311
  {}),
@@ -361,7 +366,7 @@ export class InternalGraphQLAPIClass {
361
366
  let response: any;
362
367
 
363
368
  try {
364
- const { body: responseBody } = await this._api.post({
369
+ const { body: responseBody } = await this._api.post(amplify, {
365
370
  url: new AmplifyUrl(endpoint),
366
371
  options: {
367
372
  headers,
@@ -392,7 +397,7 @@ export class InternalGraphQLAPIClass {
392
397
  null,
393
398
  null,
394
399
  null,
395
- err as any
400
+ err as any,
396
401
  ),
397
402
  ],
398
403
  };
@@ -430,7 +435,7 @@ export class InternalGraphQLAPIClass {
430
435
  { query, variables, authMode }: GraphQLOptions,
431
436
  additionalHeaders: CustomHeaders = {},
432
437
  customUserAgentDetails?: CustomUserAgentDetails,
433
- authToken?: string
438
+ authToken?: string,
434
439
  ): Observable<any> {
435
440
  const config = resolveConfig(amplify);
436
441
 
@@ -457,7 +462,7 @@ export class InternalGraphQLAPIClass {
457
462
  authToken,
458
463
  libraryConfigHeaders,
459
464
  },
460
- customUserAgentDetails
465
+ customUserAgentDetails,
461
466
  )
462
467
  .pipe(
463
468
  catchError(e => {
@@ -465,7 +470,7 @@ export class InternalGraphQLAPIClass {
465
470
  throw repackageUnauthError(e);
466
471
  }
467
472
  throw e;
468
- })
473
+ }),
469
474
  );
470
475
  }
471
476
  }
@@ -1,7 +1,11 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+ import { Hub } from '@aws-amplify/core';
4
+ import { EnumTypes, ModelTypes } from '@aws-amplify/data-schema-types';
3
5
  import { graphql, cancel, isCancelError } from './v6';
4
- import { generateModelsProperty } from './generateModelsProperty';
6
+ import { generateEnumsProperty } from './utils/generateEnumsProperty';
7
+ import { generateModelsProperty } from './utils/generateModelsProperty';
8
+ import { isApiGraphQLConfig } from './utils/isApiGraphQLProviderConfig';
5
9
  import {
6
10
  V6Client,
7
11
  __amplify,
@@ -10,8 +14,7 @@ import {
10
14
  __headers,
11
15
  } from '../types';
12
16
  import { ClientGenerationParams } from './types';
13
- import { ModelTypes } from '@aws-amplify/data-schema-types';
14
- import { Hub, HubCapsule, ResourcesConfig } from '@aws-amplify/core';
17
+ import { isConfigureEventWithResourceConfig } from './utils/isConfigureEventWithResourceConfig';
15
18
 
16
19
  /**
17
20
  * @private
@@ -23,7 +26,7 @@ import { Hub, HubCapsule, ResourcesConfig } from '@aws-amplify/core';
23
26
  * @returns
24
27
  */
25
28
  export function generateClient<T extends Record<any, any> = never>(
26
- params: ClientGenerationParams
29
+ params: ClientGenerationParams,
27
30
  ): V6Client<T> {
28
31
  const client = {
29
32
  [__amplify]: params.amplify,
@@ -33,12 +36,16 @@ export function generateClient<T extends Record<any, any> = never>(
33
36
  graphql,
34
37
  cancel,
35
38
  isCancelError,
36
- models: {},
39
+ models: emptyProperty as ModelTypes<never>,
40
+ enums: emptyProperty as EnumTypes<never>,
37
41
  } as any;
38
42
 
39
- const config = params.amplify.getConfig();
43
+ const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
40
44
 
41
- if (!config.API?.GraphQL) {
45
+ if (isApiGraphQLConfig(apiGraphqlConfig)) {
46
+ client.models = generateModelsProperty<T>(client, apiGraphqlConfig);
47
+ client.enums = generateEnumsProperty<T>(apiGraphqlConfig);
48
+ } else {
42
49
  // This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
43
50
  //
44
51
  // Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in
@@ -51,52 +58,33 @@ export function generateClient<T extends Record<any, any> = never>(
51
58
  //
52
59
  // TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints
53
60
  // configuration.
54
- client.models = emptyModels as ModelTypes<never>;
55
- generateModelsPropertyOnAmplifyConfigure<T>(client);
56
- } else {
57
- client.models = generateModelsProperty<T>(
58
- client,
59
- config.API?.GraphQL,
60
- );
61
+ generateModelsPropertyOnAmplifyConfigure(client);
61
62
  }
62
63
 
63
64
  return client as V6Client<T>;
64
65
  }
65
66
 
66
- const generateModelsPropertyOnAmplifyConfigure = <
67
- T extends Record<any, any> = never,
68
- >(clientRef: any) => {
67
+ const generateModelsPropertyOnAmplifyConfigure = (clientRef: any) => {
69
68
  Hub.listen('core', coreEvent => {
70
- if (!isConfigureEvent(coreEvent.payload)) {
69
+ if (!isConfigureEventWithResourceConfig(coreEvent.payload)) {
71
70
  return;
72
71
  }
73
72
 
74
- const { data: resourceConfig } = coreEvent.payload;
73
+ const apiGraphQLConfig = coreEvent.payload.data.API?.GraphQL;
75
74
 
76
- if (resourceConfig.API?.GraphQL) {
77
- clientRef.models = generateModelsProperty<T>(
78
- clientRef,
79
- resourceConfig.API?.GraphQL,
80
- );
75
+ if (isApiGraphQLConfig(apiGraphQLConfig)) {
76
+ clientRef.models = generateModelsProperty(clientRef, apiGraphQLConfig);
77
+ clientRef.enums = generateEnumsProperty(apiGraphQLConfig);
81
78
  }
82
79
  });
83
80
  };
84
81
 
85
- function isConfigureEvent(
86
- payload: HubCapsule<'core', { event: string; data?: unknown }>['payload'],
87
- ): payload is {
88
- event: 'configure';
89
- data: ResourcesConfig;
90
- } {
91
- return payload.event === 'configure';
92
- }
93
-
94
- const emptyModels = new Proxy(
82
+ const emptyProperty = new Proxy(
95
83
  {},
96
84
  {
97
85
  get() {
98
86
  throw new Error(
99
- 'Could not generate client. This is likely due to Amplify.configure() not being called prior to generateClient().',
87
+ 'Client could not be generated. This is likely due to `Amplify.configure()` not being called prior to `generateClient()` or because the configuration passed to `Amplify.configure()` is missing GraphQL provider configuration.',
100
88
  );
101
89
  },
102
90
  },
@@ -0,0 +1,33 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import {
5
+ ModelIntrospectionSchema,
6
+ GraphQLProviderConfig,
7
+ } from '@aws-amplify/core/internals/utils';
8
+ import { EnumTypes } from '@aws-amplify/data-schema-types';
9
+
10
+ export const generateEnumsProperty = <T extends Record<any, any> = never>(
11
+ graphqlConfig: GraphQLProviderConfig['GraphQL'],
12
+ ): EnumTypes<T> => {
13
+ const modelIntrospection: ModelIntrospectionSchema | undefined =
14
+ graphqlConfig.modelIntrospection;
15
+
16
+ if (!modelIntrospection) {
17
+ return {} as EnumTypes<never>;
18
+ }
19
+
20
+ const enums: {
21
+ [EnumName: string]: {
22
+ values: () => string[];
23
+ };
24
+ } = {};
25
+
26
+ for (const [_, enumData] of Object.entries(modelIntrospection.enums)) {
27
+ enums[enumData.name] = {
28
+ values: () => enumData.values,
29
+ };
30
+ }
31
+
32
+ return enums as EnumTypes<T>;
33
+ };
@@ -1,25 +1,27 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { ModelTypes } from '@aws-amplify/data-schema-types';
4
- import { graphQLOperationsInfo, ModelOperation } from './APIClient';
5
- import { V6Client, __authMode, __authToken } from '../types';
6
- import { listFactory } from './operations/list';
7
- import { indexQueryFactory } from './operations/indexQuery';
8
- import { getFactory } from './operations/get';
9
- import { subscriptionFactory } from './operations/subscription';
10
- import { observeQueryFactory } from './operations/observeQuery';
11
- import { ModelIntrospectionSchema } from '@aws-amplify/core/internals/utils';
12
- import { GraphQLProviderConfig } from '@aws-amplify/core';
13
- import { getSecondaryIndexesFromSchemaModel } from './clientUtils';
4
+ import { graphQLOperationsInfo, ModelOperation } from '../APIClient';
5
+ import { V6Client, __authMode, __authToken } from '../../types';
6
+ import { listFactory } from '../operations/list';
7
+ import { indexQueryFactory } from '../operations/indexQuery';
8
+ import { getFactory } from '../operations/get';
9
+ import { subscriptionFactory } from '../operations/subscription';
10
+ import { observeQueryFactory } from '../operations/observeQuery';
11
+ import {
12
+ ModelIntrospectionSchema,
13
+ GraphQLProviderConfig,
14
+ } from '@aws-amplify/core/internals/utils';
15
+ import { getSecondaryIndexesFromSchemaModel } from '../clientUtils';
14
16
 
15
17
  export function generateModelsProperty<T extends Record<any, any> = never>(
16
18
  client: V6Client<Record<string, any>>,
17
- graphqlConfig: GraphQLProviderConfig['GraphQL'],
19
+ apiGraphQLConfig: GraphQLProviderConfig['GraphQL'],
18
20
  ): ModelTypes<T> {
19
21
  const models = {} as any;
20
22
 
21
23
  const modelIntrospection: ModelIntrospectionSchema | undefined =
22
- graphqlConfig.modelIntrospection;
24
+ apiGraphQLConfig.modelIntrospection;
23
25
 
24
26
  if (!modelIntrospection) {
25
27
  return {} as ModelTypes<never>;
@@ -0,0 +1,10 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { GraphQLProviderConfig } from '@aws-amplify/core/internals/utils';
5
+
6
+ export function isApiGraphQLConfig(
7
+ apiGraphQLConfig: GraphQLProviderConfig['GraphQL'] | undefined,
8
+ ): apiGraphQLConfig is GraphQLProviderConfig['GraphQL'] {
9
+ return apiGraphQLConfig !== undefined;
10
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { HubCapsule, ResourcesConfig } from '@aws-amplify/core';
5
+
6
+ export function isConfigureEventWithResourceConfig(
7
+ payload: HubCapsule<'core', { event: string; data?: unknown }>['payload'],
8
+ ): payload is {
9
+ event: 'configure';
10
+ data: ResourcesConfig;
11
+ } {
12
+ return payload.event === 'configure';
13
+ }
@@ -1,7 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
4
- import { ModelTypes, CustomHeaders } from '@aws-amplify/data-schema-types';
4
+ import { ModelTypes, CustomHeaders, EnumTypes } from '@aws-amplify/data-schema-types';
5
5
  import { Source, DocumentNode, GraphQLError } from 'graphql';
6
6
  export { OperationTypeNode } from 'graphql';
7
7
  import { Observable } from 'rxjs';
@@ -382,6 +382,7 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
382
382
  cancel: (promise: Promise<any>, message?: string) => boolean;
383
383
  isCancelError: (error: any) => boolean;
384
384
  models: ModelTypes<T>;
385
+ enums: EnumTypes<T>;
385
386
  }>;
386
387
 
387
388
  export type V6ClientSSRRequest<T extends Record<any, any> = never> =
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateModelsProperty.js","sources":["../../../src/internals/generateModelsProperty.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateModelsProperty = void 0;\nconst APIClient_1 = require(\"./APIClient\");\nconst list_1 = require(\"./operations/list\");\nconst indexQuery_1 = require(\"./operations/indexQuery\");\nconst get_1 = require(\"./operations/get\");\nconst subscription_1 = require(\"./operations/subscription\");\nconst observeQuery_1 = require(\"./operations/observeQuery\");\nconst clientUtils_1 = require(\"./clientUtils\");\nfunction generateModelsProperty(client, graphqlConfig) {\n const models = {};\n const modelIntrospection = graphqlConfig.modelIntrospection;\n if (!modelIntrospection) {\n return {};\n }\n const SUBSCRIPTION_OPS = ['ONCREATE', 'ONUPDATE', 'ONDELETE'];\n for (const model of Object.values(modelIntrospection.models)) {\n const { name } = model;\n models[name] = {};\n Object.entries(APIClient_1.graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {\n const operation = key;\n if (operation === 'LIST') {\n models[name][operationPrefix] = (0, list_1.listFactory)(client, modelIntrospection, model);\n }\n else if (SUBSCRIPTION_OPS.includes(operation)) {\n models[name][operationPrefix] = (0, subscription_1.subscriptionFactory)(client, modelIntrospection, model, operation);\n }\n else if (operation === 'OBSERVE_QUERY') {\n models[name][operationPrefix] = (0, observeQuery_1.observeQueryFactory)(models, model);\n }\n else {\n models[name][operationPrefix] = (0, get_1.getFactory)(client, modelIntrospection, model, operation);\n }\n });\n const secondaryIdxs = (0, clientUtils_1.getSecondaryIndexesFromSchemaModel)(model);\n for (const idx of secondaryIdxs) {\n models[name][idx.queryField] = (0, indexQuery_1.indexQueryFactory)(client, modelIntrospection, model, idx);\n }\n }\n return models;\n}\nexports.generateModelsProperty = generateModelsProperty;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,sBAAsB,GAAG,KAAK,CAAC,CAAC;AACxC,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAC3C,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,YAAY,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AACxD,MAAM,KAAK,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC1C,MAAM,cAAc,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAC5D,MAAM,cAAc,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAC5D,MAAM,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;AAC/C,SAAS,sBAAs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B,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AACvG,aAAa;AACb,iBAAiB;AACjB,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,IAAI,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AACpH,aAAa;AACb,SAAS,CAAC,CAAC;AACX,QAAQ,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;AAC3F,QAAQ,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;AACzC,YAAY,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,IAAI,YAAY,CAAC,iBAAiB,EAAE,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AACvH,SAAS;AACT,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD,OAAO,CAAC,sBAAsB,GAAG,sBAAsB;;"}
@@ -1,4 +0,0 @@
1
- import { ModelTypes } from '@aws-amplify/data-schema-types';
2
- import { V6Client } from '../types';
3
- import { GraphQLProviderConfig } from '@aws-amplify/core';
4
- export declare function generateModelsProperty<T extends Record<any, any> = never>(client: V6Client<Record<string, any>>, graphqlConfig: GraphQLProviderConfig['GraphQL']): ModelTypes<T>;
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateModelsProperty.mjs","sources":["../../../src/internals/generateModelsProperty.ts"],"sourcesContent":["import { graphQLOperationsInfo } from './APIClient';\nimport { listFactory } from './operations/list';\nimport { indexQueryFactory } from './operations/indexQuery';\nimport { getFactory } from './operations/get';\nimport { subscriptionFactory } from './operations/subscription';\nimport { observeQueryFactory } from './operations/observeQuery';\nimport { getSecondaryIndexesFromSchemaModel } from './clientUtils';\nexport function generateModelsProperty(client, graphqlConfig) {\n const models = {};\n const modelIntrospection = graphqlConfig.modelIntrospection;\n if (!modelIntrospection) {\n return {};\n }\n const SUBSCRIPTION_OPS = ['ONCREATE', 'ONUPDATE', 'ONDELETE'];\n for (const model of Object.values(modelIntrospection.models)) {\n const { name } = model;\n models[name] = {};\n Object.entries(graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {\n const operation = key;\n if (operation === 'LIST') {\n models[name][operationPrefix] = listFactory(client, modelIntrospection, model);\n }\n else if (SUBSCRIPTION_OPS.includes(operation)) {\n models[name][operationPrefix] = subscriptionFactory(client, modelIntrospection, model, operation);\n }\n else if (operation === 'OBSERVE_QUERY') {\n models[name][operationPrefix] = observeQueryFactory(models, model);\n }\n else {\n models[name][operationPrefix] = getFactory(client, modelIntrospection, model, operation);\n }\n });\n const secondaryIdxs = getSecondaryIndexesFromSchemaModel(model);\n for (const idx of secondaryIdxs) {\n models[name][idx.queryField] = indexQueryFactory(client, modelIntrospection, model, idx);\n }\n }\n return models;\n}\n"],"names":[],"mappings":";;;;;;;;AAOO,SAAS,sBAAsB,CAAC,MAAM,EAAE,aAAa,EAAE;AAC9D,IAAI,MAAM,MAAM,GAAG,EAAE,CAAC;AACtB,IAAI,MAAM,kBAAkB,GAAG,aAAa,CAAC,kBAAkB,CAAC;AAChE,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC7B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,gBAAgB,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAClE,IAAI,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE;AAClE,QAAQ,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;AAC/B,QAAQ,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AAC1B,QAAQ,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,eAAe,EAAE,CAAC,KAAK;AACtF,YA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