You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.
The purpose of the dataloader is to enable per-request caching. If I fetch an item by id "1234" twice in the same request, there should only be one request to the backend. However, fetching an item by id twice results in multiple backend calls.
Example
Start the backend server in one terminal:
$ node server.js
Example app listening on port 3000!
Start the GraphQL server using live data:
$ yarn live-data
..
============================================================
GrAMPS is running in live mode on port 8080
GraphiQL: http://localhost:8080/graphiql
============================================================
And since the dataloader should cache the "1234" entity, I expect only one backend call and I expect the lucky_numbers arrays to be the same, even though lucky_numbers is an array of random numbers.
However, in server.js's logs, I can see two requests:
I believe the problem is that a new dataloader is constructed every time connector.get() is called, rather than once for every GraphQL request. I'm thinking connector's lifecycle needs to change to accommodate this.
Thanks for moving this. The default connector probably shouldn't include the dataloader with this behavior. With the new api changes, it's now possible to create dataloaders per request:
exportdefault{..,context: req=>newModel(newConnector()),// <-- problem solved}
@timrs2998 commented on Fri Nov 10 2017
@jlengstorf Attached is example code to demonstrate gramps-graphql/gramps-express#47
Problem
The purpose of the dataloader is to enable per-request caching. If I fetch an item by id "1234" twice in the same request, there should only be one request to the backend. However, fetching an item by id twice results in multiple backend calls.
Example
Start the backend server in one terminal:
$ node server.js Example app listening on port 3000!
Start the GraphQL server using live data:
$ yarn live-data .. ============================================================ GrAMPS is running in live mode on port 8080 GraphiQL: http://localhost:8080/graphiql ============================================================
Submit the following GraphQL request:
And since the dataloader should cache the "1234" entity, I expect only one backend call and I expect the lucky_numbers arrays to be the same, even though lucky_numbers is an array of random numbers.
However, in server.js's logs, I can see two requests:
and in the JSON response:
Solution
I believe the problem is that a new dataloader is constructed every time
connector.get()
is called, rather than once for every GraphQL request. I'm thinking connector's lifecycle needs to change to accommodate this.@timrs2998 commented on Fri Nov 10 2017
The text was updated successfully, but these errors were encountered: