Skip to content

Client provider subscription support#235

Open
ivelten wants to merge 2 commits intofsprojects:devfrom
ivelten:tp-provider-subs-2
Open

Client provider subscription support#235
ivelten wants to merge 2 commits intofsprojects:devfrom
ivelten:tp-provider-subs-2

Conversation

@ivelten
Copy link
Copy Markdown
Collaborator

@ivelten ivelten commented Jul 2, 2019

With this PR, I am proposing a subscription interface for the client provider.

The proposal specifies that we should try to be most agnostic possible from subscription protocols, in case the client code needs to connect to a custom implementation. We offer this spec as the default one, in case no one is provided, though.

  • Create an interface to represent a subscription handler, with all sub-interfaces needed
  • Provide a default implementation based on the GraphQL Over Web Socket specification
  • Integrate the interface and the default implementation on the provider
  • Integration tests
  • Code review and refactoring

member __.Dispose() = unsubscriber () |> Async.RunSynchronously

/// An interface for implementing subscription handlers for GraphQLProvider.
type IGraphQLSubscriptionHandler =
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is a standard interface for implementing subscription handlers, in case the client code does not use the GraphQL Over Web Socket spec that we default to.


/// A GraphQL subscription handler which uses GraphQL Over Web Socket protocol.
/// See https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md for information.
type GraphQLOverWebSocketSubscriptionHandler() =
Copy link
Copy Markdown
Collaborator Author

@ivelten ivelten Jul 2, 2019

Choose a reason for hiding this comment

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

This is the default implementation of the handler, which uses the spec we default to. The idea is to share it with each subscription call of the provider because this connection can be reused like the classical HTTP connection.

|> Seq.iter (function
| Incoming payload -> observer.OnNext(payload)
| Finished -> observer.OnCompleted())
{ new IDisposable with member __.Dispose() = () } }
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We pick the first item from the response and use it as the direct result.
The remaining items will be processed into the deferred result as an IObservable.
Every Observable returns JsonValue here. They will be mapped into provided types in the ProvidedTypesHelper.

member __.AsyncUnsubscribe() = unsubscriber ()

interface IDisposable with
member __.Dispose() = unsubscriber () |> Async.RunSynchronously
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Unsubscriber, in this case, will send a message to the server to end the connection (Stop <id>). When the server responds with Complete <id>, it will be processed in the observable above and call OnComplete to properly end the observer subscription.

@xperiandri
Copy link
Copy Markdown
Collaborator

Is it already implemented in the client?

@xperiandri
Copy link
Copy Markdown
Collaborator

@valbers I think we need to extract your server-side models, JSON serializer and common logic (if applicable) to a separate project FSharp.Data.GraphQL.WebSockets so that it is used in FSharp.Data.GraphQL.Server.AspNetCore, FSharp.Data.GraphQL.Client and Snowflaqe

@valbers
Copy link
Copy Markdown
Collaborator

valbers commented Nov 10, 2024

Just for the record: the changes in this PR are based on the superseded websockets subprotocol subscriptions-transport-ws. The current version of the protocol is graphql-ws (f.k.a. graphql-transport-ws). Our server-side subscriptions implementation over websockets already implements graphql-ws.

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.

3 participants