Code Monkey home page Code Monkey logo

Comments (5)

Shane32 avatar Shane32 commented on May 29, 2024 1

Are you implementing the 'Single connection mode' as documented in the protocol ? Or the 'Distinct connection mode' ?

I'm not very familiar with GraphQL over SSE or F# but in general it seems that:

  1. The 'Distinct connection mode' would be extremely easy to implement, but suffers from the fact that clients cannot send authentication headers along with the HTTP request. I'd probably just override GraphQLHttpMiddleware.HandleRequestAsync and see if the HTTP Accept header is text/event-stream. If not, call the base method, otherwise, execute the request and tie the subscription responses to the response stream. Easy. No need to deal with any of the WebSocket handling classes at all.
    Batched requests should be disabled in this scenario.

  2. The 'Single connection mode' could potentially reuse some of the functionality within BaseSubscriptionServer. One problem is that the message data type used is OperationMessage, which is incompatible with the SSE protocol. However, it maintains its connection to the endpoint via IOperationMessageProcessor and IWebSocketConnection. As such, the implementation of WebSocketConnection (which is what reads/writes messages to the WebSocket endpoint) could be rewritten to translate the messages in the protocol to OperationMessage messages quite easily. You'd still have to write the code that match IDs to a dictionary of active connections and forwards the message for starting/stopping messages through, etc. Even so, it may be questionable as to how much of the code within BaseSubscriptionServer is practically reusable.

Looks like subscription implementation is hidden now

Well, it's not really hidden -- almost all of the classes are public. We have simply rewritten it from scratch and removed the dependencies on third party libraries such as System.Threading.Tasks.Dataflow and System.Reactive. It's also been integrated into the main project to simplify configuration.

There is a section within the readme that gives a brief overview of all of the subscription-related classes at the below link, and every method has descriptive XML comments. Feel free to ask if anything is unclear.

https://github.com/graphql-dotnet/server#websocket-handler-classes

from server.

fallenwood avatar fallenwood commented on May 29, 2024

Thanks for answering.
It should be 2) The 'Single connection mode'. I'll follow the section to see if I need to rewrite all the code.


I took a quick look at the code today, I need to write my own IWebSocketConnection (maybe it should not rename to something more general?) and IOperationMessageProcessor, could ReusableMemoryReaderStream and AsyncMessagePump<T> be public for easy extension?

from server.

sungam3r avatar sungam3r commented on May 29, 2024

@fallenwood Do you need more help here or we may close?

from server.

Shane32 avatar Shane32 commented on May 29, 2024

FYI, AsyncMessagePump is available within the Shane32.AsyncResetEvents nuget package

from server.

fallenwood avatar fallenwood commented on May 29, 2024

FYI, AsyncMessagePump is available within the Shane32.AsyncResetEvents nuget package

Thanks for the infos :)

@fallenwood Do you need more help here or we may close?

I am not working this area these days. I can close it, thanks for your help

from server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.