@aws-amplify/api-graphql 4.0.16 → 4.0.17-unstable.1fdbb12.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 (63) 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/cjs/internals/v6.js +1 -1
  16. package/dist/cjs/internals/v6.js.map +1 -1
  17. package/dist/esm/internals/APIClient.mjs +0 -1
  18. package/dist/esm/internals/APIClient.mjs.map +1 -1
  19. package/dist/esm/internals/InternalGraphQLAPI.mjs +7 -2
  20. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  21. package/dist/esm/internals/generateClient.mjs +20 -18
  22. package/dist/esm/internals/generateClient.mjs.map +1 -1
  23. package/dist/esm/internals/utils/generateEnumsProperty.d.ts +3 -0
  24. package/dist/esm/internals/utils/generateEnumsProperty.mjs +18 -0
  25. package/dist/esm/internals/utils/generateEnumsProperty.mjs.map +1 -0
  26. package/dist/esm/internals/utils/generateModelsProperty.d.ts +4 -0
  27. package/dist/esm/internals/{generateModelsProperty.mjs → utils/generateModelsProperty.mjs} +9 -9
  28. package/dist/esm/internals/utils/generateModelsProperty.mjs.map +1 -0
  29. package/dist/esm/internals/utils/isApiGraphQLProviderConfig.d.ts +2 -0
  30. package/dist/esm/internals/utils/isApiGraphQLProviderConfig.mjs +8 -0
  31. package/dist/esm/internals/utils/isApiGraphQLProviderConfig.mjs.map +1 -0
  32. package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.d.ts +8 -0
  33. package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.mjs +8 -0
  34. package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.mjs.map +1 -0
  35. package/dist/esm/internals/v6.mjs +1 -1
  36. package/dist/esm/internals/v6.mjs.map +1 -1
  37. package/dist/esm/types/index.d.ts +2 -1
  38. package/dist/esm/utils/resolveLibraryOptions.d.ts +4 -1
  39. package/package.json +5 -5
  40. package/src/GraphQLAPI.ts +2 -2
  41. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +20 -20
  42. package/src/internals/APIClient.ts +6 -8
  43. package/src/internals/InternalGraphQLAPI.ts +25 -20
  44. package/src/internals/generateClient.ts +23 -35
  45. package/src/internals/operations/get.ts +11 -11
  46. package/src/internals/operations/list.ts +10 -10
  47. package/src/internals/operations/subscription.ts +6 -6
  48. package/src/internals/server/generateClientWithAmplifyInstance.ts +1 -1
  49. package/src/internals/utils/generateEnumsProperty.ts +33 -0
  50. package/src/internals/{generateModelsProperty.ts → utils/generateModelsProperty.ts} +14 -12
  51. package/src/internals/utils/isApiGraphQLProviderConfig.ts +10 -0
  52. package/src/internals/utils/isConfigureEventWithResourceConfig.ts +13 -0
  53. package/src/internals/v6.ts +5 -5
  54. package/src/server/generateClient.ts +2 -2
  55. package/src/types/index.ts +51 -45
  56. package/src/utils/ConnectionStateMonitor.ts +6 -6
  57. package/src/utils/errors/assertValidationError.ts +1 -1
  58. package/src/utils/findIndexByFields.ts +3 -3
  59. package/src/utils/resolveConfig.ts +2 -2
  60. package/src/utils/resolveOwnerFields.ts +1 -1
  61. package/dist/cjs/internals/generateModelsProperty.js.map +0 -1
  62. package/dist/esm/internals/generateModelsProperty.d.ts +0 -4
  63. package/dist/esm/internals/generateModelsProperty.mjs.map +0 -1
@@ -30,12 +30,12 @@ export function getFactory(
30
30
  modelIntrospection: ModelIntrospectionSchema,
31
31
  model: SchemaModel,
32
32
  operation: ModelOperation,
33
- useContext = false
33
+ useContext = false,
34
34
  ) {
35
35
  const getWithContext = async (
36
36
  contextSpec: AmplifyServer.ContextSpec & GraphQLOptionsV6<unknown, string>,
37
37
  arg?: any,
38
- options?: any
38
+ options?: any,
39
39
  ) => {
40
40
  return _get(
41
41
  client,
@@ -44,7 +44,7 @@ export function getFactory(
44
44
  arg,
45
45
  options,
46
46
  operation,
47
- contextSpec
47
+ contextSpec,
48
48
  );
49
49
  };
50
50
 
@@ -62,7 +62,7 @@ async function _get(
62
62
  arg: QueryArgs,
63
63
  options: AuthModeParams & ListArgs,
64
64
  operation: ModelOperation,
65
- context?: AmplifyServer.ContextSpec
65
+ context?: AmplifyServer.ContextSpec,
66
66
  ) {
67
67
  const { name } = model;
68
68
 
@@ -70,13 +70,13 @@ async function _get(
70
70
  modelIntrospection.models,
71
71
  name,
72
72
  operation,
73
- options
73
+ options,
74
74
  );
75
75
  const variables = buildGraphQLVariables(
76
76
  model,
77
77
  operation,
78
78
  arg,
79
- modelIntrospection
79
+ modelIntrospection,
80
80
  );
81
81
 
82
82
  try {
@@ -92,16 +92,16 @@ async function _get(
92
92
  query,
93
93
  variables,
94
94
  },
95
- headers
96
- )) as GraphQLResult<any>)
95
+ headers,
96
+ )) as GraphQLResult<any>)
97
97
  : ((await (client as V6Client<Record<string, any>>).graphql(
98
98
  {
99
99
  ...auth,
100
100
  query,
101
101
  variables,
102
102
  },
103
- headers
104
- )) as GraphQLResult<any>);
103
+ headers,
104
+ )) as GraphQLResult<any>);
105
105
 
106
106
  // flatten response
107
107
  if (data) {
@@ -119,7 +119,7 @@ async function _get(
119
119
  modelIntrospection,
120
120
  auth.authMode,
121
121
  auth.authToken,
122
- !!context
122
+ !!context,
123
123
  );
124
124
 
125
125
  return { data: initialized, extensions };
@@ -26,11 +26,11 @@ export function listFactory(
26
26
  client: ClientWithModels,
27
27
  modelIntrospection: ModelIntrospectionSchema,
28
28
  model: SchemaModel,
29
- context = false
29
+ context = false,
30
30
  ) {
31
31
  const listWithContext = async (
32
32
  contextSpec: AmplifyServer.ContextSpec,
33
- args?: ListArgs
33
+ args?: ListArgs,
34
34
  ) => {
35
35
  return _list(client, modelIntrospection, model, args, contextSpec);
36
36
  };
@@ -47,7 +47,7 @@ async function _list(
47
47
  modelIntrospection: ModelIntrospectionSchema,
48
48
  model: SchemaModel,
49
49
  args?: ListArgs & AuthModeParams,
50
- contextSpec?: AmplifyServer.ContextSpec
50
+ contextSpec?: AmplifyServer.ContextSpec,
51
51
  ) {
52
52
  const { name } = model;
53
53
 
@@ -55,13 +55,13 @@ async function _list(
55
55
  modelIntrospection.models,
56
56
  name,
57
57
  'LIST',
58
- args
58
+ args,
59
59
  );
60
60
  const variables = buildGraphQLVariables(
61
61
  model,
62
62
  'LIST',
63
63
  args,
64
- modelIntrospection
64
+ modelIntrospection,
65
65
  );
66
66
 
67
67
  try {
@@ -77,16 +77,16 @@ async function _list(
77
77
  query,
78
78
  variables,
79
79
  },
80
- headers
81
- )) as GraphQLResult<any>)
80
+ headers,
81
+ )) as GraphQLResult<any>)
82
82
  : ((await (client as V6Client<Record<string, any>>).graphql(
83
83
  {
84
84
  ...auth,
85
85
  query,
86
86
  variables,
87
87
  },
88
- headers
89
- )) as GraphQLResult<any>);
88
+ headers,
89
+ )) as GraphQLResult<any>);
90
90
 
91
91
  // flatten response
92
92
  if (data !== undefined) {
@@ -110,7 +110,7 @@ async function _list(
110
110
  modelIntrospection,
111
111
  auth.authMode,
112
112
  auth.authToken,
113
- !!contextSpec
113
+ !!contextSpec,
114
114
  );
115
115
 
116
116
  return {
@@ -20,7 +20,7 @@ export function subscriptionFactory(
20
20
  client: any,
21
21
  modelIntrospection: ModelIntrospectionSchema,
22
22
  model: SchemaModel,
23
- operation: ModelOperation
23
+ operation: ModelOperation,
24
24
  ) {
25
25
  const { name } = model as any;
26
26
 
@@ -28,13 +28,13 @@ export function subscriptionFactory(
28
28
  const query = generateGraphQLDocument(
29
29
  modelIntrospection.models,
30
30
  name,
31
- operation
31
+ operation,
32
32
  );
33
33
  const variables = buildGraphQLVariables(
34
34
  model,
35
35
  operation,
36
36
  args,
37
- modelIntrospection
37
+ modelIntrospection,
38
38
  );
39
39
 
40
40
  const auth = authModeParams(client, args);
@@ -47,7 +47,7 @@ export function subscriptionFactory(
47
47
  query,
48
48
  variables,
49
49
  },
50
- headers
50
+ headers,
51
51
  ) as GraphqlSubscriptionResult<object>;
52
52
 
53
53
  return observable.pipe(
@@ -60,10 +60,10 @@ export function subscriptionFactory(
60
60
  [data],
61
61
  modelIntrospection,
62
62
  auth.authMode,
63
- auth.authToken
63
+ auth.authToken,
64
64
  );
65
65
  return initialized;
66
- })
66
+ }),
67
67
  );
68
68
  };
69
69
 
@@ -30,7 +30,7 @@ export function generateClientWithAmplifyInstance<
30
30
  | V6ClientSSRRequest<T>
31
31
  | V6ClientSSRCookies<T> = V6ClientSSRCookies<T>,
32
32
  >(
33
- params: ServerClientGenerationParams & CommonPublicClientOptions
33
+ params: ServerClientGenerationParams & CommonPublicClientOptions,
34
34
  ): ClientType {
35
35
  const client = {
36
36
  [__amplify]: params.amplify,
@@ -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
+ }
@@ -101,12 +101,12 @@ export function graphql<
101
101
  >(
102
102
  this: V6Client,
103
103
  options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
104
- additionalHeaders?: CustomHeaders
104
+ additionalHeaders?: CustomHeaders,
105
105
  ): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING> {
106
- // inject client-level auth
106
+ // inject client-level auth
107
107
  options.authMode = options.authMode || this[__authMode];
108
108
  options.authToken = options.authToken || this[__authToken];
109
-
109
+
110
110
  /**
111
111
  * The correctness of these typings depends on correct string branding or overrides.
112
112
  * Neither of these can actually be validated at runtime. Hence, we don't perform
@@ -115,7 +115,7 @@ export function graphql<
115
115
  const result = GraphQLAPI.graphql(
116
116
  this[__amplify],
117
117
  options,
118
- additionalHeaders
118
+ additionalHeaders,
119
119
  );
120
120
  return result as any;
121
121
  }
@@ -128,7 +128,7 @@ export function graphql<
128
128
  export function cancel(
129
129
  this: V6Client,
130
130
  promise: Promise<any>,
131
- message?: string
131
+ message?: string,
132
132
  ): boolean {
133
133
  return GraphQLAPI.cancel(promise, message);
134
134
  }
@@ -52,13 +52,13 @@ export function generateClient<T extends Record<any, any> = never>({
52
52
  const wrappedGraphql = (
53
53
  contextSpec: AmplifyServer.ContextSpec,
54
54
  options: GraphQLOptionsV6,
55
- additionalHeaders?: CustomHeaders
55
+ additionalHeaders?: CustomHeaders,
56
56
  ) => {
57
57
  const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;
58
58
  return prevGraphql.call(
59
59
  { [__amplify]: amplifyInstance },
60
60
  options,
61
- additionalHeaders as any
61
+ additionalHeaders as any,
62
62
  );
63
63
  };
64
64
 
@@ -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
3
  import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
4
- import { ModelTypes, CustomHeaders } from '@aws-amplify/data-schema-types';
4
+ import {
5
+ ModelTypes,
6
+ CustomHeaders,
7
+ EnumTypes,
8
+ } from '@aws-amplify/data-schema-types';
5
9
  import { Source, DocumentNode, GraphQLError } from 'graphql';
6
10
  export { OperationTypeNode } from 'graphql';
7
11
  import { Observable } from 'rxjs';
@@ -72,7 +76,7 @@ export type GraphQLSubscription<T> = T & {
72
76
  export type GraphQLReturnType<T> = T extends {}
73
77
  ? {
74
78
  [K in keyof T]?: GraphQLReturnType<T[K]>;
75
- }
79
+ }
76
80
  : T;
77
81
 
78
82
  /**
@@ -93,13 +97,14 @@ type PagedList<T, TYPENAME> = {
93
97
  * array, this will only be the case when we also have errors,
94
98
  * which will then be *thrown*.
95
99
  */
96
- type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME>
97
- ? PagedList<Exclude<IT, null | undefined>, NAME>
98
- : T extends {}
99
- ? {
100
- [K in keyof T]: WithListsFixed<T[K]>;
101
- }
102
- : T;
100
+ type WithListsFixed<T> =
101
+ T extends PagedList<infer IT, infer NAME>
102
+ ? PagedList<Exclude<IT, null | undefined>, NAME>
103
+ : T extends {}
104
+ ? {
105
+ [K in keyof T]: WithListsFixed<T[K]>;
106
+ }
107
+ : T;
103
108
 
104
109
  /**
105
110
  * Returns an updated response type to always return a value.
@@ -115,14 +120,12 @@ type NeverEmpty<T> = {
115
120
  * If empty members are present, there will also be errors present,
116
121
  * and the response will instead be *thrown*.
117
122
  */
118
- type FixedQueryResult<T> = Exclude<
119
- T[keyof T],
120
- null | undefined
121
- > extends PagedList<any, any>
122
- ? {
123
- [K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
124
- }
125
- : T;
123
+ type FixedQueryResult<T> =
124
+ Exclude<T[keyof T], null | undefined> extends PagedList<any, any>
125
+ ? {
126
+ [K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
127
+ }
128
+ : T;
126
129
 
127
130
  /**
128
131
  * The return value from a `graphql({query})` call when `query` is a subscription.
@@ -181,7 +184,7 @@ export interface AWSAppSyncRealTimeProviderOptions {
181
184
 
182
185
  export type AWSAppSyncRealTimeProvider = {
183
186
  subscribe(
184
- options?: AWSAppSyncRealTimeProviderOptions
187
+ options?: AWSAppSyncRealTimeProviderOptions,
185
188
  ): Observable<Record<string, unknown>>;
186
189
  };
187
190
 
@@ -235,15 +238,16 @@ export type UnknownGraphQLResponse =
235
238
  export type GraphQLVariablesV6<
236
239
  FALLBACK_TYPES = unknown,
237
240
  TYPED_GQL_STRING extends string = string,
238
- > = TYPED_GQL_STRING extends GeneratedQuery<infer IN, any>
239
- ? IN
240
- : TYPED_GQL_STRING extends GeneratedMutation<infer IN, any>
241
- ? IN
242
- : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, any>
243
- ? IN
244
- : FALLBACK_TYPES extends GraphQLOperationType<infer IN, any>
245
- ? IN
246
- : any;
241
+ > =
242
+ TYPED_GQL_STRING extends GeneratedQuery<infer IN, any>
243
+ ? IN
244
+ : TYPED_GQL_STRING extends GeneratedMutation<infer IN, any>
245
+ ? IN
246
+ : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, any>
247
+ ? IN
248
+ : FALLBACK_TYPES extends GraphQLOperationType<infer IN, any>
249
+ ? IN
250
+ : any;
247
251
 
248
252
  /**
249
253
  * The expected return type with respect to the given `FALLBACK_TYPE`
@@ -252,22 +256,23 @@ export type GraphQLVariablesV6<
252
256
  export type GraphQLResponseV6<
253
257
  FALLBACK_TYPE = unknown,
254
258
  TYPED_GQL_STRING extends string = string,
255
- > = TYPED_GQL_STRING extends GeneratedQuery<infer IN, infer QUERY_OUT>
256
- ? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>>
257
- : TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT>
258
- ? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>>
259
- : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT>
260
- ? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>>
261
- : FALLBACK_TYPE extends GraphQLQuery<infer T>
262
- ? Promise<GraphQLResult<FALLBACK_TYPE>>
263
- : FALLBACK_TYPE extends GraphQLSubscription<infer T>
264
- ? GraphqlSubscriptionResult<FALLBACK_TYPE>
265
- : FALLBACK_TYPE extends GraphQLOperationType<
266
- infer IN,
267
- infer CUSTOM_OUT
268
- >
269
- ? CUSTOM_OUT
270
- : UnknownGraphQLResponse;
259
+ > =
260
+ TYPED_GQL_STRING extends GeneratedQuery<infer IN, infer QUERY_OUT>
261
+ ? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>>
262
+ : TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT>
263
+ ? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>>
264
+ : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT>
265
+ ? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>>
266
+ : FALLBACK_TYPE extends GraphQLQuery<infer T>
267
+ ? Promise<GraphQLResult<FALLBACK_TYPE>>
268
+ : FALLBACK_TYPE extends GraphQLSubscription<infer T>
269
+ ? GraphqlSubscriptionResult<FALLBACK_TYPE>
270
+ : FALLBACK_TYPE extends GraphQLOperationType<
271
+ infer IN,
272
+ infer CUSTOM_OUT
273
+ >
274
+ ? CUSTOM_OUT
275
+ : UnknownGraphQLResponse;
271
276
 
272
277
  /**
273
278
  * The shape customers can use to provide `T` to `graphql<T>()` to specify both
@@ -382,6 +387,7 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
382
387
  cancel: (promise: Promise<any>, message?: string) => boolean;
383
388
  isCancelError: (error: any) => boolean;
384
389
  models: ModelTypes<T>;
390
+ enums: EnumTypes<T>;
385
391
  }>;
386
392
 
387
393
  export type V6ClientSSRRequest<T extends Record<any, any> = never> =
@@ -413,7 +419,7 @@ export type GraphQLMethod = <
413
419
  TYPED_GQL_STRING extends string = string,
414
420
  >(
415
421
  options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
416
- additionalHeaders?: CustomHeaders | undefined
422
+ additionalHeaders?: CustomHeaders | undefined,
417
423
  ) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
418
424
 
419
425
  export type GraphQLMethodSSR = <
@@ -422,7 +428,7 @@ export type GraphQLMethodSSR = <
422
428
  >(
423
429
  contextSpec: AmplifyServer.ContextSpec,
424
430
  options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
425
- additionalHeaders?: CustomHeaders | undefined
431
+ additionalHeaders?: CustomHeaders | undefined,
426
432
  ) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
427
433
 
428
434
  /**
@@ -69,10 +69,10 @@ export class ConnectionStateMonitor {
69
69
  this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(
70
70
  ({ online }) => {
71
71
  this.record(
72
- online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE
72
+ online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE,
73
73
  );
74
74
  this._initialNetworkStateSubscription?.unsubscribe();
75
- }
75
+ },
76
76
  );
77
77
 
78
78
  this._linkedConnectionStateObservable =
@@ -94,9 +94,9 @@ export class ConnectionStateMonitor {
94
94
  this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(
95
95
  ({ online }) => {
96
96
  this.record(
97
- online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE
97
+ online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE,
98
98
  );
99
- }
99
+ },
100
100
  );
101
101
  }
102
102
  }
@@ -126,14 +126,14 @@ export class ConnectionStateMonitor {
126
126
  .pipe(
127
127
  map(value => {
128
128
  return this.connectionStatesTranslator(value);
129
- })
129
+ }),
130
130
  )
131
131
  .pipe(
132
132
  filter(current => {
133
133
  const toInclude = current !== previous;
134
134
  previous = current;
135
135
  return toInclude;
136
- })
136
+ }),
137
137
  );
138
138
  }
139
139
 
@@ -9,7 +9,7 @@ import { APIValidationErrorCode, validationErrorMap } from './validation';
9
9
  */
10
10
  export function assertValidationError(
11
11
  assertion: boolean,
12
- name: APIValidationErrorCode
12
+ name: APIValidationErrorCode,
13
13
  ): asserts assertion {
14
14
  const { message, recoverySuggestion } = validationErrorMap[name];
15
15
 
@@ -11,16 +11,16 @@
11
11
  export function findIndexByFields<T>(
12
12
  needle: T,
13
13
  haystack: T[],
14
- keyFields: Array<keyof T>
14
+ keyFields: Array<keyof T>,
15
15
  ): number {
16
16
  const searchObject = Object.fromEntries(
17
- keyFields.map(fieldName => [fieldName, needle[fieldName]])
17
+ keyFields.map(fieldName => [fieldName, needle[fieldName]]),
18
18
  );
19
19
 
20
20
  for (let i = 0; i < haystack.length; i++) {
21
21
  if (
22
22
  Object.keys(searchObject).every(
23
- k => searchObject[k] === (haystack[i] as any)[k]
23
+ k => searchObject[k] === (haystack[i] as any)[k],
24
24
  )
25
25
  ) {
26
26
  return i;
@@ -14,7 +14,7 @@ export const resolveConfig = (amplify: AmplifyClassV6) => {
14
14
 
15
15
  if (!config.API?.GraphQL) {
16
16
  logger.warn(
17
- 'The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().'
17
+ 'The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().',
18
18
  );
19
19
  }
20
20
 
@@ -31,7 +31,7 @@ export const resolveConfig = (amplify: AmplifyClassV6) => {
31
31
  // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);
32
32
  assertValidationError(
33
33
  !(!customEndpoint && customEndpointRegion),
34
- APIValidationErrorCode.NoCustomEndpoint
34
+ APIValidationErrorCode.NoCustomEndpoint,
35
35
  );
36
36
 
37
37
  return {
@@ -56,7 +56,7 @@ function isAuthAttribute(attribute: any): attribute is AuthAttribute {
56
56
  if (typeof attribute?.properties === 'object') {
57
57
  if (Array.isArray(attribute?.properties?.rules)) {
58
58
  return (attribute?.properties?.rules as Array<any>).every(
59
- rule => !!rule.allow
59
+ rule => !!rule.allow,
60
60
  );
61
61
  }
62
62
  }
@@ -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,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K,eAAe,EAAE;AACpD,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,IAAI,cAAc,CAAC,mBAAmB,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,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