Skip to content

Instantly share code, notes, and snippets.

@hohonuuli
Last active June 18, 2021 18:25
Show Gist options
  • Save hohonuuli/7803de274322866fe15e171bd03efddb to your computer and use it in GitHub Desktop.
Save hohonuuli/7803de274322866fe15e171bd03efddb to your computer and use it in GitHub Desktop.
Example using GraphQL.scala
package org.mbari.vaa.tv.graphql
import io.circe._
import io.circe.parser._
import okhttp3._
import org.mbari.vaa.tv.domain.CirceCodecs.{given}
import org.mbari.vaa.tv.domain.Track
import java.util.UUID
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Using
class TrackService(endpoint: String) {
def findTrackByVideoReference(videoReferenceUuid: UUID)(using ec: ExecutionContext): Future[List[Track]] = {
val query = s"""
|query {
| tracks(
| where:{
| videoReferenceUuid:{
| equals:"${videoReferenceUuid}"
| }
| }
| ) {
| id
| maxSurpriseId
| videoReferenceUuid
| varsConcept
| predictedVarsConcept
| events {
| id
| uuid
| x
| y
| width
| height
| time
| }
| }
|}
""".stripMargin('|')
GraphQL.queryToFuture[List[Track]](endpoint, query, List("data", "tracks"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment