@aws-amplify/api-graphql 3.4.4-api-v6.13 → 3.4.4-api-v6.24

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.
@@ -1 +1,2 @@
1
1
  export { InternalGraphQLAPI, InternalGraphQLAPIClass, } from './InternalGraphQLAPI';
2
+ export { graphql } from './v6';
@@ -5,4 +5,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  var InternalGraphQLAPI_1 = require("./InternalGraphQLAPI");
6
6
  exports.InternalGraphQLAPI = InternalGraphQLAPI_1.InternalGraphQLAPI;
7
7
  exports.InternalGraphQLAPIClass = InternalGraphQLAPI_1.InternalGraphQLAPIClass;
8
+ var v6_1 = require("./v6");
9
+ exports.graphql = v6_1.graphql;
8
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":";;AAAA,qEAAqE;AACrE,sCAAsC;AACtC,2DAG8B;AAF7B,kDAAA,kBAAkB,CAAA;AAClB,uDAAA,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":";;AAAA,qEAAqE;AACrE,sCAAsC;AACtC,2DAG8B;AAF7B,kDAAA,kBAAkB,CAAA;AAClB,uDAAA,uBAAuB,CAAA;AAGxB,2BAA+B;AAAtB,uBAAA,OAAO,CAAA"}
@@ -0,0 +1,89 @@
1
+ import { 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>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
87
+ [key: string]: string;
88
+ }): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
89
+ export { GraphQLOptionsV6, GraphQLResponseV6 };
@@ -0,0 +1,100 @@
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
+ var GraphQLAPI_1 = require("../GraphQLAPI");
6
+ /**
7
+ * Invokes graphql operations against a graphql service, providing correct input and
8
+ * output types if Amplify-generated graphql from a recent version of the CLI/codegen
9
+ * are used *or* correct typing is provided via the type argument.
10
+ *
11
+ * Amplify-generated "branded" graphql queries will look similar to this:
12
+ *
13
+ * ```ts
14
+ * //
15
+ * // |-- branding
16
+ * // v
17
+ * export const getModel = `...` as GeneratedQuery<
18
+ * GetModelQueryVariables,
19
+ * GetModelQuery
20
+ * >;
21
+ * ```
22
+ *
23
+ * If this branding is not in your generated graphql, update to a newer version of
24
+ * CLI/codegen and regenerate your graphql using `amplify codegen`.
25
+ *
26
+ * ## Using Amplify-generated graphql
27
+ *
28
+ * ```ts
29
+ * import * as queries from './graphql/queries';
30
+ *
31
+ * //
32
+ * // |-- correctly typed graphql response containing a Widget
33
+ * // v
34
+ * const queryResult = await graphql({
35
+ * query: queries.getWidget,
36
+ * variables: {
37
+ * id: "abc", // <-- type hinted/enforced
38
+ * },
39
+ * });
40
+ *
41
+ * //
42
+ * // |-- a correctly typed Widget
43
+ * // v
44
+ * const fetchedWidget = queryResult.data?.getWidget!;
45
+ * ```
46
+ *
47
+ * ## Custom input + result types
48
+ *
49
+ * To provide input types (`variables`) and result types:
50
+ *
51
+ * ```ts
52
+ * type GetById_NameOnly = {
53
+ * variables: {
54
+ * id: string
55
+ * },
56
+ * result: Promise<{
57
+ * data: { getWidget: { name: string } }
58
+ * }>
59
+ * }
60
+ *
61
+ * //
62
+ * // |-- type is GetById_NameOnly["result"]
63
+ * // v
64
+ * const result = graphql<GetById_NameOnly>({
65
+ * query: "...",
66
+ * variables: { id: "abc" } // <-- type of GetById_NameOnly["variables"]
67
+ * });
68
+ * ```
69
+ *
70
+ * ## Custom result type only
71
+ *
72
+ * To specify result types only, use a type that is *not* in the `{variables, result}` shape:
73
+ *
74
+ * ```ts
75
+ * type MyResultType = Promise<{
76
+ * data: {
77
+ * getWidget: { name: string }
78
+ * }
79
+ * }>
80
+ *
81
+ * //
82
+ * // |-- type is MyResultType
83
+ * // v
84
+ * const result = graphql<MyResultType>({query: "..."});
85
+ * ```
86
+ *
87
+ * @param options
88
+ * @param additionalHeaders
89
+ */
90
+ function graphql(options, additionalHeaders) {
91
+ /**
92
+ * The correctness of these typings depends on correct string branding or overrides.
93
+ * Neither of these can actually be validated at runtime. Hence, we don't perform
94
+ * any validation or type-guarding here.
95
+ */
96
+ var result = GraphQLAPI_1.GraphQLAPI.graphql(options, additionalHeaders);
97
+ return result;
98
+ }
99
+ exports.graphql = graphql;
100
+ //# sourceMappingURL=v6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v6.js","sourceRoot":"","sources":["../../src/internals/v6.ts"],"names":[],"mappings":";;AAAA,qEAAqE;AACrE,sCAAsC;AACtC,4CAA2C;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFG;AACH,SAAgB,OAAO,CAItB,OAA2D,EAC3D,iBAA6C;IAE7C;;;;OAIG;IACH,IAAM,MAAM,GAAG,uBAAU,CAAC,OAAO,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAC9D,OAAO,MAAa,CAAC;AACtB,CAAC;AAdD,0BAcC"}
@@ -2,6 +2,10 @@ import { Source, DocumentNode, GraphQLError } from 'graphql';
2
2
  export { OperationTypeNode } from 'graphql';
3
3
  import { GRAPHQL_AUTH_MODE } from '@aws-amplify/auth';
4
4
  export { GRAPHQL_AUTH_MODE };
5
+ import { Observable } from 'zen-observable-ts';
6
+ /**
7
+ * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
8
+ */
5
9
  export interface GraphQLOptions {
6
10
  query: string | DocumentNode;
7
11
  variables?: object;
@@ -19,6 +23,49 @@ export interface GraphQLResult<T = object> {
19
23
  [key: string]: any;
20
24
  };
21
25
  }
26
+ /**
27
+ * The return value from a `graphql({query})` call when `query` is a subscription.
28
+ *
29
+ * ```ts
30
+ * // |-- You are here
31
+ * // v
32
+ * const subResult: GraphqlSubscriptionResult<T> = client.graphql({
33
+ * query: onCreateWidget
34
+ * });
35
+ *
36
+ * const sub = subResult.subscribe({
37
+ * //
38
+ * // |-- You are here
39
+ * // v
40
+ * next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
41
+ * handle(message.value); // <-- type OnCreateWidgetSubscription
42
+ * }
43
+ * })
44
+ * ```
45
+ */
46
+ export declare type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptionMessage<T>>;
47
+ /**
48
+ * The shape of messages passed to `next()` from a graphql subscription. E.g.,
49
+ *
50
+ * ```ts
51
+ * const sub = client.graphql({
52
+ * query: onCreateWidget,
53
+ * }).subscribe({
54
+ * //
55
+ * // |-- You are here
56
+ * // v
57
+ * next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
58
+ * handle(message.value); // <-- type OnCreateWidgetSubscription
59
+ * }
60
+ * })
61
+ * ```
62
+ */
63
+ export declare type GraphqlSubscriptionMessage<T> = {
64
+ provider: any;
65
+ value: {
66
+ data: T;
67
+ };
68
+ };
22
69
  export declare enum GraphQLAuthError {
23
70
  NO_API_KEY = "No api-key configured",
24
71
  NO_CURRENT_USER = "No current user",
@@ -31,3 +78,117 @@ export declare enum GraphQLAuthError {
31
78
  * @see: https://graphql.org/graphql-js/language/#parse
32
79
  */
33
80
  export declare type GraphQLOperation = Source | string;
81
+ /**
82
+ * API V6 `graphql({options})` type that can leverage branded graphql `query`
83
+ * objects and fallback types.
84
+ */
85
+ export interface GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> {
86
+ query: TYPED_GQL_STRING | DocumentNode;
87
+ variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
88
+ authMode?: keyof typeof GRAPHQL_AUTH_MODE;
89
+ authToken?: string;
90
+ /**
91
+ * @deprecated This property should not be used
92
+ */
93
+ userAgentSuffix?: string;
94
+ }
95
+ /**
96
+ * Result type for `graphql()` operations that don't include any specific
97
+ * type information. The result could be either a `Promise` or `Subscription`.
98
+ *
99
+ * Invoking code should either cast the result or use `?` and `!` operators to
100
+ * navigate the result objects.
101
+ */
102
+ export declare type UnknownGraphQLResponse = Promise<GraphQLResult<any>> | GraphqlSubscriptionResult<any>;
103
+ /**
104
+ * The expected type for `variables` in a V6 `graphql()` operation with
105
+ * respect to the given `FALLBACK_TYPES` and `TYPED_GQL_STRING`.
106
+ */
107
+ export declare type GraphQLVariablesV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> = TYPED_GQL_STRING extends GeneratedQuery<infer IN, any> ? IN : TYPED_GQL_STRING extends GeneratedMutation<infer IN, any> ? IN : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, any> ? IN : FALLBACK_TYPES extends GraphQLOperationType<infer IN, any> ? IN : any;
108
+ /**
109
+ * The expected return type with respect to the given `FALLBACK_TYPE`
110
+ * and `TYPED_GQL_STRING`.
111
+ */
112
+ export declare type GraphQLResponseV6<FALLBACK_TYPE = UnknownGraphQLResponse, TYPED_GQL_STRING extends string = string> = TYPED_GQL_STRING extends GeneratedQuery<any, infer QUERY_OUT> ? Promise<GraphQLResult<QUERY_OUT>> : TYPED_GQL_STRING extends GeneratedMutation<any, infer MUTATION_OUT> ? Promise<GraphQLResult<MUTATION_OUT>> : TYPED_GQL_STRING extends GeneratedSubscription<any, infer SUB_OUT> ? GraphqlSubscriptionResult<SUB_OUT> : FALLBACK_TYPE extends GraphQLOperationType<any, infer CUSTOM_OUT> ? CUSTOM_OUT : FALLBACK_TYPE extends {} ? FALLBACK_TYPE : UnknownGraphQLResponse;
113
+ /**
114
+ * The shape customers can use to provide `T` to `graphql<T>()` to specify both
115
+ * `IN` and `OUT` types (the type of `variables` and the return type, respectively).
116
+ *
117
+ * I.E.,
118
+ *
119
+ * ```ts
120
+ * type MyVariablesType = { ... };
121
+ * type MyResultType = { ... };
122
+ * type MyOperationType = { variables: MyVariablesType, result: MyResultType };
123
+ *
124
+ * const result: MyResultType = graphql<MyOperationType>("graphql string", {
125
+ * variables: {
126
+ * // MyVariablesType
127
+ * }
128
+ * })
129
+ * ```
130
+ */
131
+ export declare type GraphQLOperationType<IN extends {}, OUT extends {}> = {
132
+ variables: IN;
133
+ result: OUT;
134
+ };
135
+ /**
136
+ * Nominal type for branding generated graphql query operation strings with
137
+ * input and output types.
138
+ *
139
+ * E.g.,
140
+ *
141
+ * ```ts
142
+ * export const getWidget = `...` as GeneratedQuery<
143
+ * GetWidgetQueryVariables,
144
+ * GetWidgetQuery
145
+ * >;
146
+ * ```
147
+ *
148
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
149
+ * assign types to the `variables` and result objects.
150
+ */
151
+ export declare type GeneratedQuery<InputType, OutputType> = string & {
152
+ __generatedQueryInput: InputType;
153
+ __generatedQueryOutput: OutputType;
154
+ };
155
+ /**
156
+ * Nominal type for branding generated graphql mutation operation strings with
157
+ * input and output types.
158
+ *
159
+ * E.g.,
160
+ *
161
+ * ```ts
162
+ * export const createWidget = `...` as GeneratedQuery<
163
+ * CreateWidgetMutationVariables,
164
+ * CreateWidgetMutation
165
+ * >;
166
+ * ```
167
+ *
168
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
169
+ * assign types to the `variables` and result objects.
170
+ */
171
+ export declare type GeneratedMutation<InputType, OutputType> = string & {
172
+ __generatedMutationInput: InputType;
173
+ __generatedMutationOutput: OutputType;
174
+ };
175
+ /**
176
+ * Nominal type for branding generated graphql mutation operation strings with
177
+ * input and output types.
178
+ *
179
+ * E.g.,
180
+ *
181
+ * ```ts
182
+ * export const createWidget = `...` as GeneratedMutation<
183
+ * CreateWidgetMutationVariables,
184
+ * CreateWidgetMutation
185
+ * >;
186
+ * ```
187
+ *
188
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
189
+ * assign types to the `variables` and result objects.
190
+ */
191
+ export declare type GeneratedSubscription<InputType, OutputType> = string & {
192
+ __generatedSubscriptionInput: InputType;
193
+ __generatedSubscriptionOutput: OutputType;
194
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;AAIA,0CAAsD;AAC7C,4BADA,wBAAiB,CACA;AAsB1B,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC3B,wDAAoC,CAAA;IACpC,uDAAmC,CAAA;IACnC,qDAAiC,CAAA;IACjC,yDAAqC,CAAA;IACrC,6DAAyC,CAAA;AAC1C,CAAC,EANW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAM3B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;AAIA,0CAAsD;AAC7C,4BADA,wBAAiB,CACA;AAsE1B,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC3B,wDAAoC,CAAA;IACpC,uDAAmC,CAAA;IACnC,qDAAiC,CAAA;IACjC,yDAAqC,CAAA;IACrC,6DAAyC,CAAA;AAC1C,CAAC,EANW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAM3B"}
@@ -1 +1,2 @@
1
1
  export { InternalGraphQLAPI, InternalGraphQLAPIClass, } from './InternalGraphQLAPI';
2
+ export { graphql } from './v6';
@@ -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
  export { InternalGraphQLAPI, InternalGraphQLAPIClass, } from './InternalGraphQLAPI';
4
+ export { graphql } from './v6';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EACN,kBAAkB,EAClB,uBAAuB,GACvB,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EACN,kBAAkB,EAClB,uBAAuB,GACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC"}
@@ -0,0 +1,89 @@
1
+ import { 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>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
87
+ [key: string]: string;
88
+ }): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
89
+ export { GraphQLOptionsV6, GraphQLResponseV6 };
@@ -0,0 +1,97 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { GraphQLAPI } from '../GraphQLAPI';
4
+ /**
5
+ * Invokes graphql operations against a graphql service, providing correct input and
6
+ * output types if Amplify-generated graphql from a recent version of the CLI/codegen
7
+ * are used *or* correct typing is provided via the type argument.
8
+ *
9
+ * Amplify-generated "branded" graphql queries will look similar to this:
10
+ *
11
+ * ```ts
12
+ * //
13
+ * // |-- branding
14
+ * // v
15
+ * export const getModel = `...` as GeneratedQuery<
16
+ * GetModelQueryVariables,
17
+ * GetModelQuery
18
+ * >;
19
+ * ```
20
+ *
21
+ * If this branding is not in your generated graphql, update to a newer version of
22
+ * CLI/codegen and regenerate your graphql using `amplify codegen`.
23
+ *
24
+ * ## Using Amplify-generated graphql
25
+ *
26
+ * ```ts
27
+ * import * as queries from './graphql/queries';
28
+ *
29
+ * //
30
+ * // |-- correctly typed graphql response containing a Widget
31
+ * // v
32
+ * const queryResult = await graphql({
33
+ * query: queries.getWidget,
34
+ * variables: {
35
+ * id: "abc", // <-- type hinted/enforced
36
+ * },
37
+ * });
38
+ *
39
+ * //
40
+ * // |-- a correctly typed Widget
41
+ * // v
42
+ * const fetchedWidget = queryResult.data?.getWidget!;
43
+ * ```
44
+ *
45
+ * ## Custom input + result types
46
+ *
47
+ * To provide input types (`variables`) and result types:
48
+ *
49
+ * ```ts
50
+ * type GetById_NameOnly = {
51
+ * variables: {
52
+ * id: string
53
+ * },
54
+ * result: Promise<{
55
+ * data: { getWidget: { name: string } }
56
+ * }>
57
+ * }
58
+ *
59
+ * //
60
+ * // |-- type is GetById_NameOnly["result"]
61
+ * // v
62
+ * const result = graphql<GetById_NameOnly>({
63
+ * query: "...",
64
+ * variables: { id: "abc" } // <-- type of GetById_NameOnly["variables"]
65
+ * });
66
+ * ```
67
+ *
68
+ * ## Custom result type only
69
+ *
70
+ * To specify result types only, use a type that is *not* in the `{variables, result}` shape:
71
+ *
72
+ * ```ts
73
+ * type MyResultType = Promise<{
74
+ * data: {
75
+ * getWidget: { name: string }
76
+ * }
77
+ * }>
78
+ *
79
+ * //
80
+ * // |-- type is MyResultType
81
+ * // v
82
+ * const result = graphql<MyResultType>({query: "..."});
83
+ * ```
84
+ *
85
+ * @param options
86
+ * @param additionalHeaders
87
+ */
88
+ export function graphql(options, additionalHeaders) {
89
+ /**
90
+ * The correctness of these typings depends on correct string branding or overrides.
91
+ * Neither of these can actually be validated at runtime. Hence, we don't perform
92
+ * any validation or type-guarding here.
93
+ */
94
+ var result = GraphQLAPI.graphql(options, additionalHeaders);
95
+ return result;
96
+ }
97
+ //# sourceMappingURL=v6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v6.js","sourceRoot":"","sources":["../../src/internals/v6.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFG;AACH,MAAM,UAAU,OAAO,CAItB,OAA2D,EAC3D,iBAA6C;IAE7C;;;;OAIG;IACH,IAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAC9D,OAAO,MAAa,CAAC;AACtB,CAAC"}
@@ -2,6 +2,10 @@ import { Source, DocumentNode, GraphQLError } from 'graphql';
2
2
  export { OperationTypeNode } from 'graphql';
3
3
  import { GRAPHQL_AUTH_MODE } from '@aws-amplify/auth';
4
4
  export { GRAPHQL_AUTH_MODE };
5
+ import { Observable } from 'zen-observable-ts';
6
+ /**
7
+ * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
8
+ */
5
9
  export interface GraphQLOptions {
6
10
  query: string | DocumentNode;
7
11
  variables?: object;
@@ -19,6 +23,49 @@ export interface GraphQLResult<T = object> {
19
23
  [key: string]: any;
20
24
  };
21
25
  }
26
+ /**
27
+ * The return value from a `graphql({query})` call when `query` is a subscription.
28
+ *
29
+ * ```ts
30
+ * // |-- You are here
31
+ * // v
32
+ * const subResult: GraphqlSubscriptionResult<T> = client.graphql({
33
+ * query: onCreateWidget
34
+ * });
35
+ *
36
+ * const sub = subResult.subscribe({
37
+ * //
38
+ * // |-- You are here
39
+ * // v
40
+ * next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
41
+ * handle(message.value); // <-- type OnCreateWidgetSubscription
42
+ * }
43
+ * })
44
+ * ```
45
+ */
46
+ export declare type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptionMessage<T>>;
47
+ /**
48
+ * The shape of messages passed to `next()` from a graphql subscription. E.g.,
49
+ *
50
+ * ```ts
51
+ * const sub = client.graphql({
52
+ * query: onCreateWidget,
53
+ * }).subscribe({
54
+ * //
55
+ * // |-- You are here
56
+ * // v
57
+ * next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
58
+ * handle(message.value); // <-- type OnCreateWidgetSubscription
59
+ * }
60
+ * })
61
+ * ```
62
+ */
63
+ export declare type GraphqlSubscriptionMessage<T> = {
64
+ provider: any;
65
+ value: {
66
+ data: T;
67
+ };
68
+ };
22
69
  export declare enum GraphQLAuthError {
23
70
  NO_API_KEY = "No api-key configured",
24
71
  NO_CURRENT_USER = "No current user",
@@ -31,3 +78,117 @@ export declare enum GraphQLAuthError {
31
78
  * @see: https://graphql.org/graphql-js/language/#parse
32
79
  */
33
80
  export declare type GraphQLOperation = Source | string;
81
+ /**
82
+ * API V6 `graphql({options})` type that can leverage branded graphql `query`
83
+ * objects and fallback types.
84
+ */
85
+ export interface GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> {
86
+ query: TYPED_GQL_STRING | DocumentNode;
87
+ variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
88
+ authMode?: keyof typeof GRAPHQL_AUTH_MODE;
89
+ authToken?: string;
90
+ /**
91
+ * @deprecated This property should not be used
92
+ */
93
+ userAgentSuffix?: string;
94
+ }
95
+ /**
96
+ * Result type for `graphql()` operations that don't include any specific
97
+ * type information. The result could be either a `Promise` or `Subscription`.
98
+ *
99
+ * Invoking code should either cast the result or use `?` and `!` operators to
100
+ * navigate the result objects.
101
+ */
102
+ export declare type UnknownGraphQLResponse = Promise<GraphQLResult<any>> | GraphqlSubscriptionResult<any>;
103
+ /**
104
+ * The expected type for `variables` in a V6 `graphql()` operation with
105
+ * respect to the given `FALLBACK_TYPES` and `TYPED_GQL_STRING`.
106
+ */
107
+ export declare type GraphQLVariablesV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> = TYPED_GQL_STRING extends GeneratedQuery<infer IN, any> ? IN : TYPED_GQL_STRING extends GeneratedMutation<infer IN, any> ? IN : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, any> ? IN : FALLBACK_TYPES extends GraphQLOperationType<infer IN, any> ? IN : any;
108
+ /**
109
+ * The expected return type with respect to the given `FALLBACK_TYPE`
110
+ * and `TYPED_GQL_STRING`.
111
+ */
112
+ export declare type GraphQLResponseV6<FALLBACK_TYPE = UnknownGraphQLResponse, TYPED_GQL_STRING extends string = string> = TYPED_GQL_STRING extends GeneratedQuery<any, infer QUERY_OUT> ? Promise<GraphQLResult<QUERY_OUT>> : TYPED_GQL_STRING extends GeneratedMutation<any, infer MUTATION_OUT> ? Promise<GraphQLResult<MUTATION_OUT>> : TYPED_GQL_STRING extends GeneratedSubscription<any, infer SUB_OUT> ? GraphqlSubscriptionResult<SUB_OUT> : FALLBACK_TYPE extends GraphQLOperationType<any, infer CUSTOM_OUT> ? CUSTOM_OUT : FALLBACK_TYPE extends {} ? FALLBACK_TYPE : UnknownGraphQLResponse;
113
+ /**
114
+ * The shape customers can use to provide `T` to `graphql<T>()` to specify both
115
+ * `IN` and `OUT` types (the type of `variables` and the return type, respectively).
116
+ *
117
+ * I.E.,
118
+ *
119
+ * ```ts
120
+ * type MyVariablesType = { ... };
121
+ * type MyResultType = { ... };
122
+ * type MyOperationType = { variables: MyVariablesType, result: MyResultType };
123
+ *
124
+ * const result: MyResultType = graphql<MyOperationType>("graphql string", {
125
+ * variables: {
126
+ * // MyVariablesType
127
+ * }
128
+ * })
129
+ * ```
130
+ */
131
+ export declare type GraphQLOperationType<IN extends {}, OUT extends {}> = {
132
+ variables: IN;
133
+ result: OUT;
134
+ };
135
+ /**
136
+ * Nominal type for branding generated graphql query operation strings with
137
+ * input and output types.
138
+ *
139
+ * E.g.,
140
+ *
141
+ * ```ts
142
+ * export const getWidget = `...` as GeneratedQuery<
143
+ * GetWidgetQueryVariables,
144
+ * GetWidgetQuery
145
+ * >;
146
+ * ```
147
+ *
148
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
149
+ * assign types to the `variables` and result objects.
150
+ */
151
+ export declare type GeneratedQuery<InputType, OutputType> = string & {
152
+ __generatedQueryInput: InputType;
153
+ __generatedQueryOutput: OutputType;
154
+ };
155
+ /**
156
+ * Nominal type for branding generated graphql mutation operation strings with
157
+ * input and output types.
158
+ *
159
+ * E.g.,
160
+ *
161
+ * ```ts
162
+ * export const createWidget = `...` as GeneratedQuery<
163
+ * CreateWidgetMutationVariables,
164
+ * CreateWidgetMutation
165
+ * >;
166
+ * ```
167
+ *
168
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
169
+ * assign types to the `variables` and result objects.
170
+ */
171
+ export declare type GeneratedMutation<InputType, OutputType> = string & {
172
+ __generatedMutationInput: InputType;
173
+ __generatedMutationOutput: OutputType;
174
+ };
175
+ /**
176
+ * Nominal type for branding generated graphql mutation operation strings with
177
+ * input and output types.
178
+ *
179
+ * E.g.,
180
+ *
181
+ * ```ts
182
+ * export const createWidget = `...` as GeneratedMutation<
183
+ * CreateWidgetMutationVariables,
184
+ * CreateWidgetMutation
185
+ * >;
186
+ * ```
187
+ *
188
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
189
+ * assign types to the `variables` and result objects.
190
+ */
191
+ export declare type GeneratedSubscription<InputType, OutputType> = string & {
192
+ __generatedSubscriptionInput: InputType;
193
+ __generatedSubscriptionOutput: OutputType;
194
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAsB7B,MAAM,CAAN,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC3B,wDAAoC,CAAA;IACpC,uDAAmC,CAAA;IACnC,qDAAiC,CAAA;IACjC,yDAAqC,CAAA;IACrC,6DAAyC,CAAA;AAC1C,CAAC,EANW,gBAAgB,KAAhB,gBAAgB,QAM3B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAsE7B,MAAM,CAAN,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC3B,wDAAoC,CAAA;IACpC,uDAAmC,CAAA;IACnC,qDAAiC,CAAA;IACjC,yDAAqC,CAAA;IACrC,6DAAyC,CAAA;AAC1C,CAAC,EANW,gBAAgB,KAAhB,gBAAgB,QAM3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/api-graphql",
3
- "version": "3.4.4-api-v6.13+5927d05d2",
3
+ "version": "3.4.4-api-v6.24+abe88c88f",
4
4
  "description": "Api-graphql category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -50,11 +50,11 @@
50
50
  "internals"
51
51
  ],
52
52
  "dependencies": {
53
- "@aws-amplify/api-rest": "3.3.3-api-v6.13+5927d05d2",
54
- "@aws-amplify/auth": "5.5.4-api-v6.13+5927d05d2",
55
- "@aws-amplify/cache": "5.1.4-api-v6.13+5927d05d2",
56
- "@aws-amplify/core": "5.5.3-api-v6.13+5927d05d2",
57
- "@aws-amplify/pubsub": "5.3.4-api-v6.13+5927d05d2",
53
+ "@aws-amplify/api-rest": "3.3.3-api-v6.24+abe88c88f",
54
+ "@aws-amplify/auth": "5.5.4-api-v6.24+abe88c88f",
55
+ "@aws-amplify/cache": "5.1.4-api-v6.24+abe88c88f",
56
+ "@aws-amplify/core": "5.5.3-api-v6.24+abe88c88f",
57
+ "@aws-amplify/pubsub": "5.3.4-api-v6.24+abe88c88f",
58
58
  "graphql": "15.8.0",
59
59
  "tslib": "^1.8.0",
60
60
  "uuid": "^3.2.1",
@@ -71,7 +71,7 @@
71
71
  "jest": {
72
72
  "globals": {
73
73
  "ts-jest": {
74
- "diagnostics": false,
74
+ "diagnostics": true,
75
75
  "tsConfig": {
76
76
  "lib": [
77
77
  "es5",
@@ -88,6 +88,10 @@
88
88
  "^.+\\.(js|jsx|ts|tsx)$": "ts-jest"
89
89
  },
90
90
  "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$",
91
+ "testPathIgnorePatterns": [
92
+ "__tests__/fixtures/",
93
+ "__tests__/utils/"
94
+ ],
91
95
  "moduleFileExtensions": [
92
96
  "ts",
93
97
  "tsx",
@@ -112,5 +116,5 @@
112
116
  "lib-esm"
113
117
  ]
114
118
  },
115
- "gitHead": "5927d05d267ab4d14badbb8133ee08596f1918d5"
119
+ "gitHead": "abe88c88f51044c8fe1fb14c0bc25020819e5ea6"
116
120
  }
@@ -4,3 +4,5 @@ export {
4
4
  InternalGraphQLAPI,
5
5
  InternalGraphQLAPIClass,
6
6
  } from './InternalGraphQLAPI';
7
+
8
+ export { graphql } from './v6';
@@ -0,0 +1,106 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { GraphQLAPI } from '../GraphQLAPI';
4
+ import { GraphQLOptionsV6, GraphQLResponseV6 } from '../types';
5
+
6
+ /**
7
+ * Invokes graphql operations against a graphql service, providing correct input and
8
+ * output types if Amplify-generated graphql from a recent version of the CLI/codegen
9
+ * are used *or* correct typing is provided via the type argument.
10
+ *
11
+ * Amplify-generated "branded" graphql queries will look similar to this:
12
+ *
13
+ * ```ts
14
+ * //
15
+ * // |-- branding
16
+ * // v
17
+ * export const getModel = `...` as GeneratedQuery<
18
+ * GetModelQueryVariables,
19
+ * GetModelQuery
20
+ * >;
21
+ * ```
22
+ *
23
+ * If this branding is not in your generated graphql, update to a newer version of
24
+ * CLI/codegen and regenerate your graphql using `amplify codegen`.
25
+ *
26
+ * ## Using Amplify-generated graphql
27
+ *
28
+ * ```ts
29
+ * import * as queries from './graphql/queries';
30
+ *
31
+ * //
32
+ * // |-- correctly typed graphql response containing a Widget
33
+ * // v
34
+ * const queryResult = await graphql({
35
+ * query: queries.getWidget,
36
+ * variables: {
37
+ * id: "abc", // <-- type hinted/enforced
38
+ * },
39
+ * });
40
+ *
41
+ * //
42
+ * // |-- a correctly typed Widget
43
+ * // v
44
+ * const fetchedWidget = queryResult.data?.getWidget!;
45
+ * ```
46
+ *
47
+ * ## Custom input + result types
48
+ *
49
+ * To provide input types (`variables`) and result types:
50
+ *
51
+ * ```ts
52
+ * type GetById_NameOnly = {
53
+ * variables: {
54
+ * id: string
55
+ * },
56
+ * result: Promise<{
57
+ * data: { getWidget: { name: string } }
58
+ * }>
59
+ * }
60
+ *
61
+ * //
62
+ * // |-- type is GetById_NameOnly["result"]
63
+ * // v
64
+ * const result = graphql<GetById_NameOnly>({
65
+ * query: "...",
66
+ * variables: { id: "abc" } // <-- type of GetById_NameOnly["variables"]
67
+ * });
68
+ * ```
69
+ *
70
+ * ## Custom result type only
71
+ *
72
+ * To specify result types only, use a type that is *not* in the `{variables, result}` shape:
73
+ *
74
+ * ```ts
75
+ * type MyResultType = Promise<{
76
+ * data: {
77
+ * getWidget: { name: string }
78
+ * }
79
+ * }>
80
+ *
81
+ * //
82
+ * // |-- type is MyResultType
83
+ * // v
84
+ * const result = graphql<MyResultType>({query: "..."});
85
+ * ```
86
+ *
87
+ * @param options
88
+ * @param additionalHeaders
89
+ */
90
+ export function graphql<
91
+ FALLBACK_TYPES = unknown,
92
+ TYPED_GQL_STRING extends string = string
93
+ >(
94
+ options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
95
+ additionalHeaders?: { [key: string]: string }
96
+ ): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING> {
97
+ /**
98
+ * The correctness of these typings depends on correct string branding or overrides.
99
+ * Neither of these can actually be validated at runtime. Hence, we don't perform
100
+ * any validation or type-guarding here.
101
+ */
102
+ const result = GraphQLAPI.graphql(options, additionalHeaders);
103
+ return result as any;
104
+ }
105
+
106
+ export { GraphQLOptionsV6, GraphQLResponseV6 };
@@ -1,11 +1,14 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { Source, DocumentNode, GraphQLError, OperationTypeNode } from 'graphql';
3
+ import { Source, DocumentNode, GraphQLError } from 'graphql';
4
4
  export { OperationTypeNode } from 'graphql';
5
5
  import { GRAPHQL_AUTH_MODE } from '@aws-amplify/auth';
6
6
  export { GRAPHQL_AUTH_MODE };
7
- import { CustomUserAgentDetails } from '@aws-amplify/core';
7
+ import { Observable } from 'zen-observable-ts';
8
8
 
9
+ /**
10
+ * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
11
+ */
9
12
  export interface GraphQLOptions {
10
13
  query: string | DocumentNode;
11
14
  variables?: object;
@@ -25,6 +28,51 @@ export interface GraphQLResult<T = object> {
25
28
  };
26
29
  }
27
30
 
31
+ /**
32
+ * The return value from a `graphql({query})` call when `query` is a subscription.
33
+ *
34
+ * ```ts
35
+ * // |-- You are here
36
+ * // v
37
+ * const subResult: GraphqlSubscriptionResult<T> = client.graphql({
38
+ * query: onCreateWidget
39
+ * });
40
+ *
41
+ * const sub = subResult.subscribe({
42
+ * //
43
+ * // |-- You are here
44
+ * // v
45
+ * next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
46
+ * handle(message.value); // <-- type OnCreateWidgetSubscription
47
+ * }
48
+ * })
49
+ * ```
50
+ */
51
+ export type GraphqlSubscriptionResult<T> = Observable<
52
+ GraphqlSubscriptionMessage<T>
53
+ >;
54
+
55
+ /**
56
+ * The shape of messages passed to `next()` from a graphql subscription. E.g.,
57
+ *
58
+ * ```ts
59
+ * const sub = client.graphql({
60
+ * query: onCreateWidget,
61
+ * }).subscribe({
62
+ * //
63
+ * // |-- You are here
64
+ * // v
65
+ * next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
66
+ * handle(message.value); // <-- type OnCreateWidgetSubscription
67
+ * }
68
+ * })
69
+ * ```
70
+ */
71
+ export type GraphqlSubscriptionMessage<T> = {
72
+ provider: any;
73
+ value: { data: T };
74
+ };
75
+
28
76
  export enum GraphQLAuthError {
29
77
  NO_API_KEY = 'No api-key configured',
30
78
  NO_CURRENT_USER = 'No current user',
@@ -38,3 +86,154 @@ export enum GraphQLAuthError {
38
86
  * @see: https://graphql.org/graphql-js/language/#parse
39
87
  */
40
88
  export type GraphQLOperation = Source | string;
89
+
90
+ /**
91
+ * API V6 `graphql({options})` type that can leverage branded graphql `query`
92
+ * objects and fallback types.
93
+ */
94
+ export interface GraphQLOptionsV6<
95
+ FALLBACK_TYPES = unknown,
96
+ TYPED_GQL_STRING extends string = string
97
+ > {
98
+ query: TYPED_GQL_STRING | DocumentNode;
99
+ variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
100
+ authMode?: keyof typeof GRAPHQL_AUTH_MODE;
101
+ authToken?: string;
102
+ /**
103
+ * @deprecated This property should not be used
104
+ */
105
+ userAgentSuffix?: string; // TODO: remove in v6
106
+ }
107
+
108
+ /**
109
+ * Result type for `graphql()` operations that don't include any specific
110
+ * type information. The result could be either a `Promise` or `Subscription`.
111
+ *
112
+ * Invoking code should either cast the result or use `?` and `!` operators to
113
+ * navigate the result objects.
114
+ */
115
+ export type UnknownGraphQLResponse =
116
+ | Promise<GraphQLResult<any>>
117
+ | GraphqlSubscriptionResult<any>;
118
+
119
+ /**
120
+ * The expected type for `variables` in a V6 `graphql()` operation with
121
+ * respect to the given `FALLBACK_TYPES` and `TYPED_GQL_STRING`.
122
+ */
123
+ export type GraphQLVariablesV6<
124
+ FALLBACK_TYPES = unknown,
125
+ TYPED_GQL_STRING extends string = string
126
+ > = TYPED_GQL_STRING extends GeneratedQuery<infer IN, any>
127
+ ? IN
128
+ : TYPED_GQL_STRING extends GeneratedMutation<infer IN, any>
129
+ ? IN
130
+ : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, any>
131
+ ? IN
132
+ : FALLBACK_TYPES extends GraphQLOperationType<infer IN, any>
133
+ ? IN
134
+ : any;
135
+
136
+ /**
137
+ * The expected return type with respect to the given `FALLBACK_TYPE`
138
+ * and `TYPED_GQL_STRING`.
139
+ */
140
+ export type GraphQLResponseV6<
141
+ FALLBACK_TYPE = UnknownGraphQLResponse,
142
+ TYPED_GQL_STRING extends string = string
143
+ > = TYPED_GQL_STRING extends GeneratedQuery<any, infer QUERY_OUT>
144
+ ? Promise<GraphQLResult<QUERY_OUT>>
145
+ : TYPED_GQL_STRING extends GeneratedMutation<any, infer MUTATION_OUT>
146
+ ? Promise<GraphQLResult<MUTATION_OUT>>
147
+ : TYPED_GQL_STRING extends GeneratedSubscription<any, infer SUB_OUT>
148
+ ? GraphqlSubscriptionResult<SUB_OUT>
149
+ : FALLBACK_TYPE extends GraphQLOperationType<any, infer CUSTOM_OUT>
150
+ ? CUSTOM_OUT
151
+ : FALLBACK_TYPE extends {}
152
+ ? FALLBACK_TYPE
153
+ : UnknownGraphQLResponse;
154
+
155
+ /**
156
+ * The shape customers can use to provide `T` to `graphql<T>()` to specify both
157
+ * `IN` and `OUT` types (the type of `variables` and the return type, respectively).
158
+ *
159
+ * I.E.,
160
+ *
161
+ * ```ts
162
+ * type MyVariablesType = { ... };
163
+ * type MyResultType = { ... };
164
+ * type MyOperationType = { variables: MyVariablesType, result: MyResultType };
165
+ *
166
+ * const result: MyResultType = graphql<MyOperationType>("graphql string", {
167
+ * variables: {
168
+ * // MyVariablesType
169
+ * }
170
+ * })
171
+ * ```
172
+ */
173
+ export type GraphQLOperationType<IN extends {}, OUT extends {}> = {
174
+ variables: IN;
175
+ result: OUT;
176
+ };
177
+
178
+ /**
179
+ * Nominal type for branding generated graphql query operation strings with
180
+ * input and output types.
181
+ *
182
+ * E.g.,
183
+ *
184
+ * ```ts
185
+ * export const getWidget = `...` as GeneratedQuery<
186
+ * GetWidgetQueryVariables,
187
+ * GetWidgetQuery
188
+ * >;
189
+ * ```
190
+ *
191
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
192
+ * assign types to the `variables` and result objects.
193
+ */
194
+ export type GeneratedQuery<InputType, OutputType> = string & {
195
+ __generatedQueryInput: InputType;
196
+ __generatedQueryOutput: OutputType;
197
+ };
198
+
199
+ /**
200
+ * Nominal type for branding generated graphql mutation operation strings with
201
+ * input and output types.
202
+ *
203
+ * E.g.,
204
+ *
205
+ * ```ts
206
+ * export const createWidget = `...` as GeneratedQuery<
207
+ * CreateWidgetMutationVariables,
208
+ * CreateWidgetMutation
209
+ * >;
210
+ * ```
211
+ *
212
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
213
+ * assign types to the `variables` and result objects.
214
+ */
215
+ export type GeneratedMutation<InputType, OutputType> = string & {
216
+ __generatedMutationInput: InputType;
217
+ __generatedMutationOutput: OutputType;
218
+ };
219
+
220
+ /**
221
+ * Nominal type for branding generated graphql mutation operation strings with
222
+ * input and output types.
223
+ *
224
+ * E.g.,
225
+ *
226
+ * ```ts
227
+ * export const createWidget = `...` as GeneratedMutation<
228
+ * CreateWidgetMutationVariables,
229
+ * CreateWidgetMutation
230
+ * >;
231
+ * ```
232
+ *
233
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
234
+ * assign types to the `variables` and result objects.
235
+ */
236
+ export type GeneratedSubscription<InputType, OutputType> = string & {
237
+ __generatedSubscriptionInput: InputType;
238
+ __generatedSubscriptionOutput: OutputType;
239
+ };