Skip to content

Commit

Permalink
Merge pull request #347 from camunda-community-hub/decision-evaluatio…
Browse files Browse the repository at this point in the history
…n-connection

fix: Add pagination on fetching evaluations for a decision
  • Loading branch information
saig0 authored Mar 6, 2023
2 parents ee0e4b3 + 24c9bf3 commit cb4b509
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@ import org.springframework.stereotype.Repository
@Repository
interface DecisionEvaluationRepository : PagingAndSortingRepository<DecisionEvaluation, Long> {

fun findAllByDecisionKey(decisionKey: Long): List<DecisionEvaluation>
fun findAllByDecisionKey(
decisionKey: Long,
pageable: Pageable
): List<DecisionEvaluation>

fun findAllByDecisionKeyAndStateIn(
decisionKey: Long,
stateIn: List<DecisionEvaluationState>,
pageable: Pageable
): List<DecisionEvaluation>

fun countByDecisionKeyAndStateIn(
decisionKey: Long,
stateIn: List<DecisionEvaluationState>
): Long

fun countByDecisionKey(decisionKey: Long): Long

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.zeebe.zeeqs.graphql.resolvers.type

import io.zeebe.zeeqs.data.entity.Decision
import io.zeebe.zeeqs.data.entity.DecisionEvaluationState
import io.zeebe.zeeqs.data.entity.DecisionRequirements
import io.zeebe.zeeqs.data.repository.DecisionEvaluationRepository
import io.zeebe.zeeqs.data.repository.DecisionRequirementsRepository
import io.zeebe.zeeqs.graphql.resolvers.connection.DecisionEvaluationConnection
import org.springframework.data.domain.PageRequest
import org.springframework.data.repository.findByIdOrNull
import org.springframework.graphql.data.method.annotation.Argument
import org.springframework.graphql.data.method.annotation.SchemaMapping
import org.springframework.stereotype.Controller

Expand All @@ -21,11 +24,42 @@ class DecisionResolver(
}

@SchemaMapping(typeName = "Decision", field = "evaluations")
fun evaluations(decision: Decision): DecisionEvaluationConnection {
return DecisionEvaluationConnection(
getItems = { decisionEvaluationRepository.findAllByDecisionKey(decisionKey = decision.key) },
getCount = { decisionEvaluationRepository.countByDecisionKey(decisionKey = decision.key) }
)
fun evaluations(
decision: Decision,
@Argument perPage: Int,
@Argument page: Int,
@Argument stateIn: List<DecisionEvaluationState>
): DecisionEvaluationConnection {
return if (stateIn.isEmpty()) {
DecisionEvaluationConnection(
getItems = {
decisionEvaluationRepository.findAllByDecisionKey(
decisionKey = decision.key,
pageable = PageRequest.of(page, perPage)
)
},
getCount = {
decisionEvaluationRepository.countByDecisionKey(
decisionKey = decision.key
)
})
} else {
DecisionEvaluationConnection(
getItems = {
decisionEvaluationRepository.findAllByDecisionKeyAndStateIn(
decisionKey = decision.key,
stateIn = stateIn,
pageable = PageRequest.of(page, perPage)
)
},
getCount = {
decisionEvaluationRepository.countByDecisionKeyAndStateIn(
decisionKey = decision.key,
stateIn = stateIn
)
}
)
}
}

}
6 changes: 5 additions & 1 deletion graphql-api/src/main/resources/graphql/Decision.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ type Decision {
# The decision requirements graph that contains the decision.
decisionRequirements: DecisionRequirements
# The evaluations of the decision.
evaluations: DecisionEvaluationConnection!
evaluations(
perPage: Int = 10,
page: Int = 0,
stateIn: [DecisionEvaluationState!] = [EVALUATED, FAILED]
): DecisionEvaluationConnection!
}

type DecisionConnection {
Expand Down

0 comments on commit cb4b509

Please sign in to comment.