Hi guys, can anyone help me with this? Having this...
# orm-help
t
Hi guys, can anyone help me with this? Having this simple schema
Copy code
type 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
Copy code
rules: (parent, args, ctx) => {
    return ctx.prisma.rules(args);
  }
And then I have the group and the logs resolver for the Rule
Copy code
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 ids
s
Can you create a codesandbox for this and share it here.
t
I’ll try to create one
b
Hi, Should not you use the following code for group resolver for example
Copy code
group: 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 🤔
t
@Sachin Jani I just created a codesandbox for this but I’m getting an error
👀 1
👍 1
the sandbox is here
I get “Unsupported project ID encoding.”
not sure why that is
ok I re deployed and now is working
looking at what @Bahaa said, I think the correct way would be like this
Copy code
group: (parent, args, { prisma }) => {
    const group = prisma
      .rule({
        id: parent.id
      })
      .group();
    return group;
  }
✔️ 1
even tho this works, it is still not clear if a dataloader would be neccesary or the server side or not