@aws-amplify/api-graphql 3.4.8 → 3.4.9-api-v6.d339f98.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.
- package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib/internals/InternalGraphQLAPI.js +7 -7
- package/lib/internals/InternalGraphQLAPI.js.map +1 -1
- package/lib/internals/index.d.ts +1 -0
- package/lib/internals/index.js +2 -0
- package/lib/internals/index.js.map +1 -1
- package/lib/internals/v6.d.ts +89 -0
- package/lib/internals/v6.js +100 -0
- package/lib/internals/v6.js.map +1 -0
- package/lib/types/index.d.ts +169 -0
- package/lib/types/index.js.map +1 -1
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib-esm/internals/InternalGraphQLAPI.js +7 -7
- package/lib-esm/internals/InternalGraphQLAPI.js.map +1 -1
- package/lib-esm/internals/index.d.ts +1 -0
- package/lib-esm/internals/index.js +1 -0
- package/lib-esm/internals/index.js.map +1 -1
- package/lib-esm/internals/v6.d.ts +89 -0
- package/lib-esm/internals/v6.js +97 -0
- package/lib-esm/internals/v6.js.map +1 -0
- package/lib-esm/types/index.d.ts +169 -0
- package/lib-esm/types/index.js.map +1 -1
- package/package.json +13 -9
- package/src/internals/InternalGraphQLAPI.ts +21 -7
- package/src/internals/index.ts +2 -0
- package/src/internals/v6.ts +106 -0
- package/src/types/index.ts +212 -2
|
@@ -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"}
|
package/lib-esm/types/index.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ 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
|
+
import { AWSAppSyncRealTimeProvider } from '@aws-amplify/pubsub';
|
|
7
|
+
/**
|
|
8
|
+
* Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
|
|
9
|
+
*/
|
|
5
10
|
export interface GraphQLOptions {
|
|
6
11
|
query: string | DocumentNode;
|
|
7
12
|
variables?: object;
|
|
@@ -19,6 +24,56 @@ export interface GraphQLResult<T = object> {
|
|
|
19
24
|
[key: string]: any;
|
|
20
25
|
};
|
|
21
26
|
}
|
|
27
|
+
declare const queryType: unique symbol;
|
|
28
|
+
export declare type GraphQLQuery<T> = T & {
|
|
29
|
+
readonly [queryType]: 'query';
|
|
30
|
+
};
|
|
31
|
+
export declare type GraphQLSubscription<T> = T & {
|
|
32
|
+
readonly [queryType]: 'subscription';
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The return value from a `graphql({query})` call when `query` is a subscription.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* // |-- You are here
|
|
39
|
+
* // v
|
|
40
|
+
* const subResult: GraphqlSubscriptionResult<T> = client.graphql({
|
|
41
|
+
* query: onCreateWidget
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* const sub = subResult.subscribe({
|
|
45
|
+
* //
|
|
46
|
+
* // |-- You are here
|
|
47
|
+
* // v
|
|
48
|
+
* next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
|
|
49
|
+
* handle(message.value); // <-- type OnCreateWidgetSubscription
|
|
50
|
+
* }
|
|
51
|
+
* })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptionMessage<T>>;
|
|
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 declare type GraphqlSubscriptionMessage<T> = {
|
|
72
|
+
provider: AWSAppSyncRealTimeProvider;
|
|
73
|
+
value: {
|
|
74
|
+
data?: T;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
22
77
|
export declare enum GraphQLAuthError {
|
|
23
78
|
NO_API_KEY = "No api-key configured",
|
|
24
79
|
NO_CURRENT_USER = "No current user",
|
|
@@ -31,3 +86,117 @@ export declare enum GraphQLAuthError {
|
|
|
31
86
|
* @see: https://graphql.org/graphql-js/language/#parse
|
|
32
87
|
*/
|
|
33
88
|
export declare type GraphQLOperation = Source | string;
|
|
89
|
+
/**
|
|
90
|
+
* API V6 `graphql({options})` type that can leverage branded graphql `query`
|
|
91
|
+
* objects and fallback types.
|
|
92
|
+
*/
|
|
93
|
+
export interface GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> {
|
|
94
|
+
query: TYPED_GQL_STRING | DocumentNode;
|
|
95
|
+
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
96
|
+
authMode?: keyof typeof GRAPHQL_AUTH_MODE;
|
|
97
|
+
authToken?: string;
|
|
98
|
+
/**
|
|
99
|
+
* @deprecated This property should not be used
|
|
100
|
+
*/
|
|
101
|
+
userAgentSuffix?: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Result type for `graphql()` operations that don't include any specific
|
|
105
|
+
* type information. The result could be either a `Promise` or `Subscription`.
|
|
106
|
+
*
|
|
107
|
+
* Invoking code should either cast the result or use `?` and `!` operators to
|
|
108
|
+
* navigate the result objects.
|
|
109
|
+
*/
|
|
110
|
+
export declare type UnknownGraphQLResponse = Promise<GraphQLResult<any>> | GraphqlSubscriptionResult<any>;
|
|
111
|
+
/**
|
|
112
|
+
* The expected type for `variables` in a V6 `graphql()` operation with
|
|
113
|
+
* respect to the given `FALLBACK_TYPES` and `TYPED_GQL_STRING`.
|
|
114
|
+
*/
|
|
115
|
+
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;
|
|
116
|
+
/**
|
|
117
|
+
* The expected return type with respect to the given `FALLBACK_TYPE`
|
|
118
|
+
* and `TYPED_GQL_STRING`.
|
|
119
|
+
*/
|
|
120
|
+
export declare type GraphQLResponseV6<FALLBACK_TYPE = unknown, TYPED_GQL_STRING extends string = string> = TYPED_GQL_STRING extends GeneratedQuery<infer IN, infer QUERY_OUT> ? Promise<GraphQLResult<QUERY_OUT>> : TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT> ? Promise<GraphQLResult<MUTATION_OUT>> : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT> ? GraphqlSubscriptionResult<SUB_OUT> : FALLBACK_TYPE extends GraphQLQuery<infer T> ? Promise<GraphQLResult<FALLBACK_TYPE>> : FALLBACK_TYPE extends GraphQLSubscription<infer T> ? GraphqlSubscriptionResult<FALLBACK_TYPE> : FALLBACK_TYPE extends GraphQLOperationType<infer IN, infer CUSTOM_OUT> ? CUSTOM_OUT : UnknownGraphQLResponse;
|
|
121
|
+
/**
|
|
122
|
+
* The shape customers can use to provide `T` to `graphql<T>()` to specify both
|
|
123
|
+
* `IN` and `OUT` types (the type of `variables` and the return type, respectively).
|
|
124
|
+
*
|
|
125
|
+
* I.E.,
|
|
126
|
+
*
|
|
127
|
+
* ```ts
|
|
128
|
+
* type MyVariablesType = { ... };
|
|
129
|
+
* type MyResultType = { ... };
|
|
130
|
+
* type MyOperationType = { variables: MyVariablesType, result: MyResultType };
|
|
131
|
+
*
|
|
132
|
+
* const result: MyResultType = graphql<MyOperationType>("graphql string", {
|
|
133
|
+
* variables: {
|
|
134
|
+
* // MyVariablesType
|
|
135
|
+
* }
|
|
136
|
+
* })
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare type GraphQLOperationType<IN extends {}, OUT extends {}> = {
|
|
140
|
+
variables: IN;
|
|
141
|
+
result: OUT;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Nominal type for branding generated graphql query operation strings with
|
|
145
|
+
* input and output types.
|
|
146
|
+
*
|
|
147
|
+
* E.g.,
|
|
148
|
+
*
|
|
149
|
+
* ```ts
|
|
150
|
+
* export const getWidget = `...` as GeneratedQuery<
|
|
151
|
+
* GetWidgetQueryVariables,
|
|
152
|
+
* GetWidgetQuery
|
|
153
|
+
* >;
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* This allows `graphql()` to extract `InputType` and `OutputType` to correctly
|
|
157
|
+
* assign types to the `variables` and result objects.
|
|
158
|
+
*/
|
|
159
|
+
export declare type GeneratedQuery<InputType, OutputType> = string & {
|
|
160
|
+
__generatedQueryInput: InputType;
|
|
161
|
+
__generatedQueryOutput: OutputType;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Nominal type for branding generated graphql mutation operation strings with
|
|
165
|
+
* input and output types.
|
|
166
|
+
*
|
|
167
|
+
* E.g.,
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* export const createWidget = `...` as GeneratedQuery<
|
|
171
|
+
* CreateWidgetMutationVariables,
|
|
172
|
+
* CreateWidgetMutation
|
|
173
|
+
* >;
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* This allows `graphql()` to extract `InputType` and `OutputType` to correctly
|
|
177
|
+
* assign types to the `variables` and result objects.
|
|
178
|
+
*/
|
|
179
|
+
export declare type GeneratedMutation<InputType, OutputType> = string & {
|
|
180
|
+
__generatedMutationInput: InputType;
|
|
181
|
+
__generatedMutationOutput: OutputType;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Nominal type for branding generated graphql mutation operation strings with
|
|
185
|
+
* input and output types.
|
|
186
|
+
*
|
|
187
|
+
* E.g.,
|
|
188
|
+
*
|
|
189
|
+
* ```ts
|
|
190
|
+
* export const createWidget = `...` as GeneratedMutation<
|
|
191
|
+
* CreateWidgetMutationVariables,
|
|
192
|
+
* CreateWidgetMutation
|
|
193
|
+
* >;
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* This allows `graphql()` to extract `InputType` and `OutputType` to correctly
|
|
197
|
+
* assign types to the `variables` and result objects.
|
|
198
|
+
*/
|
|
199
|
+
export declare type GeneratedSubscription<InputType, OutputType> = string & {
|
|
200
|
+
__generatedSubscriptionInput: InputType;
|
|
201
|
+
__generatedSubscriptionOutput: OutputType;
|
|
202
|
+
};
|
|
@@ -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;
|
|
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;AA+E7B,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.
|
|
3
|
+
"version": "3.4.9-api-v6.d339f98.0+d339f98",
|
|
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.5.
|
|
54
|
-
"@aws-amplify/auth": "5.6.
|
|
55
|
-
"@aws-amplify/cache": "5.1.
|
|
56
|
-
"@aws-amplify/core": "5.8.
|
|
57
|
-
"@aws-amplify/pubsub": "5.5.
|
|
53
|
+
"@aws-amplify/api-rest": "3.5.3-api-v6.d339f98.0+d339f98",
|
|
54
|
+
"@aws-amplify/auth": "5.6.3-api-v6.d339f98.0+d339f98",
|
|
55
|
+
"@aws-amplify/cache": "5.1.9-api-v6.d339f98.0+d339f98",
|
|
56
|
+
"@aws-amplify/core": "5.8.3-api-v6.d339f98.0+d339f98",
|
|
57
|
+
"@aws-amplify/pubsub": "5.5.3-api-v6.d339f98.0+d339f98",
|
|
58
58
|
"graphql": "15.8.0",
|
|
59
59
|
"tslib": "^1.8.0",
|
|
60
60
|
"uuid": "^3.2.1",
|
|
@@ -65,13 +65,13 @@
|
|
|
65
65
|
"name": "API (GraphQL client)",
|
|
66
66
|
"path": "./lib-esm/index.js",
|
|
67
67
|
"import": "{ Amplify, GraphQLAPI }",
|
|
68
|
-
"limit": "
|
|
68
|
+
"limit": "91.7 kB"
|
|
69
69
|
}
|
|
70
70
|
],
|
|
71
71
|
"jest": {
|
|
72
72
|
"globals": {
|
|
73
73
|
"ts-jest": {
|
|
74
|
-
"diagnostics":
|
|
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": "
|
|
119
|
+
"gitHead": "d339f988c4071373ec056efb79407f1e5738a201"
|
|
116
120
|
}
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
|
|
19
19
|
} from '@aws-amplify/core';
|
|
20
20
|
import { InternalPubSub } from '@aws-amplify/pubsub/internals';
|
|
21
|
-
import {
|
|
21
|
+
import { InternalAuth } from '@aws-amplify/auth/internals';
|
|
22
22
|
import { Cache } from '@aws-amplify/cache';
|
|
23
23
|
import {
|
|
24
24
|
GraphQLAuthError,
|
|
@@ -51,7 +51,7 @@ export class InternalGraphQLAPIClass {
|
|
|
51
51
|
private _options;
|
|
52
52
|
private _api = null;
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
InternalAuth = InternalAuth;
|
|
55
55
|
Cache = Cache;
|
|
56
56
|
Credentials = Credentials;
|
|
57
57
|
|
|
@@ -119,7 +119,8 @@ export class InternalGraphQLAPIClass {
|
|
|
119
119
|
|
|
120
120
|
private async _headerBasedAuth(
|
|
121
121
|
defaultAuthenticationType?,
|
|
122
|
-
additionalHeaders: { [key: string]: string } = {}
|
|
122
|
+
additionalHeaders: { [key: string]: string } = {},
|
|
123
|
+
customUserAgentDetails?: CustomUserAgentDetails
|
|
123
124
|
) {
|
|
124
125
|
const { aws_appsync_authenticationType, aws_appsync_apiKey: apiKey } =
|
|
125
126
|
this._options;
|
|
@@ -151,7 +152,10 @@ export class InternalGraphQLAPIClass {
|
|
|
151
152
|
if (federatedInfo) {
|
|
152
153
|
token = federatedInfo.token;
|
|
153
154
|
} else {
|
|
154
|
-
const currentUser = await
|
|
155
|
+
const currentUser = await InternalAuth.currentAuthenticatedUser(
|
|
156
|
+
undefined,
|
|
157
|
+
customUserAgentDetails
|
|
158
|
+
);
|
|
155
159
|
if (currentUser) {
|
|
156
160
|
token = currentUser.token;
|
|
157
161
|
}
|
|
@@ -168,7 +172,9 @@ export class InternalGraphQLAPIClass {
|
|
|
168
172
|
break;
|
|
169
173
|
case 'AMAZON_COGNITO_USER_POOLS':
|
|
170
174
|
try {
|
|
171
|
-
const session = await this.
|
|
175
|
+
const session = await this.InternalAuth.currentSession(
|
|
176
|
+
customUserAgentDetails
|
|
177
|
+
);
|
|
172
178
|
headers = {
|
|
173
179
|
Authorization: session.getAccessToken().getJwtToken(),
|
|
174
180
|
};
|
|
@@ -285,10 +291,18 @@ export class InternalGraphQLAPIClass {
|
|
|
285
291
|
|
|
286
292
|
const headers = {
|
|
287
293
|
...(!customGraphqlEndpoint &&
|
|
288
|
-
(await this._headerBasedAuth(
|
|
294
|
+
(await this._headerBasedAuth(
|
|
295
|
+
authMode,
|
|
296
|
+
additionalHeaders,
|
|
297
|
+
customUserAgentDetails
|
|
298
|
+
))),
|
|
289
299
|
...(customGraphqlEndpoint &&
|
|
290
300
|
(customEndpointRegion
|
|
291
|
-
? await this._headerBasedAuth(
|
|
301
|
+
? await this._headerBasedAuth(
|
|
302
|
+
authMode,
|
|
303
|
+
additionalHeaders,
|
|
304
|
+
customUserAgentDetails
|
|
305
|
+
)
|
|
292
306
|
: { Authorization: null })),
|
|
293
307
|
...(await graphql_headers({ query, variables })),
|
|
294
308
|
...additionalHeaders,
|
package/src/internals/index.ts
CHANGED
|
@@ -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 };
|