Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage - Can this be used on server? #13

Open
tomitrescak opened this issue Aug 30, 2018 · 5 comments
Open

Usage - Can this be used on server? #13

tomitrescak opened this issue Aug 30, 2018 · 5 comments

Comments

@tomitrescak
Copy link

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',
      }),
    };
  }
});
@samuela
Copy link

samuela commented Nov 12, 2018

Also this library requires dom so it doesn't really seem set up to work on node: #18.

@pantharshit00
Copy link

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

@tomitrescak
Copy link
Author

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

@pantharshit00
Copy link

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

@tomitrescak
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants