@aws-amplify/api-graphql 3.4.12-unstable.7762f1a.0 → 4.0.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 (116) hide show
  1. package/README.md +3 -0
  2. package/lib/GraphQLAPI.d.ts +17 -4
  3. package/lib/GraphQLAPI.js +33 -27
  4. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +64 -0
  5. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +690 -0
  6. package/lib/Providers/constants.d.ts +95 -0
  7. package/lib/Providers/constants.js +103 -0
  8. package/lib/index.d.ts +1 -3
  9. package/lib/index.js +6 -10
  10. package/lib/internals/InternalGraphQLAPI.d.ts +11 -34
  11. package/lib/internals/InternalGraphQLAPI.js +219 -345
  12. package/lib/internals/index.d.ts +1 -0
  13. package/lib/internals/index.js +4 -1
  14. package/lib/internals/v6.d.ts +101 -0
  15. package/lib/internals/v6.js +118 -0
  16. package/lib/tsconfig.tsbuildinfo +6813 -0
  17. package/lib/types/PubSub.d.ts +27 -0
  18. package/lib/types/PubSub.js +46 -0
  19. package/lib/types/index.d.ts +281 -5
  20. package/lib/types/index.js +4 -3
  21. package/lib/utils/ConnectionStateMonitor.d.ts +41 -0
  22. package/lib/utils/ConnectionStateMonitor.js +131 -0
  23. package/lib/utils/ReachabilityMonitor/index.d.ts +1 -0
  24. package/lib/utils/ReachabilityMonitor/index.js +6 -0
  25. package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -0
  26. package/lib/utils/ReachabilityMonitor/index.native.js +8 -0
  27. package/lib/utils/ReconnectionMonitor.d.ts +29 -0
  28. package/lib/utils/ReconnectionMonitor.js +68 -0
  29. package/lib/utils/errors/APIError.d.ts +7 -0
  30. package/lib/utils/errors/APIError.js +18 -0
  31. package/lib/utils/errors/assertValidationError.d.ts +5 -0
  32. package/lib/utils/errors/assertValidationError.js +16 -0
  33. package/lib/utils/errors/index.d.ts +3 -0
  34. package/lib/utils/errors/index.js +11 -0
  35. package/lib/utils/errors/validation.d.ts +7 -0
  36. package/lib/utils/errors/validation.js +25 -0
  37. package/lib/utils/index.d.ts +2 -0
  38. package/lib/utils/index.js +8 -0
  39. package/lib/utils/resolveConfig.d.ts +12 -0
  40. package/lib/utils/resolveConfig.js +22 -0
  41. package/lib/utils/resolveLibraryOptions.d.ts +11 -0
  42. package/lib/utils/resolveLibraryOptions.js +12 -0
  43. package/lib-esm/GraphQLAPI.d.ts +17 -4
  44. package/lib-esm/GraphQLAPI.js +33 -28
  45. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +64 -0
  46. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +687 -0
  47. package/lib-esm/Providers/constants.d.ts +95 -0
  48. package/lib-esm/Providers/constants.js +100 -0
  49. package/lib-esm/index.d.ts +1 -3
  50. package/lib-esm/index.js +1 -4
  51. package/lib-esm/internals/InternalGraphQLAPI.d.ts +11 -34
  52. package/lib-esm/internals/InternalGraphQLAPI.js +218 -345
  53. package/lib-esm/internals/index.d.ts +1 -0
  54. package/lib-esm/internals/index.js +1 -1
  55. package/lib-esm/internals/v6.d.ts +101 -0
  56. package/lib-esm/internals/v6.js +113 -0
  57. package/lib-esm/tsconfig.tsbuildinfo +6813 -0
  58. package/lib-esm/types/PubSub.d.ts +27 -0
  59. package/lib-esm/types/PubSub.js +44 -0
  60. package/lib-esm/types/index.d.ts +281 -5
  61. package/lib-esm/types/index.js +2 -3
  62. package/lib-esm/utils/ConnectionStateMonitor.d.ts +41 -0
  63. package/lib-esm/utils/ConnectionStateMonitor.js +128 -0
  64. package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -0
  65. package/lib-esm/utils/ReachabilityMonitor/index.js +4 -0
  66. package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -0
  67. package/lib-esm/utils/ReachabilityMonitor/index.native.js +5 -0
  68. package/lib-esm/utils/ReconnectionMonitor.d.ts +29 -0
  69. package/lib-esm/utils/ReconnectionMonitor.js +65 -0
  70. package/lib-esm/utils/errors/APIError.d.ts +7 -0
  71. package/lib-esm/utils/errors/APIError.js +15 -0
  72. package/lib-esm/utils/errors/assertValidationError.d.ts +5 -0
  73. package/lib-esm/utils/errors/assertValidationError.js +13 -0
  74. package/lib-esm/utils/errors/index.d.ts +3 -0
  75. package/lib-esm/utils/errors/index.js +5 -0
  76. package/lib-esm/utils/errors/validation.d.ts +7 -0
  77. package/lib-esm/utils/errors/validation.js +23 -0
  78. package/lib-esm/utils/index.d.ts +2 -0
  79. package/lib-esm/utils/index.js +4 -0
  80. package/lib-esm/utils/resolveConfig.d.ts +12 -0
  81. package/lib-esm/utils/resolveConfig.js +20 -0
  82. package/lib-esm/utils/resolveLibraryOptions.d.ts +11 -0
  83. package/lib-esm/utils/resolveLibraryOptions.js +10 -0
  84. package/package.json +122 -114
  85. package/src/GraphQLAPI.ts +26 -4
  86. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +998 -0
  87. package/src/Providers/constants.ts +110 -0
  88. package/src/index.ts +2 -3
  89. package/src/internals/InternalGraphQLAPI.ts +181 -218
  90. package/src/internals/index.ts +2 -0
  91. package/src/internals/v6.ts +138 -0
  92. package/src/types/PubSub.ts +56 -0
  93. package/src/types/index.ts +378 -8
  94. package/src/utils/ConnectionStateMonitor.ts +199 -0
  95. package/src/utils/ReachabilityMonitor/index.native.ts +7 -0
  96. package/src/utils/ReachabilityMonitor/index.ts +4 -0
  97. package/src/utils/ReconnectionMonitor.ts +76 -0
  98. package/src/utils/errors/APIError.ts +21 -0
  99. package/src/utils/errors/assertValidationError.ts +19 -0
  100. package/src/utils/errors/index.ts +6 -0
  101. package/src/utils/errors/validation.ts +26 -0
  102. package/src/utils/index.ts +5 -0
  103. package/src/utils/resolveConfig.ts +35 -0
  104. package/src/utils/resolveLibraryOptions.ts +13 -0
  105. package/lib/.tsbuildinfo +0 -3
  106. package/lib/GraphQLAPI.js.map +0 -1
  107. package/lib/index.js.map +0 -1
  108. package/lib/internals/InternalGraphQLAPI.js.map +0 -1
  109. package/lib/internals/index.js.map +0 -1
  110. package/lib/types/index.js.map +0 -1
  111. package/lib-esm/.tsbuildinfo +0 -3
  112. package/lib-esm/GraphQLAPI.js.map +0 -1
  113. package/lib-esm/index.js.map +0 -1
  114. package/lib-esm/internals/InternalGraphQLAPI.js.map +0 -1
  115. package/lib-esm/internals/index.js.map +0 -1
  116. package/lib-esm/types/index.js.map +0 -1
@@ -0,0 +1,101 @@
1
+ import { V6Client, GraphQLOptionsV6, GraphQLResponseV6 } from '../types';
2
+ /**
3
+ * Invokes graphql operations against a graphql service, providing correct input and
4
+ * output types if Amplify-generated graphql from a recent version of the CLI/codegen
5
+ * are used *or* correct typing is provided via the type argument.
6
+ *
7
+ * Amplify-generated "branded" graphql queries will look similar to this:
8
+ *
9
+ * ```ts
10
+ * //
11
+ * // |-- branding
12
+ * // v
13
+ * export const getModel = `...` as GeneratedQuery<
14
+ * GetModelQueryVariables,
15
+ * GetModelQuery
16
+ * >;
17
+ * ```
18
+ *
19
+ * If this branding is not in your generated graphql, update to a newer version of
20
+ * CLI/codegen and regenerate your graphql using `amplify codegen`.
21
+ *
22
+ * ## Using Amplify-generated graphql
23
+ *
24
+ * ```ts
25
+ * import * as queries from './graphql/queries';
26
+ *
27
+ * //
28
+ * // |-- correctly typed graphql response containing a Widget
29
+ * // v
30
+ * const queryResult = await graphql({
31
+ * query: queries.getWidget,
32
+ * variables: {
33
+ * id: "abc", // <-- type hinted/enforced
34
+ * },
35
+ * });
36
+ *
37
+ * //
38
+ * // |-- a correctly typed Widget
39
+ * // v
40
+ * const fetchedWidget = queryResult.data?.getWidget!;
41
+ * ```
42
+ *
43
+ * ## Custom input + result types
44
+ *
45
+ * To provide input types (`variables`) and result types:
46
+ *
47
+ * ```ts
48
+ * type GetById_NameOnly = {
49
+ * variables: {
50
+ * id: string
51
+ * },
52
+ * result: Promise<{
53
+ * data: { getWidget: { name: string } }
54
+ * }>
55
+ * }
56
+ *
57
+ * //
58
+ * // |-- type is GetById_NameOnly["result"]
59
+ * // v
60
+ * const result = graphql<GetById_NameOnly>({
61
+ * query: "...",
62
+ * variables: { id: "abc" } // <-- type of GetById_NameOnly["variables"]
63
+ * });
64
+ * ```
65
+ *
66
+ * ## Custom result type only
67
+ *
68
+ * To specify result types only, use a type that is *not* in the `{variables, result}` shape:
69
+ *
70
+ * ```ts
71
+ * type MyResultType = Promise<{
72
+ * data: {
73
+ * getWidget: { name: string }
74
+ * }
75
+ * }>
76
+ *
77
+ * //
78
+ * // |-- type is MyResultType
79
+ * // v
80
+ * const result = graphql<MyResultType>({query: "..."});
81
+ * ```
82
+ *
83
+ * @param options
84
+ * @param additionalHeaders
85
+ */
86
+ export declare function graphql<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(this: V6Client, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
87
+ [key: string]: string;
88
+ }): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
89
+ /**
90
+ * Cancels an inflight request. Only applicable for graphql queries and mutations
91
+ * @param {any} request - request to cancel
92
+ * @returns - A boolean indicating if the request was cancelled
93
+ */
94
+ export declare function cancel(this: V6Client, promise: Promise<any>, message?: string): boolean;
95
+ /**
96
+ * Checks to see if an error thrown is from an api request cancellation
97
+ * @param {any} error - Any error
98
+ * @returns - A boolean indicating if the error was from an api request cancellation
99
+ */
100
+ export declare function isCancelError(this: V6Client, error: any): boolean;
101
+ export { GraphQLOptionsV6, GraphQLResponseV6 };
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ const GraphQLAPI_1 = require("../GraphQLAPI");
6
+ const types_1 = require("../types");
7
+ /**
8
+ * Invokes graphql operations against a graphql service, providing correct input and
9
+ * output types if Amplify-generated graphql from a recent version of the CLI/codegen
10
+ * are used *or* correct typing is provided via the type argument.
11
+ *
12
+ * Amplify-generated "branded" graphql queries will look similar to this:
13
+ *
14
+ * ```ts
15
+ * //
16
+ * // |-- branding
17
+ * // v
18
+ * export const getModel = `...` as GeneratedQuery<
19
+ * GetModelQueryVariables,
20
+ * GetModelQuery
21
+ * >;
22
+ * ```
23
+ *
24
+ * If this branding is not in your generated graphql, update to a newer version of
25
+ * CLI/codegen and regenerate your graphql using `amplify codegen`.
26
+ *
27
+ * ## Using Amplify-generated graphql
28
+ *
29
+ * ```ts
30
+ * import * as queries from './graphql/queries';
31
+ *
32
+ * //
33
+ * // |-- correctly typed graphql response containing a Widget
34
+ * // v
35
+ * const queryResult = await graphql({
36
+ * query: queries.getWidget,
37
+ * variables: {
38
+ * id: "abc", // <-- type hinted/enforced
39
+ * },
40
+ * });
41
+ *
42
+ * //
43
+ * // |-- a correctly typed Widget
44
+ * // v
45
+ * const fetchedWidget = queryResult.data?.getWidget!;
46
+ * ```
47
+ *
48
+ * ## Custom input + result types
49
+ *
50
+ * To provide input types (`variables`) and result types:
51
+ *
52
+ * ```ts
53
+ * type GetById_NameOnly = {
54
+ * variables: {
55
+ * id: string
56
+ * },
57
+ * result: Promise<{
58
+ * data: { getWidget: { name: string } }
59
+ * }>
60
+ * }
61
+ *
62
+ * //
63
+ * // |-- type is GetById_NameOnly["result"]
64
+ * // v
65
+ * const result = graphql<GetById_NameOnly>({
66
+ * query: "...",
67
+ * variables: { id: "abc" } // <-- type of GetById_NameOnly["variables"]
68
+ * });
69
+ * ```
70
+ *
71
+ * ## Custom result type only
72
+ *
73
+ * To specify result types only, use a type that is *not* in the `{variables, result}` shape:
74
+ *
75
+ * ```ts
76
+ * type MyResultType = Promise<{
77
+ * data: {
78
+ * getWidget: { name: string }
79
+ * }
80
+ * }>
81
+ *
82
+ * //
83
+ * // |-- type is MyResultType
84
+ * // v
85
+ * const result = graphql<MyResultType>({query: "..."});
86
+ * ```
87
+ *
88
+ * @param options
89
+ * @param additionalHeaders
90
+ */
91
+ function graphql(options, additionalHeaders) {
92
+ /**
93
+ * The correctness of these typings depends on correct string branding or overrides.
94
+ * Neither of these can actually be validated at runtime. Hence, we don't perform
95
+ * any validation or type-guarding here.
96
+ */
97
+ const result = GraphQLAPI_1.GraphQLAPI.graphql(this[types_1.__amplify], options, additionalHeaders);
98
+ return result;
99
+ }
100
+ exports.graphql = graphql;
101
+ /**
102
+ * Cancels an inflight request. Only applicable for graphql queries and mutations
103
+ * @param {any} request - request to cancel
104
+ * @returns - A boolean indicating if the request was cancelled
105
+ */
106
+ function cancel(promise, message) {
107
+ return GraphQLAPI_1.GraphQLAPI.cancel(promise, message);
108
+ }
109
+ exports.cancel = cancel;
110
+ /**
111
+ * Checks to see if an error thrown is from an api request cancellation
112
+ * @param {any} error - Any error
113
+ * @returns - A boolean indicating if the error was from an api request cancellation
114
+ */
115
+ function isCancelError(error) {
116
+ return GraphQLAPI_1.GraphQLAPI.isCancelError(error);
117
+ }
118
+ exports.isCancelError = isCancelError;