http-link-dataloader
http-link-dataloader copied to clipboard
Usage - Can this be used on server?
I am a bit confused. If I understand this right, I can use this link on my Yoga server to cache and batch requests towards the Prisma. But where do I actually initialise this? This is the code for inititialising prisma connection inside GraphQL server. Where does it go? I know that links are used on client, not in server, yet your documentation states otherwise. If this is not the case, how can I cache queries on server?
const server = new GraphQLServer({
typeDefs: importSchema('./src/data/yoga/schema.graphql'),
resolvers,
resolverValidationOptions: {
requireResolversForResolveType: false
},
context: async (req: any) => {
return {
...req,
req: req.request,
db: new Prisma({
endpoint: 'http://localhost:4466',
}),
};
}
});
Also this library requires dom
so it doesn't really seem set up to work on node: https://github.com/prisma/http-link-dataloader/issues/18.
If you want to use this on the server, you need to use the BatchedGraphqlClient
https://github.com/prisma/http-link-dataloader/blob/master/src/BatchedGraphQLClient.ts
@pantharshit00 can you provide a code example of how to set up prismatic backend with yoga that uses caching? What you wrote I found already on forums but I never figured out how to do it.
Prisma client internally uses this package. You can see the example usage here: https://github.com/prisma/prisma/blob/e8e6c857fa9dec2bede16cda2e628abf2980410b/cli/packages/prisma-client-lib/src/Client.ts#L19
Hey, thanks for the link. I have seen this code before and what puzzles me is that if I execute the same query twice using prisma client it hits the database twice. Thatβs my problem, I do not understand why prisma is not caching data.