@aws-amplify/api-graphql 4.0.22 → 4.0.23

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 (106) 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 +4 -1
  8. package/dist/cjs/internals/generateClient.js.map +1 -1
  9. package/dist/cjs/internals/generateCustomOperationsProperty.js +6 -1
  10. package/dist/cjs/internals/generateCustomOperationsProperty.js.map +1 -1
  11. package/dist/cjs/internals/operations/custom.js +90 -7
  12. package/dist/cjs/internals/operations/custom.js.map +1 -1
  13. package/dist/cjs/internals/operations/list.js +1 -1
  14. package/dist/cjs/internals/operations/list.js.map +1 -1
  15. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +1 -1
  16. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -1
  17. package/dist/cjs/internals/server/generateModelsProperty.js +1 -1
  18. package/dist/cjs/internals/server/generateModelsProperty.js.map +1 -1
  19. package/dist/cjs/internals/v6.js +0 -2
  20. package/dist/cjs/internals/v6.js.map +1 -1
  21. package/dist/cjs/utils/errors/repackageAuthError.js +1 -1
  22. package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -1
  23. package/dist/cjs/utils/resolveOwnerFields.js +3 -0
  24. package/dist/cjs/utils/resolveOwnerFields.js.map +1 -1
  25. package/dist/esm/GraphQLAPI.d.ts +2 -2
  26. package/dist/esm/GraphQLAPI.mjs.map +1 -1
  27. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +8 -8
  28. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +40 -31
  29. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
  30. package/dist/esm/internals/APIClient.d.ts +5 -6
  31. package/dist/esm/internals/APIClient.mjs +34 -19
  32. package/dist/esm/internals/APIClient.mjs.map +1 -1
  33. package/dist/esm/internals/InternalGraphQLAPI.d.ts +1 -1
  34. package/dist/esm/internals/InternalGraphQLAPI.mjs +10 -9
  35. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  36. package/dist/esm/internals/generateClient.mjs +5 -2
  37. package/dist/esm/internals/generateClient.mjs.map +1 -1
  38. package/dist/esm/internals/generateCustomOperationsProperty.d.ts +4 -3
  39. package/dist/esm/internals/generateCustomOperationsProperty.mjs +5 -1
  40. package/dist/esm/internals/generateCustomOperationsProperty.mjs.map +1 -1
  41. package/dist/esm/internals/operations/custom.d.ts +6 -3
  42. package/dist/esm/internals/operations/custom.mjs +90 -7
  43. package/dist/esm/internals/operations/custom.mjs.map +1 -1
  44. package/dist/esm/internals/operations/get.d.ts +1 -1
  45. package/dist/esm/internals/operations/get.mjs.map +1 -1
  46. package/dist/esm/internals/operations/indexQuery.d.ts +3 -3
  47. package/dist/esm/internals/operations/indexQuery.mjs.map +1 -1
  48. package/dist/esm/internals/operations/list.d.ts +1 -1
  49. package/dist/esm/internals/operations/list.mjs +1 -1
  50. package/dist/esm/internals/operations/list.mjs.map +1 -1
  51. package/dist/esm/internals/operations/subscription.d.ts +1 -1
  52. package/dist/esm/internals/operations/subscription.mjs.map +1 -1
  53. package/dist/esm/internals/server/generateClientWithAmplifyInstance.d.ts +1 -1
  54. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs +1 -1
  55. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -1
  56. package/dist/esm/internals/server/generateModelsProperty.d.ts +3 -3
  57. package/dist/esm/internals/server/generateModelsProperty.mjs +1 -1
  58. package/dist/esm/internals/server/generateModelsProperty.mjs.map +1 -1
  59. package/dist/esm/internals/types.d.ts +2 -2
  60. package/dist/esm/internals/utils/clientProperties/generateModelsProperty.d.ts +2 -2
  61. package/dist/esm/internals/v6.d.ts +1 -1
  62. package/dist/esm/internals/v6.mjs +0 -2
  63. package/dist/esm/internals/v6.mjs.map +1 -1
  64. package/dist/esm/types/index.d.ts +34 -35
  65. package/dist/esm/utils/ConnectionStateMonitor.d.ts +2 -2
  66. package/dist/esm/utils/ConnectionStateMonitor.mjs.map +1 -1
  67. package/dist/esm/utils/ReachabilityMonitor/index.native.mjs.map +1 -1
  68. package/dist/esm/utils/errors/repackageAuthError.d.ts +2 -2
  69. package/dist/esm/utils/errors/repackageAuthError.mjs +1 -1
  70. package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -1
  71. package/dist/esm/utils/findIndexByFields.d.ts +1 -1
  72. package/dist/esm/utils/resolveOwnerFields.mjs +3 -0
  73. package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -1
  74. package/package.json +8 -7
  75. package/src/GraphQLAPI.ts +4 -3
  76. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +84 -64
  77. package/src/internals/APIClient.ts +83 -58
  78. package/src/internals/InternalGraphQLAPI.ts +26 -30
  79. package/src/internals/clientUtils.ts +1 -1
  80. package/src/internals/generateClient.ts +23 -10
  81. package/src/internals/generateCustomOperationsProperty.ts +31 -8
  82. package/src/internals/operations/custom.ts +159 -32
  83. package/src/internals/operations/get.ts +9 -8
  84. package/src/internals/operations/indexQuery.ts +12 -11
  85. package/src/internals/operations/list.ts +11 -15
  86. package/src/internals/operations/observeQuery.ts +3 -1
  87. package/src/internals/operations/subscription.ts +12 -10
  88. package/src/internals/server/generateClientWithAmplifyInstance.ts +7 -7
  89. package/src/internals/server/generateModelsProperty.ts +12 -6
  90. package/src/internals/types.ts +2 -2
  91. package/src/internals/utils/clientProperties/generateEnumsProperty.ts +7 -6
  92. package/src/internals/utils/clientProperties/generateModelsProperty.ts +8 -7
  93. package/src/internals/v6.ts +6 -4
  94. package/src/server/generateClient.ts +4 -1
  95. package/src/types/PubSub.ts +1 -0
  96. package/src/types/index.ts +51 -47
  97. package/src/utils/ConnectionStateMonitor.ts +8 -3
  98. package/src/utils/ReachabilityMonitor/index.native.ts +1 -1
  99. package/src/utils/ReachabilityMonitor/index.ts +1 -0
  100. package/src/utils/ReconnectionMonitor.ts +1 -0
  101. package/src/utils/errors/repackageAuthError.ts +6 -7
  102. package/src/utils/findIndexByFields.ts +1 -1
  103. package/src/utils/resolveConfig.ts +1 -0
  104. package/src/utils/resolveLibraryOptions.ts +1 -0
  105. package/src/utils/resolveOwnerFields.ts +16 -7
  106. package/src/utils/resolvePKFields.ts +1 -0
@@ -1,6 +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 { Observer } from 'rxjs';
4
+
4
5
  export interface SubscriptionObserver<T> {
5
6
  closed: boolean;
6
7
  next(value: T): void;
@@ -2,22 +2,23 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
4
4
  import {
5
- EnumTypes,
6
- ModelTypes,
7
5
  CustomHeaders,
8
- CustomQueries,
9
6
  CustomMutations,
7
+ CustomQueries,
8
+ CustomSubscriptions,
9
+ EnumTypes,
10
+ ModelTypes,
10
11
  } from '@aws-amplify/data-schema-types';
11
- import { Source, DocumentNode, GraphQLError } from 'graphql';
12
- export { OperationTypeNode } from 'graphql';
12
+ import { DocumentNode, GraphQLError, Source } from 'graphql';
13
13
  import { Observable } from 'rxjs';
14
-
15
14
  import {
16
- GraphQLAuthMode,
17
15
  DocumentType,
16
+ GraphQLAuthMode,
18
17
  } from '@aws-amplify/core/internals/utils';
19
18
  import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
20
19
 
20
+ export { OperationTypeNode } from 'graphql';
21
+
21
22
  export { CONTROL_MSG, ConnectionState } from './PubSub';
22
23
 
23
24
  export { SelectionSet } from '@aws-amplify/data-schema-types';
@@ -41,9 +42,7 @@ export interface GraphQLOptions {
41
42
  export interface GraphQLResult<T = object> {
42
43
  data: T;
43
44
  errors?: GraphQLError[];
44
- extensions?: {
45
- [key: string]: any;
46
- };
45
+ extensions?: Record<string, any>;
47
46
  }
48
47
 
49
48
  // Opaque type used for determining the graphql query type
@@ -75,21 +74,22 @@ export type GraphQLSubscription<T> = T & {
75
74
  *
76
75
  * This util simply makes related model properties optional recursively.
77
76
  */
78
- export type GraphQLReturnType<T> = T extends {}
79
- ? {
80
- [K in keyof T]?: GraphQLReturnType<T[K]>;
81
- }
82
- : T;
77
+ export type GraphQLReturnType<T> =
78
+ T extends Record<string, unknown>
79
+ ? {
80
+ [K in keyof T]?: GraphQLReturnType<T[K]>;
81
+ }
82
+ : T;
83
83
 
84
84
  /**
85
85
  * Describes a paged list result from AppSync, which can either
86
86
  * live at the top query or property (e.g., related model) level.
87
87
  */
88
- type PagedList<T, TYPENAME> = {
88
+ interface PagedList<T, TYPENAME> {
89
89
  __typename: TYPENAME;
90
90
  nextToken?: string | null | undefined;
91
- items: Array<T>;
92
- };
91
+ items: T[];
92
+ }
93
93
 
94
94
  /**
95
95
  * Recursively looks through a result type and removes nulls and
@@ -102,7 +102,7 @@ type PagedList<T, TYPENAME> = {
102
102
  type WithListsFixed<T> =
103
103
  T extends PagedList<infer IT, infer NAME>
104
104
  ? PagedList<Exclude<IT, null | undefined>, NAME>
105
- : T extends {}
105
+ : T extends Record<string, unknown>
106
106
  ? {
107
107
  [K in keyof T]: WithListsFixed<T[K]>;
108
108
  }
@@ -169,9 +169,9 @@ export type GraphqlSubscriptionResult<T> = Observable<
169
169
  * })
170
170
  * ```
171
171
  */
172
- export type GraphqlSubscriptionMessage<T> = {
172
+ export interface GraphqlSubscriptionMessage<T> {
173
173
  data: T;
174
- };
174
+ }
175
175
 
176
176
  export interface AWSAppSyncRealTimeProviderOptions {
177
177
  appSyncGraphqlEndpoint?: string;
@@ -180,15 +180,15 @@ export interface AWSAppSyncRealTimeProviderOptions {
180
180
  variables?: Record<string, unknown>;
181
181
  apiKey?: string;
182
182
  region?: string;
183
- libraryConfigHeaders?: () => {} | (() => Promise<{}>);
183
+ libraryConfigHeaders?(): () => Promise<Record<string, unknown> | Headers>;
184
184
  additionalHeaders?: CustomHeaders;
185
185
  }
186
186
 
187
- export type AWSAppSyncRealTimeProvider = {
187
+ export interface AWSAppSyncRealTimeProvider {
188
188
  subscribe(
189
189
  options?: AWSAppSyncRealTimeProviderOptions,
190
190
  ): Observable<Record<string, unknown>>;
191
- };
191
+ }
192
192
 
193
193
  export enum GraphQLAuthError {
194
194
  NO_API_KEY = 'No api-key configured',
@@ -259,18 +259,18 @@ export type GraphQLResponseV6<
259
259
  FALLBACK_TYPE = unknown,
260
260
  TYPED_GQL_STRING extends string = string,
261
261
  > =
262
- TYPED_GQL_STRING extends GeneratedQuery<infer IN, infer QUERY_OUT>
262
+ TYPED_GQL_STRING extends GeneratedQuery<infer _, infer QUERY_OUT>
263
263
  ? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>>
264
- : TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT>
264
+ : TYPED_GQL_STRING extends GeneratedMutation<infer _, infer MUTATION_OUT>
265
265
  ? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>>
266
- : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT>
266
+ : TYPED_GQL_STRING extends GeneratedSubscription<infer _, infer SUB_OUT>
267
267
  ? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>>
268
- : FALLBACK_TYPE extends GraphQLQuery<infer T>
268
+ : FALLBACK_TYPE extends GraphQLQuery<infer _>
269
269
  ? Promise<GraphQLResult<FALLBACK_TYPE>>
270
- : FALLBACK_TYPE extends GraphQLSubscription<infer T>
270
+ : FALLBACK_TYPE extends GraphQLSubscription<infer _>
271
271
  ? GraphqlSubscriptionResult<FALLBACK_TYPE>
272
272
  : FALLBACK_TYPE extends GraphQLOperationType<
273
- infer IN,
273
+ infer _,
274
274
  infer CUSTOM_OUT
275
275
  >
276
276
  ? CUSTOM_OUT
@@ -294,10 +294,13 @@ export type GraphQLResponseV6<
294
294
  * })
295
295
  * ```
296
296
  */
297
- export type GraphQLOperationType<IN extends {}, OUT extends {}> = {
297
+ export interface GraphQLOperationType<
298
+ IN extends Record<string, DocumentType>,
299
+ OUT extends Record<string, DocumentType>,
300
+ > {
298
301
  variables: IN;
299
302
  result: OUT;
300
- };
303
+ }
301
304
 
302
305
  /**
303
306
  * Nominal type for branding generated graphql query operation strings with
@@ -386,12 +389,13 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
386
389
  [__authToken]?: string;
387
390
  [__headers]?: CustomHeaders;
388
391
  graphql: GraphQLMethod;
389
- cancel: (promise: Promise<any>, message?: string) => boolean;
390
- isCancelError: (error: any) => boolean;
392
+ cancel(promise: Promise<any>, message?: string): boolean;
393
+ isCancelError(error: any): boolean;
391
394
  models: ModelTypes<T>;
392
395
  enums: EnumTypes<T>;
393
396
  queries: CustomQueries<T>;
394
397
  mutations: CustomMutations<T>;
398
+ subscriptions: CustomSubscriptions<T>;
395
399
  }>;
396
400
 
397
401
  export type V6ClientSSRRequest<T extends Record<any, any> = never> =
@@ -401,8 +405,8 @@ export type V6ClientSSRRequest<T extends Record<any, any> = never> =
401
405
  [__authToken]?: string;
402
406
  [__headers]?: CustomHeaders;
403
407
  graphql: GraphQLMethodSSR;
404
- cancel: (promise: Promise<any>, message?: string) => boolean;
405
- isCancelError: (error: any) => boolean;
408
+ cancel(promise: Promise<any>, message?: string): boolean;
409
+ isCancelError(error: any): boolean;
406
410
  models: ModelTypes<T, 'REQUEST'>;
407
411
  enums: EnumTypes<T>;
408
412
  queries: CustomQueries<T, 'REQUEST'>;
@@ -416,8 +420,8 @@ export type V6ClientSSRCookies<T extends Record<any, any> = never> =
416
420
  [__authToken]?: string;
417
421
  [__headers]?: CustomHeaders;
418
422
  graphql: GraphQLMethod;
419
- cancel: (promise: Promise<any>, message?: string) => boolean;
420
- isCancelError: (error: any) => boolean;
423
+ cancel(promise: Promise<any>, message?: string): boolean;
424
+ isCancelError(error: any): boolean;
421
425
  models: ModelTypes<T, 'COOKIES'>;
422
426
  enums: EnumTypes<T>;
423
427
  queries: CustomQueries<T, 'COOKIES'>;
@@ -446,30 +450,30 @@ export type GraphQLMethodSSR = <
446
450
  *
447
451
  * The knobs available for configuring `server/generateClient` internally.
448
452
  */
449
- export type ServerClientGenerationParams = {
453
+ export interface ServerClientGenerationParams {
450
454
  amplify:
451
455
  | null // null expected when used with `generateServerClient`
452
456
  // closure expected with `generateServerClientUsingCookies`
453
457
  | ((fn: (amplify: AmplifyClassV6) => Promise<any>) => Promise<any>);
454
458
  // global env-sourced config use for retrieving modelIntro
455
459
  config: ResourcesConfig;
456
- };
460
+ }
457
461
 
458
462
  export type QueryArgs = Record<string, unknown>;
459
463
 
460
- export type ListArgs = {
464
+ export interface ListArgs extends Record<string, unknown> {
461
465
  selectionSet?: string[];
462
- filter?: {};
466
+ filter?: Record<string, unknown>;
463
467
  headers?: CustomHeaders;
464
- };
468
+ }
465
469
 
466
- export type AuthModeParams = {
470
+ export interface AuthModeParams extends Record<string, unknown> {
467
471
  authMode?: GraphQLAuthMode;
468
472
  authToken?: string;
469
- };
473
+ }
470
474
 
471
- export type GenerateServerClientParams = {
475
+ export interface GenerateServerClientParams {
472
476
  config: ResourcesConfig;
473
477
  authMode?: GraphQLAuthMode;
474
478
  authToken?: string;
475
- };
479
+ }
@@ -1,19 +1,21 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { Observable, Observer, SubscriptionLike, map, filter } from 'rxjs';
4
+ import { Observable, Observer, SubscriptionLike, filter, map } from 'rxjs';
5
+
5
6
  import { ConnectionState } from '../types/PubSub';
7
+
6
8
  import { ReachabilityMonitor } from './ReachabilityMonitor';
7
9
 
8
10
  // Internal types for tracking different connection states
9
11
  type LinkedConnectionState = 'connected' | 'disconnected';
10
12
  type LinkedHealthState = 'healthy' | 'unhealthy';
11
- type LinkedConnectionStates = {
13
+ interface LinkedConnectionStates {
12
14
  networkState: LinkedConnectionState;
13
15
  connectionState: LinkedConnectionState | 'connecting';
14
16
  intendedConnectionState: LinkedConnectionState;
15
17
  keepAliveState: LinkedHealthState;
16
- };
18
+ }
17
19
 
18
20
  export const CONNECTION_CHANGE: {
19
21
  [key in
@@ -53,6 +55,7 @@ export class ConnectionStateMonitor {
53
55
  private _linkedConnectionStateObserver:
54
56
  | Observer<LinkedConnectionStates>
55
57
  | undefined;
58
+
56
59
  private _networkMonitoringSubscription?: SubscriptionLike;
57
60
  private _initialNetworkStateSubscription?: SubscriptionLike;
58
61
 
@@ -132,6 +135,7 @@ export class ConnectionStateMonitor {
132
135
  filter(current => {
133
136
  const toInclude = current !== previous;
134
137
  previous = current;
138
+
135
139
  return toInclude;
136
140
  }),
137
141
  );
@@ -196,6 +200,7 @@ export class ConnectionStateMonitor {
196
200
  // All remaining states directly correspond to the connection state
197
201
  if (connectionState === 'connecting') return ConnectionState.Connecting;
198
202
  if (connectionState === 'disconnected') return ConnectionState.Disconnected;
203
+
199
204
  return ConnectionState.Connected;
200
205
  }
201
206
  }
@@ -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 { Reachability } from '@aws-amplify/core/internals/utils';
4
- import { default as NetInfo } from '@react-native-community/netinfo';
4
+ import NetInfo from '@react-native-community/netinfo';
5
5
 
6
6
  export const ReachabilityMonitor = () =>
7
7
  new Reachability().networkMonitor(NetInfo);
@@ -1,4 +1,5 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Reachability } from '@aws-amplify/core/internals/utils';
4
+
4
5
  export const ReachabilityMonitor = () => new Reachability().networkMonitor();
@@ -1,6 +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 { Observer } from 'rxjs';
4
+
4
5
  import { RECONNECT_DELAY, RECONNECT_INTERVAL } from '../Providers/constants';
5
6
 
6
7
  export enum ReconnectEvent {
@@ -1,14 +1,11 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import {
5
- AmplifyErrorParams,
6
- GraphQLAuthMode,
7
- } from '@aws-amplify/core/internals/utils';
4
+ import { AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
8
5
 
9
- type ErrorObject = {
6
+ interface ErrorObject {
10
7
  errors: AmplifyErrorParams[];
11
- };
8
+ }
12
9
 
13
10
  /**
14
11
  * Checks to see if the given response or subscription message contains an
@@ -27,12 +24,13 @@ export function repackageUnauthError<T extends ErrorObject>(content: T): T {
27
24
  }
28
25
  });
29
26
  }
27
+
30
28
  return content;
31
29
  }
32
30
 
33
31
  function isUnauthError(error: any): boolean {
34
32
  // Error pattern corresponding to appsync calls
35
- if (error?.['originalError']?.['name']?.startsWith('UnauthorizedException')) {
33
+ if (error?.originalError?.name?.startsWith('UnauthorizedException')) {
36
34
  return true;
37
35
  }
38
36
  // Error pattern corresponding to appsync subscriptions
@@ -42,5 +40,6 @@ function isUnauthError(error: any): boolean {
42
40
  ) {
43
41
  return true;
44
42
  }
43
+
45
44
  return false;
46
45
  }
@@ -11,7 +11,7 @@
11
11
  export function findIndexByFields<T>(
12
12
  needle: T,
13
13
  haystack: T[],
14
- keyFields: Array<keyof T>,
14
+ keyFields: (keyof T)[],
15
15
  ): number {
16
16
  const searchObject = Object.fromEntries(
17
17
  keyFields.map(fieldName => [fieldName, needle[fieldName]]),
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { AmplifyClassV6, ConsoleLogger } from '@aws-amplify/core';
5
+
5
6
  import { APIValidationErrorCode, assertValidationError } from './errors';
6
7
 
7
8
  const logger = new ConsoleLogger('GraphQLAPI resolveConfig');
@@ -9,5 +9,6 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
9
9
  export const resolveLibraryOptions = (amplify: AmplifyClassV6) => {
10
10
  const headers = amplify.libraryOptions?.API?.GraphQL?.headers;
11
11
  const withCredentials = amplify.libraryOptions?.API?.GraphQL?.withCredentials;
12
+
12
13
  return { headers, withCredentials };
13
14
  };
@@ -9,20 +9,25 @@ type ModelIntrospectionSchema = Exclude<
9
9
  >;
10
10
  type Model = ModelIntrospectionSchema['models'][string];
11
11
 
12
- type AuthAttribute = {
12
+ interface AuthAttribute {
13
13
  type: 'auth';
14
14
  properties: {
15
15
  rules: AuthRule[];
16
16
  };
17
- };
17
+ }
18
18
 
19
19
  /**
20
20
  * Only the portions of an Auth rule we care about.
21
21
  */
22
- type AuthRule = {
23
- allow: string;
24
- ownerField?: string;
25
- };
22
+ type AuthRule =
23
+ | {
24
+ allow: 'owner';
25
+ ownerField?: string;
26
+ }
27
+ | {
28
+ allow: 'groups';
29
+ groupsField: string;
30
+ };
26
31
 
27
32
  /**
28
33
  * Given an introspection schema model, returns all owner fields.
@@ -37,10 +42,13 @@ export function resolveOwnerFields(model: Model): string[] {
37
42
  for (const rule of attr.properties.rules) {
38
43
  if (rule.allow === 'owner') {
39
44
  ownerFields.add(rule.ownerField || 'owner');
45
+ } else if (rule.allow === 'groups') {
46
+ ownerFields.add(rule.groupsField);
40
47
  }
41
48
  }
42
49
  }
43
50
  }
51
+
44
52
  return Array.from(ownerFields);
45
53
  }
46
54
 
@@ -55,11 +63,12 @@ function isAuthAttribute(attribute: any): attribute is AuthAttribute {
55
63
  if (attribute?.type === 'auth') {
56
64
  if (typeof attribute?.properties === 'object') {
57
65
  if (Array.isArray(attribute?.properties?.rules)) {
58
- return (attribute?.properties?.rules as Array<any>).every(
66
+ return (attribute?.properties?.rules as any[]).every(
59
67
  rule => !!rule.allow,
60
68
  );
61
69
  }
62
70
  }
63
71
  }
72
+
64
73
  return false;
65
74
  }
@@ -18,5 +18,6 @@ type SchemaModel = ModelIntrospectionSchema['models'][string];
18
18
  */
19
19
  export function resolvePKFields(model: SchemaModel) {
20
20
  const { primaryKeyFieldName, sortKeyFieldNames } = model.primaryKeyInfo;
21
+
21
22
  return [primaryKeyFieldName, ...sortKeyFieldNames];
22
23
  }