Task: Changed types for DgsConstants support

This commit is contained in:
Sambo Chea 2021-08-08 11:51:24 +07:00
parent b1d9f8eba6
commit 83477a9946
4 changed files with 8 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package com.cubetiqs.graphql.demo.resolver.mutation
import com.cubetiqs.graphql.demo.context.GMutation
import com.cubetiqs.graphql.demo.dgmodel.DgsConstants
import com.cubetiqs.graphql.demo.domain.account.Account
import com.cubetiqs.graphql.demo.domain.account.AccountInput
import com.cubetiqs.graphql.demo.domain.account.AccountMapper
@ -20,7 +21,7 @@ class AccountMutationResolver {
@Autowired
private lateinit var userRepository: UserRepository
@DgsData(parentType = "Mutation", field = "openAccount")
@DgsMutation(field = DgsConstants.MUTATION.OpenAccount)
@Transactional(propagation = Propagation.REQUIRES_NEW)
fun openAccount(input: AccountInput): Account {
val account = AccountMapper.fromInputToAccount(input)

View File

@ -1,6 +1,7 @@
package com.cubetiqs.graphql.demo.resolver.mutation
import com.cubetiqs.graphql.demo.context.GMutation
import com.cubetiqs.graphql.demo.dgmodel.DgsConstants
import com.cubetiqs.graphql.demo.domain.user.User
import com.cubetiqs.graphql.demo.domain.user.UserInput
import com.cubetiqs.graphql.demo.domain.user.UserMapper
@ -14,7 +15,7 @@ import org.springframework.transaction.annotation.Transactional
class UserMutationResolver @Autowired constructor(
private val userRepository: UserRepository,
) {
@DgsMutation(field = "createUser")
@DgsMutation(field = DgsConstants.MUTATION.CreateUser)
@Transactional(propagation = Propagation.REQUIRES_NEW)
fun createUser(input: UserInput): User {
if (userRepository.existsAllByUsername(input.username ?: "")) throw Exception("Username has been already existed!")

View File

@ -1,6 +1,7 @@
package com.cubetiqs.graphql.demo.resolver.query
import com.cubetiqs.graphql.demo.context.GQuery
import com.cubetiqs.graphql.demo.dgmodel.DgsConstants
import com.cubetiqs.graphql.demo.domain.account.Account
import com.cubetiqs.graphql.demo.repository.AccountRepository
import com.netflix.graphql.dgs.DgsQuery
@ -11,7 +12,7 @@ import org.springframework.data.domain.Pageable
class AccountQueryResolver @Autowired constructor(
private val accountRepository: AccountRepository,
) {
@DgsQuery(field = "fetchAccounts")
@DgsQuery(field = DgsConstants.QUERY.FetchAccounts)
fun fetchAccounts(): Collection<Account> {
val accounts = accountRepository.findAll(Pageable.unpaged())
return accounts.content

View File

@ -1,6 +1,7 @@
package com.cubetiqs.graphql.demo.resolver.query
import com.cubetiqs.graphql.demo.context.GQuery
import com.cubetiqs.graphql.demo.dgmodel.DgsConstants
import com.cubetiqs.graphql.demo.domain.user.User
import com.cubetiqs.graphql.demo.repository.UserRepository
import com.netflix.graphql.dgs.DgsQuery
@ -11,7 +12,7 @@ import org.springframework.data.domain.Pageable
class UserQueryResolver @Autowired constructor(
private val userRepository: UserRepository,
) {
@DgsQuery(field = "fetchUsers")
@DgsQuery(field = DgsConstants.QUERY.FetchUsers)
fun fetchUsers(): Collection<User> {
val users = userRepository.queryAllByEnabledIsTrue(Pageable.unpaged())
return users.content