i could do two queries, one to get public, and ano...
# orm-help
c
i could do two queries, one to get public, and another one with the
info
the user requested, but that seems imperformant
l
Copy code
db.query.posts({
      where: {
        public: true
      },
    }, info);
This would return all public posts. What fields the user wants will still be defined in the
info
object. Is that what you are looking for?
c
this won't work for me
sorry I omitted something
I also have an isOwner which is checking if the user is the owner of a post
so if the user is an owner, but the post is not public
I still will return it
actually though.... I could branch and do it with the where clause
and have two queries basically but only execute one if the user is an owner or not
l
Combining isOwner and public should work.
c
thanks, I appreciate it
I wasn't thinking about it right
l
no worries. Sometimes it helps writing it down to see the solution more clearly
c
do you know if there is a good way to add a field to a prisma type?
like if I have a prisma type of Posts
and I want to add a field on the yoga side, of isOwner
which comes from the yoga side, not the prisma side?
to extend the Posts object from prisma with my new field?
l
What I do is to have a is a field on my Prisma types which have a reference to the owner:
owner: User
. Then based on the userId extracted from the JWT I add it to the query on the yoga resolver:
Copy code
where: {
    owner: {
        id: context.user.id
   }
}
So only those for that user will be returned.
The isOwner notion is for me a business value and not one for the Prisma type
My use case might be a bit different as of now only users that create a type instance can return it. I might change it if I have shared data for multiple users, but again that would be purely a business concern
c
hmm
so right now what I have is
on my User, I have a posts
which is the link to all of the user's posts
ie 1 to many
and I have a function where I check isOwner and return it true based on the jwt
before I query the post
it would just be really nice if I could add that isOwner as a field to the return of the posts() query I have
without having to recreate the entire prisma "post" type
just like extend it and add a field
l
I see. I have not extened prisma types on the ypga side. I tend to recreate them and omit fields that I don't want exposed to the application. There is the idea of extending types
c
you are talking about storing "owner"
which I am doing
but im trying to make like a helper field
l
Copy code
extend type Post{
  isOwner: Boolean
}
c
called isOwner that my UI can easily key off of
yea it doesn't work
I also recreate types on the yoga side
but not all the time
if there is no fields I want to omit, I have been skipping thatt
thx though for your help I appreciate it
l
If extend does not work then not sure what else you could do. I have used extend with apollo for schema stitching and it did work but that was not using yoga
c
yea there is a big thread on extend not working
kinda sucks
l
ok. good to know