@aws-amplify/api-graphql 4.0.1-api-v6-models.9351bcf.0 → 4.0.1-api-v6-models.58f2536.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.
- package/internals/server/package.json +8 -0
- package/lib/GraphQLAPI.d.ts +1 -1
- package/lib/GraphQLAPI.js +23 -28
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +467 -582
- package/lib/index.js +1 -1
- package/lib/internals/APIClient.d.ts +16 -1
- package/lib/internals/APIClient.js +232 -206
- package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib/internals/InternalGraphQLAPI.js +205 -247
- package/lib/internals/generateClient.js +14 -13
- package/lib/internals/generateModelsProperty.js +19 -312
- package/lib/internals/operations/get.d.ts +2 -0
- package/lib/internals/operations/get.js +59 -0
- package/lib/internals/operations/list.d.ts +2 -0
- package/lib/internals/operations/list.js +71 -0
- package/lib/internals/operations/observeQuery.d.ts +2 -0
- package/lib/internals/operations/observeQuery.js +119 -0
- package/lib/internals/operations/subscription.d.ts +1 -0
- package/lib/internals/operations/subscription.js +27 -0
- package/lib/internals/server/generateClient.d.ts +11 -0
- package/lib/internals/server/generateClient.js +30 -0
- package/lib/internals/server/generateModelsProperty.d.ts +3 -0
- package/lib/internals/server/generateModelsProperty.js +45 -0
- package/lib/internals/server/index.d.ts +1 -0
- package/lib/internals/server/index.js +7 -0
- package/lib/internals/v6.js +3 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +36 -4
- package/lib/utils/ConnectionStateMonitor.js +51 -64
- package/lib/utils/ReachabilityMonitor/index.js +2 -2
- package/lib/utils/ReachabilityMonitor/index.native.js +4 -6
- package/lib/utils/ReconnectionMonitor.js +20 -24
- package/lib/utils/errors/APIError.js +7 -11
- package/lib/utils/errors/assertValidationError.js +4 -4
- package/lib/utils/errors/validation.js +5 -6
- package/lib/utils/findIndexByFields.js +4 -9
- package/lib/utils/resolveConfig.js +9 -10
- package/lib/utils/resolveLibraryOptions.js +4 -5
- package/lib/utils/resolveOwnerFields.js +10 -33
- package/lib/utils/resolvePKFields.js +2 -3
- package/lib-esm/GraphQLAPI.d.ts +1 -1
- package/lib-esm/GraphQLAPI.js +23 -29
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +459 -575
- package/lib-esm/Providers/constants.js +10 -10
- package/lib-esm/internals/APIClient.d.ts +16 -1
- package/lib-esm/internals/APIClient.js +230 -205
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib-esm/internals/InternalGraphQLAPI.js +201 -244
- package/lib-esm/internals/generateClient.js +11 -10
- package/lib-esm/internals/generateModelsProperty.js +19 -312
- package/lib-esm/internals/operations/get.d.ts +2 -0
- package/lib-esm/internals/operations/get.js +55 -0
- package/lib-esm/internals/operations/list.d.ts +2 -0
- package/lib-esm/internals/operations/list.js +67 -0
- package/lib-esm/internals/operations/observeQuery.d.ts +2 -0
- package/lib-esm/internals/operations/observeQuery.js +115 -0
- package/lib-esm/internals/operations/subscription.d.ts +1 -0
- package/lib-esm/internals/operations/subscription.js +23 -0
- package/lib-esm/internals/server/generateClient.d.ts +11 -0
- package/lib-esm/internals/server/generateClient.js +26 -0
- package/lib-esm/internals/server/generateModelsProperty.d.ts +3 -0
- package/lib-esm/internals/server/generateModelsProperty.js +41 -0
- package/lib-esm/internals/server/index.d.ts +1 -0
- package/lib-esm/internals/server/index.js +3 -0
- package/lib-esm/internals/v6.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +36 -4
- package/lib-esm/types/index.js +3 -3
- package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
- package/lib-esm/utils/ReachabilityMonitor/index.js +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +1 -3
- package/lib-esm/utils/ReconnectionMonitor.js +19 -24
- package/lib-esm/utils/errors/APIError.js +6 -11
- package/lib-esm/utils/errors/assertValidationError.js +2 -2
- package/lib-esm/utils/errors/validation.js +5 -6
- package/lib-esm/utils/findIndexByFields.js +4 -9
- package/lib-esm/utils/resolveConfig.js +8 -9
- package/lib-esm/utils/resolveLibraryOptions.js +4 -5
- package/lib-esm/utils/resolveOwnerFields.js +10 -33
- package/lib-esm/utils/resolvePKFields.js +2 -3
- package/package.json +8 -7
- package/src/GraphQLAPI.ts +6 -2
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +6 -5
- package/src/internals/APIClient.ts +122 -35
- package/src/internals/InternalGraphQLAPI.ts +35 -10
- package/src/internals/generateClient.ts +0 -1
- package/src/internals/generateModelsProperty.ts +27 -340
- package/src/internals/operations/get.ts +121 -0
- package/src/internals/operations/list.ts +111 -0
- package/src/internals/operations/observeQuery.ts +140 -0
- package/src/internals/operations/subscription.ts +59 -0
- package/src/internals/server/generateClient.ts +45 -0
- package/src/internals/server/generateModelsProperty.ts +70 -0
- package/src/internals/server/index.ts +4 -0
- package/src/types/index.ts +65 -9
package/lib-esm/types/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
1
|
+
import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
|
|
2
2
|
import { ModelTypes } from '@aws-amplify/amplify-api-next-types-alpha';
|
|
3
3
|
import { Source, DocumentNode, GraphQLError } from 'graphql';
|
|
4
4
|
export { OperationTypeNode } from 'graphql';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
6
6
|
import { GraphQLAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
|
|
7
|
+
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
7
8
|
export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
8
9
|
export { SelectionSet } from '@aws-amplify/amplify-api-next-types-alpha';
|
|
9
10
|
export { CommonPublicClientOptions } from '../internals/types';
|
|
@@ -288,10 +289,41 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
|
288
289
|
[__amplify]: AmplifyClassV6;
|
|
289
290
|
[__authMode]?: GraphQLAuthMode;
|
|
290
291
|
[__authToken]?: string;
|
|
291
|
-
graphql:
|
|
292
|
-
[key: string]: string;
|
|
293
|
-
} | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
292
|
+
graphql: GraphQLMethod;
|
|
294
293
|
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
295
294
|
isCancelError: (error: any) => boolean;
|
|
296
295
|
models: ModelTypes<T>;
|
|
297
296
|
}>;
|
|
297
|
+
export type V6ClientSSRRequest<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
298
|
+
[__amplify]: AmplifyClassV6;
|
|
299
|
+
[__authMode]?: GraphQLAuthMode;
|
|
300
|
+
[__authToken]?: string;
|
|
301
|
+
graphql: GraphQLMethodSSR;
|
|
302
|
+
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
303
|
+
isCancelError: (error: any) => boolean;
|
|
304
|
+
models: ModelTypes<T, 'REQUEST'>;
|
|
305
|
+
}>;
|
|
306
|
+
export type V6ClientSSRCookies<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
307
|
+
[__amplify]: AmplifyClassV6;
|
|
308
|
+
[__authMode]?: GraphQLAuthMode;
|
|
309
|
+
[__authToken]?: string;
|
|
310
|
+
graphql: GraphQLMethod;
|
|
311
|
+
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
312
|
+
isCancelError: (error: any) => boolean;
|
|
313
|
+
models: ModelTypes<T, 'COOKIES'>;
|
|
314
|
+
}>;
|
|
315
|
+
export type GraphQLMethod = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
|
|
316
|
+
[key: string]: string;
|
|
317
|
+
} | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
318
|
+
export type GraphQLMethodSSR = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(contextSpec: AmplifyServer.ContextSpec, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
|
|
319
|
+
[key: string]: string;
|
|
320
|
+
} | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
321
|
+
/**
|
|
322
|
+
* @private
|
|
323
|
+
*
|
|
324
|
+
* The knobs available for configuring `server/generateClient` internally.
|
|
325
|
+
*/
|
|
326
|
+
export type ServerClientGenerationParams = {
|
|
327
|
+
amplify: null | ((fn: (amplify: AmplifyClassV6) => Promise<any>) => Promise<any>);
|
|
328
|
+
config: ResourcesConfig;
|
|
329
|
+
};
|
package/lib-esm/types/index.js
CHANGED
|
@@ -7,6 +7,6 @@ export var GraphQLAuthError;
|
|
|
7
7
|
GraphQLAuthError["NO_FEDERATED_JWT"] = "No federated jwt";
|
|
8
8
|
GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
|
|
9
9
|
})(GraphQLAuthError || (GraphQLAuthError = {}));
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
10
|
+
export const __amplify = Symbol('amplify');
|
|
11
|
+
export const __authMode = Symbol('authMode');
|
|
12
|
+
export const __authToken = Symbol('authToken');
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { __assign } from "tslib";
|
|
4
3
|
import { Observable, map, filter } from 'rxjs';
|
|
5
4
|
import { ConnectionState } from '../types/PubSub';
|
|
6
5
|
import { ReachabilityMonitor } from './ReachabilityMonitor';
|
|
7
|
-
export
|
|
6
|
+
export const CONNECTION_CHANGE = {
|
|
8
7
|
KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
|
|
9
8
|
KEEP_ALIVE: { keepAliveState: 'healthy' },
|
|
10
9
|
CONNECTION_ESTABLISHED: { connectionState: 'connected' },
|
|
@@ -21,9 +20,8 @@ export var CONNECTION_CHANGE = {
|
|
|
21
20
|
ONLINE: { networkState: 'connected' },
|
|
22
21
|
OFFLINE: { networkState: 'disconnected' },
|
|
23
22
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var _this = this;
|
|
23
|
+
export class ConnectionStateMonitor {
|
|
24
|
+
constructor() {
|
|
27
25
|
this._networkMonitoringSubscription = undefined;
|
|
28
26
|
this._linkedConnectionState = {
|
|
29
27
|
networkState: 'connected',
|
|
@@ -32,73 +30,61 @@ var ConnectionStateMonitor = /** @class */ (function () {
|
|
|
32
30
|
keepAliveState: 'healthy',
|
|
33
31
|
};
|
|
34
32
|
// Attempt to update the state with the current actual network state
|
|
35
|
-
this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
_this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
|
|
39
|
-
(_b = _this._initialNetworkStateSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
|
|
33
|
+
this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(({ online }) => {
|
|
34
|
+
this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
|
|
35
|
+
this._initialNetworkStateSubscription?.unsubscribe();
|
|
40
36
|
});
|
|
41
37
|
this._linkedConnectionStateObservable =
|
|
42
|
-
new Observable(
|
|
43
|
-
connectionStateObserver.next(
|
|
44
|
-
|
|
38
|
+
new Observable(connectionStateObserver => {
|
|
39
|
+
connectionStateObserver.next(this._linkedConnectionState);
|
|
40
|
+
this._linkedConnectionStateObserver = connectionStateObserver;
|
|
45
41
|
});
|
|
46
42
|
}
|
|
47
43
|
/**
|
|
48
44
|
* Turn network state monitoring on if it isn't on already
|
|
49
45
|
*/
|
|
50
|
-
|
|
51
|
-
var _this = this;
|
|
52
|
-
var _a;
|
|
46
|
+
enableNetworkMonitoring() {
|
|
53
47
|
// If no initial network state was discovered, stop trying
|
|
54
|
-
|
|
48
|
+
this._initialNetworkStateSubscription?.unsubscribe();
|
|
55
49
|
// Maintain the network state based on the reachability monitor
|
|
56
50
|
if (this._networkMonitoringSubscription === undefined) {
|
|
57
|
-
this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(
|
|
58
|
-
|
|
59
|
-
_this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
|
|
51
|
+
this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(({ online }) => {
|
|
52
|
+
this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
|
|
60
53
|
});
|
|
61
54
|
}
|
|
62
|
-
}
|
|
55
|
+
}
|
|
63
56
|
/**
|
|
64
57
|
* Turn network state monitoring off if it isn't off already
|
|
65
58
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
(_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
59
|
+
disableNetworkMonitoring() {
|
|
60
|
+
this._networkMonitoringSubscription?.unsubscribe();
|
|
69
61
|
this._networkMonitoringSubscription = undefined;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return this.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}));
|
|
93
|
-
},
|
|
94
|
-
enumerable: false,
|
|
95
|
-
configurable: true
|
|
96
|
-
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get the observable that allows us to monitor the connection state
|
|
65
|
+
*
|
|
66
|
+
* @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
|
|
67
|
+
*/
|
|
68
|
+
get connectionStateObservable() {
|
|
69
|
+
let previous;
|
|
70
|
+
// The linked state aggregates state changes to any of the network, connection,
|
|
71
|
+
// intendedConnection and keepAliveHealth. Some states will change these independent
|
|
72
|
+
// states without changing the overall connection state.
|
|
73
|
+
// After translating from linked states to ConnectionState, then remove any duplicates
|
|
74
|
+
return this._linkedConnectionStateObservable
|
|
75
|
+
.pipe(map(value => {
|
|
76
|
+
return this.connectionStatesTranslator(value);
|
|
77
|
+
}))
|
|
78
|
+
.pipe(filter(current => {
|
|
79
|
+
const toInclude = current !== previous;
|
|
80
|
+
previous = current;
|
|
81
|
+
return toInclude;
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
97
84
|
/*
|
|
98
85
|
* Updates local connection state and emits the full state to the observer.
|
|
99
86
|
*/
|
|
100
|
-
|
|
101
|
-
var _a;
|
|
87
|
+
record(statusUpdates) {
|
|
102
88
|
// Maintain the network monitor
|
|
103
89
|
if (statusUpdates.intendedConnectionState === 'connected') {
|
|
104
90
|
this.enableNetworkMonitoring();
|
|
@@ -107,15 +93,17 @@ var ConnectionStateMonitor = /** @class */ (function () {
|
|
|
107
93
|
this.disableNetworkMonitoring();
|
|
108
94
|
}
|
|
109
95
|
// Maintain the socket state
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
96
|
+
const newSocketStatus = {
|
|
97
|
+
...this._linkedConnectionState,
|
|
98
|
+
...statusUpdates,
|
|
99
|
+
};
|
|
100
|
+
this._linkedConnectionState = { ...newSocketStatus };
|
|
101
|
+
this._linkedConnectionStateObserver?.next(this._linkedConnectionState);
|
|
102
|
+
}
|
|
114
103
|
/*
|
|
115
104
|
* Translate the ConnectionState structure into a specific ConnectionState string literal union
|
|
116
105
|
*/
|
|
117
|
-
|
|
118
|
-
var connectionState = _a.connectionState, networkState = _a.networkState, intendedConnectionState = _a.intendedConnectionState, keepAliveState = _a.keepAliveState;
|
|
106
|
+
connectionStatesTranslator({ connectionState, networkState, intendedConnectionState, keepAliveState, }) {
|
|
119
107
|
if (connectionState === 'connected' && networkState === 'disconnected')
|
|
120
108
|
return ConnectionState.ConnectedPendingNetwork;
|
|
121
109
|
if (connectionState === 'connected' &&
|
|
@@ -136,7 +124,5 @@ var ConnectionStateMonitor = /** @class */ (function () {
|
|
|
136
124
|
if (connectionState === 'disconnected')
|
|
137
125
|
return ConnectionState.Disconnected;
|
|
138
126
|
return ConnectionState.Connected;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
}());
|
|
142
|
-
export { ConnectionStateMonitor };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
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
|
-
export
|
|
4
|
+
export const ReachabilityMonitor = () => new Reachability().networkMonitor();
|
|
@@ -2,6 +2,4 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { Reachability } from '@aws-amplify/core/internals/utils';
|
|
4
4
|
import { default as NetInfo } from '@react-native-community/netinfo';
|
|
5
|
-
export
|
|
6
|
-
return new Reachability().networkMonitor(NetInfo);
|
|
7
|
-
};
|
|
5
|
+
export const ReachabilityMonitor = () => new Reachability().networkMonitor(NetInfo);
|
|
@@ -10,31 +10,30 @@ export var ReconnectEvent;
|
|
|
10
10
|
* Attempting to reconnect only once creates unrecoverable states when the network state isn't
|
|
11
11
|
* supported by the browser, so this keeps retrying every minute until halted.
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
export class ReconnectionMonitor {
|
|
14
|
+
constructor() {
|
|
15
15
|
this.reconnectObservers = [];
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Add reconnect observer to the list of observers to alert on reconnect
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
addObserver(reconnectObserver) {
|
|
21
21
|
this.reconnectObservers.push(reconnectObserver);
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
23
|
/**
|
|
24
24
|
* Given a reconnect event, start the appropriate behavior
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
|
-
var _this = this;
|
|
26
|
+
record(event) {
|
|
28
27
|
if (event === ReconnectEvent.START_RECONNECT) {
|
|
29
28
|
// If the reconnection hasn't been started
|
|
30
29
|
if (this.reconnectSetTimeoutId === undefined &&
|
|
31
30
|
this.reconnectIntervalId === undefined) {
|
|
32
|
-
this.reconnectSetTimeoutId = setTimeout(
|
|
31
|
+
this.reconnectSetTimeoutId = setTimeout(() => {
|
|
33
32
|
// Reconnect now
|
|
34
|
-
|
|
33
|
+
this._triggerReconnect();
|
|
35
34
|
// Retry reconnect every periodically until it works
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
this.reconnectIntervalId = setInterval(() => {
|
|
36
|
+
this._triggerReconnect();
|
|
38
37
|
}, RECONNECT_INTERVAL);
|
|
39
38
|
}, RECONNECT_DELAY);
|
|
40
39
|
}
|
|
@@ -49,22 +48,18 @@ var ReconnectionMonitor = /** @class */ (function () {
|
|
|
49
48
|
this.reconnectSetTimeoutId = undefined;
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
|
-
}
|
|
51
|
+
}
|
|
53
52
|
/**
|
|
54
53
|
* Complete all reconnect observers
|
|
55
54
|
*/
|
|
56
|
-
|
|
57
|
-
this.reconnectObservers.forEach(
|
|
58
|
-
|
|
59
|
-
(_a = reconnectObserver.complete) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
|
|
55
|
+
close() {
|
|
56
|
+
this.reconnectObservers.forEach(reconnectObserver => {
|
|
57
|
+
reconnectObserver.complete?.();
|
|
60
58
|
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this.reconnectObservers.forEach(
|
|
64
|
-
|
|
65
|
-
(_a = reconnectObserver.next) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
|
|
59
|
+
}
|
|
60
|
+
_triggerReconnect() {
|
|
61
|
+
this.reconnectObservers.forEach(reconnectObserver => {
|
|
62
|
+
reconnectObserver.next?.();
|
|
66
63
|
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}());
|
|
70
|
-
export { ReconnectionMonitor };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { __extends } from "tslib";
|
|
4
3
|
import { AmplifyError, } from '@aws-amplify/core/internals/utils';
|
|
5
4
|
/**
|
|
6
5
|
* @internal
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _this = _super.call(this, params) || this;
|
|
7
|
+
export class APIError extends AmplifyError {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super(params);
|
|
12
10
|
// Hack for making the custom error class work when transpiled to es5
|
|
13
11
|
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
14
|
-
|
|
15
|
-
Object.setPrototypeOf(
|
|
16
|
-
return _this;
|
|
12
|
+
this.constructor = APIError;
|
|
13
|
+
Object.setPrototypeOf(this, APIError.prototype);
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
}(AmplifyError));
|
|
20
|
-
export { APIError };
|
|
15
|
+
}
|
|
@@ -6,8 +6,8 @@ import { validationErrorMap } from './validation';
|
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
8
|
export function assertValidationError(assertion, name) {
|
|
9
|
-
|
|
9
|
+
const { message, recoverySuggestion } = validationErrorMap[name];
|
|
10
10
|
if (!assertion) {
|
|
11
|
-
throw new APIError({ name
|
|
11
|
+
throw new APIError({ name, message, recoverySuggestion });
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
var _a;
|
|
4
3
|
export var APIValidationErrorCode;
|
|
5
4
|
(function (APIValidationErrorCode) {
|
|
6
5
|
APIValidationErrorCode["NoAuthSession"] = "NoAuthSession";
|
|
7
6
|
APIValidationErrorCode["NoRegion"] = "NoRegion";
|
|
8
7
|
APIValidationErrorCode["NoCustomEndpoint"] = "NoCustomEndpoint";
|
|
9
8
|
})(APIValidationErrorCode || (APIValidationErrorCode = {}));
|
|
10
|
-
export
|
|
11
|
-
|
|
9
|
+
export const validationErrorMap = {
|
|
10
|
+
[APIValidationErrorCode.NoAuthSession]: {
|
|
12
11
|
message: 'Auth session should not be empty.',
|
|
13
12
|
},
|
|
14
13
|
// TODO: re-enable when working in all test environments:
|
|
15
14
|
// [APIValidationErrorCode.NoEndpoint]: {
|
|
16
15
|
// message: 'Missing endpoint',
|
|
17
16
|
// },
|
|
18
|
-
|
|
17
|
+
[APIValidationErrorCode.NoRegion]: {
|
|
19
18
|
message: 'Missing region.',
|
|
20
19
|
},
|
|
21
|
-
|
|
20
|
+
[APIValidationErrorCode.NoCustomEndpoint]: {
|
|
22
21
|
message: 'Custom endpoint region is present without custom endpoint.',
|
|
23
22
|
},
|
|
24
|
-
|
|
23
|
+
};
|
|
@@ -9,16 +9,11 @@
|
|
|
9
9
|
* @returns Index of `needle` in `haystack`, otherwise -1 if not found.
|
|
10
10
|
*/
|
|
11
11
|
export function findIndexByFields(needle, haystack, keyFields) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (Object.keys(searchObject).every(
|
|
15
|
-
return
|
|
12
|
+
const searchObject = Object.fromEntries(keyFields.map(fieldName => [fieldName, needle[fieldName]]));
|
|
13
|
+
for (let i = 0; i < haystack.length; i++) {
|
|
14
|
+
if (Object.keys(searchObject).every(k => searchObject[k] === haystack[i][k])) {
|
|
15
|
+
return i;
|
|
16
16
|
}
|
|
17
|
-
};
|
|
18
|
-
for (var i = 0; i < haystack.length; i++) {
|
|
19
|
-
var state_1 = _loop_1(i);
|
|
20
|
-
if (typeof state_1 === "object")
|
|
21
|
-
return state_1.value;
|
|
22
17
|
}
|
|
23
18
|
return -1;
|
|
24
19
|
}
|
|
@@ -4,18 +4,17 @@ import { APIValidationErrorCode, assertValidationError } from './errors';
|
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
var _c = (_b = (_a = amplify.getConfig().API) === null || _a === void 0 ? void 0 : _a.GraphQL) !== null && _b !== void 0 ? _b : {}, apiKey = _c.apiKey, customEndpoint = _c.customEndpoint, customEndpointRegion = _c.customEndpointRegion, defaultAuthMode = _c.defaultAuthMode, endpoint = _c.endpoint, region = _c.region;
|
|
7
|
+
export const resolveConfig = (amplify) => {
|
|
8
|
+
const { apiKey, customEndpoint, customEndpointRegion, defaultAuthMode, endpoint, region, } = amplify.getConfig().API?.GraphQL ?? {};
|
|
10
9
|
// TODO: re-enable when working in all test environments:
|
|
11
10
|
// assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);
|
|
12
11
|
assertValidationError(!(!customEndpoint && customEndpointRegion), APIValidationErrorCode.NoCustomEndpoint);
|
|
13
12
|
return {
|
|
14
|
-
apiKey
|
|
15
|
-
customEndpoint
|
|
16
|
-
customEndpointRegion
|
|
17
|
-
defaultAuthMode
|
|
18
|
-
endpoint
|
|
19
|
-
region
|
|
13
|
+
apiKey,
|
|
14
|
+
customEndpoint,
|
|
15
|
+
customEndpointRegion,
|
|
16
|
+
defaultAuthMode,
|
|
17
|
+
endpoint,
|
|
18
|
+
region,
|
|
20
19
|
};
|
|
21
20
|
};
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return { headers: headers, withCredentials: withCredentials };
|
|
6
|
+
export const resolveLibraryOptions = (amplify) => {
|
|
7
|
+
const headers = amplify.libraryOptions?.API?.GraphQL?.headers;
|
|
8
|
+
const withCredentials = amplify.libraryOptions?.API?.GraphQL?.withCredentials;
|
|
9
|
+
return { headers, withCredentials };
|
|
11
10
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __values } from "tslib";
|
|
2
1
|
/**
|
|
3
2
|
* Given an introspection schema model, returns all owner fields.
|
|
4
3
|
*
|
|
@@ -6,37 +5,16 @@ import { __values } from "tslib";
|
|
|
6
5
|
* @returns List of owner field names
|
|
7
6
|
*/
|
|
8
7
|
export function resolveOwnerFields(model) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
for (var _e = (e_2 = void 0, __values(attr.properties.rules)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
17
|
-
var rule = _f.value;
|
|
18
|
-
if (rule.allow === 'owner') {
|
|
19
|
-
ownerFields.add(rule.ownerField || 'owner');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
24
|
-
finally {
|
|
25
|
-
try {
|
|
26
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
27
|
-
}
|
|
28
|
-
finally { if (e_2) throw e_2.error; }
|
|
8
|
+
const ownerFields = new Set();
|
|
9
|
+
for (const attr of model.attributes || []) {
|
|
10
|
+
if (isAuthAttribute(attr)) {
|
|
11
|
+
for (const rule of attr.properties.rules) {
|
|
12
|
+
if (rule.allow === 'owner') {
|
|
13
|
+
ownerFields.add(rule.ownerField || 'owner');
|
|
29
14
|
}
|
|
30
15
|
}
|
|
31
16
|
}
|
|
32
17
|
}
|
|
33
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
34
|
-
finally {
|
|
35
|
-
try {
|
|
36
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
37
|
-
}
|
|
38
|
-
finally { if (e_1) throw e_1.error; }
|
|
39
|
-
}
|
|
40
18
|
return Array.from(ownerFields);
|
|
41
19
|
}
|
|
42
20
|
/**
|
|
@@ -47,11 +25,10 @@ export function resolveOwnerFields(model) {
|
|
|
47
25
|
* @returns True if given object is an auth attribute
|
|
48
26
|
*/
|
|
49
27
|
function isAuthAttribute(attribute) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return ((_b = attribute === null || attribute === void 0 ? void 0 : attribute.properties) === null || _b === void 0 ? void 0 : _b.rules).every(function (rule) { return !!rule.allow; });
|
|
28
|
+
if (attribute?.type === 'auth') {
|
|
29
|
+
if (typeof attribute?.properties === 'object') {
|
|
30
|
+
if (Array.isArray(attribute?.properties?.rules)) {
|
|
31
|
+
return (attribute?.properties?.rules).every(rule => !!rule.allow);
|
|
55
32
|
}
|
|
56
33
|
}
|
|
57
34
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __read, __spreadArray } from "tslib";
|
|
2
1
|
/**
|
|
3
2
|
* Given a SchemaModel from a ModelIntrospectionSchema, returns the primary key
|
|
4
3
|
* as an array of field names.
|
|
@@ -7,6 +6,6 @@ import { __read, __spreadArray } from "tslib";
|
|
|
7
6
|
* @returns Array of field names
|
|
8
7
|
*/
|
|
9
8
|
export function resolvePKFields(model) {
|
|
10
|
-
|
|
11
|
-
return
|
|
9
|
+
const { primaryKeyFieldName, sortKeyFieldNames } = model.primaryKeyInfo;
|
|
10
|
+
return [primaryKeyFieldName, ...sortKeyFieldNames];
|
|
12
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api-graphql",
|
|
3
|
-
"version": "4.0.1-api-v6-models.
|
|
3
|
+
"version": "4.0.1-api-v6-models.58f2536.0+58f2536",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -51,15 +51,16 @@
|
|
|
51
51
|
"internals"
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@aws-amplify/amplify-api-next-types-alpha": "^0.2.
|
|
55
|
-
"@aws-amplify/api-rest": "4.0.1-api-v6-models.
|
|
56
|
-
"@aws-amplify/auth": "6.0.1-api-v6-models.
|
|
57
|
-
"@aws-amplify/core": "6.0.1-api-v6-models.
|
|
54
|
+
"@aws-amplify/amplify-api-next-types-alpha": "^0.2.5",
|
|
55
|
+
"@aws-amplify/api-rest": "4.0.1-api-v6-models.58f2536.0+58f2536",
|
|
56
|
+
"@aws-amplify/auth": "6.0.1-api-v6-models.58f2536.0+58f2536",
|
|
57
|
+
"@aws-amplify/core": "6.0.1-api-v6-models.58f2536.0+58f2536",
|
|
58
58
|
"@aws-sdk/types": "3.387.0",
|
|
59
59
|
"graphql": "15.8.0",
|
|
60
60
|
"rxjs": "^7.8.1",
|
|
61
61
|
"tslib": "^2.6.1",
|
|
62
|
-
"url": "0.11.0"
|
|
62
|
+
"url": "0.11.0",
|
|
63
|
+
"uuid": "^3.2.1"
|
|
63
64
|
},
|
|
64
65
|
"size-limit": [
|
|
65
66
|
{
|
|
@@ -126,5 +127,5 @@
|
|
|
126
127
|
"<rootDir>/__tests__"
|
|
127
128
|
]
|
|
128
129
|
},
|
|
129
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "58f25367e844c71f102e0a33a4a1c5c6da554886"
|
|
130
131
|
}
|
package/src/GraphQLAPI.ts
CHANGED
|
@@ -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 { AmplifyClassV6 } from '@aws-amplify/core';
|
|
4
|
+
import { Category, ApiAction } from '@aws-amplify/core/internals/utils';
|
|
4
5
|
import { GraphQLOptions, GraphQLResult } from './types';
|
|
5
6
|
import { InternalGraphQLAPIClass } from './internals';
|
|
6
7
|
import { Observable } from 'rxjs';
|
|
@@ -31,11 +32,14 @@ export class GraphQLAPIClass extends InternalGraphQLAPIClass {
|
|
|
31
32
|
* @returns An Observable if the query is a subscription query, else a promise of the graphql result.
|
|
32
33
|
*/
|
|
33
34
|
graphql<T = any>(
|
|
34
|
-
amplify: AmplifyClassV6,
|
|
35
|
+
amplify: AmplifyClassV6 | (() => Promise<AmplifyClassV6>),
|
|
35
36
|
options: GraphQLOptions,
|
|
36
37
|
additionalHeaders?: { [key: string]: string }
|
|
37
38
|
): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>> {
|
|
38
|
-
return super.graphql(amplify, options, additionalHeaders
|
|
39
|
+
return super.graphql(amplify, options, additionalHeaders, {
|
|
40
|
+
category: Category.API,
|
|
41
|
+
action: ApiAction.GraphQl,
|
|
42
|
+
});
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
/**
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { Observable, SubscriptionLike } from 'rxjs';
|
|
4
4
|
import { GraphQLError } from 'graphql';
|
|
5
|
-
import * as url from 'url';
|
|
6
|
-
import { Buffer } from 'buffer';
|
|
7
5
|
import { Hub, fetchAuthSession, ConsoleLogger } from '@aws-amplify/core';
|
|
8
6
|
import { signRequest } from '@aws-amplify/core/internals/aws-client-utils';
|
|
9
7
|
import {
|
|
8
|
+
base64Encoder,
|
|
10
9
|
GraphQLAuthMode,
|
|
11
10
|
CustomUserAgentDetails,
|
|
12
11
|
NonRetryableError,
|
|
@@ -700,9 +699,9 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
700
699
|
});
|
|
701
700
|
|
|
702
701
|
const headerString = authHeader ? JSON.stringify(authHeader) : '';
|
|
703
|
-
const headerQs =
|
|
702
|
+
const headerQs = base64Encoder.convert(headerString);
|
|
704
703
|
|
|
705
|
-
const payloadQs =
|
|
704
|
+
const payloadQs = base64Encoder.convert(payloadString);
|
|
706
705
|
|
|
707
706
|
let discoverableEndpoint = appSyncGraphqlEndpoint ?? '';
|
|
708
707
|
|
|
@@ -900,7 +899,9 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
900
899
|
} else {
|
|
901
900
|
const handler = headerHandler[authenticationType];
|
|
902
901
|
|
|
903
|
-
const
|
|
902
|
+
const host = appSyncGraphqlEndpoint
|
|
903
|
+
? new AmplifyUrl(appSyncGraphqlEndpoint).host
|
|
904
|
+
: undefined;
|
|
904
905
|
|
|
905
906
|
logger.debug(`Authenticating with ${JSON.stringify(authenticationType)}`);
|
|
906
907
|
let resolvedApiKey;
|