@aws-amplify/api 5.3.4-api-v6.29 → 5.3.4-api-v6-models.34

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/API.js CHANGED
@@ -5,6 +5,11 @@ var tslib_1 = require("tslib");
5
5
  var internals_1 = require("@aws-amplify/api-graphql/internals");
6
6
  var core_1 = require("@aws-amplify/core");
7
7
  var InternalAPI_1 = require("./internals/InternalAPI");
8
+ var APIClient_1 = require("./APIClient");
9
+ /*
10
+ await post.comments()
11
+ => await graphql()
12
+ */
8
13
  var logger = new core_1.ConsoleLogger('API');
9
14
  /**
10
15
  * @deprecated
@@ -37,38 +42,76 @@ var APIClass = /** @class */ (function (_super) {
37
42
  var _loop_1 = function (model) {
38
43
  var name_1 = model.name;
39
44
  client.models[name_1] = {};
40
- Object.entries(graphQLOperationsInfo).forEach(function (_a) {
45
+ Object.entries(APIClient_1.graphQLOperationsInfo).forEach(function (_a) {
41
46
  var _b = tslib_1.__read(_a, 2), key = _b[0], operationPrefix = _b[1].operationPrefix;
42
47
  var operation = key;
43
- // e.g. clients.models.Todo.update
44
- client.models[name_1][operationPrefix] = function (arg) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
45
- var query, variables, res, _a, key_1;
46
- return tslib_1.__generator(this, function (_b) {
47
- switch (_b.label) {
48
- case 0:
49
- query = generateGraphQLDocument(model, operation);
50
- variables = buildGraphQLVariables(model, operation, arg);
51
- return [4 /*yield*/, this.graphql({
52
- query: query,
53
- variables: variables,
54
- })];
55
- case 1:
56
- res = (_b.sent());
57
- // flatten response
58
- if (res.data !== undefined) {
59
- _a = tslib_1.__read(Object.keys(res.data), 1), key_1 = _a[0];
60
- if (res.data[key_1].items) {
61
- return [2 /*return*/, res.data[key_1].items];
48
+ if (operation === 'LIST') {
49
+ client.models[name_1][operationPrefix] = function (args) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
50
+ var query, variables, res, _a, key_1, flattenedResult, initialized;
51
+ return tslib_1.__generator(this, function (_b) {
52
+ switch (_b.label) {
53
+ case 0:
54
+ query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection.models, name_1, 'LIST', args);
55
+ variables = (0, APIClient_1.buildGraphQLVariables)(model, 'LIST', args);
56
+ console.log('API list', query, variables);
57
+ return [4 /*yield*/, this.graphql({
58
+ query: query,
59
+ variables: variables,
60
+ })];
61
+ case 1:
62
+ res = (_b.sent());
63
+ // flatten response
64
+ if (res.data !== undefined) {
65
+ _a = tslib_1.__read(Object.keys(res.data), 1), key_1 = _a[0];
66
+ if (res.data[key_1].items) {
67
+ flattenedResult = res.data[key_1].items;
68
+ // don't init if custom selection set
69
+ if (args === null || args === void 0 ? void 0 : args.selectionSet) {
70
+ return [2 /*return*/, flattenedResult];
71
+ }
72
+ else {
73
+ initialized = (0, APIClient_1.initializeModel)(client, name_1, flattenedResult, modelIntrospection);
74
+ return [2 /*return*/, initialized];
75
+ }
76
+ }
77
+ return [2 /*return*/, res.data[key_1]];
62
78
  }
63
- return [2 /*return*/, res.data[key_1]];
64
- }
65
- return [2 /*return*/, res];
66
- }
67
- });
68
- }); };
79
+ return [2 /*return*/, res];
80
+ }
81
+ });
82
+ }); };
83
+ }
84
+ else {
85
+ client.models[name_1][operationPrefix] = function (arg, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
86
+ var query, variables, res, _a, key_2, _b, initialized;
87
+ return tslib_1.__generator(this, function (_c) {
88
+ switch (_c.label) {
89
+ case 0:
90
+ query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection.models, name_1, operation);
91
+ variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, arg);
92
+ console.log("API ".concat(operationPrefix), query, variables);
93
+ return [4 /*yield*/, this.graphql({
94
+ query: query,
95
+ variables: variables,
96
+ })];
97
+ case 1:
98
+ res = (_c.sent());
99
+ // flatten response
100
+ if (res.data !== undefined) {
101
+ _a = tslib_1.__read(Object.keys(res.data), 1), key_2 = _a[0];
102
+ _b = tslib_1.__read((0, APIClient_1.initializeModel)(client, name_1, [res.data[key_2]], modelIntrospection), 1), initialized = _b[0];
103
+ return [2 /*return*/, initialized];
104
+ }
105
+ return [2 /*return*/, res];
106
+ }
107
+ });
108
+ }); };
109
+ }
69
110
  });
70
111
  };
71
112
  try {
113
+ // TODO: refactor this to use separate methods for each CRUDL.
114
+ // Doesn't make sense to gen the methods dynamically given the different args and return values
72
115
  for (var _b = tslib_1.__values(Object.values(modelIntrospection.models)), _c = _b.next(); !_c.done; _c = _b.next()) {
73
116
  var model = _c.value;
74
117
  _loop_1(model);
@@ -86,109 +129,5 @@ var APIClass = /** @class */ (function (_super) {
86
129
  return APIClass;
87
130
  }(InternalAPI_1.InternalAPIClass));
88
131
  exports.APIClass = APIClass;
89
- var graphQLOperationsInfo = {
90
- CREATE: { operationPrefix: 'create', usePlural: false },
91
- READ: { operationPrefix: 'get', usePlural: false },
92
- UPDATE: { operationPrefix: 'update', usePlural: false },
93
- DELETE: { operationPrefix: 'delete', usePlural: false },
94
- LIST: { operationPrefix: 'list', usePlural: true },
95
- };
96
- var graphQLDocumentsCache = new Map();
97
- function generateGraphQLDocument(modelDefinition, modelOperation) {
98
- var _a;
99
- var _b, _c;
100
- var name = modelDefinition.name, pluralName = modelDefinition.pluralName, fields = modelDefinition.fields, _d = modelDefinition.primaryKeyInfo, isCustomPrimaryKey = _d.isCustomPrimaryKey, primaryKeyFieldName = _d.primaryKeyFieldName, sortKeyFieldNames = _d.sortKeyFieldNames;
101
- var _e = graphQLOperationsInfo[modelOperation], operationPrefix = _e.operationPrefix, usePlural = _e.usePlural;
102
- var fromCache = (_b = graphQLDocumentsCache.get(name)) === null || _b === void 0 ? void 0 : _b.get(modelOperation);
103
- if (fromCache !== undefined) {
104
- return fromCache;
105
- }
106
- if (!graphQLDocumentsCache.has(name)) {
107
- graphQLDocumentsCache.set(name, new Map());
108
- }
109
- var graphQLFieldName = "".concat(operationPrefix).concat(usePlural ? pluralName : name);
110
- var graphQLOperationType;
111
- var graphQLSelectionSet;
112
- var graphQLArguments;
113
- var selectionSetFields = Object.values(fields)
114
- .map(function (_a) {
115
- var type = _a.type, name = _a.name;
116
- return typeof type === 'string' && name;
117
- }) // Only scalars for now
118
- .filter(Boolean)
119
- .join(' ');
120
- switch (modelOperation) {
121
- case 'CREATE':
122
- case 'UPDATE':
123
- case 'DELETE':
124
- graphQLArguments !== null && graphQLArguments !== void 0 ? graphQLArguments : (graphQLArguments = {
125
- input: "".concat(operationPrefix.charAt(0).toLocaleUpperCase() +
126
- operationPrefix.slice(1)).concat(name, "Input!"),
127
- });
128
- graphQLOperationType !== null && graphQLOperationType !== void 0 ? graphQLOperationType : (graphQLOperationType = 'mutation');
129
- case 'READ':
130
- graphQLArguments !== null && graphQLArguments !== void 0 ? graphQLArguments : (graphQLArguments = isCustomPrimaryKey
131
- ? tslib_1.__spreadArray([primaryKeyFieldName], tslib_1.__read(sortKeyFieldNames), false).reduce(function (acc, fieldName) {
132
- acc[fieldName] = fields[fieldName].type;
133
- return acc;
134
- }, {})
135
- : (_a = {},
136
- _a[primaryKeyFieldName] = "".concat(fields[primaryKeyFieldName].type, "!"),
137
- _a));
138
- graphQLSelectionSet !== null && graphQLSelectionSet !== void 0 ? graphQLSelectionSet : (graphQLSelectionSet = selectionSetFields);
139
- case 'LIST':
140
- graphQLOperationType !== null && graphQLOperationType !== void 0 ? graphQLOperationType : (graphQLOperationType = 'query');
141
- graphQLSelectionSet !== null && graphQLSelectionSet !== void 0 ? graphQLSelectionSet : (graphQLSelectionSet = "items { ".concat(selectionSetFields, " }"));
142
- }
143
- var graphQLDocument = "".concat(graphQLOperationType).concat(graphQLArguments
144
- ? "(".concat(Object.entries(graphQLArguments).map(function (_a) {
145
- var _b = tslib_1.__read(_a, 2), fieldName = _b[0], type = _b[1];
146
- return "$".concat(fieldName, ": ").concat(type);
147
- }), ")")
148
- : '', " { ").concat(graphQLFieldName).concat(graphQLArguments
149
- ? "(".concat(Object.keys(graphQLArguments).map(function (fieldName) { return "".concat(fieldName, ": $").concat(fieldName); }), ")")
150
- : '', " { ").concat(graphQLSelectionSet, " } }");
151
- (_c = graphQLDocumentsCache.get(name)) === null || _c === void 0 ? void 0 : _c.set(modelOperation, graphQLDocument);
152
- return graphQLDocument;
153
- }
154
- function buildGraphQLVariables(modelDefinition, operation, arg) {
155
- var _a;
156
- var fields = modelDefinition.fields, _b = modelDefinition.primaryKeyInfo, isCustomPrimaryKey = _b.isCustomPrimaryKey, primaryKeyFieldName = _b.primaryKeyFieldName, sortKeyFieldNames = _b.sortKeyFieldNames;
157
- var variables = {};
158
- switch (operation) {
159
- case 'CREATE':
160
- variables = { input: arg };
161
- break;
162
- case 'UPDATE':
163
- // readonly fields are not updated
164
- variables = {
165
- input: Object.fromEntries(Object.entries(arg).filter(function (_a) {
166
- var _b = tslib_1.__read(_a, 1), fieldName = _b[0];
167
- var isReadOnly = fields[fieldName].isReadOnly;
168
- return !isReadOnly;
169
- })),
170
- };
171
- break;
172
- case 'READ':
173
- case 'DELETE':
174
- // only identifiers are sent
175
- variables = isCustomPrimaryKey
176
- ? tslib_1.__spreadArray([primaryKeyFieldName], tslib_1.__read(sortKeyFieldNames), false).reduce(function (acc, fieldName) {
177
- acc[fieldName] = arg[fieldName];
178
- return acc;
179
- }, {})
180
- : (_a = {}, _a[primaryKeyFieldName] = arg[primaryKeyFieldName], _a);
181
- if (operation === 'DELETE') {
182
- variables = { input: variables };
183
- }
184
- break;
185
- case 'LIST':
186
- break;
187
- default:
188
- var exhaustiveCheck = operation;
189
- throw new Error("Unhandled operation case: ".concat(exhaustiveCheck));
190
- }
191
- return variables;
192
- }
193
132
  exports.API = new APIClass(null);
194
133
  core_1.Amplify.register(exports.API);
@@ -0,0 +1,31 @@
1
+ type ListArgs = {
2
+ selectionSet?: string[];
3
+ filter?: {};
4
+ };
5
+ export declare function initializeModel(client: any, modelName: string, result: any[], modelIntrospection: any): any[];
6
+ export declare const graphQLOperationsInfo: {
7
+ CREATE: {
8
+ operationPrefix: "create";
9
+ usePlural: boolean;
10
+ };
11
+ READ: {
12
+ operationPrefix: "get";
13
+ usePlural: boolean;
14
+ };
15
+ UPDATE: {
16
+ operationPrefix: "update";
17
+ usePlural: boolean;
18
+ };
19
+ DELETE: {
20
+ operationPrefix: "delete";
21
+ usePlural: boolean;
22
+ };
23
+ LIST: {
24
+ operationPrefix: "list";
25
+ usePlural: boolean;
26
+ };
27
+ };
28
+ export type ModelOperation = keyof typeof graphQLOperationsInfo;
29
+ export declare function generateGraphQLDocument(modelIntrospection: any, modelName: string, modelOperation: ModelOperation, listArgs?: ListArgs): string;
30
+ export declare function buildGraphQLVariables(modelDefinition: any, operation: ModelOperation, arg: any): object;
31
+ export {};
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.buildGraphQLVariables = exports.generateGraphQLDocument = exports.graphQLOperationsInfo = exports.initializeModel = void 0;
6
+ var tslib_1 = require("tslib");
7
+ // TODO: this should accept single result to support CRUD methods; create helper for array/list
8
+ function initializeModel(client, modelName, result, modelIntrospection) {
9
+ var _this = this;
10
+ var introModel = modelIntrospection.models[modelName];
11
+ var introModelFields = introModel.fields;
12
+ var modelFields = Object.entries(introModelFields)
13
+ .filter(function (_a) {
14
+ var _b = tslib_1.__read(_a, 2), _ = _b[0], field = _b[1];
15
+ return typeof field.type !== 'string';
16
+ })
17
+ .map(function (_a) {
18
+ var _b = tslib_1.__read(_a, 1), fieldName = _b[0];
19
+ return fieldName;
20
+ });
21
+ return result.map(function (record) {
22
+ var e_1, _a;
23
+ var initialized = {};
24
+ var _loop_1 = function (field) {
25
+ var relatedModel = introModelFields[field].type.model;
26
+ var connectionField = introModelFields[field].association.associatedWith;
27
+ // TODO: support sort key
28
+ var parentPk = introModel.primaryKeyInfo.primaryKeyFieldName;
29
+ initialized[field] = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
30
+ var _a;
31
+ return tslib_1.__generator(this, function (_b) {
32
+ return [2 /*return*/, client.models[relatedModel].list({
33
+ filter: (_a = {}, _a[connectionField] = { eq: record[parentPk] }, _a),
34
+ })];
35
+ });
36
+ }); };
37
+ };
38
+ try {
39
+ for (var modelFields_1 = tslib_1.__values(modelFields), modelFields_1_1 = modelFields_1.next(); !modelFields_1_1.done; modelFields_1_1 = modelFields_1.next()) {
40
+ var field = modelFields_1_1.value;
41
+ _loop_1(field);
42
+ }
43
+ }
44
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
45
+ finally {
46
+ try {
47
+ if (modelFields_1_1 && !modelFields_1_1.done && (_a = modelFields_1.return)) _a.call(modelFields_1);
48
+ }
49
+ finally { if (e_1) throw e_1.error; }
50
+ }
51
+ return tslib_1.__assign(tslib_1.__assign({}, record), initialized);
52
+ });
53
+ }
54
+ exports.initializeModel = initializeModel;
55
+ exports.graphQLOperationsInfo = {
56
+ CREATE: { operationPrefix: 'create', usePlural: false },
57
+ READ: { operationPrefix: 'get', usePlural: false },
58
+ UPDATE: { operationPrefix: 'update', usePlural: false },
59
+ DELETE: { operationPrefix: 'delete', usePlural: false },
60
+ LIST: { operationPrefix: 'list', usePlural: true },
61
+ };
62
+ var graphQLDocumentsCache = new Map();
63
+ var SELECTION_SET_ALL_NESTED = '*';
64
+ function defaultSelectionSetForModel(modelDefinition) {
65
+ var fields = modelDefinition.fields;
66
+ return Object.values(fields)
67
+ .map(function (_a) {
68
+ var type = _a.type, name = _a.name;
69
+ return typeof type === 'string' && name;
70
+ }) // Default selection set omits model fields
71
+ .filter(Boolean)
72
+ .join(' ');
73
+ }
74
+ function generateSelectionSet(modelIntrospection, modelName, selectionSet) {
75
+ var e_2, _a;
76
+ var _b, _c, _d;
77
+ var modelDefinition = modelIntrospection[modelName];
78
+ var fields = modelDefinition.fields;
79
+ if (!selectionSet) {
80
+ return defaultSelectionSetForModel(modelDefinition);
81
+ }
82
+ var selSet = [];
83
+ try {
84
+ for (var selectionSet_1 = tslib_1.__values(selectionSet), selectionSet_1_1 = selectionSet_1.next(); !selectionSet_1_1.done; selectionSet_1_1 = selectionSet_1.next()) {
85
+ var f = selectionSet_1_1.value;
86
+ var nested = f.includes('.');
87
+ if (nested) {
88
+ var _e = tslib_1.__read(f.split('.'), 2), modelFieldName = _e[0], selectedField = _e[1];
89
+ var relatedModel = (_c = (_b = fields[modelFieldName]) === null || _b === void 0 ? void 0 : _b.type) === null || _c === void 0 ? void 0 : _c.model;
90
+ if (!relatedModel) {
91
+ // TODO: may need to change this to support custom types
92
+ throw Error("".concat(modelFieldName, " is not a model field"));
93
+ }
94
+ if (selectedField === SELECTION_SET_ALL_NESTED) {
95
+ var relatedModelDefinition = modelIntrospection[relatedModel];
96
+ var defaultSelectionSet = defaultSelectionSetForModel(relatedModelDefinition);
97
+ if ((_d = fields[modelFieldName]) === null || _d === void 0 ? void 0 : _d.isArray) {
98
+ selSet.push("".concat(modelFieldName, " { items { ").concat(defaultSelectionSet, " } }"));
99
+ }
100
+ else {
101
+ selSet.push("".concat(modelFieldName, " { ").concat(defaultSelectionSet, " }"));
102
+ }
103
+ }
104
+ }
105
+ else {
106
+ var exists = Boolean(fields[f]);
107
+ if (!exists) {
108
+ throw Error("".concat(f, " is not a field of model ").concat(modelName));
109
+ }
110
+ selSet.push(f);
111
+ }
112
+ }
113
+ }
114
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
115
+ finally {
116
+ try {
117
+ if (selectionSet_1_1 && !selectionSet_1_1.done && (_a = selectionSet_1.return)) _a.call(selectionSet_1);
118
+ }
119
+ finally { if (e_2) throw e_2.error; }
120
+ }
121
+ return selSet.join(' ');
122
+ }
123
+ function generateGraphQLDocument(modelIntrospection, modelName, modelOperation, listArgs) {
124
+ var _a;
125
+ var _b, _c;
126
+ var modelDefinition = modelIntrospection[modelName];
127
+ var name = modelDefinition.name, pluralName = modelDefinition.pluralName, fields = modelDefinition.fields, _d = modelDefinition.primaryKeyInfo, isCustomPrimaryKey = _d.isCustomPrimaryKey, primaryKeyFieldName = _d.primaryKeyFieldName, sortKeyFieldNames = _d.sortKeyFieldNames;
128
+ var _e = exports.graphQLOperationsInfo[modelOperation], operationPrefix = _e.operationPrefix, usePlural = _e.usePlural;
129
+ var selectionSet = (listArgs || {}).selectionSet;
130
+ var fromCache = (_b = graphQLDocumentsCache.get(name)) === null || _b === void 0 ? void 0 : _b.get(modelOperation);
131
+ if (fromCache !== undefined) {
132
+ return fromCache;
133
+ }
134
+ if (!graphQLDocumentsCache.has(name)) {
135
+ graphQLDocumentsCache.set(name, new Map());
136
+ }
137
+ var graphQLFieldName = "".concat(operationPrefix).concat(usePlural ? pluralName : name);
138
+ var graphQLOperationType;
139
+ var graphQLSelectionSet;
140
+ var graphQLArguments;
141
+ var selectionSetFields = generateSelectionSet(modelIntrospection, modelName, selectionSet);
142
+ console.log('generated sel set', selectionSetFields);
143
+ switch (modelOperation) {
144
+ case 'CREATE':
145
+ case 'UPDATE':
146
+ case 'DELETE':
147
+ graphQLArguments !== null && graphQLArguments !== void 0 ? graphQLArguments : (graphQLArguments = {
148
+ input: "".concat(operationPrefix.charAt(0).toLocaleUpperCase() +
149
+ operationPrefix.slice(1)).concat(name, "Input!"),
150
+ });
151
+ graphQLOperationType !== null && graphQLOperationType !== void 0 ? graphQLOperationType : (graphQLOperationType = 'mutation');
152
+ case 'READ':
153
+ graphQLArguments !== null && graphQLArguments !== void 0 ? graphQLArguments : (graphQLArguments = isCustomPrimaryKey
154
+ ? tslib_1.__spreadArray([primaryKeyFieldName], tslib_1.__read(sortKeyFieldNames), false).reduce(function (acc, fieldName) {
155
+ acc[fieldName] = fields[fieldName].type;
156
+ return acc;
157
+ }, {})
158
+ : (_a = {},
159
+ _a[primaryKeyFieldName] = "".concat(fields[primaryKeyFieldName].type, "!"),
160
+ _a));
161
+ graphQLSelectionSet !== null && graphQLSelectionSet !== void 0 ? graphQLSelectionSet : (graphQLSelectionSet = selectionSetFields);
162
+ case 'LIST':
163
+ graphQLArguments !== null && graphQLArguments !== void 0 ? graphQLArguments : (graphQLArguments = {
164
+ filter: "Model".concat(name, "FilterInput"),
165
+ });
166
+ graphQLOperationType !== null && graphQLOperationType !== void 0 ? graphQLOperationType : (graphQLOperationType = 'query');
167
+ graphQLSelectionSet !== null && graphQLSelectionSet !== void 0 ? graphQLSelectionSet : (graphQLSelectionSet = "items { ".concat(selectionSetFields, " }"));
168
+ }
169
+ var graphQLDocument = "".concat(graphQLOperationType).concat(graphQLArguments
170
+ ? "(".concat(Object.entries(graphQLArguments).map(function (_a) {
171
+ var _b = tslib_1.__read(_a, 2), fieldName = _b[0], type = _b[1];
172
+ return "$".concat(fieldName, ": ").concat(type);
173
+ }), ")")
174
+ : '', " { ").concat(graphQLFieldName).concat(graphQLArguments
175
+ ? "(".concat(Object.keys(graphQLArguments).map(function (fieldName) { return "".concat(fieldName, ": $").concat(fieldName); }), ")")
176
+ : '', " { ").concat(graphQLSelectionSet, " } }");
177
+ (_c = graphQLDocumentsCache.get(name)) === null || _c === void 0 ? void 0 : _c.set(modelOperation, graphQLDocument);
178
+ return graphQLDocument;
179
+ }
180
+ exports.generateGraphQLDocument = generateGraphQLDocument;
181
+ function buildGraphQLVariables(modelDefinition, operation, arg) {
182
+ var _a;
183
+ var fields = modelDefinition.fields, _b = modelDefinition.primaryKeyInfo, isCustomPrimaryKey = _b.isCustomPrimaryKey, primaryKeyFieldName = _b.primaryKeyFieldName, sortKeyFieldNames = _b.sortKeyFieldNames;
184
+ var variables = {};
185
+ // TODO: process input
186
+ switch (operation) {
187
+ case 'CREATE':
188
+ variables = { input: arg };
189
+ break;
190
+ case 'UPDATE':
191
+ // readonly fields are not updated
192
+ variables = {
193
+ input: Object.fromEntries(Object.entries(arg).filter(function (_a) {
194
+ var _b = tslib_1.__read(_a, 1), fieldName = _b[0];
195
+ var isReadOnly = fields[fieldName].isReadOnly;
196
+ return !isReadOnly;
197
+ })),
198
+ };
199
+ break;
200
+ case 'READ':
201
+ case 'DELETE':
202
+ // only identifiers are sent
203
+ variables = isCustomPrimaryKey
204
+ ? tslib_1.__spreadArray([primaryKeyFieldName], tslib_1.__read(sortKeyFieldNames), false).reduce(function (acc, fieldName) {
205
+ acc[fieldName] = arg[fieldName];
206
+ return acc;
207
+ }, {})
208
+ : (_a = {}, _a[primaryKeyFieldName] = arg[primaryKeyFieldName], _a);
209
+ if (operation === 'DELETE') {
210
+ variables = { input: variables };
211
+ }
212
+ break;
213
+ case 'LIST':
214
+ if (arg === null || arg === void 0 ? void 0 : arg.filter) {
215
+ variables = { filter: arg.filter };
216
+ }
217
+ break;
218
+ default:
219
+ var exhaustiveCheck = operation;
220
+ throw new Error("Unhandled operation case: ".concat(exhaustiveCheck));
221
+ }
222
+ return variables;
223
+ }
224
+ exports.buildGraphQLVariables = buildGraphQLVariables;