Schema delegation
See original GitHub issueI’m modifying the original issue according to https://github.com/prisma/prisma/issues/117#issuecomment-626689015
For GraphQL APIs, schema delegation was a very handy feature in Prisma 1. It would be nice to have it in Prisma 2 as well, especially for those who want to migrate from v1.
Basically, the idea is that Prisma 2 understands the GraphQL’s info
object to query data. I can think of two ways to implement this:
- As a core feature of Prisma Client itself: instead of using
select
orincludes
, we just passinfo
object and it’s used for querying. - As a small external tool that transforms
info
object into something that can be passed to Prisma Client’sselect
. A proof of concept for this can be found here (a bit outdated since it still uses PhotonJS API).
The premise for all of this is that fields included in the info
object (from GraphQL server API) must match the DB fields. If some field doesn’t match, it should be ignored.
Advantages: Very handy for GraphQL servers; It would be way simpler to migrate from Prisma 1 + bindings to Prisma 2. Disadvantages: I think editor type autocompletion wouldn’t work since this all happens at run time.
Edit: Just found @prisma-tools, which might be enough to implement all of this.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (2 by maintainers)
we have built and open sourced a new data-provider for rect-admin https://github.com/panter/ra-data-prisma
it also comes with some helper function that exposes all needed mutations and queries for a given resource using nexus
@macrozone @marcantoine I just created a small tool to transform
info
into PhotonJS’s select API at runtime: https://github.com/frandiox/graphql-info-transformerIt’s just a proof of concept but might be helpful. It doesn’t need Nexus although generating a DB-GraphQL-schema without it might be hard (for things like “UpdateUserWhereInput” and stuff like that).