-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add dataloader pattern #159
Conversation
2683c4d
to
2859636
Compare
|
||
if (!a) { | ||
throw new ForbiddenError( | ||
"You must be authenticated to update an authority." | ||
); | ||
} | ||
|
||
const strategies = executor.strategies; | ||
const pool = executor.connection; | ||
if (!(pool instanceof Pool)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea if this is a good idea, but it seems like this code fragment appears an awful lot. Could we have some kind of executor.pool
getter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one comment, and it doesn't really matter that much.
|
||
if (!a) { | ||
throw new ForbiddenError("You must be authenticated to create a client."); | ||
} | ||
|
||
const strategies = executor.strategies; | ||
const pool = executor.connection; | ||
if (!(pool instanceof Pool)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we do this a lot, we could change this to be some kind of executor.pool
getter.
This addresses #158 by using the dataloader pattern to batch and memoize entity calls within the same request.
The design followed here introduces the concept of an "execution context" or
Executor
. AnExecutor
instance is unique to the request, and is to be used as a key toWeakMap
caches of entities.Special care must be taken to avoid reusing stale data after a mutation. Accordingly, the
Executor
instance is replaced in the broader context object by each mutation. Because GraphQL guarantees that mutations are run serially, we don't have to worry about race conditions here.