question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Schema delegation

See original GitHub issue

I’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 or includes, we just pass info 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’s select. 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:open
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
macrozonecommented, May 11, 2020

@macrozone I use the same setup (with a fork of ra-data-opencrud). Did you figure out how we can use delegation/forward with nexus-prisma &prisma2 since then?

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

2reactions
frandioxcommented, Oct 23, 2019

@macrozone @marcantoine I just created a small tool to transform info into PhotonJS’s select API at runtime: https://github.com/frandiox/graphql-info-transformer

It’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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL schema delegation
In this article I'm going to talk about schema delegation — a way to automatically forward a GraphQL query (or a part of...
Read more >
Schema Delegation – GraphQL Tools
Schema delegation is a way to automatically forward a query (or a part of a query) from a parent schema to another schema...
Read more >
GraphQL Schema Stitching explained: Schema Delegation
Schema delegation is a mechanism to forward (delegate) the execution of a resolver function to another resolver in a different (or even the...
Read more >
GraphQL Schema Delegation through Declarative Programming
Yes, it's possible. You can use the @delegate directive to delegate your query to the appropriate schema. The sample below assumes you are ......
Read more >
Beyond Schema Delegation | Alec Aivazis
This post describes a few common pain points with the current approach to consolidating multiple GraphQL APIs known as “schema delegation”.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found