nexus-plugin-prisma
nexus-plugin-prisma copied to clipboard
Feature request: Modify final result of crud
Hi, I would like to discuss the ability to change the final result of the crud via resolve
.
The example below is simple, but the query I am trying to solve is composed of 10 nested object types and multiple computed fields. I also don't want to provide the user with these filters, I need to apply them to filter out, parts that don't make sense, or even should not be seen by him!
export const ClientOffer = objectType({
name: 'ClientOffer',
definition(t) {
const model = t.model('Offer');
model.offerID();
model.title();
model.carriersOfOffer({
pagination: false,
});
},
});
export extendType({
type: 'Query',
definition(t) {
t.crud.offer({
alias: 'clientOffer',
type: 'ClientOffer',
async resolve(root, args, ctx, info, originalResolve) {
const resolved = await originalResolve(root, args, ctx, info);
// This won't work, since `carriersOfOffer` will be undefined. It is part of other `objectType`
const replacementCategoryID = 4;
resolve.carriersOfOffer.filter(carreir => {
return carrier.periods.some(period => {
return period.selected
|| period.groups.some(group => group.categoryID == replacementCategoryID);
});
});
return resolved;
},
});
},
});
Above is a very simple example of data, that needs to be filtered, it is part of business logic, no need to send client data that he will never see.
In my actual code, I need to filter multiple properties, that are nested on multiple different levels.
I would like to propose a solution that I have in mind to solve this. A method that can manipulate data after it has been processed from DB.
definition(t) {
t.crud.offer({
alias: 'clientOffer',
type: 'ClientOffer',
async onceResolved(root, args, ctx, info, resolved) {
return {
...resolved,
carriersOfOffer: resolve.carriersOfOffer.filter(carreir => {
return carrier.periods.some(period => {
return period.selected
|| period.groups.some(group => group.categoryID == replacementCategoryID);
});
}),
};
},
});
},
@Weakky I would like to ask if there are any plans to support this kind of thing. I need it quite a bit, but I am not sure what to do about it.