OK, so I’ve been trying to understand this one fo...
# orm-help
d
OK, so I’ve been trying to understand this one for a couple of hours now. Here’s my prisma db call (in a Query resolver in a Yoga server):
Copy code
const posts = await ctx.prisma.posts(null, " { id } ")
And here’s the corresponding log from prisma client lib:
Copy code
Query:
{
  posts {
    id
    title
    url
  }
}
Why…. does the logged query have
title
and
url
in when I’m specifying only
"{ id }"
in my query call?
🏁 1
n
Hey @danlucraft 👋 it seems to me like you're confusing the APIs of Prisma client and Prisma bindings. I believe you're trying to do a selection of specified fields of the
Post
type. With the Prisma client, this is possible via the
$fragment
API, with Prisma bindings it should be possible using the same API call that you're showing here.
This is from the Prisma client docs:
Whenever a model is queried using the Prisma client, all scalar fields of that model are fetched. This is true no matter if a single object or a list of objects is queried.
https://www.prisma.io/docs/prisma-client/basic-data-access/reading-data-JAVASCRIPT-rsc2
d
@nikolasburk Thank you! I was not at all clear on the difference between those two libraries.
🙌 1
@nikolasburk Just a follow up question: philosophically when would you use one over the other? It seems that they do very similar things: auto-generate a client library for a GraphQL API…. I guess prisma-binding let’s you proxy the selection set so that it’s easier to proxy the API? But why couldn’t prisma-client just have an option to do that?
n
Check this forum post for a perspective on the client vs bindings topic 🙂 https://www.prisma.io/forum/t/help-understanding-prisma-clients-value-proposition/4394/17?u=nikolas
d
Cheers!