Skip to content

Commit

Permalink
add fetchers to resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhayhurst committed Oct 24, 2024
1 parent 71789db commit cf86bd8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 3 additions & 0 deletions app/models/GQLSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ trait GQLEntities extends Logging {}

object GQLSchema {
val resolvers: DeferredResolver[Backend] = DeferredResolver.fetchers(
biosamplesFetcher,
credibleSetFetcher,
l2gFetcher,
targetsFetcher,
drugsFetcher,
diseasesFetcher,
Expand Down
16 changes: 5 additions & 11 deletions app/models/entities/GwasIndex.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package models.entities

import models.Backend
import models.gql.Fetchers.{biosamplesFetcher, diseasesFetcher, targetsFetcher}
import models.gql.Fetchers.{biosamplesFetcher, credibleSetFetcher, diseasesFetcher, targetsFetcher}
import play.api.Logging
import play.api.libs.json.{JsValue, Json, OFormat}
import models.entities.CredibleSet.credibleSetImp
import models.entities.CredibleSet.{credibleSetImp, credibleSetWithoutStudyImp}
import models.gql.Objects.{diseaseImp, targetImp, biosampleImp}
import sangria.schema.{
BooleanType,
Expand All @@ -17,7 +17,6 @@ import sangria.schema.{
fields,
DeferredValue
}
import models.entities.CredibleSet.credibleSetWithoutStudyImp
import models.gql.StudyTypeEnum
import models.gql.Arguments.{pageArg, StudyType}

Expand Down Expand Up @@ -86,12 +85,8 @@ object GwasIndex extends Logging {
OptionType(biosampleImp),
Some("biosample"),
resolve = js => {
val biosampleId = (js.value \ "biosampleFromSourceId").asOpt[String].getOrElse("")
if (biosampleId.isEmpty) {
None
} else {
js.ctx.getBiosamples(Seq(biosampleId)).map(_.headOption)
}
val biosampleId = (js.value \ "biosampleFromSourceId").asOpt[String]
DeferredValue(biosamplesFetcher.deferOpt(biosampleId))
}
),
Field(
Expand Down Expand Up @@ -239,8 +234,7 @@ object GwasIndex extends Logging {
description = Some("Credible sets"),
resolve = js => {
val studyIdSeq = Seq((js.value \ "studyId").as[String])
val credSetQueryArgs = CredibleSetQueryArgs(studyIds = studyIdSeq)
js.ctx.getCredibleSets(credSetQueryArgs, js.arg(pageArg))
DeferredValue(credibleSetFetcher.deferSeqOpt(studyIdSeq))
}
)
lazy val gwasImp: ObjectType[Backend, JsValue] = ObjectType(
Expand Down

0 comments on commit cf86bd8

Please sign in to comment.