Skip to content

Commit

Permalink
refactor query term validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhayhurst committed Nov 18, 2024
1 parent 45aec0d commit 6a544a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 8 additions & 6 deletions app/models/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,14 @@ class Backend @Inject() (implicit
e <- defaultESSettings.entities
if (entityNames.contains(e.name) && e.searchIndex.isDefined)
} yield e
withQueryTermsNumberValidation(queryTerms, defaultOTSettings.qValidationLimitNTerms) match {
case Success(terms) =>
esRetriever.getTermsResultsMapping(entities, terms)
case Failure(error) =>
Future.failed(error)
}
esRetriever.getTermsResultsMapping(entities, queryTerms)

// withQueryTermsNumberValidation(queryTerms, defaultOTSettings.qValidationLimitNTerms) match {
// case Success(terms) =>
// esRetriever.getTermsResultsMapping(entities, terms)
// case Failure(error) =>
// Future.failed(error)
// }

}

Expand Down
10 changes: 7 additions & 3 deletions app/models/GQLSchema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import entities._
import models.entities.CredibleSet.credibleSetImp
import models.entities.GwasIndex.gwasImp
import sangria.execution.deferred._

import gql.validators.QueryTermsValidator._
import scala.concurrent.ExecutionContext.Implicits.global
import models.entities.Interaction._
import models.gql.Objects._
import models.gql.Arguments._
import models.gql.Fetchers._
import org.checkerframework.checker.units.qual.C
import scala.concurrent._
import scala.util.{Try, Failure, Success}

trait GQLEntities extends Logging {}

Expand Down Expand Up @@ -116,7 +117,10 @@ object GQLSchema {
arguments = queryTerms :: entityNames :: Nil,
resolve = ctx => {
val entities = ctx.arg(entityNames).getOrElse(Seq.empty)
ctx.ctx.mapIds(ctx.arg(queryTerms), entities)
withQueryTermsNumberValidation(ctx.arg(queryTerms), Pagination.sizeMax) match {
case Success(terms) => ctx.ctx.mapIds(terms, entities)
case Failure(error) => Future.failed(error)
}
}
),
Field(
Expand Down

0 comments on commit 6a544a0

Please sign in to comment.