Trevor Radcliffe
03/23/2021, 6:34 PMroot
object passed into my Nexus resolvers to contain my relation fields from Prisma. ie, imagine this as a resolver for tableA
t.field('tableBFoo', {
type: 'DateTime',
async resolve(root, _args, { prisma }) {
const valueB = prisma.tableB.findUnique({
select: {
foo: true,
},
where: {
objectId: root.tableB.objectId,
},
})
return valueB.foo
},
})
root.tableA
comes up null in this example. Not sure if this translates exactly, haven't tried it out, but the model for the above, if done the same way that we have it, should look like this:
model TableA {
objectId String @id
tableBId String @map("tableB")
tableB TableB? @relation(fields: [tableBId], references: [objectId])
}
model TableB {
objectId String @id
foo String
}
I know what we're doing there is pretty weird, i.e., using the name we want for the relational field for the ID in our database...We're working with (and trying to replace) a legacy system, but we would prefer to use the names as expected. Is there a way to achieve this?