Skip to content

Commit

Permalink
Merge pull request #345 from camunda-community-hub/query-devision-eva…
Browse files Browse the repository at this point in the history
…luations

feat: Query for decision evaluations
  • Loading branch information
saig0 authored Mar 2, 2023
2 parents 5def3ef + 1d9eb9b commit 9449b77
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.zeebe.zeeqs.data.repository

import io.zeebe.zeeqs.data.entity.DecisionEvaluation
import io.zeebe.zeeqs.data.entity.DecisionEvaluationState
import org.springframework.data.domain.Pageable
import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.stereotype.Repository

Expand All @@ -18,4 +20,11 @@ interface DecisionEvaluationRepository : PagingAndSortingRepository<DecisionEval
fun findAllByElementInstanceKey(elementInstanceKey: Long): List<DecisionEvaluation>

fun countByElementInstanceKey(elementInstanceKey: Long): Long

fun findByStateIn(
stateIn: List<DecisionEvaluationState>,
pageable: Pageable
): List<DecisionEvaluation>

fun countByStateIn(stateIn: List<DecisionEvaluationState>): Long
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.zeebe.zeeqs.graphql.resolvers.query

import io.zeebe.zeeqs.data.entity.DecisionEvaluation
import io.zeebe.zeeqs.data.entity.DecisionEvaluationState
import io.zeebe.zeeqs.data.repository.DecisionEvaluationRepository
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.QueryMapping
import org.springframework.stereotype.Controller

@Controller
class DecisionEvaluationQueryResolver(
private val decisionEvaluationRepository: DecisionEvaluationRepository
) {

@QueryMapping
fun decisionEvaluations(
@Argument perPage: Int,
@Argument page: Int,
@Argument stateIn: List<DecisionEvaluationState>
): DecisionEvaluationConnection {
return DecisionEvaluationConnection(
getItems = {
decisionEvaluationRepository.findByStateIn(
stateIn,
PageRequest.of(page, perPage)
)
},
getCount = { decisionEvaluationRepository.countByStateIn(stateIn) }
)
}

@QueryMapping
fun decisionEvaluation(@Argument key: Long): DecisionEvaluation? {
return decisionEvaluationRepository.findByIdOrNull(key)
}

}
13 changes: 13 additions & 0 deletions graphql-api/src/main/resources/graphql/DecisionEvaluation.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ type DecisionEvaluationConnection {
nodes: [DecisionEvaluation!]!
}

extend type Query {
# Find the decision evaluation with the given key.
decisionEvaluation(key: ID!): DecisionEvaluation

# Find all decision evaluations.
decisionEvaluations(
perPage: Int = 10,
page: Int = 0,
stateIn: [DecisionEvaluationState!] = [EVALUATED, FAILED]
): DecisionEvaluationConnection!

}

extend type Subscription {
# Subscribe to updates of decision evaluations (i.e. a decision was evaluated).
decisionEvaluationUpdates(
Expand Down

0 comments on commit 9449b77

Please sign in to comment.