-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added support for Flow publishers coming back from the subscription field data fetcher #3910
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/groovy/graphql/execution/pubsub/CommonMessagePublisher.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package graphql.execution.pubsub; | ||
|
|
||
| import org.reactivestreams.example.unicast.AsyncIterablePublisher; | ||
|
|
||
| import java.util.Iterator; | ||
| import java.util.concurrent.ForkJoinPool; | ||
| import java.util.function.Function; | ||
|
|
||
| class CommonMessagePublisher { | ||
|
|
||
| protected final AsyncIterablePublisher<Message> iterablePublisher; | ||
|
|
||
| protected CommonMessagePublisher(final int count) { | ||
| Iterable<Message> iterable = mkIterable(count, at -> { | ||
| Message message = new Message("sender" + at, "text" + at); | ||
| return examineMessage(message, at); | ||
| }); | ||
| iterablePublisher = new AsyncIterablePublisher<>(iterable, ForkJoinPool.commonPool()); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| protected Message examineMessage(Message message, Integer at) { | ||
| return message; | ||
| } | ||
|
|
||
| private static Iterable<Message> mkIterable(int count, Function<Integer, Message> msgMaker) { | ||
| return () -> new Iterator<>() { | ||
| private int at = 0; | ||
|
|
||
| @Override | ||
| public boolean hasNext() { | ||
| return at < count; | ||
| } | ||
|
|
||
| @Override | ||
| public Message next() { | ||
| Message message = msgMaker.apply(at); | ||
| at++; | ||
| return message; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| } |
22 changes: 22 additions & 0 deletions
22
src/test/groovy/graphql/execution/pubsub/FlowMessagePublisher.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package graphql.execution.pubsub; | ||
|
|
||
| import org.reactivestreams.FlowAdapters; | ||
|
|
||
| import java.util.concurrent.Flow; | ||
|
|
||
| /** | ||
| * This example publisher will create count "messages" and then terminate. It | ||
| * uses the reactive streams TCK as its implementation but presents itself | ||
| * as a {@link Flow.Publisher} | ||
| */ | ||
| public class FlowMessagePublisher extends CommonMessagePublisher implements Flow.Publisher<Message> { | ||
|
|
||
| public FlowMessagePublisher(int count) { | ||
| super(count); | ||
| } | ||
|
|
||
| @Override | ||
| public void subscribe(Flow.Subscriber<? super Message> s) { | ||
| iterablePublisher.subscribe(FlowAdapters.toSubscriber(s)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,54 +2,20 @@ | |
|
|
||
| import org.reactivestreams.Publisher; | ||
| import org.reactivestreams.Subscriber; | ||
| import org.reactivestreams.example.unicast.AsyncIterablePublisher; | ||
|
|
||
| import java.util.Iterator; | ||
| import java.util.concurrent.ForkJoinPool; | ||
| import java.util.function.Function; | ||
|
|
||
| /** | ||
| * This example publisher will create count "messages" and then terminate. It | ||
| * uses the reactive streams TCK as its implementation | ||
| */ | ||
| public class ReactiveStreamsMessagePublisher implements Publisher<Message> { | ||
|
|
||
| private final AsyncIterablePublisher<Message> iterablePublisher; | ||
| public class ReactiveStreamsMessagePublisher extends CommonMessagePublisher implements Publisher<Message> { | ||
|
|
||
| public ReactiveStreamsMessagePublisher(final int count) { | ||
| Iterable<Message> iterable = mkIterable(count, at -> { | ||
| Message message = new Message("sender" + at, "text" + at); | ||
| return examineMessage(message, at); | ||
| }); | ||
| iterablePublisher = new AsyncIterablePublisher<>(iterable, ForkJoinPool.commonPool()); | ||
| super(count); | ||
| } | ||
|
|
||
| @Override | ||
| public void subscribe(Subscriber<? super Message> s) { | ||
| iterablePublisher.subscribe(s); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| protected Message examineMessage(Message message, Integer at) { | ||
| return message; | ||
| } | ||
|
|
||
| private static Iterable<Message> mkIterable(int count, Function<Integer, Message> msgMaker) { | ||
| return () -> new Iterator<Message>() { | ||
| private int at = 0; | ||
|
|
||
| @Override | ||
| public boolean hasNext() { | ||
| return at < count; | ||
| } | ||
|
|
||
| @Override | ||
| public Message next() { | ||
| Message message = msgMaker.apply(at); | ||
| at++; | ||
| return message; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this code into CommonMessagePublisher for re-use reasons |
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 redundant variables cleanup