Open naccio8 opened 3 months ago
I temporarily fixed it with a prisma extension
import { Prisma } from '@prisma/client'
function removeNestedSet(obj: any): any {
if (typeof obj !== 'object' || obj === null) {
return obj;
}
if (Array.isArray(obj)) {
return obj.map(removeNestedSet);
}
const result: any = {};
for (const [key, value] of Object.entries(obj)) {
if (typeof value === 'object' && value !== null) {
if ('set' in value && Object.keys(value).length === 1) {
result[key] = removeNestedSet(value.set);
} else {
result[key] = removeNestedSet(value);
}
} else {
result[key] = value;
}
}
return result;
}
export const removeNestedSetExtension = Prisma.defineExtension((client) => {
return client.$extends({
query: {
$allModels: {
async $allOperations({ args, query }) {
const cleanedArgs = removeNestedSet(args);
return query(cleanedArgs);
},
},
},
});
});
const prismaMongo = new PrismaMongo().$extends(removeNestedSetExtension);
Bug description
I nees to update a scalar list nested into object on mongodb. The generated script made this query
and generate this error
Failed to convert 'Object([("set", List([String("07:00"), String("18:00")]))])' to 'String
It work if I remove "set" in fascia_oraria and give the array directly:
but the original query that was made by typegraphql-prisma required in graphql schema the second set and if I remove it the query failed in graphql. The problem is that if the object to set is nested in another it should not require the second set.
How to reproduce
run the script
Expected behavior
No response
Prisma information
prisma.schema
test.ts
Environment & setup
Prisma Version