Skip to content

Commit

Permalink
add credset by study fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhayhurst committed Oct 24, 2024
1 parent 867377f commit cfc59b1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/models/GQLSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object GQLSchema {
val resolvers: DeferredResolver[Backend] = DeferredResolver.fetchers(
biosamplesFetcher,
credibleSetFetcher,
credibleSetByStudyFetcher,
l2gFetcher,
targetsFetcher,
drugsFetcher,
Expand Down
8 changes: 4 additions & 4 deletions app/models/entities/CredibleSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ object CredibleSet extends Logging {
"variantId",
Field(
"variant",
variantIndexImp,
OptionType(variantIndexImp),
description = None,
resolve = r => {
val variantId = r.value.variantId.getOrElse("")
logger.debug(s"Finding variant index: $variantId")
DeferredValue(variantFetcher.defer(variantId))
DeferredValue(variantFetcher.deferOpt(variantId))
}
)
)
Expand All @@ -128,9 +128,9 @@ object CredibleSet extends Logging {
OptionType(variantIndexImp),
description = None,
resolve = js => {
val id = (js.value \ "variantId").as[String]
val id = (js.value \ "variantId").asOpt[String]
logger.debug(s"Finding variant for id: $id")
DeferredValue(variantFetcher.defer(id))
DeferredValue(variantFetcher.deferOpt(id))
}
),
Field(
Expand Down
9 changes: 7 additions & 2 deletions app/models/entities/GwasIndex.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package models.entities

import models.Backend
import models.gql.Fetchers.{biosamplesFetcher, credibleSetFetcher, diseasesFetcher, targetsFetcher}
import models.gql.Fetchers.{
biosamplesFetcher,
credibleSetByStudyFetcher,
diseasesFetcher,
targetsFetcher
}
import play.api.Logging
import play.api.libs.json.{JsValue, Json, OFormat}
import models.entities.CredibleSet.{credibleSetImp, credibleSetWithoutStudyImp}
Expand Down Expand Up @@ -234,7 +239,7 @@ object GwasIndex extends Logging {
description = Some("Credible sets"),
resolve = js => {
val studyIdSeq = Seq((js.value \ "studyId").as[String])
DeferredValue(credibleSetFetcher.deferSeqOpt(studyIdSeq))
DeferredValue(credibleSetByStudyFetcher.deferSeqOpt(studyIdSeq))
}
)
lazy val gwasImp: ObjectType[Backend, JsValue] = ObjectType(
Expand Down
15 changes: 15 additions & 0 deletions app/models/gql/Fetchers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import models.{Backend, entities}
import play.api.Logging
import play.api.libs.json.{JsValue, __}
import sangria.execution.deferred.{Fetcher, FetcherCache, FetcherConfig, HasId, SimpleFetcherCache}
import models.gql.Arguments.studyId

object Fetchers extends Logging {
val soTermsFetcherCache = FetcherCache.simple
Expand Down Expand Up @@ -155,6 +156,20 @@ object Fetchers extends Logging {
)
}

val credibleSetByStudyFetcherCache = FetcherCache.simple
val credibleSetByStudyFetcher: Fetcher[Backend, JsValue, JsValue, String] = {
implicit val credibleSetByStudyFetcherId: HasId[JsValue, String] =
HasId[JsValue, String](js => (js \ "studyId").as[String])
Fetcher(
config = FetcherConfig
.maxBatchSize(entities.Configuration.batchSize)
.caching(credibleSetByStudyFetcherCache),
fetch = (ctx: Backend, ids: Seq[String]) => {
ctx.getCredibleSets(entities.CredibleSetQueryArgs(studyIds = ids), None)
}
)
}

implicit val l2gFetcherId: HasId[L2GPredictions, String] =
HasId[L2GPredictions, String](_.studyLocusId)
val l2gFetcherCache = FetcherCache.simple
Expand Down

0 comments on commit cfc59b1

Please sign in to comment.