Skip to content
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

Variables in Subscription #348

Closed
mitsutaka-takeda opened this issue Apr 24, 2020 · 1 comment
Closed

Variables in Subscription #348

mitsutaka-takeda opened this issue Apr 24, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@mitsutaka-takeda
Copy link
Contributor

Hi. Thank you for the great library!

I started playing around with caliban and tried to use a variable in my subscription query like this one.

subscription OnEvent($topic: String!) {
    onEvent(topic: $topic) {
        name
    }
}

But caliban fails to execute query because it can not resolve the variable "$topic". I checked the WebSocket message and it contains variable definitions as expected.

{
  "id": "1",
  "type": "start",
  "payload": {
    "variables": {
      "topic": "mytopic"
    },
    "extensions": {},
    "operationName": "OnEvent",
    "query": "subscription OnEvent($topic: String!) { onEvent(topic: $topic) {name}}"
  }
}

The code for Http4sAdapter ignores the variables in payload is this intentional?

Task.whenCase(payload.downField("query").success.flatMap(_.value.asString)) {

When I change the line to something like this it can execute a query

val payload = msg.hcursor.downField("payload")
val id = msg.hcursor.downField("id").success.flatMap(_.value.asString).getOrElse("")
Task.whenCase(payload.as[GraphQLRequest]) {
   case Right(req) =>
       (for {
          result <- interpreter.execute(req.query.get, req.operationName, req.variables.getOrElse(Map.empty), req.extensions.getOrElse(Map.empty), skipValidation = skipValidation)
@ghostdogpr
Copy link
Owner

ghostdogpr commented Apr 24, 2020

Hi! This is definitely not intentional, good catch 😄 Would you like to submit a PR to fix it? I’m guessing the problem might exist on all adapters that support WebSockets (that’d be http4s, Akka and uzhttp).

@ghostdogpr ghostdogpr added the bug Something isn't working label Apr 24, 2020
mitsutaka-takeda added a commit to mitsutaka-takeda/caliban that referenced this issue Apr 25, 2020
mitsutaka-takeda added a commit to mitsutaka-takeda/caliban that referenced this issue Apr 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants