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

GraphQLTransportWS: Always return an id upon errors #1845

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import caliban.interop.tapir.WebSocketHooks
import zio.stm.TMap
import zio.stream.{ UStream, ZStream }
import zio.{ Duration, Promise, Queue, Ref, Schedule, UIO, URIO, ZIO }
import java.util.UUID

sealed trait Protocol {
def name: String
Expand Down Expand Up @@ -49,15 +50,20 @@ object Protocol {
override def complete(id: String): GraphQLWSOutput =
GraphQLWSOutput(Ops.Complete, Some(id), None)

override def error[E](id: Option[String], e: E): GraphQLWSOutput =
override def error[E](id: Option[String], e: E): GraphQLWSOutput = {
val outputId = id match {
case None => Some(UUID.randomUUID().toString)
Copy link
Collaborator

@paulpdaniels paulpdaniels Aug 23, 2023

Choose a reason for hiding this comment

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

Nit: It would be better to use the zio.Random construct, though you'll then need to push the id generation up where you will still be in ZIO land

Copy link
Owner

Choose a reason for hiding this comment

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

@SvenW can you just update that one? Then it's good to go 🙏

case Some(_) => id
}
GraphQLWSOutput(
Ops.Error,
id,
outputId,
Some(ResponseValue.ListValue(List(e match {
case e: CalibanError => e.toResponseValue
case e => StringValue(e.toString)
})))
)
}
}

override def make[R, E](
Expand Down