@@ -27385,19 +27385,21 @@ var Transformer = /** @class */ (function () {
2738527385 *
2738627386 * @param model
2738727387 * @param {Data} data
27388+ * @param {Array<String>} whitelist of fields
2738827389 * @returns {Data}
2738927390 */
27390- Transformer.transformOutgoingData = function (model, data) {
27391+ Transformer.transformOutgoingData = function (model, data, whitelist ) {
2739127392 var _this = this;
2739227393 var context = Context.getInstance();
2739327394 var relations = model.getRelations();
2739427395 var returnValue = {};
2739527396 Object.keys(data).forEach(function (key) {
2739627397 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
2740127403 ? context.getModel(inflection$1.singularize(relations.get(key).parent.entity), true)
2740227404 : null;
2740327405 if (value instanceof Array) {
@@ -28194,9 +28196,9 @@ var QueryBuilder = /** @class */ (function () {
2819428196 typeOrValue = value.__type + 'Input!';
2819528197 }
2819628198 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 );
2819828200 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 );
2820028202 typeOrValue = Schema.getTypeNameOfField(arg) + '!';
2820128203 }
2820228204 else if (schemaField && Schema.getTypeNameOfField(schemaField)) {
@@ -28283,15 +28285,16 @@ var QueryBuilder = /** @class */ (function () {
2828328285 var schemaField;
2828428286 if (field) {
2828528287 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;
2828928290 }
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 : '(?)'));
2829528298 }
2829628299 return schemaField;
2829728300 };
@@ -28749,7 +28752,8 @@ var Fetch = /** @class */ (function (_super) {
2874928752 case 1:
2875028753 _b.sent();
2875128754 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)) : {};
2875328757 bypassCache = params && params.bypassCache;
2875428758 multiple = !filter['id'];
2875528759 name = NameGenerator.getNameForFetch(model, multiple);
0 commit comments