@aws-amplify/api-graphql 4.0.1-console-preview.4ae78ed.0 → 4.0.1-console-preview.8637b15.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/GraphQLAPI.d.ts +2 -2
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +1 -0
- package/lib/internals/InternalGraphQLAPI.d.ts +2 -2
- package/lib/internals/InternalGraphQLAPI.js +40 -38
- package/lib/tsconfig.tsbuildinfo +10 -9
- package/lib/types/PubSub.d.ts +1 -1
- package/lib/types/index.d.ts +63 -3
- package/lib/utils/resolveCredentials.d.ts +3 -3
- package/lib-esm/GraphQLAPI.d.ts +2 -2
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +1 -0
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +2 -2
- package/lib-esm/internals/InternalGraphQLAPI.js +40 -38
- package/lib-esm/tsconfig.tsbuildinfo +10 -9
- package/lib-esm/types/PubSub.d.ts +1 -1
- package/lib-esm/types/index.d.ts +63 -3
- package/lib-esm/utils/resolveCredentials.d.ts +3 -3
- package/package.json +6 -5
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +3 -2
- package/src/internals/InternalGraphQLAPI.ts +9 -7
- package/src/types/PubSub.ts +1 -1
- package/src/types/index.ts +81 -5
package/lib/GraphQLAPI.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { GraphQLOptions, GraphQLResult } from './types';
|
|
2
2
|
import { InternalGraphQLAPIClass } from './internals';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
|
-
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string) => {
|
|
4
|
+
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string | undefined) => {
|
|
5
5
|
query: any;
|
|
6
6
|
variables: {};
|
|
7
|
-
authToken: string;
|
|
7
|
+
authToken: string | undefined;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Export Cloud Logic APIs
|
|
@@ -781,6 +781,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
781
781
|
url: new URL(request.url),
|
|
782
782
|
body: request.data,
|
|
783
783
|
}, {
|
|
784
|
+
// TODO: What do we need to do to remove these !'s?
|
|
784
785
|
credentials: creds,
|
|
785
786
|
signingRegion: endpointInfo.region,
|
|
786
787
|
signingService: endpointInfo.service,
|
|
@@ -2,10 +2,10 @@ import { OperationTypeNode } from 'graphql';
|
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { CustomUserAgentDetails } from '@aws-amplify/core/internals/utils';
|
|
4
4
|
import { GraphQLResult, GraphQLOperation, GraphQLOptions } from '../types';
|
|
5
|
-
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string) => {
|
|
5
|
+
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string | undefined) => {
|
|
6
6
|
query: any;
|
|
7
7
|
variables: {};
|
|
8
|
-
authToken: string;
|
|
8
|
+
authToken: string | undefined;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Export Cloud Logic APIs
|
|
@@ -39,18 +39,18 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
39
39
|
};
|
|
40
40
|
InternalGraphQLAPIClass.prototype._headerBasedAuth = function (authMode, additionalHeaders) {
|
|
41
41
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
42
|
-
var _a;
|
|
42
|
+
var _a, _b;
|
|
43
43
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
44
|
-
var config,
|
|
45
|
-
return tslib_1.__generator(this, function (
|
|
46
|
-
switch (
|
|
44
|
+
var config, _c, region, appSyncGraphqlEndpoint, apiKey, defaultAuthMode, authenticationType, headers, _d, session, token, e_1;
|
|
45
|
+
return tslib_1.__generator(this, function (_e) {
|
|
46
|
+
switch (_e.label) {
|
|
47
47
|
case 0:
|
|
48
48
|
config = core_1.Amplify.getConfig();
|
|
49
|
-
|
|
49
|
+
_c = ((_a = config.API) === null || _a === void 0 ? void 0 : _a.GraphQL) || {}, region = _c.region, appSyncGraphqlEndpoint = _c.endpoint, apiKey = _c.apiKey, defaultAuthMode = _c.defaultAuthMode;
|
|
50
50
|
authenticationType = authMode || defaultAuthMode || 'iam';
|
|
51
51
|
headers = {};
|
|
52
|
-
|
|
53
|
-
switch (
|
|
52
|
+
_d = authenticationType;
|
|
53
|
+
switch (_d) {
|
|
54
54
|
case 'apiKey': return [3 /*break*/, 1];
|
|
55
55
|
case 'iam': return [3 /*break*/, 2];
|
|
56
56
|
case 'oidc': return [3 /*break*/, 4];
|
|
@@ -69,17 +69,17 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
69
69
|
return [3 /*break*/, 11];
|
|
70
70
|
case 2: return [4 /*yield*/, core_1.fetchAuthSession()];
|
|
71
71
|
case 3:
|
|
72
|
-
session =
|
|
72
|
+
session = _e.sent();
|
|
73
73
|
if (session.credentials === undefined) {
|
|
74
74
|
throw new Error(types_1.GraphQLAuthError.NO_CREDENTIALS);
|
|
75
75
|
}
|
|
76
76
|
return [3 /*break*/, 11];
|
|
77
77
|
case 4:
|
|
78
|
-
|
|
78
|
+
_e.trys.push([4, 6, , 7]);
|
|
79
79
|
token = void 0;
|
|
80
80
|
return [4 /*yield*/, core_1.fetchAuthSession()];
|
|
81
81
|
case 5:
|
|
82
|
-
token = (
|
|
82
|
+
token = (_b = (_e.sent()).tokens) === null || _b === void 0 ? void 0 : _b.accessToken.toString();
|
|
83
83
|
if (!token) {
|
|
84
84
|
throw new Error(types_1.GraphQLAuthError.NO_FEDERATED_JWT);
|
|
85
85
|
}
|
|
@@ -88,7 +88,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
88
88
|
};
|
|
89
89
|
return [3 /*break*/, 7];
|
|
90
90
|
case 6:
|
|
91
|
-
e_1 =
|
|
91
|
+
e_1 = _e.sent();
|
|
92
92
|
throw new Error(types_1.GraphQLAuthError.NO_CURRENT_USER);
|
|
93
93
|
case 7: return [3 /*break*/, 11];
|
|
94
94
|
case 8:
|
|
@@ -155,45 +155,47 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
155
155
|
InternalGraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders, abortController, customUserAgentDetails) {
|
|
156
156
|
var query = _a.query, variables = _a.variables, authMode = _a.authMode;
|
|
157
157
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
158
|
+
var _b;
|
|
158
159
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
159
|
-
var config,
|
|
160
|
-
var
|
|
161
|
-
return tslib_1.__generator(this, function (
|
|
162
|
-
switch (
|
|
160
|
+
var config, _c, region, appSyncGraphqlEndpoint, customGraphqlEndpoint, customEndpointRegion, headers, _d, _e, _f, _g, _h, body, endpoint, error, response, responseBody, result, err_1, errors;
|
|
161
|
+
var _j;
|
|
162
|
+
return tslib_1.__generator(this, function (_k) {
|
|
163
|
+
switch (_k.label) {
|
|
163
164
|
case 0:
|
|
164
165
|
config = core_1.Amplify.getConfig();
|
|
165
|
-
_b = config.API.GraphQL, region =
|
|
166
|
+
_c = ((_b = config.API) === null || _b === void 0 ? void 0 : _b.GraphQL) || {}, region = _c.region, appSyncGraphqlEndpoint = _c.endpoint;
|
|
166
167
|
customGraphqlEndpoint = null;
|
|
167
168
|
customEndpointRegion = null;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (!
|
|
169
|
+
_d = [{}];
|
|
170
|
+
_e = !customGraphqlEndpoint;
|
|
171
|
+
if (!_e) return [3 /*break*/, 2];
|
|
171
172
|
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
|
|
172
173
|
case 1:
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
_e = (_k.sent());
|
|
175
|
+
_k.label = 2;
|
|
175
176
|
case 2:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (!
|
|
177
|
+
_f = [tslib_1.__assign.apply(void 0, _d.concat([(_e)]))];
|
|
178
|
+
_g = customGraphqlEndpoint;
|
|
179
|
+
if (!_g) return [3 /*break*/, 6];
|
|
179
180
|
if (!customEndpointRegion) return [3 /*break*/, 4];
|
|
180
181
|
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
|
|
181
182
|
case 3:
|
|
182
|
-
|
|
183
|
+
_h = _k.sent();
|
|
183
184
|
return [3 /*break*/, 5];
|
|
184
185
|
case 4:
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
_h = { Authorization: null };
|
|
187
|
+
_k.label = 5;
|
|
187
188
|
case 5:
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
_g = (_h);
|
|
190
|
+
_k.label = 6;
|
|
190
191
|
case 6:
|
|
191
|
-
headers = tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0,
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
headers = tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0, [tslib_1.__assign.apply(void 0, _f.concat([((_g) ||
|
|
193
|
+
{})])), additionalHeaders]), (!customGraphqlEndpoint && (_j = {},
|
|
194
|
+
_j[USER_AGENT_HEADER] = utils_1.getAmplifyUserAgent(customUserAgentDetails),
|
|
195
|
+
_j))]);
|
|
194
196
|
body = {
|
|
195
197
|
query: graphql_1.print(query),
|
|
196
|
-
variables: variables,
|
|
198
|
+
variables: variables || null,
|
|
197
199
|
};
|
|
198
200
|
endpoint = customGraphqlEndpoint || appSyncGraphqlEndpoint;
|
|
199
201
|
if (!endpoint) {
|
|
@@ -203,9 +205,9 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
203
205
|
errors: [error],
|
|
204
206
|
};
|
|
205
207
|
}
|
|
206
|
-
|
|
208
|
+
_k.label = 7;
|
|
207
209
|
case 7:
|
|
208
|
-
|
|
210
|
+
_k.trys.push([7, 10, , 11]);
|
|
209
211
|
return [4 /*yield*/, this._api.post({
|
|
210
212
|
url: new URL(endpoint),
|
|
211
213
|
options: {
|
|
@@ -219,14 +221,14 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
219
221
|
abortController: abortController,
|
|
220
222
|
})];
|
|
221
223
|
case 8:
|
|
222
|
-
responseBody = (
|
|
224
|
+
responseBody = (_k.sent()).body;
|
|
223
225
|
return [4 /*yield*/, responseBody.json()];
|
|
224
226
|
case 9:
|
|
225
|
-
result =
|
|
227
|
+
result = _k.sent();
|
|
226
228
|
response = result;
|
|
227
229
|
return [3 /*break*/, 11];
|
|
228
230
|
case 10:
|
|
229
|
-
err_1 =
|
|
231
|
+
err_1 = _k.sent();
|
|
230
232
|
// If the exception is because user intentionally
|
|
231
233
|
// cancelled the request, do not modify the exception
|
|
232
234
|
// so that clients can identify the exception correctly.
|
package/lib/tsconfig.tsbuildinfo
CHANGED
|
@@ -1318,12 +1318,12 @@
|
|
|
1318
1318
|
"signature": "77d9972e4e2dd35f88e03335d8d0d9592a754693e4ea00d27f0ccc44f43c1c59"
|
|
1319
1319
|
},
|
|
1320
1320
|
"../src/types/PubSub.ts": {
|
|
1321
|
-
"version": "
|
|
1322
|
-
"signature": "
|
|
1321
|
+
"version": "14b4a96cd324440e30040d2a8d147af5f71ac1603546e16a9e0b56aa705aeb05",
|
|
1322
|
+
"signature": "69998b609508e9a6a8acbba64b5e4cdbe313c53451b349fe049d56786c2afd14"
|
|
1323
1323
|
},
|
|
1324
1324
|
"../src/types/index.ts": {
|
|
1325
|
-
"version": "
|
|
1326
|
-
"signature": "
|
|
1325
|
+
"version": "93ad3a1a8ee1d0a593f245ad2a9e4558de336823e21ecb3310584dec9ad26193",
|
|
1326
|
+
"signature": "1ec49e2a63d9fe4506977191b899c08704ef20f62611498215f2235e6e8f5113"
|
|
1327
1327
|
},
|
|
1328
1328
|
"../../core/lib-esm/singleton/apis/fetchAuthSession.d.ts": {
|
|
1329
1329
|
"version": "df1a1f23d18a3dac758a03f4f8f6a3d14e83fb78a45431d15e6833fb53ed8055",
|
|
@@ -1450,12 +1450,12 @@
|
|
|
1450
1450
|
"signature": "b0afc2803af9e818fad28464e4e62ee1b255d282f8f19ba8a2459b7bab4d789e"
|
|
1451
1451
|
},
|
|
1452
1452
|
"../src/Providers/AWSAppSyncRealTimeProvider/index.ts": {
|
|
1453
|
-
"version": "
|
|
1453
|
+
"version": "70307fdb8b8731ddf884d9974e4c6995a8882d434a9e89d0bcaf865a4e6f1fab",
|
|
1454
1454
|
"signature": "1e99d3031c6655bc40f2a8d877d7a10a8747d29046f6e4b0e1dba3590cd2fdf8"
|
|
1455
1455
|
},
|
|
1456
1456
|
"../src/internals/InternalGraphQLAPI.ts": {
|
|
1457
|
-
"version": "
|
|
1458
|
-
"signature": "
|
|
1457
|
+
"version": "4b77a15f276dd6a438831595b4ebe9edd9da3f3ec60504a9dc6d727ba25179db",
|
|
1458
|
+
"signature": "2935cf9761be3485380b77cbe856f428a1c342ca4377ad1dfa72af6eac46db2e"
|
|
1459
1459
|
},
|
|
1460
1460
|
"../src/internals/v6.ts": {
|
|
1461
1461
|
"version": "2acd7dbd0aa7c028f597a68a21cce2b24e9ed4a254a650ed144a162a9653f476",
|
|
@@ -1467,7 +1467,7 @@
|
|
|
1467
1467
|
},
|
|
1468
1468
|
"../src/GraphQLAPI.ts": {
|
|
1469
1469
|
"version": "e728905616fa216dfc13c3f044c4f349ff3a534c3849888b6614cf40e2cc899b",
|
|
1470
|
-
"signature": "
|
|
1470
|
+
"signature": "5db56760293eb5283bccc3ec49e63afe428213aad441147f90fe6e28f655f1a6"
|
|
1471
1471
|
},
|
|
1472
1472
|
"../src/index.ts": {
|
|
1473
1473
|
"version": "98d8433766c112c8658d03649ac495f403979234c503594a7b7baf3b5f8e5a02",
|
|
@@ -1495,7 +1495,7 @@
|
|
|
1495
1495
|
},
|
|
1496
1496
|
"../src/utils/resolveCredentials.ts": {
|
|
1497
1497
|
"version": "22c610d9879b27de3f79333284f54ce4f330b35e930837627cdfc0d276bf8a57",
|
|
1498
|
-
"signature": "
|
|
1498
|
+
"signature": "f848a594e5ecbebed6b9e7a2b62c57466dbf0faede2b27e3538a1c7fe2efb2e1"
|
|
1499
1499
|
},
|
|
1500
1500
|
"../src/utils/index.ts": {
|
|
1501
1501
|
"version": "6601832367b2c1359b16db86700174171375fa7d1403c5558910962ce36fa70a",
|
|
@@ -1541,6 +1541,7 @@
|
|
|
1541
1541
|
"node"
|
|
1542
1542
|
],
|
|
1543
1543
|
"strict": false,
|
|
1544
|
+
"strictNullChecks": true,
|
|
1544
1545
|
"skipLibCheck": true,
|
|
1545
1546
|
"module": 1,
|
|
1546
1547
|
"outDir": "./",
|
package/lib/types/PubSub.d.ts
CHANGED
|
@@ -23,5 +23,5 @@ export declare enum ConnectionState {
|
|
|
23
23
|
Disconnected = "Disconnected",
|
|
24
24
|
ConnectedPendingKeepAlive = "ConnectedPendingKeepAlive"
|
|
25
25
|
}
|
|
26
|
-
export declare type PubSubContent = Record<string, unknown
|
|
26
|
+
export declare type PubSubContent = Record<string, unknown>;
|
|
27
27
|
export declare type PubSubContentObserver = Observer<PubSubContent>;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface GraphQLOptions {
|
|
|
17
17
|
userAgentSuffix?: string;
|
|
18
18
|
}
|
|
19
19
|
export interface GraphQLResult<T = object> {
|
|
20
|
-
data
|
|
20
|
+
data: T;
|
|
21
21
|
errors?: GraphQLError[];
|
|
22
22
|
extensions?: {
|
|
23
23
|
[key: string]: any;
|
|
@@ -30,6 +30,66 @@ export declare type GraphQLQuery<T> = T & {
|
|
|
30
30
|
export declare type GraphQLSubscription<T> = T & {
|
|
31
31
|
readonly [queryType]: 'subscription';
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Accepts a code generated model type and returns a supertype that
|
|
35
|
+
* can accept return values from the relevant graphql operations.
|
|
36
|
+
*
|
|
37
|
+
* For example:
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import { GraphQLReturnType } from 'aws-amplify/api';
|
|
41
|
+
* import { MyModel } from './API';
|
|
42
|
+
* import { getMyModel } from './graphql/queries';
|
|
43
|
+
*
|
|
44
|
+
* const [item, setItem] = useState<GraphQLReturnType<MyModel>>();
|
|
45
|
+
* setItem(await client.graphql({ query: getMyModel }).data.getMyModel!)
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* Trying to assign the result of a `getMyModel` operation directly to a
|
|
49
|
+
* `MyModel` variables won't necessarily work, because normally-required related
|
|
50
|
+
* models might not be part of the selection set.
|
|
51
|
+
*
|
|
52
|
+
* This util simply makes related model properties optional recursively.
|
|
53
|
+
*/
|
|
54
|
+
export declare type GraphQLReturnType<T> = T extends {} ? {
|
|
55
|
+
[K in keyof T]?: GraphQLReturnType<T[K]>;
|
|
56
|
+
} : T;
|
|
57
|
+
/**
|
|
58
|
+
* Describes a paged list result from AppSync, which can either
|
|
59
|
+
* live at the top query or property (e.g., related model) level.
|
|
60
|
+
*/
|
|
61
|
+
declare type PagedList<T, TYPENAME> = {
|
|
62
|
+
__typename: TYPENAME;
|
|
63
|
+
nextToken?: string | null | undefined;
|
|
64
|
+
items: Array<T>;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Recursively looks through a result type and removes nulls and
|
|
68
|
+
* and undefined from `PagedList` types.
|
|
69
|
+
*
|
|
70
|
+
* Although a graphql response might contain empty values in an
|
|
71
|
+
* array, this will only be the case when we also have errors,
|
|
72
|
+
* which will then be *thrown*.
|
|
73
|
+
*/
|
|
74
|
+
declare type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME> ? PagedList<Exclude<IT, null | undefined>, NAME> : T extends {} ? {
|
|
75
|
+
[K in keyof T]: WithListsFixed<T[K]>;
|
|
76
|
+
} : T;
|
|
77
|
+
/**
|
|
78
|
+
* Returns an updated response type to always return a value.
|
|
79
|
+
*/
|
|
80
|
+
declare type NeverEmpty<T> = {
|
|
81
|
+
[K in keyof T]-?: Exclude<WithListsFixed<T[K]>, undefined | null>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Replaces all list result types in a query result with types to exclude
|
|
85
|
+
* nulls and undefined from list member unions.
|
|
86
|
+
*
|
|
87
|
+
* If empty members are present, there will also be errors present,
|
|
88
|
+
* and the response will instead be *thrown*.
|
|
89
|
+
*/
|
|
90
|
+
declare type FixedQueryResult<T> = Exclude<T[keyof T], null | undefined> extends PagedList<any, any> ? {
|
|
91
|
+
[K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
|
|
92
|
+
} : T;
|
|
33
93
|
/**
|
|
34
94
|
* The return value from a `graphql({query})` call when `query` is a subscription.
|
|
35
95
|
*
|
|
@@ -68,7 +128,7 @@ export declare type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptio
|
|
|
68
128
|
* ```
|
|
69
129
|
*/
|
|
70
130
|
export declare type GraphqlSubscriptionMessage<T> = {
|
|
71
|
-
data
|
|
131
|
+
data: T;
|
|
72
132
|
};
|
|
73
133
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
74
134
|
appSyncGraphqlEndpoint?: string;
|
|
@@ -128,7 +188,7 @@ export declare type GraphQLVariablesV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRIN
|
|
|
128
188
|
* The expected return type with respect to the given `FALLBACK_TYPE`
|
|
129
189
|
* and `TYPED_GQL_STRING`.
|
|
130
190
|
*/
|
|
131
|
-
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
|
|
191
|
+
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<FixedQueryResult<QUERY_OUT>>> : TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT> ? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>> : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT> ? GraphqlSubscriptionResult<NeverEmpty<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;
|
|
132
192
|
/**
|
|
133
193
|
* The shape customers can use to provide `T` to `graphql<T>()` to specify both
|
|
134
194
|
* `IN` and `OUT` types (the type of `variables` and the return type, respectively).
|
|
@@ -5,8 +5,8 @@ export declare const resolveCredentials: () => Promise<{
|
|
|
5
5
|
credentials: {
|
|
6
6
|
accessKeyId: string;
|
|
7
7
|
secretAccessKey: string;
|
|
8
|
-
sessionToken?: string;
|
|
9
|
-
expiration?: Date;
|
|
8
|
+
sessionToken?: string | undefined;
|
|
9
|
+
expiration?: Date | undefined;
|
|
10
10
|
};
|
|
11
|
-
identityId: string;
|
|
11
|
+
identityId: string | undefined;
|
|
12
12
|
}>;
|
package/lib-esm/GraphQLAPI.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { GraphQLOptions, GraphQLResult } from './types';
|
|
2
2
|
import { InternalGraphQLAPIClass } from './internals';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
|
-
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string) => {
|
|
4
|
+
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string | undefined) => {
|
|
5
5
|
query: any;
|
|
6
6
|
variables: {};
|
|
7
|
-
authToken: string;
|
|
7
|
+
authToken: string | undefined;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Export Cloud Logic APIs
|
|
@@ -779,6 +779,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
779
779
|
url: new URL(request.url),
|
|
780
780
|
body: request.data,
|
|
781
781
|
}, {
|
|
782
|
+
// TODO: What do we need to do to remove these !'s?
|
|
782
783
|
credentials: creds,
|
|
783
784
|
signingRegion: endpointInfo.region,
|
|
784
785
|
signingService: endpointInfo.service,
|
|
@@ -2,10 +2,10 @@ import { OperationTypeNode } from 'graphql';
|
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { CustomUserAgentDetails } from '@aws-amplify/core/internals/utils';
|
|
4
4
|
import { GraphQLResult, GraphQLOperation, GraphQLOptions } from '../types';
|
|
5
|
-
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string) => {
|
|
5
|
+
export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string | undefined) => {
|
|
6
6
|
query: any;
|
|
7
7
|
variables: {};
|
|
8
|
-
authToken: string;
|
|
8
|
+
authToken: string | undefined;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Export Cloud Logic APIs
|
|
@@ -37,18 +37,18 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
37
37
|
};
|
|
38
38
|
InternalGraphQLAPIClass.prototype._headerBasedAuth = function (authMode, additionalHeaders) {
|
|
39
39
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
40
|
-
var _a;
|
|
40
|
+
var _a, _b;
|
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
42
|
-
var config,
|
|
43
|
-
return __generator(this, function (
|
|
44
|
-
switch (
|
|
42
|
+
var config, _c, region, appSyncGraphqlEndpoint, apiKey, defaultAuthMode, authenticationType, headers, _d, session, token, e_1;
|
|
43
|
+
return __generator(this, function (_e) {
|
|
44
|
+
switch (_e.label) {
|
|
45
45
|
case 0:
|
|
46
46
|
config = Amplify.getConfig();
|
|
47
|
-
|
|
47
|
+
_c = ((_a = config.API) === null || _a === void 0 ? void 0 : _a.GraphQL) || {}, region = _c.region, appSyncGraphqlEndpoint = _c.endpoint, apiKey = _c.apiKey, defaultAuthMode = _c.defaultAuthMode;
|
|
48
48
|
authenticationType = authMode || defaultAuthMode || 'iam';
|
|
49
49
|
headers = {};
|
|
50
|
-
|
|
51
|
-
switch (
|
|
50
|
+
_d = authenticationType;
|
|
51
|
+
switch (_d) {
|
|
52
52
|
case 'apiKey': return [3 /*break*/, 1];
|
|
53
53
|
case 'iam': return [3 /*break*/, 2];
|
|
54
54
|
case 'oidc': return [3 /*break*/, 4];
|
|
@@ -67,17 +67,17 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
67
67
|
return [3 /*break*/, 11];
|
|
68
68
|
case 2: return [4 /*yield*/, fetchAuthSession()];
|
|
69
69
|
case 3:
|
|
70
|
-
session =
|
|
70
|
+
session = _e.sent();
|
|
71
71
|
if (session.credentials === undefined) {
|
|
72
72
|
throw new Error(GraphQLAuthError.NO_CREDENTIALS);
|
|
73
73
|
}
|
|
74
74
|
return [3 /*break*/, 11];
|
|
75
75
|
case 4:
|
|
76
|
-
|
|
76
|
+
_e.trys.push([4, 6, , 7]);
|
|
77
77
|
token = void 0;
|
|
78
78
|
return [4 /*yield*/, fetchAuthSession()];
|
|
79
79
|
case 5:
|
|
80
|
-
token = (
|
|
80
|
+
token = (_b = (_e.sent()).tokens) === null || _b === void 0 ? void 0 : _b.accessToken.toString();
|
|
81
81
|
if (!token) {
|
|
82
82
|
throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);
|
|
83
83
|
}
|
|
@@ -86,7 +86,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
86
86
|
};
|
|
87
87
|
return [3 /*break*/, 7];
|
|
88
88
|
case 6:
|
|
89
|
-
e_1 =
|
|
89
|
+
e_1 = _e.sent();
|
|
90
90
|
throw new Error(GraphQLAuthError.NO_CURRENT_USER);
|
|
91
91
|
case 7: return [3 /*break*/, 11];
|
|
92
92
|
case 8:
|
|
@@ -153,45 +153,47 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
153
153
|
InternalGraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders, abortController, customUserAgentDetails) {
|
|
154
154
|
var query = _a.query, variables = _a.variables, authMode = _a.authMode;
|
|
155
155
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
156
|
+
var _b;
|
|
156
157
|
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
-
var config,
|
|
158
|
-
var
|
|
159
|
-
return __generator(this, function (
|
|
160
|
-
switch (
|
|
158
|
+
var config, _c, region, appSyncGraphqlEndpoint, customGraphqlEndpoint, customEndpointRegion, headers, _d, _e, _f, _g, _h, body, endpoint, error, response, responseBody, result, err_1, errors;
|
|
159
|
+
var _j;
|
|
160
|
+
return __generator(this, function (_k) {
|
|
161
|
+
switch (_k.label) {
|
|
161
162
|
case 0:
|
|
162
163
|
config = Amplify.getConfig();
|
|
163
|
-
_b = config.API.GraphQL, region =
|
|
164
|
+
_c = ((_b = config.API) === null || _b === void 0 ? void 0 : _b.GraphQL) || {}, region = _c.region, appSyncGraphqlEndpoint = _c.endpoint;
|
|
164
165
|
customGraphqlEndpoint = null;
|
|
165
166
|
customEndpointRegion = null;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (!
|
|
167
|
+
_d = [{}];
|
|
168
|
+
_e = !customGraphqlEndpoint;
|
|
169
|
+
if (!_e) return [3 /*break*/, 2];
|
|
169
170
|
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
|
|
170
171
|
case 1:
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
_e = (_k.sent());
|
|
173
|
+
_k.label = 2;
|
|
173
174
|
case 2:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (!
|
|
175
|
+
_f = [__assign.apply(void 0, _d.concat([(_e)]))];
|
|
176
|
+
_g = customGraphqlEndpoint;
|
|
177
|
+
if (!_g) return [3 /*break*/, 6];
|
|
177
178
|
if (!customEndpointRegion) return [3 /*break*/, 4];
|
|
178
179
|
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
|
|
179
180
|
case 3:
|
|
180
|
-
|
|
181
|
+
_h = _k.sent();
|
|
181
182
|
return [3 /*break*/, 5];
|
|
182
183
|
case 4:
|
|
183
|
-
|
|
184
|
-
|
|
184
|
+
_h = { Authorization: null };
|
|
185
|
+
_k.label = 5;
|
|
185
186
|
case 5:
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
_g = (_h);
|
|
188
|
+
_k.label = 6;
|
|
188
189
|
case 6:
|
|
189
|
-
headers = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0,
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
headers = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _f.concat([((_g) ||
|
|
191
|
+
{})])), additionalHeaders]), (!customGraphqlEndpoint && (_j = {},
|
|
192
|
+
_j[USER_AGENT_HEADER] = getAmplifyUserAgent(customUserAgentDetails),
|
|
193
|
+
_j))]);
|
|
192
194
|
body = {
|
|
193
195
|
query: print(query),
|
|
194
|
-
variables: variables,
|
|
196
|
+
variables: variables || null,
|
|
195
197
|
};
|
|
196
198
|
endpoint = customGraphqlEndpoint || appSyncGraphqlEndpoint;
|
|
197
199
|
if (!endpoint) {
|
|
@@ -201,9 +203,9 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
201
203
|
errors: [error],
|
|
202
204
|
};
|
|
203
205
|
}
|
|
204
|
-
|
|
206
|
+
_k.label = 7;
|
|
205
207
|
case 7:
|
|
206
|
-
|
|
208
|
+
_k.trys.push([7, 10, , 11]);
|
|
207
209
|
return [4 /*yield*/, this._api.post({
|
|
208
210
|
url: new URL(endpoint),
|
|
209
211
|
options: {
|
|
@@ -217,14 +219,14 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
217
219
|
abortController: abortController,
|
|
218
220
|
})];
|
|
219
221
|
case 8:
|
|
220
|
-
responseBody = (
|
|
222
|
+
responseBody = (_k.sent()).body;
|
|
221
223
|
return [4 /*yield*/, responseBody.json()];
|
|
222
224
|
case 9:
|
|
223
|
-
result =
|
|
225
|
+
result = _k.sent();
|
|
224
226
|
response = result;
|
|
225
227
|
return [3 /*break*/, 11];
|
|
226
228
|
case 10:
|
|
227
|
-
err_1 =
|
|
229
|
+
err_1 = _k.sent();
|
|
228
230
|
// If the exception is because user intentionally
|
|
229
231
|
// cancelled the request, do not modify the exception
|
|
230
232
|
// so that clients can identify the exception correctly.
|
|
@@ -1318,12 +1318,12 @@
|
|
|
1318
1318
|
"signature": "77d9972e4e2dd35f88e03335d8d0d9592a754693e4ea00d27f0ccc44f43c1c59"
|
|
1319
1319
|
},
|
|
1320
1320
|
"../src/types/PubSub.ts": {
|
|
1321
|
-
"version": "
|
|
1322
|
-
"signature": "
|
|
1321
|
+
"version": "14b4a96cd324440e30040d2a8d147af5f71ac1603546e16a9e0b56aa705aeb05",
|
|
1322
|
+
"signature": "69998b609508e9a6a8acbba64b5e4cdbe313c53451b349fe049d56786c2afd14"
|
|
1323
1323
|
},
|
|
1324
1324
|
"../src/types/index.ts": {
|
|
1325
|
-
"version": "
|
|
1326
|
-
"signature": "
|
|
1325
|
+
"version": "93ad3a1a8ee1d0a593f245ad2a9e4558de336823e21ecb3310584dec9ad26193",
|
|
1326
|
+
"signature": "1ec49e2a63d9fe4506977191b899c08704ef20f62611498215f2235e6e8f5113"
|
|
1327
1327
|
},
|
|
1328
1328
|
"../../core/lib-esm/singleton/apis/fetchAuthSession.d.ts": {
|
|
1329
1329
|
"version": "df1a1f23d18a3dac758a03f4f8f6a3d14e83fb78a45431d15e6833fb53ed8055",
|
|
@@ -1450,12 +1450,12 @@
|
|
|
1450
1450
|
"signature": "b0afc2803af9e818fad28464e4e62ee1b255d282f8f19ba8a2459b7bab4d789e"
|
|
1451
1451
|
},
|
|
1452
1452
|
"../src/Providers/AWSAppSyncRealTimeProvider/index.ts": {
|
|
1453
|
-
"version": "
|
|
1453
|
+
"version": "70307fdb8b8731ddf884d9974e4c6995a8882d434a9e89d0bcaf865a4e6f1fab",
|
|
1454
1454
|
"signature": "1e99d3031c6655bc40f2a8d877d7a10a8747d29046f6e4b0e1dba3590cd2fdf8"
|
|
1455
1455
|
},
|
|
1456
1456
|
"../src/internals/InternalGraphQLAPI.ts": {
|
|
1457
|
-
"version": "
|
|
1458
|
-
"signature": "
|
|
1457
|
+
"version": "4b77a15f276dd6a438831595b4ebe9edd9da3f3ec60504a9dc6d727ba25179db",
|
|
1458
|
+
"signature": "2935cf9761be3485380b77cbe856f428a1c342ca4377ad1dfa72af6eac46db2e"
|
|
1459
1459
|
},
|
|
1460
1460
|
"../src/internals/v6.ts": {
|
|
1461
1461
|
"version": "2acd7dbd0aa7c028f597a68a21cce2b24e9ed4a254a650ed144a162a9653f476",
|
|
@@ -1467,7 +1467,7 @@
|
|
|
1467
1467
|
},
|
|
1468
1468
|
"../src/GraphQLAPI.ts": {
|
|
1469
1469
|
"version": "e728905616fa216dfc13c3f044c4f349ff3a534c3849888b6614cf40e2cc899b",
|
|
1470
|
-
"signature": "
|
|
1470
|
+
"signature": "5db56760293eb5283bccc3ec49e63afe428213aad441147f90fe6e28f655f1a6"
|
|
1471
1471
|
},
|
|
1472
1472
|
"../src/index.ts": {
|
|
1473
1473
|
"version": "98d8433766c112c8658d03649ac495f403979234c503594a7b7baf3b5f8e5a02",
|
|
@@ -1495,7 +1495,7 @@
|
|
|
1495
1495
|
},
|
|
1496
1496
|
"../src/utils/resolveCredentials.ts": {
|
|
1497
1497
|
"version": "22c610d9879b27de3f79333284f54ce4f330b35e930837627cdfc0d276bf8a57",
|
|
1498
|
-
"signature": "
|
|
1498
|
+
"signature": "f848a594e5ecbebed6b9e7a2b62c57466dbf0faede2b27e3538a1c7fe2efb2e1"
|
|
1499
1499
|
},
|
|
1500
1500
|
"../src/utils/index.ts": {
|
|
1501
1501
|
"version": "6601832367b2c1359b16db86700174171375fa7d1403c5558910962ce36fa70a",
|
|
@@ -1541,6 +1541,7 @@
|
|
|
1541
1541
|
"node"
|
|
1542
1542
|
],
|
|
1543
1543
|
"strict": false,
|
|
1544
|
+
"strictNullChecks": true,
|
|
1544
1545
|
"skipLibCheck": true,
|
|
1545
1546
|
"module": 99,
|
|
1546
1547
|
"outDir": "./",
|
|
@@ -23,5 +23,5 @@ export declare enum ConnectionState {
|
|
|
23
23
|
Disconnected = "Disconnected",
|
|
24
24
|
ConnectedPendingKeepAlive = "ConnectedPendingKeepAlive"
|
|
25
25
|
}
|
|
26
|
-
export declare type PubSubContent = Record<string, unknown
|
|
26
|
+
export declare type PubSubContent = Record<string, unknown>;
|
|
27
27
|
export declare type PubSubContentObserver = Observer<PubSubContent>;
|
package/lib-esm/types/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface GraphQLOptions {
|
|
|
17
17
|
userAgentSuffix?: string;
|
|
18
18
|
}
|
|
19
19
|
export interface GraphQLResult<T = object> {
|
|
20
|
-
data
|
|
20
|
+
data: T;
|
|
21
21
|
errors?: GraphQLError[];
|
|
22
22
|
extensions?: {
|
|
23
23
|
[key: string]: any;
|
|
@@ -30,6 +30,66 @@ export declare type GraphQLQuery<T> = T & {
|
|
|
30
30
|
export declare type GraphQLSubscription<T> = T & {
|
|
31
31
|
readonly [queryType]: 'subscription';
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Accepts a code generated model type and returns a supertype that
|
|
35
|
+
* can accept return values from the relevant graphql operations.
|
|
36
|
+
*
|
|
37
|
+
* For example:
|
|
38
|
+
*
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import { GraphQLReturnType } from 'aws-amplify/api';
|
|
41
|
+
* import { MyModel } from './API';
|
|
42
|
+
* import { getMyModel } from './graphql/queries';
|
|
43
|
+
*
|
|
44
|
+
* const [item, setItem] = useState<GraphQLReturnType<MyModel>>();
|
|
45
|
+
* setItem(await client.graphql({ query: getMyModel }).data.getMyModel!)
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* Trying to assign the result of a `getMyModel` operation directly to a
|
|
49
|
+
* `MyModel` variables won't necessarily work, because normally-required related
|
|
50
|
+
* models might not be part of the selection set.
|
|
51
|
+
*
|
|
52
|
+
* This util simply makes related model properties optional recursively.
|
|
53
|
+
*/
|
|
54
|
+
export declare type GraphQLReturnType<T> = T extends {} ? {
|
|
55
|
+
[K in keyof T]?: GraphQLReturnType<T[K]>;
|
|
56
|
+
} : T;
|
|
57
|
+
/**
|
|
58
|
+
* Describes a paged list result from AppSync, which can either
|
|
59
|
+
* live at the top query or property (e.g., related model) level.
|
|
60
|
+
*/
|
|
61
|
+
declare type PagedList<T, TYPENAME> = {
|
|
62
|
+
__typename: TYPENAME;
|
|
63
|
+
nextToken?: string | null | undefined;
|
|
64
|
+
items: Array<T>;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Recursively looks through a result type and removes nulls and
|
|
68
|
+
* and undefined from `PagedList` types.
|
|
69
|
+
*
|
|
70
|
+
* Although a graphql response might contain empty values in an
|
|
71
|
+
* array, this will only be the case when we also have errors,
|
|
72
|
+
* which will then be *thrown*.
|
|
73
|
+
*/
|
|
74
|
+
declare type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME> ? PagedList<Exclude<IT, null | undefined>, NAME> : T extends {} ? {
|
|
75
|
+
[K in keyof T]: WithListsFixed<T[K]>;
|
|
76
|
+
} : T;
|
|
77
|
+
/**
|
|
78
|
+
* Returns an updated response type to always return a value.
|
|
79
|
+
*/
|
|
80
|
+
declare type NeverEmpty<T> = {
|
|
81
|
+
[K in keyof T]-?: Exclude<WithListsFixed<T[K]>, undefined | null>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Replaces all list result types in a query result with types to exclude
|
|
85
|
+
* nulls and undefined from list member unions.
|
|
86
|
+
*
|
|
87
|
+
* If empty members are present, there will also be errors present,
|
|
88
|
+
* and the response will instead be *thrown*.
|
|
89
|
+
*/
|
|
90
|
+
declare type FixedQueryResult<T> = Exclude<T[keyof T], null | undefined> extends PagedList<any, any> ? {
|
|
91
|
+
[K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
|
|
92
|
+
} : T;
|
|
33
93
|
/**
|
|
34
94
|
* The return value from a `graphql({query})` call when `query` is a subscription.
|
|
35
95
|
*
|
|
@@ -68,7 +128,7 @@ export declare type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptio
|
|
|
68
128
|
* ```
|
|
69
129
|
*/
|
|
70
130
|
export declare type GraphqlSubscriptionMessage<T> = {
|
|
71
|
-
data
|
|
131
|
+
data: T;
|
|
72
132
|
};
|
|
73
133
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
74
134
|
appSyncGraphqlEndpoint?: string;
|
|
@@ -128,7 +188,7 @@ export declare type GraphQLVariablesV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRIN
|
|
|
128
188
|
* The expected return type with respect to the given `FALLBACK_TYPE`
|
|
129
189
|
* and `TYPED_GQL_STRING`.
|
|
130
190
|
*/
|
|
131
|
-
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
|
|
191
|
+
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<FixedQueryResult<QUERY_OUT>>> : TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT> ? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>> : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT> ? GraphqlSubscriptionResult<NeverEmpty<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;
|
|
132
192
|
/**
|
|
133
193
|
* The shape customers can use to provide `T` to `graphql<T>()` to specify both
|
|
134
194
|
* `IN` and `OUT` types (the type of `variables` and the return type, respectively).
|
|
@@ -5,8 +5,8 @@ export declare const resolveCredentials: () => Promise<{
|
|
|
5
5
|
credentials: {
|
|
6
6
|
accessKeyId: string;
|
|
7
7
|
secretAccessKey: string;
|
|
8
|
-
sessionToken?: string;
|
|
9
|
-
expiration?: Date;
|
|
8
|
+
sessionToken?: string | undefined;
|
|
9
|
+
expiration?: Date | undefined;
|
|
10
10
|
};
|
|
11
|
-
identityId: string;
|
|
11
|
+
identityId: string | undefined;
|
|
12
12
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api-graphql",
|
|
3
|
-
"version": "4.0.1-console-preview.
|
|
3
|
+
"version": "4.0.1-console-preview.8637b15.0+8637b15",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"internals"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@aws-amplify/api-rest": "4.0.1-console-preview.
|
|
51
|
-
"@aws-amplify/auth": "6.0.1-console-preview.
|
|
52
|
-
"@aws-amplify/core": "6.0.1-console-preview.
|
|
50
|
+
"@aws-amplify/api-rest": "4.0.1-console-preview.8637b15.0+8637b15",
|
|
51
|
+
"@aws-amplify/auth": "6.0.1-console-preview.8637b15.0+8637b15",
|
|
52
|
+
"@aws-amplify/core": "6.0.1-console-preview.8637b15.0+8637b15",
|
|
53
53
|
"@aws-sdk/types": "3.387.0",
|
|
54
54
|
"graphql": "15.8.0",
|
|
55
55
|
"rxjs": "^7.8.1",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
],
|
|
82
82
|
"allowJs": true,
|
|
83
83
|
"noEmitOnError": false,
|
|
84
|
+
"strictNullChecks": true,
|
|
84
85
|
"types": [
|
|
85
86
|
"@types/jest"
|
|
86
87
|
]
|
|
@@ -121,5 +122,5 @@
|
|
|
121
122
|
"<rootDir>/__tests__"
|
|
122
123
|
]
|
|
123
124
|
},
|
|
124
|
-
"gitHead": "
|
|
125
|
+
"gitHead": "8637b15b240e2ea176ac025bd6fc12e25a46118d"
|
|
125
126
|
}
|
|
@@ -972,8 +972,9 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
972
972
|
body: request.data,
|
|
973
973
|
},
|
|
974
974
|
{
|
|
975
|
-
|
|
976
|
-
|
|
975
|
+
// TODO: What do we need to do to remove these !'s?
|
|
976
|
+
credentials: creds!,
|
|
977
|
+
signingRegion: endpointInfo.region!,
|
|
977
978
|
signingService: endpointInfo.service,
|
|
978
979
|
}
|
|
979
980
|
);
|
|
@@ -80,7 +80,7 @@ export class InternalGraphQLAPIClass {
|
|
|
80
80
|
endpoint: appSyncGraphqlEndpoint,
|
|
81
81
|
apiKey,
|
|
82
82
|
defaultAuthMode,
|
|
83
|
-
} = config.API
|
|
83
|
+
} = config.API?.GraphQL || {};
|
|
84
84
|
|
|
85
85
|
const authenticationType = authMode || defaultAuthMode || 'iam';
|
|
86
86
|
let headers = {};
|
|
@@ -215,18 +215,20 @@ export class InternalGraphQLAPIClass {
|
|
|
215
215
|
const config = Amplify.getConfig();
|
|
216
216
|
|
|
217
217
|
const { region: region, endpoint: appSyncGraphqlEndpoint } =
|
|
218
|
-
config.API
|
|
218
|
+
config.API?.GraphQL || {};
|
|
219
219
|
|
|
220
220
|
const customGraphqlEndpoint = null;
|
|
221
221
|
const customEndpointRegion = null;
|
|
222
222
|
|
|
223
|
+
// TODO: Figure what we need to do to remove `!`'s.
|
|
223
224
|
const headers = {
|
|
224
225
|
...(!customGraphqlEndpoint &&
|
|
225
|
-
(await this._headerBasedAuth(authMode
|
|
226
|
-
...(customGraphqlEndpoint &&
|
|
226
|
+
(await this._headerBasedAuth(authMode!, additionalHeaders))),
|
|
227
|
+
...((customGraphqlEndpoint &&
|
|
227
228
|
(customEndpointRegion
|
|
228
|
-
? await this._headerBasedAuth(authMode
|
|
229
|
-
: { Authorization: null }))
|
|
229
|
+
? await this._headerBasedAuth(authMode!, additionalHeaders)
|
|
230
|
+
: { Authorization: null })) ||
|
|
231
|
+
{}),
|
|
230
232
|
...additionalHeaders,
|
|
231
233
|
...(!customGraphqlEndpoint && {
|
|
232
234
|
[USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),
|
|
@@ -235,7 +237,7 @@ export class InternalGraphQLAPIClass {
|
|
|
235
237
|
|
|
236
238
|
const body = {
|
|
237
239
|
query: print(query as DocumentNode),
|
|
238
|
-
variables,
|
|
240
|
+
variables: variables || null,
|
|
239
241
|
};
|
|
240
242
|
|
|
241
243
|
const endpoint = customGraphqlEndpoint || appSyncGraphqlEndpoint;
|
package/src/types/PubSub.ts
CHANGED
|
@@ -52,5 +52,5 @@ export enum ConnectionState {
|
|
|
52
52
|
ConnectedPendingKeepAlive = 'ConnectedPendingKeepAlive',
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
export type PubSubContent = Record<string, unknown
|
|
55
|
+
export type PubSubContent = Record<string, unknown>;
|
|
56
56
|
export type PubSubContentObserver = Observer<PubSubContent>;
|
package/src/types/index.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface GraphQLOptions {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface GraphQLResult<T = object> {
|
|
24
|
-
data
|
|
24
|
+
data: T;
|
|
25
25
|
errors?: GraphQLError[];
|
|
26
26
|
extensions?: {
|
|
27
27
|
[key: string]: any;
|
|
@@ -36,6 +36,82 @@ export type GraphQLSubscription<T> = T & {
|
|
|
36
36
|
readonly [queryType]: 'subscription';
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Accepts a code generated model type and returns a supertype that
|
|
41
|
+
* can accept return values from the relevant graphql operations.
|
|
42
|
+
*
|
|
43
|
+
* For example:
|
|
44
|
+
*
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { GraphQLReturnType } from 'aws-amplify/api';
|
|
47
|
+
* import { MyModel } from './API';
|
|
48
|
+
* import { getMyModel } from './graphql/queries';
|
|
49
|
+
*
|
|
50
|
+
* const [item, setItem] = useState<GraphQLReturnType<MyModel>>();
|
|
51
|
+
* setItem(await client.graphql({ query: getMyModel }).data.getMyModel!)
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* Trying to assign the result of a `getMyModel` operation directly to a
|
|
55
|
+
* `MyModel` variables won't necessarily work, because normally-required related
|
|
56
|
+
* models might not be part of the selection set.
|
|
57
|
+
*
|
|
58
|
+
* This util simply makes related model properties optional recursively.
|
|
59
|
+
*/
|
|
60
|
+
export type GraphQLReturnType<T> = T extends {}
|
|
61
|
+
? {
|
|
62
|
+
[K in keyof T]?: GraphQLReturnType<T[K]>;
|
|
63
|
+
}
|
|
64
|
+
: T;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Describes a paged list result from AppSync, which can either
|
|
68
|
+
* live at the top query or property (e.g., related model) level.
|
|
69
|
+
*/
|
|
70
|
+
type PagedList<T, TYPENAME> = {
|
|
71
|
+
__typename: TYPENAME;
|
|
72
|
+
nextToken?: string | null | undefined;
|
|
73
|
+
items: Array<T>;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Recursively looks through a result type and removes nulls and
|
|
78
|
+
* and undefined from `PagedList` types.
|
|
79
|
+
*
|
|
80
|
+
* Although a graphql response might contain empty values in an
|
|
81
|
+
* array, this will only be the case when we also have errors,
|
|
82
|
+
* which will then be *thrown*.
|
|
83
|
+
*/
|
|
84
|
+
type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME>
|
|
85
|
+
? PagedList<Exclude<IT, null | undefined>, NAME>
|
|
86
|
+
: T extends {}
|
|
87
|
+
? {
|
|
88
|
+
[K in keyof T]: WithListsFixed<T[K]>;
|
|
89
|
+
}
|
|
90
|
+
: T;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Returns an updated response type to always return a value.
|
|
94
|
+
*/
|
|
95
|
+
type NeverEmpty<T> = {
|
|
96
|
+
[K in keyof T]-?: Exclude<WithListsFixed<T[K]>, undefined | null>;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Replaces all list result types in a query result with types to exclude
|
|
101
|
+
* nulls and undefined from list member unions.
|
|
102
|
+
*
|
|
103
|
+
* If empty members are present, there will also be errors present,
|
|
104
|
+
* and the response will instead be *thrown*.
|
|
105
|
+
*/
|
|
106
|
+
type FixedQueryResult<T> = Exclude<
|
|
107
|
+
T[keyof T],
|
|
108
|
+
null | undefined
|
|
109
|
+
> extends PagedList<any, any>
|
|
110
|
+
? {
|
|
111
|
+
[K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
|
|
112
|
+
}
|
|
113
|
+
: T;
|
|
114
|
+
|
|
39
115
|
/**
|
|
40
116
|
* The return value from a `graphql({query})` call when `query` is a subscription.
|
|
41
117
|
*
|
|
@@ -77,7 +153,7 @@ export type GraphqlSubscriptionResult<T> = Observable<
|
|
|
77
153
|
* ```
|
|
78
154
|
*/
|
|
79
155
|
export type GraphqlSubscriptionMessage<T> = {
|
|
80
|
-
data
|
|
156
|
+
data: T;
|
|
81
157
|
};
|
|
82
158
|
|
|
83
159
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
@@ -165,11 +241,11 @@ export type GraphQLResponseV6<
|
|
|
165
241
|
FALLBACK_TYPE = unknown,
|
|
166
242
|
TYPED_GQL_STRING extends string = string
|
|
167
243
|
> = TYPED_GQL_STRING extends GeneratedQuery<infer IN, infer QUERY_OUT>
|
|
168
|
-
? Promise<GraphQLResult<QUERY_OUT
|
|
244
|
+
? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>>
|
|
169
245
|
: TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT>
|
|
170
|
-
? Promise<GraphQLResult<MUTATION_OUT
|
|
246
|
+
? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>>
|
|
171
247
|
: TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT>
|
|
172
|
-
? GraphqlSubscriptionResult<SUB_OUT
|
|
248
|
+
? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>>
|
|
173
249
|
: FALLBACK_TYPE extends GraphQLQuery<infer T>
|
|
174
250
|
? Promise<GraphQLResult<FALLBACK_TYPE>>
|
|
175
251
|
: FALLBACK_TYPE extends GraphQLSubscription<infer T>
|