-
Notifications
You must be signed in to change notification settings - Fork 35
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
Absinthe subscriptions support #70
Open
karlosmid
wants to merge
10
commits into
uesteibar:master
Choose a base branch
from
karlosmid:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
801c0fd
feat(neuron_subscription.ex): support for subscriptions where transpo…
karlosmid 3169e4f
refactor(neuron_subscription.ex): send to supervisor method url as se…
karlosmid 2c1825c
feat(neuron_subscription.ex): abshinthe subscriptions
karlosmid 166f3b1
feat(neuron_subscription.ex): support for query variables in subscrip…
karlosmid 807d5b6
docs(neuron_subscription.ex): how to set up Abshinthe subscriptions
karlosmid e57d2f1
Merge pull request #1 from karlosmid/subscriptions
karlosmid 7b690df
add to readme.md server side absinthe subscription implementation.
karlosmid 93e645a
absinthe websocket bug fix for double callbacks on reconnect.
karlosmid b38500c
refactor(neuron_subscription.ex): add to supervisor method id parameter
karlosmid d00ddab
docs(neuron_subscriptions): logger configuration that logs subscripti…
karlosmid 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 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 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,33 @@ | ||
defmodule Neuron.Subscription do | ||
use GenServer | ||
|
||
@impl true | ||
def init(opts) do | ||
{:ok, opts} | ||
end | ||
|
||
def supervisor(subscriber: subscriber, url: url, token: token, id: id) do | ||
Supervisor.child_spec({AbsintheWebSocket.Supervisor, | ||
[ | ||
subscriber: subscriber, | ||
url: url, | ||
token: token, | ||
base_name: subscriber, | ||
async: true | ||
]}, id: id) | ||
end | ||
|
||
def subscribe(module, query, %{} = variables) do | ||
callback = fn result -> | ||
apply(module, :handle_update, [result]) | ||
end | ||
|
||
AbsintheWebSocket.SubscriptionServer.subscribe( | ||
Module.concat(module, SubscriptionServer), | ||
Neuron.Subscription, | ||
callback, | ||
query, | ||
variables | ||
) | ||
end | ||
end |
This file contains 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 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
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.
I'm probably missing something as to why we've chosen this API, but do you think we could make it so that the user can start it as a regular supervisor/process?
I'm not familiar with
AbsintheWebSocket
but as far as I can gather we can alwaysimport AbsintheWebSocket.Supervisor
and build our own supervisor. wdyt?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.
Hi @uesteibar
AbsintheWebSocket
does all the heavy lifting of WebSocket protocol implementation. This is why I decided to use this library.AbsintheWebSocket.Supervisor
does all the magic of WebSocket subscriptions. This is why it must be used.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.
Regarding testing. As we only add a wrapper around
AbsintheWebSocket.Supervisor
,AbsintheWebSocket
has all the tests.As a proof that this wrapper works, I added it in this
Absinthe
repo as a integration test:https://github.com/karlosmid/zoom/tree/master
README.md has all instructions about
Absinthe
subscriptions.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.
@karlosmid I understand
AbsintheWebSocket.Supervisor
does the "magic", however I think we can still have our own supervisor by usingimport
and thus allow folks to use them as regular processes.Did you consider an API like the one defined in #33?
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.
regarding testing, I feel strongly that if this library offers an API, we do need tests that ensure it behaves as expected.
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.
Hi @uesteibar.
Do you agree that this is what I need to do:
AbsintheWebSocket.Supervisor
andAbsintheWebSocket.SubscriptionServer.subscribe
and testhandle_update
method callThere 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.
sounds good 👍 I'd also be fine if we test it without mocking
AbsintheWebSocket.Supervisor
, but it might be harder 😄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.
@karlosmid did you get around to handling the 2 PR task lists?