@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
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');
|
|
@@ -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";
|
|
@@ -31,7 +31,7 @@ export var flattenItems = function (obj) {
|
|
|
31
31
|
return res;
|
|
32
32
|
};
|
|
33
33
|
// TODO: this should accept single result to support CRUD methods; create helper for array/list
|
|
34
|
-
export function initializeModel(client, modelName, result, modelIntrospection) {
|
|
34
|
+
export function initializeModel(client, modelName, result, modelIntrospection, authMode, authToken) {
|
|
35
35
|
var introModel = modelIntrospection.models[modelName];
|
|
36
36
|
var introModelFields = introModel.fields;
|
|
37
37
|
var modelFields = Object.entries(introModelFields)
|
|
@@ -64,10 +64,13 @@ export function initializeModel(client, modelName, result, modelIntrospection) {
|
|
|
64
64
|
return (acc[curVal] = record[curVal]);
|
|
65
65
|
}
|
|
66
66
|
}, {});
|
|
67
|
-
initializedRelationalFields[field] = function () {
|
|
67
|
+
initializedRelationalFields[field] = function (options) {
|
|
68
68
|
var _a;
|
|
69
69
|
if (record[targetNames[0]]) {
|
|
70
|
-
return client.models[relatedModelName].get(__assign((_a = {}, _a[relatedModelPKFieldName] = record[targetNames[0]], _a), sortKeyValues_1)
|
|
70
|
+
return client.models[relatedModelName].get(__assign((_a = {}, _a[relatedModelPKFieldName] = record[targetNames[0]], _a), sortKeyValues_1), {
|
|
71
|
+
authMode: (options === null || options === void 0 ? void 0 : options.authMode) || authMode,
|
|
72
|
+
authToken: (options === null || options === void 0 ? void 0 : options.authToken) || authToken,
|
|
73
|
+
});
|
|
71
74
|
}
|
|
72
75
|
return undefined;
|
|
73
76
|
};
|
|
@@ -85,10 +88,12 @@ export function initializeModel(client, modelName, result, modelIntrospection) {
|
|
|
85
88
|
}
|
|
86
89
|
return _b = {}, _b[field] = { eq: record[parentSK_1[idx - 1]] }, _b;
|
|
87
90
|
});
|
|
88
|
-
initializedRelationalFields[field] = function () {
|
|
91
|
+
initializedRelationalFields[field] = function (options) {
|
|
89
92
|
if (record[parentPk_1]) {
|
|
90
93
|
return client.models[relatedModelName].list({
|
|
91
94
|
filter: { and: hasManyFilter_1 },
|
|
95
|
+
authMode: (options === null || options === void 0 ? void 0 : options.authMode) || authMode,
|
|
96
|
+
authToken: (options === null || options === void 0 ? void 0 : options.authToken) || authToken,
|
|
92
97
|
});
|
|
93
98
|
}
|
|
94
99
|
return [];
|
|
@@ -102,10 +107,12 @@ export function initializeModel(client, modelName, result, modelIntrospection) {
|
|
|
102
107
|
}
|
|
103
108
|
return _b = {}, _b[field] = { eq: record[parentSK_1[idx - 1]] }, _b;
|
|
104
109
|
});
|
|
105
|
-
initializedRelationalFields[field] = function () {
|
|
110
|
+
initializedRelationalFields[field] = function (options) {
|
|
106
111
|
if (record[parentPk_1]) {
|
|
107
112
|
return client.models[relatedModelName].list({
|
|
108
113
|
filter: { and: hasManyFilter_2 },
|
|
114
|
+
authMode: (options === null || options === void 0 ? void 0 : options.authMode) || authMode,
|
|
115
|
+
authToken: (options === null || options === void 0 ? void 0 : options.authToken) || authToken,
|
|
109
116
|
});
|
|
110
117
|
}
|
|
111
118
|
return [];
|
|
@@ -303,7 +303,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
303
303
|
variables: variables,
|
|
304
304
|
appSyncGraphqlEndpoint: config === null || config === void 0 ? void 0 : config.endpoint,
|
|
305
305
|
region: config === null || config === void 0 ? void 0 : config.region,
|
|
306
|
-
authenticationType: config === null || config === void 0 ? void 0 : config.defaultAuthMode,
|
|
306
|
+
authenticationType: authMode || (config === null || config === void 0 ? void 0 : config.defaultAuthMode),
|
|
307
307
|
apiKey: config === null || config === void 0 ? void 0 : config.apiKey,
|
|
308
308
|
additionalHeaders: additionalHeaders,
|
|
309
309
|
}, customUserAgentDetails);
|
|
@@ -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, _a, data, extensions, _b, key_1, flattenedResult, initialized, error_1;
|
|
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,10 +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
|
-
variables: variables,
|
|
35
|
-
})];
|
|
49
|
+
auth = authModeParams(client, args);
|
|
50
|
+
return [4 /*yield*/, client.graphql(__assign(__assign({}, auth), { query: query, variables: variables }))];
|
|
36
51
|
case 2:
|
|
37
52
|
_a = (_c.sent()), data = _a.data, extensions = _a.extensions;
|
|
38
53
|
// flatten response
|
|
@@ -49,7 +64,7 @@ export function generateModelsProperty(client, params) {
|
|
|
49
64
|
}];
|
|
50
65
|
}
|
|
51
66
|
else {
|
|
52
|
-
initialized = initializeModel(client, name_1, flattenedResult, modelIntrospection);
|
|
67
|
+
initialized = initializeModel(client, name_1, flattenedResult, modelIntrospection, auth.authMode, auth.authToken);
|
|
53
68
|
return [2 /*return*/, {
|
|
54
69
|
data: initialized,
|
|
55
70
|
nextToken: data[key_1].nextToken,
|
|
@@ -81,21 +96,20 @@ export function generateModelsProperty(client, params) {
|
|
|
81
96
|
}); };
|
|
82
97
|
}
|
|
83
98
|
else if (['ONCREATE', 'ONUPDATE', 'ONDELETE'].includes(operation)) {
|
|
84
|
-
models[name_1][operationPrefix] = function (
|
|
99
|
+
models[name_1][operationPrefix] = function (args) {
|
|
85
100
|
var query = generateGraphQLDocument(modelIntrospection.models, name_1, operation);
|
|
86
|
-
var variables = buildGraphQLVariables(model, operation,
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
variables: variables,
|
|
90
|
-
});
|
|
101
|
+
var variables = buildGraphQLVariables(model, operation, args, modelIntrospection);
|
|
102
|
+
var auth = authModeParams(client, args);
|
|
103
|
+
var observable = client.graphql(__assign(__assign({}, auth), { query: query, variables: variables }));
|
|
91
104
|
return observable.pipe(map(function (value) {
|
|
92
105
|
var _a = __read(Object.keys(value.data), 1), key = _a[0];
|
|
93
|
-
|
|
106
|
+
var _b = __read(initializeModel(client, name_1, [value.data[key]], modelIntrospection, auth.authMode, auth.authToken), 1), initialized = _b[0];
|
|
107
|
+
return initialized;
|
|
94
108
|
}));
|
|
95
109
|
};
|
|
96
110
|
}
|
|
97
111
|
else if (operation === 'OBSERVE_QUERY') {
|
|
98
|
-
models[name_1][operationPrefix] = function (arg
|
|
112
|
+
models[name_1][operationPrefix] = function (arg) {
|
|
99
113
|
return new Observable(function (subscriber) {
|
|
100
114
|
// what we'll be sending to our subscribers
|
|
101
115
|
var items = [];
|
|
@@ -113,9 +127,7 @@ export function generateModelsProperty(client, params) {
|
|
|
113
127
|
return messageQueue.push.apply(messageQueue, __spreadArray([], __read(messages), false));
|
|
114
128
|
};
|
|
115
129
|
// start subscriptions
|
|
116
|
-
var onCreateSub = models[name_1]
|
|
117
|
-
.onCreate(arg, options)
|
|
118
|
-
.subscribe({
|
|
130
|
+
var onCreateSub = models[name_1].onCreate(arg).subscribe({
|
|
119
131
|
next: function (item) {
|
|
120
132
|
receiveMessages({ item: item, type: 'create' });
|
|
121
133
|
},
|
|
@@ -123,9 +135,7 @@ export function generateModelsProperty(client, params) {
|
|
|
123
135
|
subscriber.error({ type: 'onCreate', error: error });
|
|
124
136
|
},
|
|
125
137
|
});
|
|
126
|
-
var onUpdateSub = models[name_1]
|
|
127
|
-
.onUpdate(arg, options)
|
|
128
|
-
.subscribe({
|
|
138
|
+
var onUpdateSub = models[name_1].onUpdate(arg).subscribe({
|
|
129
139
|
next: function (item) {
|
|
130
140
|
receiveMessages({ item: item, type: 'update' });
|
|
131
141
|
},
|
|
@@ -133,9 +143,7 @@ export function generateModelsProperty(client, params) {
|
|
|
133
143
|
subscriber.error({ type: 'onUpdate', error: error });
|
|
134
144
|
},
|
|
135
145
|
});
|
|
136
|
-
var onDeleteSub = models[name_1]
|
|
137
|
-
.onDelete(arg, options)
|
|
138
|
-
.subscribe({
|
|
146
|
+
var onDeleteSub = models[name_1].onDelete(arg).subscribe({
|
|
139
147
|
next: function (item) {
|
|
140
148
|
receiveMessages({ item: item, type: 'delete' });
|
|
141
149
|
},
|
|
@@ -194,7 +202,7 @@ export function generateModelsProperty(client, params) {
|
|
|
194
202
|
case 1:
|
|
195
203
|
if (!(!subscriber.closed && (firstPage || nextToken))) return [3 /*break*/, 3];
|
|
196
204
|
firstPage = false;
|
|
197
|
-
return [4 /*yield*/, models[name_1].list(__assign(__assign({}, arg), { nextToken: nextToken })
|
|
205
|
+
return [4 /*yield*/, models[name_1].list(__assign(__assign({}, arg), { nextToken: nextToken }))];
|
|
198
206
|
case 2:
|
|
199
207
|
_a = _c.sent(), page = _a.data, errors = _a.errors, _nextToken = _a.nextToken;
|
|
200
208
|
nextToken = _nextToken;
|
|
@@ -253,7 +261,7 @@ export function generateModelsProperty(client, params) {
|
|
|
253
261
|
}
|
|
254
262
|
else {
|
|
255
263
|
models[name_1][operationPrefix] = function (arg, options) { return __awaiter(_this, void 0, void 0, function () {
|
|
256
|
-
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;
|
|
257
265
|
return __generator(this, function (_d) {
|
|
258
266
|
switch (_d.label) {
|
|
259
267
|
case 0:
|
|
@@ -262,10 +270,8 @@ export function generateModelsProperty(client, params) {
|
|
|
262
270
|
_d.label = 1;
|
|
263
271
|
case 1:
|
|
264
272
|
_d.trys.push([1, 3, , 4]);
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
variables: variables,
|
|
268
|
-
})];
|
|
273
|
+
auth = authModeParams(client, options);
|
|
274
|
+
return [4 /*yield*/, client.graphql(__assign(__assign({}, auth), { query: query, variables: variables }))];
|
|
269
275
|
case 2:
|
|
270
276
|
_a = (_d.sent()), data = _a.data, extensions = _a.extensions;
|
|
271
277
|
// flatten response
|
|
@@ -276,7 +282,7 @@ export function generateModelsProperty(client, params) {
|
|
|
276
282
|
return [2 /*return*/, { data: flattenedResult, extensions: extensions }];
|
|
277
283
|
}
|
|
278
284
|
else {
|
|
279
|
-
_c = __read(initializeModel(client, name_1, [flattenedResult], modelIntrospection), 1), initialized = _c[0];
|
|
285
|
+
_c = __read(initializeModel(client, name_1, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken), 1), initialized = _c[0];
|
|
280
286
|
return [2 /*return*/, { data: initialized, extensions: extensions }];
|
|
281
287
|
}
|
|
282
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
|
};
|