Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add pagination on fetching evaluations for a decision #347

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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