Hi, just migrating to prisma client. Using the gra...
# orm-help
m
Hi, just migrating to prisma client. Using the graphql yoga as a server environment, what is the best way to hand over the query to the client from a resolver in the usual form, i.e.
Copy code
groups(parent, args, ctx, info) {
    // pass the query params to the client
  }
? should I simply stick to the
$delegate
option like mentioned in @lawjolla migration guide, or is it intended to be used with the
$request(query)
options from the docs? Whats the way to go?
👍 1
d
I have this same question too. It looks like
$delegate
has been removed from Prisma Client 1.17 (https://github.com/prisma/prisma/pull/3108), and I don’t see
$request
defined on the new Client either. Any ideas?
Reading the “Reading Data” docs (https://www.prisma.io/docs/prisma-client/api-reference/reading-data-JAVASCRIPT-rsc2/), I’ve discovered
$fragment
might be the way to go for now.
Copy code
const fragment = `
fragment UserWithLinks on User {
  name
  email
  links {
    description
    url
  }
}
`

const userWithPosts = await prisma.users().$fragment(fragment)
Though, this seems unnecessarily verbose. Why doesn’t
prisma.users()
return the links relationship by default?
m
Mhh ok so its not just me… How is prisma client interaction with graphql supposed to look?
d
I’m not sure right now. There’s an open issue here: https://github.com/prisma/prisma/issues/3104 and it seems the maintainers are busy working to document the migration path
n
If you want to keep using schema delegation, you can do so. Building resolvers with Prisma Client works on a much more granular level than with
prisma-binding
(this is exactly the schema delegation part). You would implement the resolution of every field on a type resolver level, like here: https://github.com/prisma/graphql-prisma-typescript/blob/master/src/resolvers/City.ts#L9-L12
m
Thanks @nilan, that clears up things a little. So whenever I use the prisma client, I have to implement all child resolvers to a root type manually using the client. Thus, when I simply want to expose prisma CRUD logic, I can resort to the good-old binding/delegation approach to avoid the overhead. However, concerning the examples you posted, you are taking a different approach exposing the prisma resolvers. Is this new? I havent seen it before. In the airbnb clone, I see no delegation/bindings in the resolvers.