@aws-amplify/api-graphql 4.0.17 → 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 (170) 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 -54
  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 +0 -2
  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 -54
  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 +0 -2
  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/resolveOwnerFields.mjs +6 -0
  114. package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -1
  115. package/package.json +8 -7
  116. package/src/GraphQLAPI.ts +4 -3
  117. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +84 -64
  118. package/src/internals/APIClient.ts +242 -104
  119. package/src/internals/InternalGraphQLAPI.ts +65 -75
  120. package/src/internals/clientUtils.ts +1 -1
  121. package/src/internals/generateClient.ts +43 -6
  122. package/src/internals/generateCustomOperationsProperty.ts +112 -0
  123. package/src/internals/operations/custom.ts +492 -0
  124. package/src/internals/operations/get.ts +10 -9
  125. package/src/internals/operations/indexQuery.ts +13 -12
  126. package/src/internals/operations/list.ts +11 -15
  127. package/src/internals/operations/observeQuery.ts +3 -1
  128. package/src/internals/operations/subscription.ts +14 -10
  129. package/src/internals/server/generateClientWithAmplifyInstance.ts +26 -7
  130. package/src/internals/server/generateModelsProperty.ts +12 -6
  131. package/src/internals/types.ts +2 -2
  132. package/src/internals/utils/{generateEnumsProperty.ts → clientProperties/generateEnumsProperty.ts} +7 -6
  133. package/src/internals/utils/{generateModelsProperty.ts → clientProperties/generateModelsProperty.ts} +11 -10
  134. package/src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts +15 -0
  135. package/src/internals/v6.ts +6 -4
  136. package/src/server/generateClient.ts +4 -1
  137. package/src/types/PubSub.ts +1 -0
  138. package/src/types/index.ts +61 -45
  139. package/src/utils/ConnectionStateMonitor.ts +8 -3
  140. package/src/utils/ReachabilityMonitor/index.native.ts +1 -1
  141. package/src/utils/ReachabilityMonitor/index.ts +1 -0
  142. package/src/utils/ReconnectionMonitor.ts +1 -0
  143. package/src/utils/errors/constants.ts +56 -0
  144. package/src/utils/errors/createGraphQLResultWithError.ts +15 -0
  145. package/src/utils/errors/index.ts +1 -0
  146. package/src/utils/errors/repackageAuthError.ts +11 -14
  147. package/src/utils/findIndexByFields.ts +1 -1
  148. package/src/utils/resolveConfig.ts +1 -0
  149. package/src/utils/resolveLibraryOptions.ts +1 -0
  150. package/src/utils/resolveOwnerFields.ts +19 -7
  151. package/src/utils/resolvePKFields.ts +1 -0
  152. package/dist/cjs/internals/utils/generateEnumsProperty.js.map +0 -1
  153. package/dist/cjs/internals/utils/generateModelsProperty.js.map +0 -1
  154. package/dist/cjs/internals/utils/isApiGraphQLProviderConfig.js.map +0 -1
  155. package/dist/cjs/internals/utils/isConfigureEventWithResourceConfig.js.map +0 -1
  156. package/dist/esm/internals/utils/generateEnumsProperty.mjs.map +0 -1
  157. package/dist/esm/internals/utils/generateModelsProperty.mjs.map +0 -1
  158. package/dist/esm/internals/utils/isApiGraphQLProviderConfig.mjs.map +0 -1
  159. package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.mjs.map +0 -1
  160. /package/dist/cjs/internals/utils/{generateEnumsProperty.js → clientProperties/generateEnumsProperty.js} +0 -0
  161. /package/dist/cjs/internals/utils/{isApiGraphQLProviderConfig.js → runtimeTypeGuards/isApiGraphQLProviderConfig.js} +0 -0
  162. /package/dist/cjs/internals/utils/{isConfigureEventWithResourceConfig.js → runtimeTypeGuards/isConfigureEventWithResourceConfig.js} +0 -0
  163. /package/dist/esm/internals/utils/{generateEnumsProperty.d.ts → clientProperties/generateEnumsProperty.d.ts} +0 -0
  164. /package/dist/esm/internals/utils/{generateEnumsProperty.mjs → clientProperties/generateEnumsProperty.mjs} +0 -0
  165. /package/dist/esm/internals/utils/{isApiGraphQLProviderConfig.d.ts → runtimeTypeGuards/isApiGraphQLProviderConfig.d.ts} +0 -0
  166. /package/dist/esm/internals/utils/{isApiGraphQLProviderConfig.mjs → runtimeTypeGuards/isApiGraphQLProviderConfig.mjs} +0 -0
  167. /package/dist/esm/internals/utils/{isConfigureEventWithResourceConfig.d.ts → runtimeTypeGuards/isConfigureEventWithResourceConfig.d.ts} +0 -0
  168. /package/dist/esm/internals/utils/{isConfigureEventWithResourceConfig.mjs → runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs} +0 -0
  169. /package/src/internals/utils/{isApiGraphQLProviderConfig.ts → runtimeTypeGuards/isApiGraphQLProviderConfig.ts} +0 -0
  170. /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
 
4
- import { graphql, cancel, isCancelError } from '..';
5
- import { generateModelsProperty } from './generateModelsProperty';
4
+ import { cancel, graphql, isCancelError } from '..';
6
5
  import {
6
+ CommonPublicClientOptions,
7
+ ServerClientGenerationParams,
8
+ V6ClientSSRCookies,
9
+ V6ClientSSRRequest,
7
10
  __amplify,
8
11
  __authMode,
9
12
  __authToken,
10
- V6ClientSSRRequest,
11
- V6ClientSSRCookies,
12
- ServerClientGenerationParams,
13
- CommonPublicClientOptions,
13
+ __headers,
14
14
  } from '../../types';
15
+ import { isApiGraphQLConfig } from '../utils/runtimeTypeGuards/isApiGraphQLProviderConfig';
16
+ import { generateEnumsProperty } from '../utils/clientProperties/generateEnumsProperty';
17
+ import {
18
+ generateCustomMutationsProperty,
19
+ generateCustomQueriesProperty,
20
+ } from '../generateCustomOperationsProperty';
21
+
22
+ import { generateModelsProperty } from './generateModelsProperty';
15
23
 
16
24
  /**
17
25
  * @private
@@ -36,12 +44,23 @@ export function generateClientWithAmplifyInstance<
36
44
  [__amplify]: params.amplify,
37
45
  [__authMode]: params.authMode,
38
46
  [__authToken]: params.authToken,
47
+ [__headers]: params.headers,
39
48
  graphql,
40
49
  cancel,
41
50
  isCancelError,
42
51
  } as any;
43
52
 
44
- client.models = generateModelsProperty<T>(client, params);
53
+ const apiGraphqlConfig = params.config?.API?.GraphQL;
54
+
55
+ if (isApiGraphQLConfig(apiGraphqlConfig)) {
56
+ client.models = generateModelsProperty<T>(client, params);
57
+ client.enums = generateEnumsProperty<T>(apiGraphqlConfig);
58
+ client.queries = generateCustomQueriesProperty<T>(client, apiGraphqlConfig);
59
+ client.mutations = generateCustomMutationsProperty<T>(
60
+ client,
61
+ apiGraphqlConfig,
62
+ );
63
+ }
45
64
 
46
65
  return client as ClientType;
47
66
  }
@@ -1,26 +1,32 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { ModelTypes } from '@aws-amplify/data-schema-types';
4
- import { graphQLOperationsInfo, ModelOperation } from '../APIClient';
5
- import { ServerClientGenerationParams } from '../../types/';
6
- import { V6ClientSSRRequest, V6ClientSSRCookies } from '../../types';
7
4
  import { ModelIntrospectionSchema } from '@aws-amplify/core/internals/utils';
8
5
 
6
+ import { ModelOperation, graphQLOperationsInfo } from '../APIClient';
7
+ import {
8
+ ServerClientGenerationParams,
9
+ V6ClientSSRCookies,
10
+ V6ClientSSRRequest,
11
+ } from '../../types/';
9
12
  import { listFactory } from '../operations/list';
10
13
  import { indexQueryFactory } from '../operations/indexQuery';
11
14
  import { getFactory } from '../operations/get';
12
15
  import { getSecondaryIndexesFromSchemaModel } from '../clientUtils';
13
16
 
14
17
  export function generateModelsProperty<
15
- _T extends Record<any, any> = never,
18
+ T extends Record<any, any> = never,
16
19
  ClientType extends
17
20
  | V6ClientSSRRequest<Record<string, any>>
18
21
  | V6ClientSSRCookies<Record<string, any>> = V6ClientSSRCookies<
19
22
  Record<string, any>
20
23
  >,
21
- >(client: ClientType, params: ServerClientGenerationParams): ClientType {
24
+ >(
25
+ client: ClientType,
26
+ params: ServerClientGenerationParams,
27
+ ): ModelTypes<T> | ModelTypes<never> {
22
28
  const models = {} as any;
23
- const config = params.config;
29
+ const { config } = params;
24
30
  const useContext = params.amplify === null;
25
31
 
26
32
  if (!config) {
@@ -16,8 +16,8 @@ export type ClientGenerationParams = {
16
16
  /**
17
17
  * Common options that can be used on public `generateClient()` interfaces.
18
18
  */
19
- export type CommonPublicClientOptions = {
19
+ export interface CommonPublicClientOptions {
20
20
  authMode?: GraphQLAuthMode;
21
21
  authToken?: string;
22
22
  headers?: CustomHeaders;
23
- };
23
+ }
@@ -2,8 +2,8 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import {
5
- ModelIntrospectionSchema,
6
5
  GraphQLProviderConfig,
6
+ ModelIntrospectionSchema,
7
7
  } from '@aws-amplify/core/internals/utils';
8
8
  import { EnumTypes } from '@aws-amplify/data-schema-types';
9
9
 
@@ -17,11 +17,12 @@ export const generateEnumsProperty = <T extends Record<any, any> = never>(
17
17
  return {} as EnumTypes<never>;
18
18
  }
19
19
 
20
- const enums: {
21
- [EnumName: string]: {
22
- values: () => string[];
23
- };
24
- } = {};
20
+ const enums: Record<
21
+ string,
22
+ {
23
+ values(): string[];
24
+ }
25
+ > = {};
25
26
 
26
27
  for (const [_, enumData] of Object.entries(modelIntrospection.enums)) {
27
28
  enums[enumData.name] = {
@@ -1,23 +1,24 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { ModelTypes } from '@aws-amplify/data-schema-types';
4
- import { graphQLOperationsInfo, ModelOperation } from '../APIClient';
5
- import { V6Client, __authMode, __authToken } from '../../types';
6
- import { listFactory } from '../operations/list';
7
- import { indexQueryFactory } from '../operations/indexQuery';
8
- import { getFactory } from '../operations/get';
9
- import { subscriptionFactory } from '../operations/subscription';
10
- import { observeQueryFactory } from '../operations/observeQuery';
11
4
  import {
12
- ModelIntrospectionSchema,
13
5
  GraphQLProviderConfig,
6
+ ModelIntrospectionSchema,
14
7
  } from '@aws-amplify/core/internals/utils';
15
- import { getSecondaryIndexesFromSchemaModel } from '../clientUtils';
8
+
9
+ import { ModelOperation, graphQLOperationsInfo } from '../../APIClient';
10
+ import { V6Client } from '../../../types';
11
+ import { listFactory } from '../../operations/list';
12
+ import { indexQueryFactory } from '../../operations/indexQuery';
13
+ import { getFactory } from '../../operations/get';
14
+ import { subscriptionFactory } from '../../operations/subscription';
15
+ import { observeQueryFactory } from '../../operations/observeQuery';
16
+ import { getSecondaryIndexesFromSchemaModel } from '../../clientUtils';
16
17
 
17
18
  export function generateModelsProperty<T extends Record<any, any> = never>(
18
19
  client: V6Client<Record<string, any>>,
19
20
  apiGraphQLConfig: GraphQLProviderConfig['GraphQL'],
20
- ): ModelTypes<T> {
21
+ ): ModelTypes<T> | ModelTypes<never> {
21
22
  const models = {} as any;
22
23
 
23
24
  const modelIntrospection: ModelIntrospectionSchema | undefined =
@@ -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 { GraphQLResult } from '../../../types';
5
+
6
+ export function isGraphQLResponseWithErrors(
7
+ response: unknown,
8
+ ): response is GraphQLResult {
9
+ if (!response) {
10
+ return false;
11
+ }
12
+ const r = response as GraphQLResult;
13
+
14
+ return Array.isArray(r.errors) && r.errors.length > 0;
15
+ }
@@ -1,15 +1,16 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+ import { CustomHeaders } from '@aws-amplify/data-schema-types';
4
+
3
5
  import { GraphQLAPI } from '../GraphQLAPI';
4
6
  import {
7
+ GraphQLOptionsV6,
8
+ GraphQLResponseV6,
9
+ V6Client,
5
10
  __amplify,
6
11
  __authMode,
7
12
  __authToken,
8
- V6Client,
9
- GraphQLOptionsV6,
10
- GraphQLResponseV6,
11
13
  } from '../types';
12
- import { CustomHeaders } from '@aws-amplify/data-schema-types';
13
14
 
14
15
  /**
15
16
  * Invokes graphql operations against a graphql service, providing correct input and
@@ -117,6 +118,7 @@ export function graphql<
117
118
  options,
118
119
  additionalHeaders,
119
120
  );
121
+
120
122
  return result as any;
121
123
  }
122
124
 
@@ -5,6 +5,8 @@ import {
5
5
  AmplifyServer,
6
6
  getAmplifyServerContext,
7
7
  } from '@aws-amplify/core/internals/adapter-core';
8
+ import { CustomHeaders } from '@aws-amplify/data-schema-types';
9
+
8
10
  import { generateClientWithAmplifyInstance } from '../internals/server';
9
11
  import {
10
12
  GenerateServerClientParams,
@@ -14,7 +16,6 @@ import {
14
16
  V6ClientSSRRequest,
15
17
  __amplify,
16
18
  } from '../types';
17
- import { CustomHeaders } from '@aws-amplify/data-schema-types';
18
19
 
19
20
  /**
20
21
  * Generates an GraphQL API client that works with Amplify server context.
@@ -55,6 +56,7 @@ export function generateClient<T extends Record<any, any> = never>({
55
56
  additionalHeaders?: CustomHeaders,
56
57
  ) => {
57
58
  const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;
59
+
58
60
  return prevGraphql.call(
59
61
  { [__amplify]: amplifyInstance },
60
62
  options,
@@ -63,5 +65,6 @@ export function generateClient<T extends Record<any, any> = never>({
63
65
  };
64
66
 
65
67
  client.graphql = wrappedGraphql as unknown as GraphQLMethodSSR;
68
+
66
69
  return client;
67
70
  }
@@ -1,6 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Observer } from 'rxjs';
4
+
4
5
  export interface SubscriptionObserver<T> {
5
6
  closed: boolean;
6
7
  next(value: T): void;
@@ -2,20 +2,24 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
4
4
  import {
5
- ModelTypes,
6
5
  CustomHeaders,
6
+ CustomMutations,
7
+ CustomQueries,
8
+ CustomSubscriptions,
7
9
  EnumTypes,
10
+ ModelSortDirection,
11
+ ModelTypes,
8
12
  } from '@aws-amplify/data-schema-types';
9
- import { Source, DocumentNode, GraphQLError } from 'graphql';
10
- export { OperationTypeNode } from 'graphql';
13
+ import { DocumentNode, GraphQLError, Source } from 'graphql';
11
14
  import { Observable } from 'rxjs';
12
-
13
15
  import {
14
- GraphQLAuthMode,
15
16
  DocumentType,
17
+ GraphQLAuthMode,
16
18
  } from '@aws-amplify/core/internals/utils';
17
19
  import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
18
20
 
21
+ export { OperationTypeNode } from 'graphql';
22
+
19
23
  export { CONTROL_MSG, ConnectionState } from './PubSub';
20
24
 
21
25
  export { SelectionSet } from '@aws-amplify/data-schema-types';
@@ -39,9 +43,7 @@ export interface GraphQLOptions {
39
43
  export interface GraphQLResult<T = object> {
40
44
  data: T;
41
45
  errors?: GraphQLError[];
42
- extensions?: {
43
- [key: string]: any;
44
- };
46
+ extensions?: Record<string, any>;
45
47
  }
46
48
 
47
49
  // Opaque type used for determining the graphql query type
@@ -73,21 +75,22 @@ export type GraphQLSubscription<T> = T & {
73
75
  *
74
76
  * This util simply makes related model properties optional recursively.
75
77
  */
76
- export type GraphQLReturnType<T> = T extends {}
77
- ? {
78
- [K in keyof T]?: GraphQLReturnType<T[K]>;
79
- }
80
- : T;
78
+ export type GraphQLReturnType<T> =
79
+ T extends Record<string, unknown>
80
+ ? {
81
+ [K in keyof T]?: GraphQLReturnType<T[K]>;
82
+ }
83
+ : T;
81
84
 
82
85
  /**
83
86
  * Describes a paged list result from AppSync, which can either
84
87
  * live at the top query or property (e.g., related model) level.
85
88
  */
86
- type PagedList<T, TYPENAME> = {
89
+ interface PagedList<T, TYPENAME> {
87
90
  __typename: TYPENAME;
88
91
  nextToken?: string | null | undefined;
89
- items: Array<T>;
90
- };
92
+ items: T[];
93
+ }
91
94
 
92
95
  /**
93
96
  * Recursively looks through a result type and removes nulls and
@@ -100,7 +103,7 @@ type PagedList<T, TYPENAME> = {
100
103
  type WithListsFixed<T> =
101
104
  T extends PagedList<infer IT, infer NAME>
102
105
  ? PagedList<Exclude<IT, null | undefined>, NAME>
103
- : T extends {}
106
+ : T extends Record<string, unknown>
104
107
  ? {
105
108
  [K in keyof T]: WithListsFixed<T[K]>;
106
109
  }
@@ -167,9 +170,9 @@ export type GraphqlSubscriptionResult<T> = Observable<
167
170
  * })
168
171
  * ```
169
172
  */
170
- export type GraphqlSubscriptionMessage<T> = {
173
+ export interface GraphqlSubscriptionMessage<T> {
171
174
  data: T;
172
- };
175
+ }
173
176
 
174
177
  export interface AWSAppSyncRealTimeProviderOptions {
175
178
  appSyncGraphqlEndpoint?: string;
@@ -178,15 +181,15 @@ export interface AWSAppSyncRealTimeProviderOptions {
178
181
  variables?: Record<string, unknown>;
179
182
  apiKey?: string;
180
183
  region?: string;
181
- libraryConfigHeaders?: () => {} | (() => Promise<{}>);
184
+ libraryConfigHeaders?(): () => Promise<Record<string, unknown> | Headers>;
182
185
  additionalHeaders?: CustomHeaders;
183
186
  }
184
187
 
185
- export type AWSAppSyncRealTimeProvider = {
188
+ export interface AWSAppSyncRealTimeProvider {
186
189
  subscribe(
187
190
  options?: AWSAppSyncRealTimeProviderOptions,
188
191
  ): Observable<Record<string, unknown>>;
189
- };
192
+ }
190
193
 
191
194
  export enum GraphQLAuthError {
192
195
  NO_API_KEY = 'No api-key configured',
@@ -257,18 +260,18 @@ export type GraphQLResponseV6<
257
260
  FALLBACK_TYPE = unknown,
258
261
  TYPED_GQL_STRING extends string = string,
259
262
  > =
260
- TYPED_GQL_STRING extends GeneratedQuery<infer IN, infer QUERY_OUT>
263
+ TYPED_GQL_STRING extends GeneratedQuery<infer _, infer QUERY_OUT>
261
264
  ? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>>
262
- : TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT>
265
+ : TYPED_GQL_STRING extends GeneratedMutation<infer _, infer MUTATION_OUT>
263
266
  ? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>>
264
- : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT>
267
+ : TYPED_GQL_STRING extends GeneratedSubscription<infer _, infer SUB_OUT>
265
268
  ? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>>
266
- : FALLBACK_TYPE extends GraphQLQuery<infer T>
269
+ : FALLBACK_TYPE extends GraphQLQuery<infer _>
267
270
  ? Promise<GraphQLResult<FALLBACK_TYPE>>
268
- : FALLBACK_TYPE extends GraphQLSubscription<infer T>
271
+ : FALLBACK_TYPE extends GraphQLSubscription<infer _>
269
272
  ? GraphqlSubscriptionResult<FALLBACK_TYPE>
270
273
  : FALLBACK_TYPE extends GraphQLOperationType<
271
- infer IN,
274
+ infer _,
272
275
  infer CUSTOM_OUT
273
276
  >
274
277
  ? CUSTOM_OUT
@@ -292,10 +295,13 @@ export type GraphQLResponseV6<
292
295
  * })
293
296
  * ```
294
297
  */
295
- export type GraphQLOperationType<IN extends {}, OUT extends {}> = {
298
+ export interface GraphQLOperationType<
299
+ IN extends Record<string, DocumentType>,
300
+ OUT extends Record<string, DocumentType>,
301
+ > {
296
302
  variables: IN;
297
303
  result: OUT;
298
- };
304
+ }
299
305
 
300
306
  /**
301
307
  * Nominal type for branding generated graphql query operation strings with
@@ -384,10 +390,13 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
384
390
  [__authToken]?: string;
385
391
  [__headers]?: CustomHeaders;
386
392
  graphql: GraphQLMethod;
387
- cancel: (promise: Promise<any>, message?: string) => boolean;
388
- isCancelError: (error: any) => boolean;
393
+ cancel(promise: Promise<any>, message?: string): boolean;
394
+ isCancelError(error: any): boolean;
389
395
  models: ModelTypes<T>;
390
396
  enums: EnumTypes<T>;
397
+ queries: CustomQueries<T>;
398
+ mutations: CustomMutations<T>;
399
+ subscriptions: CustomSubscriptions<T>;
391
400
  }>;
392
401
 
393
402
  export type V6ClientSSRRequest<T extends Record<any, any> = never> =
@@ -397,9 +406,12 @@ export type V6ClientSSRRequest<T extends Record<any, any> = never> =
397
406
  [__authToken]?: string;
398
407
  [__headers]?: CustomHeaders;
399
408
  graphql: GraphQLMethodSSR;
400
- cancel: (promise: Promise<any>, message?: string) => boolean;
401
- isCancelError: (error: any) => boolean;
409
+ cancel(promise: Promise<any>, message?: string): boolean;
410
+ isCancelError(error: any): boolean;
402
411
  models: ModelTypes<T, 'REQUEST'>;
412
+ enums: EnumTypes<T>;
413
+ queries: CustomQueries<T, 'REQUEST'>;
414
+ mutations: CustomMutations<T, 'REQUEST'>;
403
415
  }>;
404
416
 
405
417
  export type V6ClientSSRCookies<T extends Record<any, any> = never> =
@@ -409,9 +421,12 @@ export type V6ClientSSRCookies<T extends Record<any, any> = never> =
409
421
  [__authToken]?: string;
410
422
  [__headers]?: CustomHeaders;
411
423
  graphql: GraphQLMethod;
412
- cancel: (promise: Promise<any>, message?: string) => boolean;
413
- isCancelError: (error: any) => boolean;
424
+ cancel(promise: Promise<any>, message?: string): boolean;
425
+ isCancelError(error: any): boolean;
414
426
  models: ModelTypes<T, 'COOKIES'>;
427
+ enums: EnumTypes<T>;
428
+ queries: CustomQueries<T, 'COOKIES'>;
429
+ mutations: CustomMutations<T, 'COOKIES'>;
415
430
  }>;
416
431
 
417
432
  export type GraphQLMethod = <
@@ -436,30 +451,31 @@ export type GraphQLMethodSSR = <
436
451
  *
437
452
  * The knobs available for configuring `server/generateClient` internally.
438
453
  */
439
- export type ServerClientGenerationParams = {
454
+ export interface ServerClientGenerationParams {
440
455
  amplify:
441
456
  | null // null expected when used with `generateServerClient`
442
457
  // closure expected with `generateServerClientUsingCookies`
443
458
  | ((fn: (amplify: AmplifyClassV6) => Promise<any>) => Promise<any>);
444
459
  // global env-sourced config use for retrieving modelIntro
445
460
  config: ResourcesConfig;
446
- };
461
+ }
447
462
 
448
463
  export type QueryArgs = Record<string, unknown>;
449
464
 
450
- export type ListArgs = {
465
+ export interface ListArgs extends Record<string, unknown> {
451
466
  selectionSet?: string[];
452
- filter?: {};
467
+ filter?: Record<string, unknown>;
468
+ sortDirection?: ModelSortDirection;
453
469
  headers?: CustomHeaders;
454
- };
470
+ }
455
471
 
456
- export type AuthModeParams = {
472
+ export interface AuthModeParams extends Record<string, unknown> {
457
473
  authMode?: GraphQLAuthMode;
458
474
  authToken?: string;
459
- };
475
+ }
460
476
 
461
- export type GenerateServerClientParams = {
477
+ export interface GenerateServerClientParams {
462
478
  config: ResourcesConfig;
463
479
  authMode?: GraphQLAuthMode;
464
480
  authToken?: string;
465
- };
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
 
@@ -132,6 +135,7 @@ export class ConnectionStateMonitor {
132
135
  filter(current => {
133
136
  const toInclude = current !== previous;
134
137
  previous = current;
138
+
135
139
  return toInclude;
136
140
  }),
137
141
  );
@@ -196,6 +200,7 @@ export class ConnectionStateMonitor {
196
200
  // All remaining states directly correspond to the connection state
197
201
  if (connectionState === 'connecting') return ConnectionState.Connecting;
198
202
  if (connectionState === 'disconnected') return ConnectionState.Disconnected;
203
+
199
204
  return ConnectionState.Connected;
200
205
  }
201
206
  }
@@ -1,7 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Reachability } from '@aws-amplify/core/internals/utils';
4
- import { default as NetInfo } from '@react-native-community/netinfo';
4
+ import NetInfo from '@react-native-community/netinfo';
5
5
 
6
6
  export const ReachabilityMonitor = () =>
7
7
  new Reachability().networkMonitor(NetInfo);
@@ -1,4 +1,5 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Reachability } from '@aws-amplify/core/internals/utils';
4
+
4
5
  export const ReachabilityMonitor = () => new Reachability().networkMonitor();
@@ -1,6 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Observer } from 'rxjs';
4
+
4
5
  import { RECONNECT_DELAY, RECONNECT_INTERVAL } from '../Providers/constants';
5
6
 
6
7
  export enum ReconnectEvent {
@@ -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';