@aws-amplify/api-graphql 4.0.1-api-v6-models.c1977f8.0 → 4.0.1-api-v6-models.9351bcf.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/APIClient.d.ts +1 -1
- package/lib/internals/generateClient.js +2 -0
- package/lib/internals/generateModelsProperty.js +28 -18
- package/lib/internals/types.d.ts +8 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +5 -0
- package/lib/types/index.js +3 -1
- package/lib-esm/internals/APIClient.d.ts +1 -1
- package/lib-esm/internals/generateClient.js +3 -1
- package/lib-esm/internals/generateModelsProperty.js +28 -18
- package/lib-esm/internals/types.d.ts +8 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +5 -0
- package/lib-esm/types/index.js +2 -0
- package/package.json +6 -6
- package/src/internals/APIClient.ts +1 -1
- package/src/internals/generateClient.ts +3 -1
- package/src/internals/generateModelsProperty.ts +43 -16
- package/src/internals/types.ts +9 -0
- package/src/types/index.ts +6 -0
package/lib/types/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { Observable } from 'rxjs';
|
|
|
6
6
|
import { GraphQLAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
|
|
7
7
|
export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
8
8
|
export { SelectionSet } from '@aws-amplify/amplify-api-next-types-alpha';
|
|
9
|
+
export { CommonPublicClientOptions } from '../internals/types';
|
|
9
10
|
/**
|
|
10
11
|
* Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
|
|
11
12
|
*/
|
|
@@ -281,8 +282,12 @@ type ExcludeNeverFields<O> = {
|
|
|
281
282
|
[K in FilteredKeys<O>]: O[K];
|
|
282
283
|
};
|
|
283
284
|
export declare const __amplify: unique symbol;
|
|
285
|
+
export declare const __authMode: unique symbol;
|
|
286
|
+
export declare const __authToken: unique symbol;
|
|
284
287
|
export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
285
288
|
[__amplify]: AmplifyClassV6;
|
|
289
|
+
[__authMode]?: GraphQLAuthMode;
|
|
290
|
+
[__authToken]?: string;
|
|
286
291
|
graphql: <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
|
|
287
292
|
[key: string]: string;
|
|
288
293
|
} | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
package/lib/types/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.__amplify = exports.GraphQLAuthError = exports.ConnectionState = exports.CONTROL_MSG = void 0;
|
|
3
|
+
exports.__authToken = exports.__authMode = exports.__amplify = exports.GraphQLAuthError = exports.ConnectionState = exports.CONTROL_MSG = void 0;
|
|
4
4
|
var PubSub_1 = require("./PubSub");
|
|
5
5
|
Object.defineProperty(exports, "CONTROL_MSG", { enumerable: true, get: function () { return PubSub_1.CONTROL_MSG; } });
|
|
6
6
|
Object.defineProperty(exports, "ConnectionState", { enumerable: true, get: function () { return PubSub_1.ConnectionState; } });
|
|
@@ -13,3 +13,5 @@ var GraphQLAuthError;
|
|
|
13
13
|
GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
|
|
14
14
|
})(GraphQLAuthError || (exports.GraphQLAuthError = GraphQLAuthError = {}));
|
|
15
15
|
exports.__amplify = Symbol('amplify');
|
|
16
|
+
exports.__authMode = Symbol('authMode');
|
|
17
|
+
exports.__authToken = Symbol('authToken');
|
|
@@ -9,7 +9,7 @@ type ListArgs = {
|
|
|
9
9
|
* @returns response object with `items` properties flattened
|
|
10
10
|
*/
|
|
11
11
|
export declare const flattenItems: (obj: Record<string, any>) => Record<string, any>;
|
|
12
|
-
export declare function initializeModel(client: any, modelName: string, result: any[], modelIntrospection: any, authMode: GraphQLAuthMode, authToken: string | undefined): any[];
|
|
12
|
+
export declare function initializeModel(client: any, modelName: string, result: any[], modelIntrospection: any, authMode: GraphQLAuthMode | undefined, authToken: string | undefined): any[];
|
|
13
13
|
export declare const graphQLOperationsInfo: {
|
|
14
14
|
CREATE: {
|
|
15
15
|
operationPrefix: "create";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { graphql, cancel, isCancelError } from './v6';
|
|
2
2
|
import { generateModelsProperty } from './generateModelsProperty';
|
|
3
|
-
import { __amplify } from '../types';
|
|
3
|
+
import { __amplify, __authMode, __authToken } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* @private
|
|
6
6
|
*
|
|
@@ -14,6 +14,8 @@ export function generateClient(params) {
|
|
|
14
14
|
var _a;
|
|
15
15
|
var client = (_a = {},
|
|
16
16
|
_a[__amplify] = params.amplify,
|
|
17
|
+
_a[__authMode] = params.authMode,
|
|
18
|
+
_a[__authToken] = params.authToken,
|
|
17
19
|
_a.graphql = graphql,
|
|
18
20
|
_a.cancel = cancel,
|
|
19
21
|
_a.isCancelError = isCancelError,
|
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator, __read, __spreadArray, __values } from "tslib";
|
|
2
2
|
import { initializeModel, generateGraphQLDocument, buildGraphQLVariables, graphQLOperationsInfo, flattenItems, } from './APIClient';
|
|
3
|
+
import { __authMode, __authToken, } from '../types';
|
|
3
4
|
import { findIndexByFields, resolvePKFields } from '../utils';
|
|
4
5
|
import { Observable, map } from 'rxjs';
|
|
6
|
+
/**
|
|
7
|
+
* Produces a parameter object that can contains auth mode/token overrides
|
|
8
|
+
* only if present in either `options` (first) or configured on the `client`
|
|
9
|
+
* as a fallback.
|
|
10
|
+
*
|
|
11
|
+
* @param client Configured client from `generateClient`
|
|
12
|
+
* @param options Args/Options obect from call site.
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
function authModeParams(client, options) {
|
|
16
|
+
if (options === void 0) { options = {}; }
|
|
17
|
+
return {
|
|
18
|
+
authMode: options.authMode || client[__authMode],
|
|
19
|
+
authToken: options.authToken || client[__authToken],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
5
22
|
export function generateModelsProperty(client, params) {
|
|
6
23
|
var e_1, _a;
|
|
7
24
|
var _this = this;
|
|
@@ -20,7 +37,7 @@ export function generateModelsProperty(client, params) {
|
|
|
20
37
|
var operation = key;
|
|
21
38
|
if (operation === 'LIST') {
|
|
22
39
|
models[name_1][operationPrefix] = function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
23
|
-
var query, variables,
|
|
40
|
+
var query, variables, auth, _a, data, extensions, _b, key_1, flattenedResult, initialized, error_1;
|
|
24
41
|
return __generator(this, function (_c) {
|
|
25
42
|
switch (_c.label) {
|
|
26
43
|
case 0:
|
|
@@ -29,12 +46,8 @@ export function generateModelsProperty(client, params) {
|
|
|
29
46
|
_c.label = 1;
|
|
30
47
|
case 1:
|
|
31
48
|
_c.trys.push([1, 3, , 4]);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
options.authMode = args === null || args === void 0 ? void 0 : args.authMode;
|
|
35
|
-
if (args === null || args === void 0 ? void 0 : args.authToken)
|
|
36
|
-
options.authToken = args === null || args === void 0 ? void 0 : args.authToken;
|
|
37
|
-
return [4 /*yield*/, client.graphql(__assign(__assign({}, options), { query: query, variables: variables }))];
|
|
49
|
+
auth = authModeParams(client, args);
|
|
50
|
+
return [4 /*yield*/, client.graphql(__assign(__assign({}, auth), { query: query, variables: variables }))];
|
|
38
51
|
case 2:
|
|
39
52
|
_a = (_c.sent()), data = _a.data, extensions = _a.extensions;
|
|
40
53
|
// flatten response
|
|
@@ -51,7 +64,7 @@ export function generateModelsProperty(client, params) {
|
|
|
51
64
|
}];
|
|
52
65
|
}
|
|
53
66
|
else {
|
|
54
|
-
initialized = initializeModel(client, name_1, flattenedResult, modelIntrospection,
|
|
67
|
+
initialized = initializeModel(client, name_1, flattenedResult, modelIntrospection, auth.authMode, auth.authToken);
|
|
55
68
|
return [2 /*return*/, {
|
|
56
69
|
data: initialized,
|
|
57
70
|
nextToken: data[key_1].nextToken,
|
|
@@ -86,15 +99,11 @@ export function generateModelsProperty(client, params) {
|
|
|
86
99
|
models[name_1][operationPrefix] = function (args) {
|
|
87
100
|
var query = generateGraphQLDocument(modelIntrospection.models, name_1, operation);
|
|
88
101
|
var variables = buildGraphQLVariables(model, operation, args, modelIntrospection);
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
options.authMode = args === null || args === void 0 ? void 0 : args.authMode;
|
|
92
|
-
if (args === null || args === void 0 ? void 0 : args.authToken)
|
|
93
|
-
options.authToken = args === null || args === void 0 ? void 0 : args.authToken;
|
|
94
|
-
var observable = client.graphql(__assign(__assign({}, options), { query: query, variables: variables }));
|
|
102
|
+
var auth = authModeParams(client, args);
|
|
103
|
+
var observable = client.graphql(__assign(__assign({}, auth), { query: query, variables: variables }));
|
|
95
104
|
return observable.pipe(map(function (value) {
|
|
96
105
|
var _a = __read(Object.keys(value.data), 1), key = _a[0];
|
|
97
|
-
var _b = __read(initializeModel(client, name_1, [value.data[key]], modelIntrospection,
|
|
106
|
+
var _b = __read(initializeModel(client, name_1, [value.data[key]], modelIntrospection, auth.authMode, auth.authToken), 1), initialized = _b[0];
|
|
98
107
|
return initialized;
|
|
99
108
|
}));
|
|
100
109
|
};
|
|
@@ -252,7 +261,7 @@ export function generateModelsProperty(client, params) {
|
|
|
252
261
|
}
|
|
253
262
|
else {
|
|
254
263
|
models[name_1][operationPrefix] = function (arg, options) { return __awaiter(_this, void 0, void 0, function () {
|
|
255
|
-
var query, variables, _a, data, extensions, _b, key_2, flattenedResult, _c, initialized, error_2;
|
|
264
|
+
var query, variables, auth, _a, data, extensions, _b, key_2, flattenedResult, _c, initialized, error_2;
|
|
256
265
|
return __generator(this, function (_d) {
|
|
257
266
|
switch (_d.label) {
|
|
258
267
|
case 0:
|
|
@@ -261,7 +270,8 @@ export function generateModelsProperty(client, params) {
|
|
|
261
270
|
_d.label = 1;
|
|
262
271
|
case 1:
|
|
263
272
|
_d.trys.push([1, 3, , 4]);
|
|
264
|
-
|
|
273
|
+
auth = authModeParams(client, options);
|
|
274
|
+
return [4 /*yield*/, client.graphql(__assign(__assign({}, auth), { query: query, variables: variables }))];
|
|
265
275
|
case 2:
|
|
266
276
|
_a = (_d.sent()), data = _a.data, extensions = _a.extensions;
|
|
267
277
|
// flatten response
|
|
@@ -272,7 +282,7 @@ export function generateModelsProperty(client, params) {
|
|
|
272
282
|
return [2 /*return*/, { data: flattenedResult, extensions: extensions }];
|
|
273
283
|
}
|
|
274
284
|
else {
|
|
275
|
-
_c = __read(initializeModel(client, name_1, [flattenedResult], modelIntrospection,
|
|
285
|
+
_c = __read(initializeModel(client, name_1, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken), 1), initialized = _c[0];
|
|
276
286
|
return [2 /*return*/, { data: initialized, extensions: extensions }];
|
|
277
287
|
}
|
|
278
288
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
2
3
|
/**
|
|
3
4
|
* @private
|
|
4
5
|
*
|
|
@@ -6,4 +7,11 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
|
6
7
|
*/
|
|
7
8
|
export type ClientGenerationParams = {
|
|
8
9
|
amplify: AmplifyClassV6;
|
|
10
|
+
} & CommonPublicClientOptions;
|
|
11
|
+
/**
|
|
12
|
+
* Common options that can be used on public `generateClient()` interfaces.
|
|
13
|
+
*/
|
|
14
|
+
export type CommonPublicClientOptions = {
|
|
15
|
+
authMode?: GraphQLAuthMode;
|
|
16
|
+
authToken?: string;
|
|
9
17
|
};
|