@aws-amplify/api-graphql 4.0.1-api-v6-models.c1977f8.0 → 4.0.1-api-v6-models.891fe0d.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 (99) hide show
  1. package/internals/server/package.json +8 -0
  2. package/lib/GraphQLAPI.d.ts +1 -1
  3. package/lib/GraphQLAPI.js +23 -28
  4. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +467 -582
  5. package/lib/index.js +1 -1
  6. package/lib/internals/APIClient.d.ts +16 -1
  7. package/lib/internals/APIClient.js +232 -206
  8. package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
  9. package/lib/internals/InternalGraphQLAPI.js +205 -247
  10. package/lib/internals/generateClient.js +14 -11
  11. package/lib/internals/generateModelsProperty.js +19 -302
  12. package/lib/internals/operations/get.d.ts +2 -0
  13. package/lib/internals/operations/get.js +59 -0
  14. package/lib/internals/operations/list.d.ts +2 -0
  15. package/lib/internals/operations/list.js +71 -0
  16. package/lib/internals/operations/observeQuery.d.ts +2 -0
  17. package/lib/internals/operations/observeQuery.js +119 -0
  18. package/lib/internals/operations/subscription.d.ts +1 -0
  19. package/lib/internals/operations/subscription.js +27 -0
  20. package/lib/internals/server/generateClient.d.ts +11 -0
  21. package/lib/internals/server/generateClient.js +30 -0
  22. package/lib/internals/server/generateModelsProperty.d.ts +3 -0
  23. package/lib/internals/server/generateModelsProperty.js +45 -0
  24. package/lib/internals/server/index.d.ts +1 -0
  25. package/lib/internals/server/index.js +7 -0
  26. package/lib/internals/types.d.ts +8 -0
  27. package/lib/internals/v6.js +3 -3
  28. package/lib/tsconfig.tsbuildinfo +1 -1
  29. package/lib/types/index.d.ts +41 -4
  30. package/lib/types/index.js +3 -1
  31. package/lib/utils/ConnectionStateMonitor.js +51 -64
  32. package/lib/utils/ReachabilityMonitor/index.js +2 -2
  33. package/lib/utils/ReachabilityMonitor/index.native.js +4 -6
  34. package/lib/utils/ReconnectionMonitor.js +20 -24
  35. package/lib/utils/errors/APIError.js +7 -11
  36. package/lib/utils/errors/assertValidationError.js +4 -4
  37. package/lib/utils/errors/validation.js +5 -6
  38. package/lib/utils/findIndexByFields.js +4 -9
  39. package/lib/utils/resolveConfig.js +9 -10
  40. package/lib/utils/resolveLibraryOptions.js +4 -5
  41. package/lib/utils/resolveOwnerFields.js +10 -33
  42. package/lib/utils/resolvePKFields.js +2 -3
  43. package/lib-esm/GraphQLAPI.d.ts +1 -1
  44. package/lib-esm/GraphQLAPI.js +23 -29
  45. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +459 -575
  46. package/lib-esm/Providers/constants.js +10 -10
  47. package/lib-esm/internals/APIClient.d.ts +16 -1
  48. package/lib-esm/internals/APIClient.js +230 -205
  49. package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
  50. package/lib-esm/internals/InternalGraphQLAPI.js +201 -244
  51. package/lib-esm/internals/generateClient.js +12 -9
  52. package/lib-esm/internals/generateModelsProperty.js +19 -302
  53. package/lib-esm/internals/operations/get.d.ts +2 -0
  54. package/lib-esm/internals/operations/get.js +55 -0
  55. package/lib-esm/internals/operations/list.d.ts +2 -0
  56. package/lib-esm/internals/operations/list.js +67 -0
  57. package/lib-esm/internals/operations/observeQuery.d.ts +2 -0
  58. package/lib-esm/internals/operations/observeQuery.js +115 -0
  59. package/lib-esm/internals/operations/subscription.d.ts +1 -0
  60. package/lib-esm/internals/operations/subscription.js +23 -0
  61. package/lib-esm/internals/server/generateClient.d.ts +11 -0
  62. package/lib-esm/internals/server/generateClient.js +26 -0
  63. package/lib-esm/internals/server/generateModelsProperty.d.ts +3 -0
  64. package/lib-esm/internals/server/generateModelsProperty.js +41 -0
  65. package/lib-esm/internals/server/index.d.ts +1 -0
  66. package/lib-esm/internals/server/index.js +3 -0
  67. package/lib-esm/internals/types.d.ts +8 -0
  68. package/lib-esm/internals/v6.js +1 -1
  69. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  70. package/lib-esm/types/index.d.ts +41 -4
  71. package/lib-esm/types/index.js +3 -1
  72. package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
  73. package/lib-esm/utils/ReachabilityMonitor/index.js +1 -1
  74. package/lib-esm/utils/ReachabilityMonitor/index.native.js +1 -3
  75. package/lib-esm/utils/ReconnectionMonitor.js +19 -24
  76. package/lib-esm/utils/errors/APIError.js +6 -11
  77. package/lib-esm/utils/errors/assertValidationError.js +2 -2
  78. package/lib-esm/utils/errors/validation.js +5 -6
  79. package/lib-esm/utils/findIndexByFields.js +4 -9
  80. package/lib-esm/utils/resolveConfig.js +8 -9
  81. package/lib-esm/utils/resolveLibraryOptions.js +4 -5
  82. package/lib-esm/utils/resolveOwnerFields.js +10 -33
  83. package/lib-esm/utils/resolvePKFields.js +2 -3
  84. package/package.json +8 -7
  85. package/src/GraphQLAPI.ts +6 -2
  86. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +6 -5
  87. package/src/internals/APIClient.ts +123 -36
  88. package/src/internals/InternalGraphQLAPI.ts +35 -10
  89. package/src/internals/generateClient.ts +3 -2
  90. package/src/internals/generateModelsProperty.ts +28 -314
  91. package/src/internals/operations/get.ts +121 -0
  92. package/src/internals/operations/list.ts +111 -0
  93. package/src/internals/operations/observeQuery.ts +140 -0
  94. package/src/internals/operations/subscription.ts +59 -0
  95. package/src/internals/server/generateClient.ts +45 -0
  96. package/src/internals/server/generateModelsProperty.ts +70 -0
  97. package/src/internals/server/index.ts +4 -0
  98. package/src/internals/types.ts +9 -0
  99. package/src/types/index.ts +71 -9
@@ -1,11 +1,13 @@
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';
10
+ export { CommonPublicClientOptions } from '../internals/types';
9
11
  /**
10
12
  * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
11
13
  */
@@ -281,12 +283,47 @@ type ExcludeNeverFields<O> = {
281
283
  [K in FilteredKeys<O>]: O[K];
282
284
  };
283
285
  export declare const __amplify: unique symbol;
286
+ export declare const __authMode: unique symbol;
287
+ export declare const __authToken: unique symbol;
284
288
  export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
285
289
  [__amplify]: AmplifyClassV6;
286
- graphql: <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
287
- [key: string]: string;
288
- } | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
290
+ [__authMode]?: GraphQLAuthMode;
291
+ [__authToken]?: string;
292
+ graphql: GraphQLMethod;
289
293
  cancel: (promise: Promise<any>, message?: string) => boolean;
290
294
  isCancelError: (error: any) => boolean;
291
295
  models: ModelTypes<T>;
292
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
+ };
@@ -7,4 +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 var __amplify = Symbol('amplify');
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 var CONNECTION_CHANGE = {
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
- var ConnectionStateMonitor = /** @class */ (function () {
25
- function ConnectionStateMonitor() {
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(function (_a) {
36
- var _b;
37
- var online = _a.online;
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(function (connectionStateObserver) {
43
- connectionStateObserver.next(_this._linkedConnectionState);
44
- _this._linkedConnectionStateObserver = connectionStateObserver;
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
- ConnectionStateMonitor.prototype.enableNetworkMonitoring = function () {
51
- var _this = this;
52
- var _a;
46
+ enableNetworkMonitoring() {
53
47
  // If no initial network state was discovered, stop trying
54
- (_a = this._initialNetworkStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
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(function (_a) {
58
- var online = _a.online;
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
- ConnectionStateMonitor.prototype.disableNetworkMonitoring = function () {
67
- var _a;
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
- Object.defineProperty(ConnectionStateMonitor.prototype, "connectionStateObservable", {
72
- /**
73
- * Get the observable that allows us to monitor the connection state
74
- *
75
- * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
76
- */
77
- get: function () {
78
- var _this = this;
79
- var previous;
80
- // The linked state aggregates state changes to any of the network, connection,
81
- // intendedConnection and keepAliveHealth. Some states will change these independent
82
- // states without changing the overall connection state.
83
- // After translating from linked states to ConnectionState, then remove any duplicates
84
- return this._linkedConnectionStateObservable
85
- .pipe(map(function (value) {
86
- return _this.connectionStatesTranslator(value);
87
- }))
88
- .pipe(filter(function (current) {
89
- var toInclude = current !== previous;
90
- previous = current;
91
- return toInclude;
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
- ConnectionStateMonitor.prototype.record = function (statusUpdates) {
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
- var newSocketStatus = __assign(__assign({}, this._linkedConnectionState), statusUpdates);
111
- this._linkedConnectionState = __assign({}, newSocketStatus);
112
- (_a = this._linkedConnectionStateObserver) === null || _a === void 0 ? void 0 : _a.next(this._linkedConnectionState);
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
- ConnectionStateMonitor.prototype.connectionStatesTranslator = function (_a) {
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
- return ConnectionStateMonitor;
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 var ReachabilityMonitor = function () { return new Reachability().networkMonitor(); };
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 var ReachabilityMonitor = function () {
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
- var ReconnectionMonitor = /** @class */ (function () {
14
- function ReconnectionMonitor() {
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
- ReconnectionMonitor.prototype.addObserver = function (reconnectObserver) {
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
- ReconnectionMonitor.prototype.record = function (event) {
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(function () {
31
+ this.reconnectSetTimeoutId = setTimeout(() => {
33
32
  // Reconnect now
34
- _this._triggerReconnect();
33
+ this._triggerReconnect();
35
34
  // Retry reconnect every periodically until it works
36
- _this.reconnectIntervalId = setInterval(function () {
37
- _this._triggerReconnect();
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
- ReconnectionMonitor.prototype.close = function () {
57
- this.reconnectObservers.forEach(function (reconnectObserver) {
58
- var _a;
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
- ReconnectionMonitor.prototype._triggerReconnect = function () {
63
- this.reconnectObservers.forEach(function (reconnectObserver) {
64
- var _a;
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
- return ReconnectionMonitor;
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
- var APIError = /** @class */ (function (_super) {
9
- __extends(APIError, _super);
10
- function APIError(params) {
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
- _this.constructor = APIError;
15
- Object.setPrototypeOf(_this, APIError.prototype);
16
- return _this;
12
+ this.constructor = APIError;
13
+ Object.setPrototypeOf(this, APIError.prototype);
17
14
  }
18
- return APIError;
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
- var _a = validationErrorMap[name], message = _a.message, recoverySuggestion = _a.recoverySuggestion;
9
+ const { message, recoverySuggestion } = validationErrorMap[name];
10
10
  if (!assertion) {
11
- throw new APIError({ name: name, message: message, recoverySuggestion: recoverySuggestion });
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 var validationErrorMap = (_a = {},
11
- _a[APIValidationErrorCode.NoAuthSession] = {
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
- _a[APIValidationErrorCode.NoRegion] = {
17
+ [APIValidationErrorCode.NoRegion]: {
19
18
  message: 'Missing region.',
20
19
  },
21
- _a[APIValidationErrorCode.NoCustomEndpoint] = {
20
+ [APIValidationErrorCode.NoCustomEndpoint]: {
22
21
  message: 'Custom endpoint region is present without custom endpoint.',
23
22
  },
24
- _a);
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
- var searchObject = Object.fromEntries(keyFields.map(function (fieldName) { return [fieldName, needle[fieldName]]; }));
13
- var _loop_1 = function (i) {
14
- if (Object.keys(searchObject).every(function (k) { return searchObject[k] === haystack[i][k]; })) {
15
- return { value: i };
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 var resolveConfig = function (amplify) {
8
- var _a, _b;
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: apiKey,
15
- customEndpoint: customEndpoint,
16
- customEndpointRegion: customEndpointRegion,
17
- defaultAuthMode: defaultAuthMode,
18
- endpoint: endpoint,
19
- region: 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 var resolveLibraryOptions = function (amplify) {
7
- var _a, _b, _c, _d, _e, _f;
8
- var headers = (_c = (_b = (_a = amplify.libraryOptions) === null || _a === void 0 ? void 0 : _a.API) === null || _b === void 0 ? void 0 : _b.GraphQL) === null || _c === void 0 ? void 0 : _c.headers;
9
- var withCredentials = (_f = (_e = (_d = amplify.libraryOptions) === null || _d === void 0 ? void 0 : _d.API) === null || _e === void 0 ? void 0 : _e.GraphQL) === null || _f === void 0 ? void 0 : _f.withCredentials;
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
- var e_1, _a, e_2, _b;
10
- var ownerFields = new Set();
11
- try {
12
- for (var _c = __values(model.attributes || []), _d = _c.next(); !_d.done; _d = _c.next()) {
13
- var attr = _d.value;
14
- if (isAuthAttribute(attr)) {
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
- var _a, _b;
51
- if ((attribute === null || attribute === void 0 ? void 0 : attribute.type) === 'auth') {
52
- if (typeof (attribute === null || attribute === void 0 ? void 0 : attribute.properties) === 'object') {
53
- if (Array.isArray((_a = attribute === null || attribute === void 0 ? void 0 : attribute.properties) === null || _a === void 0 ? void 0 : _a.rules)) {
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
- var _a = model.primaryKeyInfo, primaryKeyFieldName = _a.primaryKeyFieldName, sortKeyFieldNames = _a.sortKeyFieldNames;
11
- return __spreadArray([primaryKeyFieldName], __read(sortKeyFieldNames), false);
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.c1977f8.0+c1977f8",
3
+ "version": "4.0.1-api-v6-models.891fe0d.0+891fe0d",
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.0",
55
- "@aws-amplify/api-rest": "4.0.1-api-v6-models.c1977f8.0+c1977f8",
56
- "@aws-amplify/auth": "6.0.1-api-v6-models.c1977f8.0+c1977f8",
57
- "@aws-amplify/core": "6.0.1-api-v6-models.c1977f8.0+c1977f8",
54
+ "@aws-amplify/amplify-api-next-types-alpha": "^0.2.5",
55
+ "@aws-amplify/api-rest": "4.0.1-api-v6-models.891fe0d.0+891fe0d",
56
+ "@aws-amplify/auth": "6.0.1-api-v6-models.891fe0d.0+891fe0d",
57
+ "@aws-amplify/core": "6.0.1-api-v6-models.891fe0d.0+891fe0d",
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": "c1977f8efaae41b693495a2d6c53c503d0038e95"
130
+ "gitHead": "891fe0dc64e168de42b3b8d42def3eb9aed89efa"
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
  /**