@aws-amplify/api-graphql 4.0.17-unstable.e316a2e.0 → 4.0.18-experimental-lerna-test.d2b0b08.55

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 (172) 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 +145 -55
  4. package/dist/cjs/internals/APIClient.js.map +1 -1
  5. package/dist/cjs/internals/InternalGraphQLAPI.js +41 -42
  6. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
  7. package/dist/cjs/internals/generateClient.js +15 -5
  8. package/dist/cjs/internals/generateClient.js.map +1 -1
  9. package/dist/cjs/internals/generateCustomOperationsProperty.js +50 -0
  10. package/dist/cjs/internals/generateCustomOperationsProperty.js.map +1 -0
  11. package/dist/cjs/internals/operations/custom.js +356 -0
  12. package/dist/cjs/internals/operations/custom.js.map +1 -0
  13. package/dist/cjs/internals/operations/get.js +1 -1
  14. package/dist/cjs/internals/operations/get.js.map +1 -1
  15. package/dist/cjs/internals/operations/indexQuery.js +1 -1
  16. package/dist/cjs/internals/operations/indexQuery.js.map +1 -1
  17. package/dist/cjs/internals/operations/list.js +2 -2
  18. package/dist/cjs/internals/operations/list.js.map +1 -1
  19. package/dist/cjs/internals/operations/subscription.js +1 -1
  20. package/dist/cjs/internals/operations/subscription.js.map +1 -1
  21. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +12 -2
  22. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -1
  23. package/dist/cjs/internals/server/generateModelsProperty.js +1 -1
  24. package/dist/cjs/internals/server/generateModelsProperty.js.map +1 -1
  25. package/dist/cjs/internals/utils/clientProperties/generateEnumsProperty.js.map +1 -0
  26. package/dist/cjs/internals/utils/{generateModelsProperty.js → clientProperties/generateModelsProperty.js} +7 -7
  27. package/dist/cjs/internals/utils/clientProperties/generateModelsProperty.js.map +1 -0
  28. package/dist/cjs/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.js.map +1 -0
  29. package/dist/cjs/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.js.map +1 -0
  30. package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js +15 -0
  31. package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js.map +1 -0
  32. package/dist/cjs/internals/v6.js +1 -3
  33. package/dist/cjs/internals/v6.js.map +1 -1
  34. package/dist/cjs/utils/errors/constants.js +47 -0
  35. package/dist/cjs/utils/errors/constants.js.map +1 -0
  36. package/dist/cjs/utils/errors/createGraphQLResultWithError.js +15 -0
  37. package/dist/cjs/utils/errors/createGraphQLResultWithError.js.map +1 -0
  38. package/dist/cjs/utils/errors/index.js +3 -1
  39. package/dist/cjs/utils/errors/index.js.map +1 -1
  40. package/dist/cjs/utils/errors/repackageAuthError.js +7 -7
  41. package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -1
  42. package/dist/cjs/utils/resolveOwnerFields.js +6 -0
  43. package/dist/cjs/utils/resolveOwnerFields.js.map +1 -1
  44. package/dist/esm/GraphQLAPI.d.ts +2 -2
  45. package/dist/esm/GraphQLAPI.mjs.map +1 -1
  46. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +8 -8
  47. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +40 -31
  48. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
  49. package/dist/esm/internals/APIClient.d.ts +10 -9
  50. package/dist/esm/internals/APIClient.mjs +144 -55
  51. package/dist/esm/internals/APIClient.mjs.map +1 -1
  52. package/dist/esm/internals/InternalGraphQLAPI.d.ts +1 -1
  53. package/dist/esm/internals/InternalGraphQLAPI.mjs +45 -44
  54. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  55. package/dist/esm/internals/generateClient.mjs +15 -5
  56. package/dist/esm/internals/generateClient.mjs.map +1 -1
  57. package/dist/esm/internals/generateCustomOperationsProperty.d.ts +9 -0
  58. package/dist/esm/internals/generateCustomOperationsProperty.mjs +45 -0
  59. package/dist/esm/internals/generateCustomOperationsProperty.mjs.map +1 -0
  60. package/dist/esm/internals/operations/custom.d.ts +63 -0
  61. package/dist/esm/internals/operations/custom.mjs +354 -0
  62. package/dist/esm/internals/operations/custom.mjs.map +1 -0
  63. package/dist/esm/internals/operations/get.d.ts +1 -1
  64. package/dist/esm/internals/operations/get.mjs +1 -1
  65. package/dist/esm/internals/operations/get.mjs.map +1 -1
  66. package/dist/esm/internals/operations/indexQuery.d.ts +3 -3
  67. package/dist/esm/internals/operations/indexQuery.mjs +1 -1
  68. package/dist/esm/internals/operations/indexQuery.mjs.map +1 -1
  69. package/dist/esm/internals/operations/list.d.ts +1 -1
  70. package/dist/esm/internals/operations/list.mjs +2 -2
  71. package/dist/esm/internals/operations/list.mjs.map +1 -1
  72. package/dist/esm/internals/operations/subscription.d.ts +1 -1
  73. package/dist/esm/internals/operations/subscription.mjs +1 -1
  74. package/dist/esm/internals/operations/subscription.mjs.map +1 -1
  75. package/dist/esm/internals/server/generateClientWithAmplifyInstance.d.ts +1 -1
  76. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs +12 -2
  77. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -1
  78. package/dist/esm/internals/server/generateModelsProperty.d.ts +3 -3
  79. package/dist/esm/internals/server/generateModelsProperty.mjs +1 -1
  80. package/dist/esm/internals/server/generateModelsProperty.mjs.map +1 -1
  81. package/dist/esm/internals/types.d.ts +2 -2
  82. package/dist/esm/internals/utils/clientProperties/generateEnumsProperty.mjs.map +1 -0
  83. package/dist/esm/internals/utils/{generateModelsProperty.d.ts → clientProperties/generateModelsProperty.d.ts} +2 -2
  84. package/dist/esm/internals/utils/{generateModelsProperty.mjs → clientProperties/generateModelsProperty.mjs} +7 -7
  85. package/dist/esm/internals/utils/clientProperties/generateModelsProperty.mjs.map +1 -0
  86. package/dist/esm/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs.map +1 -0
  87. package/dist/esm/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs.map +1 -0
  88. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.d.ts +2 -0
  89. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs +12 -0
  90. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs.map +1 -0
  91. package/dist/esm/internals/v6.d.ts +1 -1
  92. package/dist/esm/internals/v6.mjs +1 -3
  93. package/dist/esm/internals/v6.mjs.map +1 -1
  94. package/dist/esm/types/index.d.ts +43 -35
  95. package/dist/esm/utils/ConnectionStateMonitor.d.ts +2 -2
  96. package/dist/esm/utils/ConnectionStateMonitor.mjs.map +1 -1
  97. package/dist/esm/utils/ReachabilityMonitor/index.native.mjs.map +1 -1
  98. package/dist/esm/utils/errors/constants.d.ts +7 -0
  99. package/dist/esm/utils/errors/constants.mjs +46 -0
  100. package/dist/esm/utils/errors/constants.mjs.map +1 -0
  101. package/dist/esm/utils/errors/createGraphQLResultWithError.d.ts +2 -0
  102. package/dist/esm/utils/errors/createGraphQLResultWithError.mjs +13 -0
  103. package/dist/esm/utils/errors/createGraphQLResultWithError.mjs.map +1 -0
  104. package/dist/esm/utils/errors/index.d.ts +1 -0
  105. package/dist/esm/utils/errors/index.mjs +1 -0
  106. package/dist/esm/utils/errors/index.mjs.map +1 -1
  107. package/dist/esm/utils/errors/repackageAuthError.d.ts +3 -7
  108. package/dist/esm/utils/errors/repackageAuthError.mjs +6 -6
  109. package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -1
  110. package/dist/esm/utils/findIndexByFields.d.ts +1 -1
  111. package/dist/esm/utils/resolveConfig.mjs +1 -0
  112. package/dist/esm/utils/resolveConfig.mjs.map +1 -1
  113. package/dist/esm/utils/resolveLibraryOptions.d.ts +4 -1
  114. package/dist/esm/utils/resolveOwnerFields.mjs +6 -0
  115. package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -1
  116. package/package.json +8 -7
  117. package/src/GraphQLAPI.ts +6 -5
  118. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +102 -82
  119. package/src/internals/APIClient.ts +248 -112
  120. package/src/internals/InternalGraphQLAPI.ts +66 -76
  121. package/src/internals/clientUtils.ts +1 -1
  122. package/src/internals/generateClient.ts +43 -6
  123. package/src/internals/generateCustomOperationsProperty.ts +112 -0
  124. package/src/internals/operations/custom.ts +492 -0
  125. package/src/internals/operations/get.ts +21 -20
  126. package/src/internals/operations/indexQuery.ts +13 -12
  127. package/src/internals/operations/list.ts +20 -24
  128. package/src/internals/operations/observeQuery.ts +3 -1
  129. package/src/internals/operations/subscription.ts +20 -16
  130. package/src/internals/server/generateClientWithAmplifyInstance.ts +27 -8
  131. package/src/internals/server/generateModelsProperty.ts +12 -6
  132. package/src/internals/types.ts +2 -2
  133. package/src/internals/utils/{generateEnumsProperty.ts → clientProperties/generateEnumsProperty.ts} +7 -6
  134. package/src/internals/utils/{generateModelsProperty.ts → clientProperties/generateModelsProperty.ts} +11 -10
  135. package/src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts +15 -0
  136. package/src/internals/v6.ts +11 -9
  137. package/src/server/generateClient.ts +6 -3
  138. package/src/types/PubSub.ts +1 -0
  139. package/src/types/index.ts +102 -81
  140. package/src/utils/ConnectionStateMonitor.ts +14 -9
  141. package/src/utils/ReachabilityMonitor/index.native.ts +1 -1
  142. package/src/utils/ReachabilityMonitor/index.ts +1 -0
  143. package/src/utils/ReconnectionMonitor.ts +1 -0
  144. package/src/utils/errors/assertValidationError.ts +1 -1
  145. package/src/utils/errors/constants.ts +56 -0
  146. package/src/utils/errors/createGraphQLResultWithError.ts +15 -0
  147. package/src/utils/errors/index.ts +1 -0
  148. package/src/utils/errors/repackageAuthError.ts +11 -14
  149. package/src/utils/findIndexByFields.ts +3 -3
  150. package/src/utils/resolveConfig.ts +3 -2
  151. package/src/utils/resolveLibraryOptions.ts +1 -0
  152. package/src/utils/resolveOwnerFields.ts +20 -8
  153. package/src/utils/resolvePKFields.ts +1 -0
  154. package/dist/cjs/internals/utils/generateEnumsProperty.js.map +0 -1
  155. package/dist/cjs/internals/utils/generateModelsProperty.js.map +0 -1
  156. package/dist/cjs/internals/utils/isApiGraphQLProviderConfig.js.map +0 -1
  157. package/dist/cjs/internals/utils/isConfigureEventWithResourceConfig.js.map +0 -1
  158. package/dist/esm/internals/utils/generateEnumsProperty.mjs.map +0 -1
  159. package/dist/esm/internals/utils/generateModelsProperty.mjs.map +0 -1
  160. package/dist/esm/internals/utils/isApiGraphQLProviderConfig.mjs.map +0 -1
  161. package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.mjs.map +0 -1
  162. /package/dist/cjs/internals/utils/{generateEnumsProperty.js → clientProperties/generateEnumsProperty.js} +0 -0
  163. /package/dist/cjs/internals/utils/{isApiGraphQLProviderConfig.js → runtimeTypeGuards/isApiGraphQLProviderConfig.js} +0 -0
  164. /package/dist/cjs/internals/utils/{isConfigureEventWithResourceConfig.js → runtimeTypeGuards/isConfigureEventWithResourceConfig.js} +0 -0
  165. /package/dist/esm/internals/utils/{generateEnumsProperty.d.ts → clientProperties/generateEnumsProperty.d.ts} +0 -0
  166. /package/dist/esm/internals/utils/{generateEnumsProperty.mjs → clientProperties/generateEnumsProperty.mjs} +0 -0
  167. /package/dist/esm/internals/utils/{isApiGraphQLProviderConfig.d.ts → runtimeTypeGuards/isApiGraphQLProviderConfig.d.ts} +0 -0
  168. /package/dist/esm/internals/utils/{isApiGraphQLProviderConfig.mjs → runtimeTypeGuards/isApiGraphQLProviderConfig.mjs} +0 -0
  169. /package/dist/esm/internals/utils/{isConfigureEventWithResourceConfig.d.ts → runtimeTypeGuards/isConfigureEventWithResourceConfig.d.ts} +0 -0
  170. /package/dist/esm/internals/utils/{isConfigureEventWithResourceConfig.mjs → runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs} +0 -0
  171. /package/src/internals/utils/{isApiGraphQLProviderConfig.ts → runtimeTypeGuards/isApiGraphQLProviderConfig.ts} +0 -0
  172. /package/src/internals/utils/{isConfigureEventWithResourceConfig.ts → runtimeTypeGuards/isConfigureEventWithResourceConfig.ts} +0 -0
@@ -1,17 +1,25 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
4
- import { ModelTypes, CustomHeaders, EnumTypes } from '@aws-amplify/data-schema-types';
5
- import { Source, DocumentNode, GraphQLError } from 'graphql';
6
- export { OperationTypeNode } from 'graphql';
4
+ import {
5
+ CustomHeaders,
6
+ CustomMutations,
7
+ CustomQueries,
8
+ CustomSubscriptions,
9
+ EnumTypes,
10
+ ModelSortDirection,
11
+ ModelTypes,
12
+ } from '@aws-amplify/data-schema-types';
13
+ import { DocumentNode, GraphQLError, Source } from 'graphql';
7
14
  import { Observable } from 'rxjs';
8
-
9
15
  import {
10
- GraphQLAuthMode,
11
16
  DocumentType,
17
+ GraphQLAuthMode,
12
18
  } from '@aws-amplify/core/internals/utils';
13
19
  import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
14
20
 
21
+ export { OperationTypeNode } from 'graphql';
22
+
15
23
  export { CONTROL_MSG, ConnectionState } from './PubSub';
16
24
 
17
25
  export { SelectionSet } from '@aws-amplify/data-schema-types';
@@ -35,9 +43,7 @@ export interface GraphQLOptions {
35
43
  export interface GraphQLResult<T = object> {
36
44
  data: T;
37
45
  errors?: GraphQLError[];
38
- extensions?: {
39
- [key: string]: any;
40
- };
46
+ extensions?: Record<string, any>;
41
47
  }
42
48
 
43
49
  // Opaque type used for determining the graphql query type
@@ -69,21 +75,22 @@ export type GraphQLSubscription<T> = T & {
69
75
  *
70
76
  * This util simply makes related model properties optional recursively.
71
77
  */
72
- export type GraphQLReturnType<T> = T extends {}
73
- ? {
74
- [K in keyof T]?: GraphQLReturnType<T[K]>;
75
- }
76
- : T;
78
+ export type GraphQLReturnType<T> =
79
+ T extends Record<string, unknown>
80
+ ? {
81
+ [K in keyof T]?: GraphQLReturnType<T[K]>;
82
+ }
83
+ : T;
77
84
 
78
85
  /**
79
86
  * Describes a paged list result from AppSync, which can either
80
87
  * live at the top query or property (e.g., related model) level.
81
88
  */
82
- type PagedList<T, TYPENAME> = {
89
+ interface PagedList<T, TYPENAME> {
83
90
  __typename: TYPENAME;
84
91
  nextToken?: string | null | undefined;
85
- items: Array<T>;
86
- };
92
+ items: T[];
93
+ }
87
94
 
88
95
  /**
89
96
  * Recursively looks through a result type and removes nulls and
@@ -93,13 +100,14 @@ type PagedList<T, TYPENAME> = {
93
100
  * array, this will only be the case when we also have errors,
94
101
  * which will then be *thrown*.
95
102
  */
96
- type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME>
97
- ? PagedList<Exclude<IT, null | undefined>, NAME>
98
- : T extends {}
99
- ? {
100
- [K in keyof T]: WithListsFixed<T[K]>;
101
- }
102
- : T;
103
+ type WithListsFixed<T> =
104
+ T extends PagedList<infer IT, infer NAME>
105
+ ? PagedList<Exclude<IT, null | undefined>, NAME>
106
+ : T extends Record<string, unknown>
107
+ ? {
108
+ [K in keyof T]: WithListsFixed<T[K]>;
109
+ }
110
+ : T;
103
111
 
104
112
  /**
105
113
  * Returns an updated response type to always return a value.
@@ -115,14 +123,12 @@ type NeverEmpty<T> = {
115
123
  * If empty members are present, there will also be errors present,
116
124
  * and the response will instead be *thrown*.
117
125
  */
118
- type FixedQueryResult<T> = Exclude<
119
- T[keyof T],
120
- null | undefined
121
- > extends PagedList<any, any>
122
- ? {
123
- [K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
124
- }
125
- : T;
126
+ type FixedQueryResult<T> =
127
+ Exclude<T[keyof T], null | undefined> extends PagedList<any, any>
128
+ ? {
129
+ [K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
130
+ }
131
+ : T;
126
132
 
127
133
  /**
128
134
  * The return value from a `graphql({query})` call when `query` is a subscription.
@@ -164,9 +170,9 @@ export type GraphqlSubscriptionResult<T> = Observable<
164
170
  * })
165
171
  * ```
166
172
  */
167
- export type GraphqlSubscriptionMessage<T> = {
173
+ export interface GraphqlSubscriptionMessage<T> {
168
174
  data: T;
169
- };
175
+ }
170
176
 
171
177
  export interface AWSAppSyncRealTimeProviderOptions {
172
178
  appSyncGraphqlEndpoint?: string;
@@ -175,15 +181,15 @@ export interface AWSAppSyncRealTimeProviderOptions {
175
181
  variables?: Record<string, unknown>;
176
182
  apiKey?: string;
177
183
  region?: string;
178
- libraryConfigHeaders?: () => {} | (() => Promise<{}>);
184
+ libraryConfigHeaders?(): () => Promise<Record<string, unknown> | Headers>;
179
185
  additionalHeaders?: CustomHeaders;
180
186
  }
181
187
 
182
- export type AWSAppSyncRealTimeProvider = {
188
+ export interface AWSAppSyncRealTimeProvider {
183
189
  subscribe(
184
- options?: AWSAppSyncRealTimeProviderOptions
190
+ options?: AWSAppSyncRealTimeProviderOptions,
185
191
  ): Observable<Record<string, unknown>>;
186
- };
192
+ }
187
193
 
188
194
  export enum GraphQLAuthError {
189
195
  NO_API_KEY = 'No api-key configured',
@@ -235,15 +241,16 @@ export type UnknownGraphQLResponse =
235
241
  export type GraphQLVariablesV6<
236
242
  FALLBACK_TYPES = unknown,
237
243
  TYPED_GQL_STRING extends string = string,
238
- > = TYPED_GQL_STRING extends GeneratedQuery<infer IN, any>
239
- ? IN
240
- : TYPED_GQL_STRING extends GeneratedMutation<infer IN, any>
241
- ? IN
242
- : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, any>
243
- ? IN
244
- : FALLBACK_TYPES extends GraphQLOperationType<infer IN, any>
245
- ? IN
246
- : any;
244
+ > =
245
+ TYPED_GQL_STRING extends GeneratedQuery<infer IN, any>
246
+ ? IN
247
+ : TYPED_GQL_STRING extends GeneratedMutation<infer IN, any>
248
+ ? IN
249
+ : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, any>
250
+ ? IN
251
+ : FALLBACK_TYPES extends GraphQLOperationType<infer IN, any>
252
+ ? IN
253
+ : any;
247
254
 
248
255
  /**
249
256
  * The expected return type with respect to the given `FALLBACK_TYPE`
@@ -252,22 +259,23 @@ export type GraphQLVariablesV6<
252
259
  export type GraphQLResponseV6<
253
260
  FALLBACK_TYPE = unknown,
254
261
  TYPED_GQL_STRING extends string = string,
255
- > = TYPED_GQL_STRING extends GeneratedQuery<infer IN, infer QUERY_OUT>
256
- ? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>>
257
- : TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT>
258
- ? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>>
259
- : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT>
260
- ? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>>
261
- : FALLBACK_TYPE extends GraphQLQuery<infer T>
262
- ? Promise<GraphQLResult<FALLBACK_TYPE>>
263
- : FALLBACK_TYPE extends GraphQLSubscription<infer T>
264
- ? GraphqlSubscriptionResult<FALLBACK_TYPE>
265
- : FALLBACK_TYPE extends GraphQLOperationType<
266
- infer IN,
267
- infer CUSTOM_OUT
268
- >
269
- ? CUSTOM_OUT
270
- : UnknownGraphQLResponse;
262
+ > =
263
+ TYPED_GQL_STRING extends GeneratedQuery<infer _, infer QUERY_OUT>
264
+ ? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>>
265
+ : TYPED_GQL_STRING extends GeneratedMutation<infer _, infer MUTATION_OUT>
266
+ ? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>>
267
+ : TYPED_GQL_STRING extends GeneratedSubscription<infer _, infer SUB_OUT>
268
+ ? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>>
269
+ : FALLBACK_TYPE extends GraphQLQuery<infer _>
270
+ ? Promise<GraphQLResult<FALLBACK_TYPE>>
271
+ : FALLBACK_TYPE extends GraphQLSubscription<infer _>
272
+ ? GraphqlSubscriptionResult<FALLBACK_TYPE>
273
+ : FALLBACK_TYPE extends GraphQLOperationType<
274
+ infer _,
275
+ infer CUSTOM_OUT
276
+ >
277
+ ? CUSTOM_OUT
278
+ : UnknownGraphQLResponse;
271
279
 
272
280
  /**
273
281
  * The shape customers can use to provide `T` to `graphql<T>()` to specify both
@@ -287,10 +295,13 @@ export type GraphQLResponseV6<
287
295
  * })
288
296
  * ```
289
297
  */
290
- export type GraphQLOperationType<IN extends {}, OUT extends {}> = {
298
+ export interface GraphQLOperationType<
299
+ IN extends Record<string, DocumentType>,
300
+ OUT extends Record<string, DocumentType>,
301
+ > {
291
302
  variables: IN;
292
303
  result: OUT;
293
- };
304
+ }
294
305
 
295
306
  /**
296
307
  * Nominal type for branding generated graphql query operation strings with
@@ -379,10 +390,13 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
379
390
  [__authToken]?: string;
380
391
  [__headers]?: CustomHeaders;
381
392
  graphql: GraphQLMethod;
382
- cancel: (promise: Promise<any>, message?: string) => boolean;
383
- isCancelError: (error: any) => boolean;
393
+ cancel(promise: Promise<any>, message?: string): boolean;
394
+ isCancelError(error: any): boolean;
384
395
  models: ModelTypes<T>;
385
396
  enums: EnumTypes<T>;
397
+ queries: CustomQueries<T>;
398
+ mutations: CustomMutations<T>;
399
+ subscriptions: CustomSubscriptions<T>;
386
400
  }>;
387
401
 
388
402
  export type V6ClientSSRRequest<T extends Record<any, any> = never> =
@@ -392,9 +406,12 @@ export type V6ClientSSRRequest<T extends Record<any, any> = never> =
392
406
  [__authToken]?: string;
393
407
  [__headers]?: CustomHeaders;
394
408
  graphql: GraphQLMethodSSR;
395
- cancel: (promise: Promise<any>, message?: string) => boolean;
396
- isCancelError: (error: any) => boolean;
409
+ cancel(promise: Promise<any>, message?: string): boolean;
410
+ isCancelError(error: any): boolean;
397
411
  models: ModelTypes<T, 'REQUEST'>;
412
+ enums: EnumTypes<T>;
413
+ queries: CustomQueries<T, 'REQUEST'>;
414
+ mutations: CustomMutations<T, 'REQUEST'>;
398
415
  }>;
399
416
 
400
417
  export type V6ClientSSRCookies<T extends Record<any, any> = never> =
@@ -404,9 +421,12 @@ export type V6ClientSSRCookies<T extends Record<any, any> = never> =
404
421
  [__authToken]?: string;
405
422
  [__headers]?: CustomHeaders;
406
423
  graphql: GraphQLMethod;
407
- cancel: (promise: Promise<any>, message?: string) => boolean;
408
- isCancelError: (error: any) => boolean;
424
+ cancel(promise: Promise<any>, message?: string): boolean;
425
+ isCancelError(error: any): boolean;
409
426
  models: ModelTypes<T, 'COOKIES'>;
427
+ enums: EnumTypes<T>;
428
+ queries: CustomQueries<T, 'COOKIES'>;
429
+ mutations: CustomMutations<T, 'COOKIES'>;
410
430
  }>;
411
431
 
412
432
  export type GraphQLMethod = <
@@ -414,7 +434,7 @@ export type GraphQLMethod = <
414
434
  TYPED_GQL_STRING extends string = string,
415
435
  >(
416
436
  options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
417
- additionalHeaders?: CustomHeaders | undefined
437
+ additionalHeaders?: CustomHeaders | undefined,
418
438
  ) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
419
439
 
420
440
  export type GraphQLMethodSSR = <
@@ -423,7 +443,7 @@ export type GraphQLMethodSSR = <
423
443
  >(
424
444
  contextSpec: AmplifyServer.ContextSpec,
425
445
  options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
426
- additionalHeaders?: CustomHeaders | undefined
446
+ additionalHeaders?: CustomHeaders | undefined,
427
447
  ) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
428
448
 
429
449
  /**
@@ -431,30 +451,31 @@ export type GraphQLMethodSSR = <
431
451
  *
432
452
  * The knobs available for configuring `server/generateClient` internally.
433
453
  */
434
- export type ServerClientGenerationParams = {
454
+ export interface ServerClientGenerationParams {
435
455
  amplify:
436
456
  | null // null expected when used with `generateServerClient`
437
457
  // closure expected with `generateServerClientUsingCookies`
438
458
  | ((fn: (amplify: AmplifyClassV6) => Promise<any>) => Promise<any>);
439
459
  // global env-sourced config use for retrieving modelIntro
440
460
  config: ResourcesConfig;
441
- };
461
+ }
442
462
 
443
463
  export type QueryArgs = Record<string, unknown>;
444
464
 
445
- export type ListArgs = {
465
+ export interface ListArgs extends Record<string, unknown> {
446
466
  selectionSet?: string[];
447
- filter?: {};
467
+ filter?: Record<string, unknown>;
468
+ sortDirection?: ModelSortDirection;
448
469
  headers?: CustomHeaders;
449
- };
470
+ }
450
471
 
451
- export type AuthModeParams = {
472
+ export interface AuthModeParams extends Record<string, unknown> {
452
473
  authMode?: GraphQLAuthMode;
453
474
  authToken?: string;
454
- };
475
+ }
455
476
 
456
- export type GenerateServerClientParams = {
477
+ export interface GenerateServerClientParams {
457
478
  config: ResourcesConfig;
458
479
  authMode?: GraphQLAuthMode;
459
480
  authToken?: string;
460
- };
481
+ }
@@ -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
 
@@ -69,10 +72,10 @@ export class ConnectionStateMonitor {
69
72
  this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(
70
73
  ({ online }) => {
71
74
  this.record(
72
- online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE
75
+ online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE,
73
76
  );
74
77
  this._initialNetworkStateSubscription?.unsubscribe();
75
- }
78
+ },
76
79
  );
77
80
 
78
81
  this._linkedConnectionStateObservable =
@@ -94,9 +97,9 @@ export class ConnectionStateMonitor {
94
97
  this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(
95
98
  ({ online }) => {
96
99
  this.record(
97
- online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE
100
+ online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE,
98
101
  );
99
- }
102
+ },
100
103
  );
101
104
  }
102
105
  }
@@ -126,14 +129,15 @@ export class ConnectionStateMonitor {
126
129
  .pipe(
127
130
  map(value => {
128
131
  return this.connectionStatesTranslator(value);
129
- })
132
+ }),
130
133
  )
131
134
  .pipe(
132
135
  filter(current => {
133
136
  const toInclude = current !== previous;
134
137
  previous = current;
138
+
135
139
  return toInclude;
136
- })
140
+ }),
137
141
  );
138
142
  }
139
143
 
@@ -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 {
@@ -9,7 +9,7 @@ import { APIValidationErrorCode, validationErrorMap } from './validation';
9
9
  */
10
10
  export function assertValidationError(
11
11
  assertion: boolean,
12
- name: APIValidationErrorCode
12
+ name: APIValidationErrorCode,
13
13
  ): asserts assertion {
14
14
  const { message, recoverySuggestion } = validationErrorMap[name];
15
15
 
@@ -0,0 +1,56 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
5
+
6
+ import { GraphQLAuthError } from '../../types';
7
+
8
+ export const NO_API_KEY: AmplifyErrorParams = {
9
+ name: 'NoApiKey',
10
+ // ideal: No API key configured.
11
+ message: GraphQLAuthError.NO_API_KEY,
12
+ recoverySuggestion:
13
+ 'The API request was made with `authMode: "apiKey"` but no API Key was passed into `Amplify.configure()`. Review if your API key is passed into the `Amplify.configure()` function.',
14
+ };
15
+
16
+ export const NO_VALID_CREDENTIALS: AmplifyErrorParams = {
17
+ name: 'NoCredentials',
18
+ // ideal: No auth credentials available.
19
+ message: GraphQLAuthError.NO_CREDENTIALS,
20
+ recoverySuggestion: `The API request was made with \`authMode: "iam"\` but no authentication credentials are available.
21
+
22
+ If you intended to make a request using an authenticated role, review if your user is signed in before making the request.
23
+
24
+ If you intend to make a request using an unauthenticated role or also known as "guest access", verify if "Auth.Cognito.allowGuestAccess" is set to "true" in the \`Amplify.configure()\` function.`,
25
+ };
26
+
27
+ export const NO_VALID_AUTH_TOKEN: AmplifyErrorParams = {
28
+ name: 'NoValidAuthTokens',
29
+ // ideal: No valid JWT auth token provided to make the API request..
30
+ message: GraphQLAuthError.NO_FEDERATED_JWT,
31
+ recoverySuggestion:
32
+ 'If you intended to make an authenticated API request, review if the current user is signed in.',
33
+ };
34
+
35
+ export const NO_SIGNED_IN_USER: AmplifyErrorParams = {
36
+ name: 'NoSignedUser',
37
+ // ideal: Couldn't retrieve authentication credentials to make the API request.
38
+ message: GraphQLAuthError.NO_CURRENT_USER,
39
+ recoverySuggestion:
40
+ 'Review the underlying exception field for more details. If you intended to make an authenticated API request, review if the current user is signed in.',
41
+ };
42
+
43
+ export const NO_AUTH_TOKEN_HEADER: AmplifyErrorParams = {
44
+ name: 'NoAuthorizationHeader',
45
+ // ideal: Authorization header not specified.
46
+ message: GraphQLAuthError.NO_AUTH_TOKEN,
47
+ recoverySuggestion:
48
+ 'The API request was made with `authMode: "lambda"` but no `authToken` is set. Review if a valid authToken is passed into the request options or in the `Amplify.configure()` function.',
49
+ };
50
+
51
+ export const NO_ENDPOINT: AmplifyErrorParams = {
52
+ name: 'NoEndpoint',
53
+ message: 'No GraphQL endpoint configured in `Amplify.configure()`.',
54
+ recoverySuggestion:
55
+ 'Review if the GraphQL API endpoint is set in the `Amplify.configure()` function.',
56
+ };
@@ -0,0 +1,15 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { GraphQLError } from 'graphql';
5
+
6
+ import { GraphQLResult } from '../../types';
7
+
8
+ export const createGraphQLResultWithError = <T>(
9
+ error: Error,
10
+ ): GraphQLResult<T> => {
11
+ return {
12
+ data: {} as T,
13
+ errors: [new GraphQLError(error.message, null, null, null, null, error)],
14
+ };
15
+ };
@@ -4,3 +4,4 @@
4
4
  export { GraphQLApiError } from './GraphQLApiError';
5
5
  export { assertValidationError } from './assertValidationError';
6
6
  export { APIValidationErrorCode, validationErrorMap } from './validation';
7
+ export { createGraphQLResultWithError } from './createGraphQLResultWithError';
@@ -1,38 +1,34 @@
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';
8
-
9
- type ErrorObject = {
10
- errors: AmplifyErrorParams[];
11
- };
4
+ import { GraphQLResult } from '../../types';
12
5
 
13
6
  /**
14
7
  * Checks to see if the given response or subscription message contains an
15
- * unauth error. If it does, it changes the error message to include instructions
8
+ * Unauthorized error. If it does, it changes the error message to include instructions
16
9
  * for the app developer.
17
10
  */
18
- export function repackageUnauthError<T extends ErrorObject>(content: T): T {
11
+ export function repackageUnauthorizedError<T extends GraphQLResult<any>>(
12
+ content: T,
13
+ ): T {
19
14
  if (content.errors && Array.isArray(content.errors)) {
20
15
  content.errors.forEach(e => {
21
- if (isUnauthError(e)) {
16
+ if (isUnauthorizedError(e)) {
22
17
  e.message = 'Unauthorized';
23
- e.recoverySuggestion =
18
+ (e as any).recoverySuggestion =
24
19
  `If you're calling an Amplify-generated API, make sure ` +
25
20
  `to set the "authMode" in generateClient({ authMode: '...' }) to the backend authorization ` +
26
21
  `rule's auth provider ('apiKey', 'userPool', 'iam', 'oidc', 'lambda')`;
27
22
  }
28
23
  });
29
24
  }
25
+
30
26
  return content;
31
27
  }
32
28
 
33
- function isUnauthError(error: any): boolean {
29
+ function isUnauthorizedError(error: any): boolean {
34
30
  // Error pattern corresponding to appsync calls
35
- if (error?.['originalError']?.['name']?.startsWith('UnauthorizedException')) {
31
+ if (error?.originalError?.name?.startsWith('UnauthorizedException')) {
36
32
  return true;
37
33
  }
38
34
  // Error pattern corresponding to appsync subscriptions
@@ -42,5 +38,6 @@ function isUnauthError(error: any): boolean {
42
38
  ) {
43
39
  return true;
44
40
  }
41
+
45
42
  return false;
46
43
  }
@@ -11,16 +11,16 @@
11
11
  export function findIndexByFields<T>(
12
12
  needle: T,
13
13
  haystack: T[],
14
- keyFields: Array<keyof T>
14
+ keyFields: (keyof T)[],
15
15
  ): number {
16
16
  const searchObject = Object.fromEntries(
17
- keyFields.map(fieldName => [fieldName, needle[fieldName]])
17
+ keyFields.map(fieldName => [fieldName, needle[fieldName]]),
18
18
  );
19
19
 
20
20
  for (let i = 0; i < haystack.length; i++) {
21
21
  if (
22
22
  Object.keys(searchObject).every(
23
- k => searchObject[k] === (haystack[i] as any)[k]
23
+ k => searchObject[k] === (haystack[i] as any)[k],
24
24
  )
25
25
  ) {
26
26
  return i;
@@ -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');
@@ -14,7 +15,7 @@ export const resolveConfig = (amplify: AmplifyClassV6) => {
14
15
 
15
16
  if (!config.API?.GraphQL) {
16
17
  logger.warn(
17
- 'The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().'
18
+ 'The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().',
18
19
  );
19
20
  }
20
21
 
@@ -31,7 +32,7 @@ export const resolveConfig = (amplify: AmplifyClassV6) => {
31
32
  // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);
32
33
  assertValidationError(
33
34
  !(!customEndpoint && customEndpointRegion),
34
- APIValidationErrorCode.NoCustomEndpoint
35
+ APIValidationErrorCode.NoCustomEndpoint,
35
36
  );
36
37
 
37
38
  return {
@@ -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
  };