@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
@@ -0,0 +1,41 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { graphQLOperationsInfo } from '../APIClient';
4
+ import { listFactory } from '../operations/list';
5
+ import { getFactory } from '../operations/get';
6
+ export function generateModelsProperty(client, params) {
7
+ const models = {};
8
+ const config = params.config;
9
+ const useContext = client === null;
10
+ if (!config) {
11
+ // TODO: improve
12
+ throw new Error('generateModelsProperty cannot retrieve Amplify config');
13
+ }
14
+ const modelIntrospection = config.API?.GraphQL?.modelIntrospection;
15
+ if (!modelIntrospection) {
16
+ return {};
17
+ }
18
+ const SSR_UNSUPORTED_OPS = [
19
+ 'ONCREATE',
20
+ 'ONUPDATE',
21
+ 'ONDELETE',
22
+ 'OBSERVE_QUERY',
23
+ ];
24
+ for (const model of Object.values(modelIntrospection.models)) {
25
+ const { name } = model;
26
+ models[name] = {};
27
+ Object.entries(graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {
28
+ const operation = key;
29
+ // subscriptions are not supported in SSR
30
+ if (SSR_UNSUPORTED_OPS.includes(operation))
31
+ return;
32
+ if (operation === 'LIST') {
33
+ models[name][operationPrefix] = listFactory(client, modelIntrospection, model, useContext);
34
+ }
35
+ else {
36
+ models[name][operationPrefix] = getFactory(client, modelIntrospection, model, operation, useContext);
37
+ }
38
+ });
39
+ }
40
+ return models;
41
+ }
@@ -0,0 +1 @@
1
+ export { generateClient } from './generateClient';
@@ -0,0 +1,3 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export { generateClient } from './generateClient';
@@ -1,4 +1,5 @@
1
1
  import { AmplifyClassV6 } from '@aws-amplify/core';
2
+ import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
2
3
  /**
3
4
  * @private
4
5
  *
@@ -6,4 +7,11 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
6
7
  */
7
8
  export type ClientGenerationParams = {
8
9
  amplify: AmplifyClassV6;
10
+ } & CommonPublicClientOptions;
11
+ /**
12
+ * Common options that can be used on public `generateClient()` interfaces.
13
+ */
14
+ export type CommonPublicClientOptions = {
15
+ authMode?: GraphQLAuthMode;
16
+ authToken?: string;
9
17
  };
@@ -92,7 +92,7 @@ export function graphql(options, additionalHeaders) {
92
92
  * Neither of these can actually be validated at runtime. Hence, we don't perform
93
93
  * any validation or type-guarding here.
94
94
  */
95
- var result = GraphQLAPI.graphql(this[__amplify], options, additionalHeaders);
95
+ const result = GraphQLAPI.graphql(this[__amplify], options, additionalHeaders);
96
96
  return result;
97
97
  }
98
98
  /**