Giter Club home page Giter Club logo

Comments (8)

tsegismont avatar tsegismont commented on June 22, 2024

@aleksandar78 looks like an omission to me. Would you like to contribute the enhancement?

from vertx-web.

aleksandar78 avatar aleksandar78 commented on June 22, 2024

@tsegismont I found a way to pass the handler when the close socket event is called.
Inside connectionInitHandler where init Message is passed as the argument for the first time, the WebSocket instance can be used for the same purpose as endHandler in the ApolloWSHandler.

This is the trick that works well but it's not clear on the GraphQLWSHandler API level, IMO. The solution could be exposing endHandler or adding an example in official documentation to explain how to handle this kind of situation.

What do you think?

Anyway, I'm available to help.

from vertx-web.

tsegismont avatar tsegismont commented on June 22, 2024

Can you paste a snippet to better understand your workaround?

from vertx-web.

aleksandar78 avatar aleksandar78 commented on June 22, 2024

This is kotlin pseudo-code passed to GraphQLWSHandler.connectionInitHandler

fun onInit(event: ConnectionInitEvent) {
    val socket = event.message().socket()

    // validate token sent by graphql client
    validateToken(event.message())
      .compose { username ->
          fetchUser(username)
      }
      .onSuccess { user -> 
        val textHandlerID = socket.textHandlerID()
        sessionMap[textHandlerID] = user
        socket.closeHandler {
          sessionMap.remove(textHandlerID)
        }
        event.complete()
      }
      .onFailure { ex ->
        val error = createAuthException(ex, socket)
        event.fail(error)
      }
  }

from vertx-web.

tsegismont avatar tsegismont commented on June 22, 2024

This is kotlin pseudo-code passed to GraphQLWSHandler.connectionInitHandler

Thank you @aleksandar78

The problem with this code is that the WebSocket can have only one closeHandler, which means this will not be invoked:

So, having an endHandler to set in io.vertx.ext.web.handler.graphql.ws.GraphQLWSHandler and invoking it in io.vertx.ext.web.handler.graphql.impl.ws.ConnectionHandler#close seems like the right thing to do

from vertx-web.

aleksandar78 avatar aleksandar78 commented on June 22, 2024

@tsegismont can you point to me vert.x contributor's guide (if any) before I make the pull request?
I can make the effort but I'm not familiar with your branching strategy.

Thanks

from vertx-web.

tsegismont avatar tsegismont commented on June 22, 2024

https://github.com/eclipse-vertx/vert.x/blob/master/CONTRIBUTING.md

First, you need to make a pull request to master branch (which is where Vert.x 5 development happens now). Then you can backport to the 4.x branch (by creating another pull request).

from vertx-web.

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.