I’ve never done this with Prisma so I can’t help you directly, but it could be possible to do this optimisation, but the results are probably negligible if you’re already using the findUnique loader Prisma has with relations. Since code-first libraries like Pothos & Nexus know the schema of Prisma & GraphQL, it might make more sense to see if there is anyway to bridge those with Redwood somehow.
I did once build a function that “projected” a GraphQL query onto Mongo that used the query selectionSet.selections and filtered through any Field/Fragments etc and built the appropriate query but it didn’t really provide any meaningful improvements.
I know this doesn’t really help, but your best bet for true optimisation here is having some kind of bridge (like Pothos/Nexus) that can project the query onto GraphQL properly.
@masterbater One other important consideration is what comes back from the service here has to match up with all the required fields from your SDL. So, they will have to at least match on that level.
I did found a way using graphql-fields or graphql-parse-resolve-info, But found a plugin where it can do this and I rewritten the code to be much more concise. The original plugin is here Prisma Select Convert | Pal.js Start your NodeJs, Prisma, GraphQL, React project it did still use graphql-fields but has a code that helps traversing and formatting the resolverInfo into select object even supports deeply nested relation.
@notrab@dthyresson thanks for the reply I also read pothos its also great. Hope redwoodjs can have some convention to support code first third party libraries like typegraphql , nexus.