Suppose have the following kind of graphql schema built with nexus-prisma
library :
- Root : contains id and list of A
- A : contains id and list of B
- B : contains id and list of C
- C : contains id
I have a graphqlServer built this way :
import { GraphQLServer } from 'graphql-yoga';
import { prisma } from '../generated/prisma-client';
const server = new GraphQLServer({
schema,
context: (request) => ({ request, prisma })
});
And a user defined resolver :
const Query = prismaObjectType({
name: 'Query',
definition: (t) => {
t.field('aWithABC', {
type: 'Root',
args: {},
list: true,
resolve: async (parent, args, ctx) => {
// The following line returns everything I need within 50ms
return ctx.prisma.roots().$fragment('{ id A { id B { id C { id } } } }')
}
}
})
When I call the server with route 'aWithABC' and the { id A { id B { id C { id } } } }
fragment as in the resolver, the resolver is very fast and only performs a single request agains my PosgreSQL server, which is great.
My problem is that just after, the graphql module makes hundreds of requests against PostreSQL to resolve nested fields which take many seconds, while all it needs is in the result of the resolver.
Is there a way to tell graphql module that there is no need to perform more requests after my resolver ?
Why is graphql module making hundreds of requests while it could only call "prisma.roots()" with the correct fragment ?
edit : versions of packages :
graphql: "^14.6.0"
graphql-yoga: "^1.18.3"
nexus": "^0.11.7"
nexus-prisma: "^0.3.7"
prisma-client-lib: "^1.34.10"
and my prisma server is running on a docker with image prismagraphql/prisma:1.34