I have two types: Account and User Account owns [U...
# orm-help
d
I have two types: Account and User Account owns [User] on relation: "Members" Account owns User on relation: "AccountOwner" I am trying to build resolvers for querying: { accounts { id members { id email } accountOwner { id email } } }
e
Technically, if you already have the "@relation" directives, you don't need the nested resolvers with prisma-binding
d
If I remove the members resolver it just returns members: null?
e
Really? What does your datamodel and schema.graphql look like ?
d
datamodel
type Account { id: ID! @unique name: String members: [User!]! @relation(name: "Members" onDelete: SET_NULL) accountOwner: User! @relation(name: "AccountOwner" onDelete: CASCADE) tags: [Tag!]! } type User { id: ID! @unique email: String! @unique password: String firstName: String lastName: String role: Role @default(value: "ADMIN") isEmployee: Boolean! @default(value: "false") activationStatus: ActivationStatus @default(value: "PENDING") isActive: Boolean! @default(value: "true") images: [Image!]! account: Account! @relation(name: "Members") tags: [Tag!]! }
schema
# import Account from './generated/prisma.graphql' type Query { accounts: [Account] }
e
You may need to also import User:
Copy code
# import Account, User from './generated/prisma.graphql'

type Query {
  accounts: [Account]
}
d
still returns members: null
should i not be able to write a resolver like: return context.prisma.query.account({ where: { id: account.id } }, info).accountOwner()
e
I don't know, it's supposed to work without sub resolvers (it works on my projet)
d
Alright. Ill try and find some more documentation on it. Seems like most of the prisma-binding docs disappeared after prisma-client
thanks
Figured it out!
changed my accounts resolver to: accounts: forwardTo('prisma')
now those nested resolvers work
e
Oh, I know! You forgot to pass the "args" to your accounts query:
Copy code
return context.prisma.query.accounts(args,info)
Because the
info
object was used as
args
, the query didn't know that you wanted the "members" and "accountOwner" nodes, therefore not returning them to you
forwardTo('prisma') is also a good choice if you don't need additional actions (log stuff and such)
d
That's exactly what it was! Thank you!