cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Inmemory Cache implementation in using Apollo client

hi, I am a newbie in graphql and cahing implementations.
I need to cache the values for some field resolvers that make a database call. I don't want to cache all the fileds or queries with theier response.
Here is my resolver in which a DB call is made: -
`
const resolvers={

Employee: {
    empId: async (obj, params, ctx, resolverInfo) => {
        
        return db.one('SELECT iuid FROM iuidtest WHERE empid = $1', [999])
        .then(iuidtest => {
            return iuidtest.iuid; 
        })
    
    }
}`

I am using inmemory cache over here:-
const httpLink = createHttpLink({
uri: 'http://127.0.0.1:3003/',
fetch: fetch
})
const client = new ApolloClient({
link: httpLink,
cache: new InMemoryCache()
});
This is my graphql server hosted on localhost: -

const server = new ApolloServer({ schema, context: { driver } });
server.listen(3003, '127.0.0.1').then(({ url }) => {
console.log(GraphQL API ready at ${url});
});

For now I'm trying to cache the whole query response but that does not seem to be working as I'm getting the same delay in response as before.
Here is my query: -
{
employee(first:20000)
{
empId
iuid
name

}

}
While using the readQuery method also i'm nt ableto validate by making the query call to cache also.
Any help would be appreciated.

2 REPLIES 2

Did you figure this out? I'm in the same boat. Nothing is caching. I had the exact same configuration other than the link to the graphql API and caching was working. Changed servers (to a grand stack) and now no caching.

Any solution with this issue? I've just run into the same thing myself

John-Dag