@aws-amplify/api-graphql 4.0.1-api-v6-models.01b2bb8.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 +2 -1
- package/lib/internals/APIClient.js +12 -5
- package/lib/internals/InternalGraphQLAPI.js +1 -1
- package/lib/internals/generateClient.js +2 -0
- package/lib/internals/generateModelsProperty.js +36 -30
- 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 +2 -1
- package/lib-esm/internals/APIClient.js +12 -5
- package/lib-esm/internals/InternalGraphQLAPI.js +1 -1
- package/lib-esm/internals/generateClient.js +3 -1
- package/lib-esm/internals/generateModelsProperty.js +36 -30
- 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 +28 -8
- package/src/internals/InternalGraphQLAPI.ts +1 -1
- package/src/internals/generateClient.ts +3 -1
- package/src/internals/generateModelsProperty.ts +82 -38
- package/src/internals/types.ts +9 -0
- package/src/types/index.ts +6 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
1
2
|
type ListArgs = {
|
|
2
3
|
selectionSet?: string[];
|
|
3
4
|
filter?: {};
|
|
@@ -8,7 +9,7 @@ type ListArgs = {
|
|
|
8
9
|
* @returns response object with `items` properties flattened
|
|
9
10
|
*/
|
|
10
11
|
export declare const flattenItems: (obj: Record<string, any>) => Record<string, any>;
|
|
11
|
-
export declare function initializeModel(client: any, modelName: string, result: any[], modelIntrospection: any): any[];
|
|
12
|
+
export declare function initializeModel(client: any, modelName: string, result: any[], modelIntrospection: any, authMode: GraphQLAuthMode | undefined, authToken: string | undefined): any[];
|
|
12
13
|
export declare const graphQLOperationsInfo: {
|
|
13
14
|
CREATE: {
|
|
14
15
|
operationPrefix: "create";
|
|
@@ -35,7 +35,7 @@ var flattenItems = function (obj) {
|
|
|
35
35
|
};
|
|
36
36
|
exports.flattenItems = flattenItems;
|
|
37
37
|
// TODO: this should accept single result to support CRUD methods; create helper for array/list
|
|
38
|
-
function initializeModel(client, modelName, result, modelIntrospection) {
|
|
38
|
+
function initializeModel(client, modelName, result, modelIntrospection, authMode, authToken) {
|
|
39
39
|
var introModel = modelIntrospection.models[modelName];
|
|
40
40
|
var introModelFields = introModel.fields;
|
|
41
41
|
var modelFields = Object.entries(introModelFields)
|
|
@@ -68,10 +68,13 @@ function initializeModel(client, modelName, result, modelIntrospection) {
|
|
|
68
68
|
return (acc[curVal] = record[curVal]);
|
|
69
69
|
}
|
|
70
70
|
}, {});
|
|
71
|
-
initializedRelationalFields[field] = function () {
|
|
71
|
+
initializedRelationalFields[field] = function (options) {
|
|
72
72
|
var _a;
|
|
73
73
|
if (record[targetNames[0]]) {
|
|
74
|
-
return client.models[relatedModelName].get(tslib_1.__assign((_a = {}, _a[relatedModelPKFieldName] = record[targetNames[0]], _a), sortKeyValues_1)
|
|
74
|
+
return client.models[relatedModelName].get(tslib_1.__assign((_a = {}, _a[relatedModelPKFieldName] = record[targetNames[0]], _a), sortKeyValues_1), {
|
|
75
|
+
authMode: (options === null || options === void 0 ? void 0 : options.authMode) || authMode,
|
|
76
|
+
authToken: (options === null || options === void 0 ? void 0 : options.authToken) || authToken,
|
|
77
|
+
});
|
|
75
78
|
}
|
|
76
79
|
return undefined;
|
|
77
80
|
};
|
|
@@ -89,10 +92,12 @@ function initializeModel(client, modelName, result, modelIntrospection) {
|
|
|
89
92
|
}
|
|
90
93
|
return _b = {}, _b[field] = { eq: record[parentSK_1[idx - 1]] }, _b;
|
|
91
94
|
});
|
|
92
|
-
initializedRelationalFields[field] = function () {
|
|
95
|
+
initializedRelationalFields[field] = function (options) {
|
|
93
96
|
if (record[parentPk_1]) {
|
|
94
97
|
return client.models[relatedModelName].list({
|
|
95
98
|
filter: { and: hasManyFilter_1 },
|
|
99
|
+
authMode: (options === null || options === void 0 ? void 0 : options.authMode) || authMode,
|
|
100
|
+
authToken: (options === null || options === void 0 ? void 0 : options.authToken) || authToken,
|
|
96
101
|
});
|
|
97
102
|
}
|
|
98
103
|
return [];
|
|
@@ -106,10 +111,12 @@ function initializeModel(client, modelName, result, modelIntrospection) {
|
|
|
106
111
|
}
|
|
107
112
|
return _b = {}, _b[field] = { eq: record[parentSK_1[idx - 1]] }, _b;
|
|
108
113
|
});
|
|
109
|
-
initializedRelationalFields[field] = function () {
|
|
114
|
+
initializedRelationalFields[field] = function (options) {
|
|
110
115
|
if (record[parentPk_1]) {
|
|
111
116
|
return client.models[relatedModelName].list({
|
|
112
117
|
filter: { and: hasManyFilter_2 },
|
|
118
|
+
authMode: (options === null || options === void 0 ? void 0 : options.authMode) || authMode,
|
|
119
|
+
authToken: (options === null || options === void 0 ? void 0 : options.authToken) || authToken,
|
|
113
120
|
});
|
|
114
121
|
}
|
|
115
122
|
return [];
|
|
@@ -307,7 +307,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
307
307
|
variables: variables,
|
|
308
308
|
appSyncGraphqlEndpoint: config === null || config === void 0 ? void 0 : config.endpoint,
|
|
309
309
|
region: config === null || config === void 0 ? void 0 : config.region,
|
|
310
|
-
authenticationType: config === null || config === void 0 ? void 0 : config.defaultAuthMode,
|
|
310
|
+
authenticationType: authMode || (config === null || config === void 0 ? void 0 : config.defaultAuthMode),
|
|
311
311
|
apiKey: config === null || config === void 0 ? void 0 : config.apiKey,
|
|
312
312
|
additionalHeaders: additionalHeaders,
|
|
313
313
|
}, customUserAgentDetails);
|
|
@@ -17,6 +17,8 @@ function generateClient(params) {
|
|
|
17
17
|
var _a;
|
|
18
18
|
var client = (_a = {},
|
|
19
19
|
_a[types_1.__amplify] = params.amplify,
|
|
20
|
+
_a[types_1.__authMode] = params.authMode,
|
|
21
|
+
_a[types_1.__authToken] = params.authToken,
|
|
20
22
|
_a.graphql = v6_1.graphql,
|
|
21
23
|
_a.cancel = v6_1.cancel,
|
|
22
24
|
_a.isCancelError = v6_1.isCancelError,
|
|
@@ -3,8 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateModelsProperty = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var APIClient_1 = require("./APIClient");
|
|
6
|
+
var types_1 = require("../types");
|
|
6
7
|
var utils_1 = require("../utils");
|
|
7
8
|
var rxjs_1 = require("rxjs");
|
|
9
|
+
/**
|
|
10
|
+
* Produces a parameter object that can contains auth mode/token overrides
|
|
11
|
+
* only if present in either `options` (first) or configured on the `client`
|
|
12
|
+
* as a fallback.
|
|
13
|
+
*
|
|
14
|
+
* @param client Configured client from `generateClient`
|
|
15
|
+
* @param options Args/Options obect from call site.
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
function authModeParams(client, options) {
|
|
19
|
+
if (options === void 0) { options = {}; }
|
|
20
|
+
return {
|
|
21
|
+
authMode: options.authMode || client[types_1.__authMode],
|
|
22
|
+
authToken: options.authToken || client[types_1.__authToken],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
8
25
|
function generateModelsProperty(client, params) {
|
|
9
26
|
var e_1, _a;
|
|
10
27
|
var _this = this;
|
|
@@ -23,7 +40,7 @@ function generateModelsProperty(client, params) {
|
|
|
23
40
|
var operation = key;
|
|
24
41
|
if (operation === 'LIST') {
|
|
25
42
|
models[name_1][operationPrefix] = function (args) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
26
|
-
var query, variables, _a, data, extensions, _b, key_1, flattenedResult, initialized, error_1;
|
|
43
|
+
var query, variables, auth, _a, data, extensions, _b, key_1, flattenedResult, initialized, error_1;
|
|
27
44
|
return tslib_1.__generator(this, function (_c) {
|
|
28
45
|
switch (_c.label) {
|
|
29
46
|
case 0:
|
|
@@ -32,10 +49,8 @@ function generateModelsProperty(client, params) {
|
|
|
32
49
|
_c.label = 1;
|
|
33
50
|
case 1:
|
|
34
51
|
_c.trys.push([1, 3, , 4]);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
variables: variables,
|
|
38
|
-
})];
|
|
52
|
+
auth = authModeParams(client, args);
|
|
53
|
+
return [4 /*yield*/, client.graphql(tslib_1.__assign(tslib_1.__assign({}, auth), { query: query, variables: variables }))];
|
|
39
54
|
case 2:
|
|
40
55
|
_a = (_c.sent()), data = _a.data, extensions = _a.extensions;
|
|
41
56
|
// flatten response
|
|
@@ -52,7 +67,7 @@ function generateModelsProperty(client, params) {
|
|
|
52
67
|
}];
|
|
53
68
|
}
|
|
54
69
|
else {
|
|
55
|
-
initialized = (0, APIClient_1.initializeModel)(client, name_1, flattenedResult, modelIntrospection);
|
|
70
|
+
initialized = (0, APIClient_1.initializeModel)(client, name_1, flattenedResult, modelIntrospection, auth.authMode, auth.authToken);
|
|
56
71
|
return [2 /*return*/, {
|
|
57
72
|
data: initialized,
|
|
58
73
|
nextToken: data[key_1].nextToken,
|
|
@@ -84,21 +99,20 @@ function generateModelsProperty(client, params) {
|
|
|
84
99
|
}); };
|
|
85
100
|
}
|
|
86
101
|
else if (['ONCREATE', 'ONUPDATE', 'ONDELETE'].includes(operation)) {
|
|
87
|
-
models[name_1][operationPrefix] = function (
|
|
102
|
+
models[name_1][operationPrefix] = function (args) {
|
|
88
103
|
var query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection.models, name_1, operation);
|
|
89
|
-
var variables = (0, APIClient_1.buildGraphQLVariables)(model, operation,
|
|
90
|
-
var
|
|
91
|
-
|
|
92
|
-
variables: variables,
|
|
93
|
-
});
|
|
104
|
+
var variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, args, modelIntrospection);
|
|
105
|
+
var auth = authModeParams(client, args);
|
|
106
|
+
var observable = client.graphql(tslib_1.__assign(tslib_1.__assign({}, auth), { query: query, variables: variables }));
|
|
94
107
|
return observable.pipe((0, rxjs_1.map)(function (value) {
|
|
95
108
|
var _a = tslib_1.__read(Object.keys(value.data), 1), key = _a[0];
|
|
96
|
-
|
|
109
|
+
var _b = tslib_1.__read((0, APIClient_1.initializeModel)(client, name_1, [value.data[key]], modelIntrospection, auth.authMode, auth.authToken), 1), initialized = _b[0];
|
|
110
|
+
return initialized;
|
|
97
111
|
}));
|
|
98
112
|
};
|
|
99
113
|
}
|
|
100
114
|
else if (operation === 'OBSERVE_QUERY') {
|
|
101
|
-
models[name_1][operationPrefix] = function (arg
|
|
115
|
+
models[name_1][operationPrefix] = function (arg) {
|
|
102
116
|
return new rxjs_1.Observable(function (subscriber) {
|
|
103
117
|
// what we'll be sending to our subscribers
|
|
104
118
|
var items = [];
|
|
@@ -116,9 +130,7 @@ function generateModelsProperty(client, params) {
|
|
|
116
130
|
return messageQueue.push.apply(messageQueue, tslib_1.__spreadArray([], tslib_1.__read(messages), false));
|
|
117
131
|
};
|
|
118
132
|
// start subscriptions
|
|
119
|
-
var onCreateSub = models[name_1]
|
|
120
|
-
.onCreate(arg, options)
|
|
121
|
-
.subscribe({
|
|
133
|
+
var onCreateSub = models[name_1].onCreate(arg).subscribe({
|
|
122
134
|
next: function (item) {
|
|
123
135
|
receiveMessages({ item: item, type: 'create' });
|
|
124
136
|
},
|
|
@@ -126,9 +138,7 @@ function generateModelsProperty(client, params) {
|
|
|
126
138
|
subscriber.error({ type: 'onCreate', error: error });
|
|
127
139
|
},
|
|
128
140
|
});
|
|
129
|
-
var onUpdateSub = models[name_1]
|
|
130
|
-
.onUpdate(arg, options)
|
|
131
|
-
.subscribe({
|
|
141
|
+
var onUpdateSub = models[name_1].onUpdate(arg).subscribe({
|
|
132
142
|
next: function (item) {
|
|
133
143
|
receiveMessages({ item: item, type: 'update' });
|
|
134
144
|
},
|
|
@@ -136,9 +146,7 @@ function generateModelsProperty(client, params) {
|
|
|
136
146
|
subscriber.error({ type: 'onUpdate', error: error });
|
|
137
147
|
},
|
|
138
148
|
});
|
|
139
|
-
var onDeleteSub = models[name_1]
|
|
140
|
-
.onDelete(arg, options)
|
|
141
|
-
.subscribe({
|
|
149
|
+
var onDeleteSub = models[name_1].onDelete(arg).subscribe({
|
|
142
150
|
next: function (item) {
|
|
143
151
|
receiveMessages({ item: item, type: 'delete' });
|
|
144
152
|
},
|
|
@@ -197,7 +205,7 @@ function generateModelsProperty(client, params) {
|
|
|
197
205
|
case 1:
|
|
198
206
|
if (!(!subscriber.closed && (firstPage || nextToken))) return [3 /*break*/, 3];
|
|
199
207
|
firstPage = false;
|
|
200
|
-
return [4 /*yield*/, models[name_1].list(tslib_1.__assign(tslib_1.__assign({}, arg), { nextToken: nextToken })
|
|
208
|
+
return [4 /*yield*/, models[name_1].list(tslib_1.__assign(tslib_1.__assign({}, arg), { nextToken: nextToken }))];
|
|
201
209
|
case 2:
|
|
202
210
|
_a = _c.sent(), page = _a.data, errors = _a.errors, _nextToken = _a.nextToken;
|
|
203
211
|
nextToken = _nextToken;
|
|
@@ -256,7 +264,7 @@ function generateModelsProperty(client, params) {
|
|
|
256
264
|
}
|
|
257
265
|
else {
|
|
258
266
|
models[name_1][operationPrefix] = function (arg, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
259
|
-
var query, variables, _a, data, extensions, _b, key_2, flattenedResult, _c, initialized, error_2;
|
|
267
|
+
var query, variables, auth, _a, data, extensions, _b, key_2, flattenedResult, _c, initialized, error_2;
|
|
260
268
|
return tslib_1.__generator(this, function (_d) {
|
|
261
269
|
switch (_d.label) {
|
|
262
270
|
case 0:
|
|
@@ -265,10 +273,8 @@ function generateModelsProperty(client, params) {
|
|
|
265
273
|
_d.label = 1;
|
|
266
274
|
case 1:
|
|
267
275
|
_d.trys.push([1, 3, , 4]);
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
variables: variables,
|
|
271
|
-
})];
|
|
276
|
+
auth = authModeParams(client, options);
|
|
277
|
+
return [4 /*yield*/, client.graphql(tslib_1.__assign(tslib_1.__assign({}, auth), { query: query, variables: variables }))];
|
|
272
278
|
case 2:
|
|
273
279
|
_a = (_d.sent()), data = _a.data, extensions = _a.extensions;
|
|
274
280
|
// flatten response
|
|
@@ -279,7 +285,7 @@ function generateModelsProperty(client, params) {
|
|
|
279
285
|
return [2 /*return*/, { data: flattenedResult, extensions: extensions }];
|
|
280
286
|
}
|
|
281
287
|
else {
|
|
282
|
-
_c = tslib_1.__read((0, APIClient_1.initializeModel)(client, name_1, [flattenedResult], modelIntrospection), 1), initialized = _c[0];
|
|
288
|
+
_c = tslib_1.__read((0, APIClient_1.initializeModel)(client, name_1, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken), 1), initialized = _c[0];
|
|
283
289
|
return [2 /*return*/, { data: initialized, extensions: extensions }];
|
|
284
290
|
}
|
|
285
291
|
}
|
package/lib/internals/types.d.ts
CHANGED
|
@@ -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
|
};
|