In order to use the TTL your request has to look something like this: const response = await this.post('your_url', payload, { headers: headers, cacheOptions: { ttl: 300 } } I think this also work with a get request :)
Hello, I want to know if fetch is possible to use on production? If not which one could be a better option to do this? And if will be possible a quick example of how to use and configure with Apollo please. Thank you beforehand
Hi Ben. I usually do as you described re setting up a redis cache that saves the rest call for 30 seconds which means you don’t hit the end point repeatedly. That works awesome. So using datasource for me only makes sense for multiple requests in single resolver but then it’s quite like dataloader. I’ll have to try it but don’t think I’ll use it much.
What you are doing wrong is that you pass TTL as second parameter in the get method. That is where the body goes. you have to go like: this.get("", null, { cacheOptions: { ttl: 5 } }) The TTL should be in an object as third parameter to the GET/POST/PUT/PATCH/DELETE method.
I didn't know about it! Thanks for shared. I have one question, it only works with rest apis based on Json? If I use something like soap or wsdl or a api rest using XML... It'll work?
Hmm, this could be a quite useful tool for systems integration projects for major corporations: Graph QL as a generic API hub for integrating multiple types of sources of data (SQL, NoSQL, OData, REST). Did you find a way to reuse the (JSON) type definitions of REST or NoSQL (Mongo/Mongoose, for example) when creating Graph QL schemata/types/IDL/API, whatever?
Hey dude when will you stop? You never give up... Thank you so much, you are impressive!
😂😂, I have no plans to stop anytime soon :)
Good! Love the stack you teach.
This is why we should patron him so that he keeps going!
:)
In order to use the TTL your request has to look something like this:
const response = await this.post('your_url', payload, {
headers: headers,
cacheOptions: { ttl: 300 }
}
I think this also work with a get request :)
Hello, I want to know if fetch is possible to use on production? If not which one could be a better option to do this? And if will be possible a quick example of how to use and configure with Apollo please.
Thank you beforehand
I think fetch is good for production
Hi Ben. I usually do as you described re setting up a redis cache that saves the rest call for 30 seconds which means you don’t hit the end point repeatedly. That works awesome. So using datasource for me only makes sense for multiple requests in single resolver but then it’s quite like dataloader. I’ll have to try it but don’t think I’ll use it much.
yeah, I feel the same way
What you are doing wrong is that you pass TTL as second parameter in the get method. That is where the body goes. you have to go like: this.get("", null, { cacheOptions: { ttl: 5 } }) The TTL should be in an object as third parameter to the GET/POST/PUT/PATCH/DELETE method.
Is using rest as source slowing the request rather than using a database request directly at first request? Caching is very nice though
yeah it will be faster if you talk directly to the db
I didn't know about it! Thanks for shared. I have one question, it only works with rest apis based on Json? If I use something like soap or wsdl or a api rest using XML... It'll work?
I'm not sure
I guess you need to parse that response and then return it
Thank u for this awesome video
I'm getting that the data is undefined, and I've basically got the exact same thing as you set up :/ so strange
how can i fetch data from elastic search. Please tell me
you can use fetch
Hmm, this could be a quite useful tool for systems integration projects for major corporations: Graph QL as a generic API hub for integrating multiple types of sources of data (SQL, NoSQL, OData, REST). Did you find a way to reuse the (JSON) type definitions of REST or NoSQL (Mongo/Mongoose, for example) when creating Graph QL schemata/types/IDL/API, whatever?
I haven't tried reusing the types like that