tafelito
05/24/2019, 8:25 PMtype Group {
id: ID!
name: String!
rule: [Rule!]
}
type Rule {
id: ID!
name: String!
group: Group
logs: [Log]
}
type Log {
id: ID!
text: String
rule: Rule!
}
The rules resolver just uses the prisma client
rules: (parent, args, ctx) => {
return ctx.prisma.rules(args);
}
And then I have the group and the logs resolver for the Rule
group: async (parent, args, { prisma }) => {
const [group] = await prisma.rulesGroups({
where: { rules_some: { id: parent.id } },
});
return group;
},
logs: async (parent, args, { prisma, logLoader }) => {
const logs = await prisma.logs({
where: { rule: { id: parent.id } },
});
return logs;
}
The problem I see here is that in the group resolver, I don’t have the groupId from the parent rule, so I need to query all groups that has that rule id that is always going to be 1. Same apply for the logs
Another problem without having this is if I want to implement a dataloader because I’m seeing a lot of request to the DB. (I’m not sure if I need it for the prisma client as I read at the docs that prisma includes a Dataloader I wasn’t sure if that’s internally or if I still need to do it myself on the server) But in case I needed to, I would still need the idsSachin Jani
05/25/2019, 7:30 AMtafelito
05/25/2019, 6:12 PMBahaa
05/26/2019, 3:51 AMgroup: async (parent, args, { prisma }) => {
const [group] = await prisma.rules({ id: parent.id }).group();
return group;
},
sometimes also, I need to store like 'goup_id' as a String field in rules (in addition to the relation field) to overcome some issues 🤔tafelito
05/30/2019, 5:46 PMtafelito
05/30/2019, 5:46 PMtafelito
05/30/2019, 5:46 PMtafelito
05/30/2019, 5:46 PMtafelito
05/30/2019, 5:49 PMtafelito
05/31/2019, 2:51 PMtafelito
05/31/2019, 3:08 PMtafelito
05/31/2019, 3:10 PMgroup: (parent, args, { prisma }) => {
const group = prisma
.rule({
id: parent.id
})
.group();
return group;
}
tafelito
06/03/2019, 5:26 PM