Skip to content
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

Return a normal Promise object from GraphQL::Batch::Loader#load #65

Merged
merged 2 commits into from
Sep 1, 2017

Conversation

dylanahsmith
Copy link
Contributor

Fixes #60 (cc @jpserra)

@arthurschreiber would this remove the need for lgierth/promise.rb#35 ?

As I mentioned in #60

The reason for the difference is more of an implementation detail. The only difference between ::Promise and GraphQL::Batch::Promise is that GraphQL::Batch::Promise overrides defer so that we can use GraphQL::Batch::Executor.current.loading in tests to detect when an unbatched query is performed in a test.

so I refactored the code so that GraphQL::Batch::Loader's fulfill and reject methods call executor.around_promise_callbacks do around the actually fulfillment or rejection of the promise, allowing the executor to set its loading flag to false before promise callbacks are called and reset back to true for the remainder of the loaders perform method.

@dylanahsmith dylanahsmith requested a review from xuorig August 31, 2017 15:53
@@ -92,6 +95,14 @@ def cache_key(load_key)

private

def finish_resolve(key)
promise = promise_for(key)
return yield(promise) unless executor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this line necessary since it will raise if not wrapped in GraphQL::Batch.batch in for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The executor is mostly just used for storing loaders so they can be looked up for grouping, however, an alternative would be to store loaders in a context. We started supporting using loaders without an executor in #35.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes, of course! 👍

GraphQL::Batch::Promise is now deprecated and will be removed in
the future, since all we used it for was to set a loading flag to
`false` in the executor so that we could distinguish between batch
queries performed in the loader and non-batched queries performed
in the promise callbacks.
@dylanahsmith dylanahsmith force-pushed the remove-derived-promise-class branch from 72280d9 to 076aaa0 Compare September 1, 2017 14:49
@dylanahsmith dylanahsmith merged commit 44e7ff9 into master Sep 1, 2017
@dylanahsmith dylanahsmith deleted the remove-derived-promise-class branch September 1, 2017 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants