@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.
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +40 -31
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/dist/cjs/internals/APIClient.js +34 -19
- package/dist/cjs/internals/APIClient.js.map +1 -1
- package/dist/cjs/internals/InternalGraphQLAPI.js +10 -9
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/cjs/internals/generateClient.js +4 -1
- package/dist/cjs/internals/generateClient.js.map +1 -1
- package/dist/cjs/internals/generateCustomOperationsProperty.js +6 -1
- package/dist/cjs/internals/generateCustomOperationsProperty.js.map +1 -1
- package/dist/cjs/internals/operations/custom.js +90 -7
- package/dist/cjs/internals/operations/custom.js.map +1 -1
- package/dist/cjs/internals/operations/list.js +1 -1
- package/dist/cjs/internals/operations/list.js.map +1 -1
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +1 -1
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -1
- package/dist/cjs/internals/server/generateModelsProperty.js +1 -1
- package/dist/cjs/internals/server/generateModelsProperty.js.map +1 -1
- package/dist/cjs/internals/v6.js +0 -2
- package/dist/cjs/internals/v6.js.map +1 -1
- package/dist/cjs/utils/errors/repackageAuthError.js +1 -1
- package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -1
- package/dist/cjs/utils/resolveOwnerFields.js +3 -0
- package/dist/cjs/utils/resolveOwnerFields.js.map +1 -1
- package/dist/esm/GraphQLAPI.d.ts +2 -2
- package/dist/esm/GraphQLAPI.mjs.map +1 -1
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +8 -8
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +40 -31
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
- package/dist/esm/internals/APIClient.d.ts +5 -6
- package/dist/esm/internals/APIClient.mjs +34 -19
- package/dist/esm/internals/APIClient.mjs.map +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.mjs +10 -9
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/dist/esm/internals/generateClient.mjs +5 -2
- package/dist/esm/internals/generateClient.mjs.map +1 -1
- package/dist/esm/internals/generateCustomOperationsProperty.d.ts +4 -3
- package/dist/esm/internals/generateCustomOperationsProperty.mjs +5 -1
- package/dist/esm/internals/generateCustomOperationsProperty.mjs.map +1 -1
- package/dist/esm/internals/operations/custom.d.ts +6 -3
- package/dist/esm/internals/operations/custom.mjs +90 -7
- package/dist/esm/internals/operations/custom.mjs.map +1 -1
- package/dist/esm/internals/operations/get.d.ts +1 -1
- package/dist/esm/internals/operations/get.mjs.map +1 -1
- package/dist/esm/internals/operations/indexQuery.d.ts +3 -3
- package/dist/esm/internals/operations/indexQuery.mjs.map +1 -1
- package/dist/esm/internals/operations/list.d.ts +1 -1
- package/dist/esm/internals/operations/list.mjs +1 -1
- package/dist/esm/internals/operations/list.mjs.map +1 -1
- package/dist/esm/internals/operations/subscription.d.ts +1 -1
- package/dist/esm/internals/operations/subscription.mjs.map +1 -1
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.d.ts +1 -1
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs +1 -1
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -1
- package/dist/esm/internals/server/generateModelsProperty.d.ts +3 -3
- package/dist/esm/internals/server/generateModelsProperty.mjs +1 -1
- package/dist/esm/internals/server/generateModelsProperty.mjs.map +1 -1
- package/dist/esm/internals/types.d.ts +2 -2
- package/dist/esm/internals/utils/clientProperties/generateModelsProperty.d.ts +2 -2
- package/dist/esm/internals/v6.d.ts +1 -1
- package/dist/esm/internals/v6.mjs +0 -2
- package/dist/esm/internals/v6.mjs.map +1 -1
- package/dist/esm/types/index.d.ts +34 -35
- package/dist/esm/utils/ConnectionStateMonitor.d.ts +2 -2
- package/dist/esm/utils/ConnectionStateMonitor.mjs.map +1 -1
- package/dist/esm/utils/ReachabilityMonitor/index.native.mjs.map +1 -1
- package/dist/esm/utils/errors/repackageAuthError.d.ts +2 -2
- package/dist/esm/utils/errors/repackageAuthError.mjs +1 -1
- package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -1
- package/dist/esm/utils/findIndexByFields.d.ts +1 -1
- package/dist/esm/utils/resolveOwnerFields.mjs +3 -0
- package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -1
- package/package.json +8 -7
- package/src/GraphQLAPI.ts +4 -3
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +84 -64
- package/src/internals/APIClient.ts +83 -58
- package/src/internals/InternalGraphQLAPI.ts +26 -30
- package/src/internals/clientUtils.ts +1 -1
- package/src/internals/generateClient.ts +23 -10
- package/src/internals/generateCustomOperationsProperty.ts +31 -8
- package/src/internals/operations/custom.ts +159 -32
- package/src/internals/operations/get.ts +9 -8
- package/src/internals/operations/indexQuery.ts +12 -11
- package/src/internals/operations/list.ts +11 -15
- package/src/internals/operations/observeQuery.ts +3 -1
- package/src/internals/operations/subscription.ts +12 -10
- package/src/internals/server/generateClientWithAmplifyInstance.ts +7 -7
- package/src/internals/server/generateModelsProperty.ts +12 -6
- package/src/internals/types.ts +2 -2
- package/src/internals/utils/clientProperties/generateEnumsProperty.ts +7 -6
- package/src/internals/utils/clientProperties/generateModelsProperty.ts +8 -7
- package/src/internals/v6.ts +6 -4
- package/src/server/generateClient.ts +4 -1
- package/src/types/PubSub.ts +1 -0
- package/src/types/index.ts +51 -47
- package/src/utils/ConnectionStateMonitor.ts +8 -3
- package/src/utils/ReachabilityMonitor/index.native.ts +1 -1
- package/src/utils/ReachabilityMonitor/index.ts +1 -0
- package/src/utils/ReconnectionMonitor.ts +1 -0
- package/src/utils/errors/repackageAuthError.ts +6 -7
- package/src/utils/findIndexByFields.ts +1 -1
- package/src/utils/resolveConfig.ts +1 -0
- package/src/utils/resolveLibraryOptions.ts +1 -0
- package/src/utils/resolveOwnerFields.ts +16 -7
- package/src/utils/resolvePKFields.ts +1 -0
package/src/types/PubSub.ts
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -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 {
|
|
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> =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
88
|
+
interface PagedList<T, TYPENAME> {
|
|
89
89
|
__typename: TYPENAME;
|
|
90
90
|
nextToken?: string | null | undefined;
|
|
91
|
-
items:
|
|
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
|
|
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
|
|
183
|
+
libraryConfigHeaders?(): () => Promise<Record<string, unknown> | Headers>;
|
|
184
184
|
additionalHeaders?: CustomHeaders;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
export
|
|
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
|
|
262
|
+
TYPED_GQL_STRING extends GeneratedQuery<infer _, infer QUERY_OUT>
|
|
263
263
|
? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>>
|
|
264
|
-
: TYPED_GQL_STRING extends GeneratedMutation<infer
|
|
264
|
+
: TYPED_GQL_STRING extends GeneratedMutation<infer _, infer MUTATION_OUT>
|
|
265
265
|
? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>>
|
|
266
|
-
: TYPED_GQL_STRING extends GeneratedSubscription<infer
|
|
266
|
+
: TYPED_GQL_STRING extends GeneratedSubscription<infer _, infer SUB_OUT>
|
|
267
267
|
? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>>
|
|
268
|
-
: FALLBACK_TYPE extends GraphQLQuery<infer
|
|
268
|
+
: FALLBACK_TYPE extends GraphQLQuery<infer _>
|
|
269
269
|
? Promise<GraphQLResult<FALLBACK_TYPE>>
|
|
270
|
-
: FALLBACK_TYPE extends GraphQLSubscription<infer
|
|
270
|
+
: FALLBACK_TYPE extends GraphQLSubscription<infer _>
|
|
271
271
|
? GraphqlSubscriptionResult<FALLBACK_TYPE>
|
|
272
272
|
: FALLBACK_TYPE extends GraphQLOperationType<
|
|
273
|
-
infer
|
|
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
|
|
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
|
|
390
|
-
isCancelError
|
|
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
|
|
405
|
-
isCancelError
|
|
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
|
|
420
|
-
isCancelError
|
|
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
|
|
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
|
|
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
|
|
470
|
+
export interface AuthModeParams extends Record<string, unknown> {
|
|
467
471
|
authMode?: GraphQLAuthMode;
|
|
468
472
|
authToken?: string;
|
|
469
|
-
}
|
|
473
|
+
}
|
|
470
474
|
|
|
471
|
-
export
|
|
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,
|
|
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
|
-
|
|
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
|
|
4
|
+
import NetInfo from '@react-native-community/netinfo';
|
|
5
5
|
|
|
6
6
|
export const ReachabilityMonitor = () =>
|
|
7
7
|
new Reachability().networkMonitor(NetInfo);
|
|
@@ -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
|
-
|
|
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?.
|
|
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
|
}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
|
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
|
}
|