http-link-dataloader icon indicating copy to clipboard operation
http-link-dataloader copied to clipboard

Usage - Can this be used on server?

Open tomitrescak opened this issue 5 years ago β€’ 5 comments

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',
      }),
    };
  }
});

tomitrescak avatar Aug 30 '18 00:08 tomitrescak

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.

samuela avatar Nov 12 '18 06:11 samuela

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 avatar Dec 20 '18 15:12 pantharshit00

@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.

tomitrescak avatar Dec 20 '18 20:12 tomitrescak

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

pantharshit00 avatar Dec 22 '18 07:12 pantharshit00

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.

tomitrescak avatar Dec 23 '18 03:12 tomitrescak