If I use Prisma, can I add a field that query data...
# prisma-whats-new
g
If I use Prisma, can I add a field that query data from a redis db? Also what about implementing my own caching layer on top of psql? Is this possible?
a
Yeah, you can absolutely do that. You have to define a sub-resolver in your application schema and there you could fetch the data from a different data source. Please note that you have to write the particular fetch mechanism yourself then.
g
Ok
a
Let me know, if you have any further questions. Iā€™m happy to help šŸ™‚
g
So calling external apis would be also possible right?
How about implementing caching layer using Redis?
a
Yes, calling external APIs is possible. You can communicate with any external system you want.
With caching layer, you mean a layer between your application and the actual Prisma database?
g
Yup. For example if I need to get a list of messages, if it's already in redis, then fetch it. Otherwise query it from psql db
Something like that
Or maybe, for a list of messages, first 10 will be retrieved from redis, paging rest will be from db
a
Not at the moment, no.
Prisma
has an internal caching mechanism built-in though. It is memory only and not based on an external system,
g
Internal caching layer? Wow
a
There are plans for having a Redis connector: You can track the progress here: https://github.com/graphcool/prisma/issues/1722
g
So how does it work? Inbuilt memory?
Is it possible to invalidate cache and get a control over it?
a
Yes, it utilizes Facebooks
dataloader
, you can find the Graphcool library here: https://github.com/graphcool/http-link-dataloader
g
Hmm. Let me go through it
a
šŸ‘
To answer your question, yeah it is in-memory šŸ™‚
g
My application is pretty big, not just a curd. Currently it's built with Apollo graphql. Would like to migrate to Prisma. Have to make sure Prisma is customizable for my needs
What would you suggest?
Is Prisma mature enough for this?
a
You could definitely write your own caching mechanism which wraps the
context.db
calls and goes to the Prisma service. That is the approach I would suggest: Write an own layer that uses
conext.db
and your
Redis caching implementation
and utilize that in your resolver functions.
g
Great!