@@ -27385,19 +27385,21 @@ var Transformer = /** @class */ (function () {
27385
27385
*
27386
27386
* @param model
27387
27387
* @param {Data} data
27388
+ * @param {Array<String>} whitelist of fields
27388
27389
* @returns {Data}
27389
27390
*/
27390
- Transformer.transformOutgoingData = function (model, data) {
27391
+ Transformer.transformOutgoingData = function (model, data, whitelist ) {
27391
27392
var _this = this;
27392
27393
var context = Context.getInstance();
27393
27394
var relations = model.getRelations();
27394
27395
var returnValue = {};
27395
27396
Object.keys(data).forEach(function (key) {
27396
27397
var value = data[key];
27397
- // Ignore hasMany/One connections, empty fields and internal fields ($)
27398
- if ((!relations.has(key) || relations.get(key) instanceof context.components.BelongsTo) &&
27399
- !key.startsWith('$') && value !== null) {
27400
- var relatedModel = relations.get(key)
27398
+ // Always add fields on the whitelist. Ignore hasMany/One connections, empty fields and internal fields ($)
27399
+ if ((whitelist && whitelist.includes(key)) ||
27400
+ ((!relations.has(key) || relations.get(key) instanceof context.components.BelongsTo) &&
27401
+ !key.startsWith('$') && value !== null)) {
27402
+ var relatedModel = relations.get(key) && relations.get(key).parent
27401
27403
? context.getModel(inflection$1.singularize(relations.get(key).parent.entity), true)
27402
27404
: null;
27403
27405
if (value instanceof Array) {
@@ -28194,9 +28196,9 @@ var QueryBuilder = /** @class */ (function () {
28194
28196
typeOrValue = value.__type + 'Input!';
28195
28197
}
28196
28198
else if (isArray(value) && field) {
28197
- var arg = field.args.find(function (f) { return f.name === key; } );
28199
+ var arg = QueryBuilder.findSchemaFieldForArgument(key, field, model, filter );
28198
28200
if (!arg)
28199
- throw new Error("A argument is of type array but it's not possible to determine the type" );
28201
+ throw new Error("The argument " + key + " is of type array but it's not possible to determine the type, because it's not in the field " + field.name );
28200
28202
typeOrValue = Schema.getTypeNameOfField(arg) + '!';
28201
28203
}
28202
28204
else if (schemaField && Schema.getTypeNameOfField(schemaField)) {
@@ -28283,15 +28285,16 @@ var QueryBuilder = /** @class */ (function () {
28283
28285
var schemaField;
28284
28286
if (field) {
28285
28287
schemaField = field.args.find(function (f) { return f.name === name; });
28286
- if (!schemaField) {
28287
- Context.getInstance().logger.warn("Could find the argument with name " + name + " for the mutation/query " + field.name);
28288
- }
28288
+ if (schemaField)
28289
+ return schemaField;
28289
28290
}
28290
- else {
28291
- // We try to find the FilterType or at least the Type this query belongs to.
28292
- var type = schema.getType(model.singularName + (isFilter ? 'Filter' : ''));
28293
- // Next we try to find the field from the type
28294
- schemaField = type ? (isFilter ? type.inputFields : type.fields).find(function (f) { return f.name === name; }) : undefined;
28291
+ // We try to find the FilterType or at least the Type this query belongs to.
28292
+ var type = schema.getType(model.singularName + (isFilter ? 'Filter' : ''));
28293
+ // Next we try to find the field from the type
28294
+ schemaField = type ? (isFilter ? type.inputFields : type.fields).find(function (f) { return f.name === name; }) : undefined;
28295
+ // Warn before we return null
28296
+ if (!schemaField) {
28297
+ Context.getInstance().logger.warn("Couldn't find the argument with name " + name + " for the mutation/query " + (field ? field.name : '(?)'));
28295
28298
}
28296
28299
return schemaField;
28297
28300
};
@@ -28749,7 +28752,8 @@ var Fetch = /** @class */ (function (_super) {
28749
28752
case 1:
28750
28753
_b.sent();
28751
28754
model = this.getModelFromState(state);
28752
- filter = params && params.filter ? Transformer.transformOutgoingData(model, params.filter) : {};
28755
+ filter = params && params.filter ?
28756
+ Transformer.transformOutgoingData(model, params.filter, Object.keys(params.filter)) : {};
28753
28757
bypassCache = params && params.bypassCache;
28754
28758
multiple = !filter['id'];
28755
28759
name = NameGenerator.getNameForFetch(model, multiple);
0 commit comments