hi all, I’m using prisma to generate golang code f...
# orm-help
p
hi all, I’m using prisma to generate golang code for prisma-client use, and I’m wondering how I can retrieve an object and it’s relation in a creation call. I have an
*ObjectExec
which I can call
.Exec(ctx)
on or
.MyRelation().Exec(ctx)
on, is there a way to get both objects at once?
d
You should be able to do something like User().Todo().Exec(ctx)
See getTodoUser function!
p
so if i do
User().Todo().Exec(ctx)
, the client code I have (using
prisma/1.19.0-alpha.21
) gives me back a
*prisma.Todo
what id like is a
*prisma.User
and a
*prisma.Todo
somehow, but the
*prisma.User
only has the scalar fields, not the relations
s
Why do you need to output both Todo and User in your go code when your resolver does already that for you ? In your mutation you can do something like this client this
mutation createTodo{createTodo(text:"mytodo"){ text createdBy { name} } }
see you can access the nodes in a one-to-many relations (one user can have many todoes like this) like in the schema below : type Query { todo(id: ID!): Todo todos: [Todo!]! } type Mutation { createTodo(text: String!, done: Boolean): Todo! } type User { id: ID! name: String! todoes: [Todo!]! } type Todo { id: ID! text: String! done: Boolean! createdBy : User! }`
p
because I’m not using this in a graphql resolver, it’s a go program consuming a prisma graphql endpoint directly. It seems like it’s not possible to get both an object and it’s relation out in the generated code without making two queries.
but i dont see an equivalent way of achieving that with the golang client
s
Ok I see. I'm still new to golang so sorry if my idea is stupid but maybe you can do something with the context package or/and by storing your object and your object relation in two seperate variables ?
Anyway if you need an example with the go-client part I've made an example available here with some relations. https://github.com/Sach97/prisma-go-hackernews/tree/prisma-1.19.0-alpha21
p
no worries! basically i can get what i need in two queries, but it’d be nice if it could be handle in one