Skip to content

Commit

Permalink
use fetcher relations for credsets
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhayhurst committed Oct 25, 2024
1 parent cfc59b1 commit f7b0ef3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
1 change: 0 additions & 1 deletion app/models/GQLSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ object GQLSchema {
val resolvers: DeferredResolver[Backend] = DeferredResolver.fetchers(
biosamplesFetcher,
credibleSetFetcher,
credibleSetByStudyFetcher,
l2gFetcher,
targetsFetcher,
drugsFetcher,
Expand Down
10 changes: 5 additions & 5 deletions app/models/entities/GwasIndex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package models.entities
import models.Backend
import models.gql.Fetchers.{
biosamplesFetcher,
credibleSetByStudyFetcher,
credibleSetFetcher,
credibleSetByStudyRel,
diseasesFetcher,
targetsFetcher
}
Expand Down Expand Up @@ -49,7 +50,6 @@ object GwasIndex extends Logging {
deriveObjectType[Backend, LdPopulationStructure]()
implicit val sampleImp: ObjectType[Backend, Sample] = deriveObjectType[Backend, Sample]()
implicit val sumStatQCImp: ObjectType[Backend, SumStatQC] = deriveObjectType[Backend, SumStatQC]()
implicit val ec: scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global
val gwasFields: Seq[Field[Backend, JsValue]] = Seq(
Field(
"studyId",
Expand Down Expand Up @@ -234,12 +234,12 @@ object GwasIndex extends Logging {
lazy val credibleSetField: Field[Backend, JsValue] =
Field(
"credibleSets",
OptionType(ListType(credibleSetWithoutStudyImp)),
OptionType(ListType(credibleSetImp)),
arguments = pageArg :: Nil,
description = Some("Credible sets"),
resolve = js => {
val studyIdSeq = Seq((js.value \ "studyId").as[String])
DeferredValue(credibleSetByStudyFetcher.deferSeqOpt(studyIdSeq))
val studyId = (js.value \ "studyId").as[String]
DeferredValue(credibleSetFetcher.deferRelSeq(credibleSetByStudyRel, studyId))
}
)
lazy val gwasImp: ObjectType[Backend, JsValue] = ObjectType(
Expand Down
33 changes: 17 additions & 16 deletions app/models/gql/Fetchers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ import models.entities.{
import models.{Backend, entities}
import play.api.Logging
import play.api.libs.json.{JsValue, __}
import sangria.execution.deferred.{Fetcher, FetcherCache, FetcherConfig, HasId, SimpleFetcherCache}
import sangria.execution.deferred.{
Relation,
RelationIds,
Fetcher,
FetcherCache,
FetcherConfig,
HasId,
SimpleFetcherCache
}
import models.gql.Arguments.studyId

object Fetchers extends Logging {
Expand Down Expand Up @@ -143,29 +151,22 @@ object Fetchers extends Logging {
)

val credibleSetFetcherCache = FetcherCache.simple
val credibleSetByStudyRel =
Relation[JsValue, String]("byStudy", js => Seq((js \ "studyId").as[String]))
val credibleSetFetcher: Fetcher[Backend, JsValue, JsValue, String] = {
implicit val credibleSetFetcherId: HasId[JsValue, String] =
HasId[JsValue, String](js => (js \ "studyLocusId").as[String])
Fetcher(
Fetcher.rel(
config = FetcherConfig
.maxBatchSize(entities.Configuration.batchSize)
.caching(credibleSetFetcherCache),
fetch = (ctx: Backend, ids: Seq[String]) => {
ctx.getCredibleSets(entities.CredibleSetQueryArgs(ids = ids), None)
}
)
}

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)
},
fetchRel = (ctx: Backend, ids: RelationIds[JsValue]) => {
ctx.getCredibleSets(entities.CredibleSetQueryArgs(studyIds = ids(credibleSetByStudyRel)),
None
)
}
)
}
Expand Down

0 comments on commit f7b0ef3

Please sign in to comment.