Skip to content

Add full support for subscription #226

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

seriyps
Copy link

@seriyps seriyps commented Nov 23, 2023

Implemented according to https://spec.graphql.org/October2021/#sec-Subscription

The idea is that the callback module that backs the subscription field exports 2 functions: normal execute/4 but also subscribe/3.

subscribe/3 should initiate the subscription (it returns some abstract subscription identifier)
execute/4 is implemented almost as any other execute/4 but the "Source Object" (2nd argument) of this function will be the 2-tuple: forementioned "subscription identifier" and the message received from pub-sub system:

case graphql:execute(Ctx, AST) of
    #{subscription := {Identifier, OpaqueContext}} ->
        receive {my_pubsub, Tag, Message} ->  % in real code it will be `handle_info` gen server callback
           assert_match(Identifier, Tag),
           #{data := ...} = graphql:handle_subscription_event(#{}, Identifier, OpaqueContext, Message),
           ...
        end;
   #{data := ...} -> ...

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.

1 participant