Task: Changed types for DgsConstants support
This commit is contained in:
parent
b1d9f8eba6
commit
83477a9946
@ -1,6 +1,7 @@
|
|||||||
package com.cubetiqs.graphql.demo.resolver.mutation
|
package com.cubetiqs.graphql.demo.resolver.mutation
|
||||||
|
|
||||||
import com.cubetiqs.graphql.demo.context.GMutation
|
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.Account
|
||||||
import com.cubetiqs.graphql.demo.domain.account.AccountInput
|
import com.cubetiqs.graphql.demo.domain.account.AccountInput
|
||||||
import com.cubetiqs.graphql.demo.domain.account.AccountMapper
|
import com.cubetiqs.graphql.demo.domain.account.AccountMapper
|
||||||
@ -20,7 +21,7 @@ class AccountMutationResolver {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private lateinit var userRepository: UserRepository
|
private lateinit var userRepository: UserRepository
|
||||||
|
|
||||||
@DgsData(parentType = "Mutation", field = "openAccount")
|
@DgsMutation(field = DgsConstants.MUTATION.OpenAccount)
|
||||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||||
fun openAccount(input: AccountInput): Account {
|
fun openAccount(input: AccountInput): Account {
|
||||||
val account = AccountMapper.fromInputToAccount(input)
|
val account = AccountMapper.fromInputToAccount(input)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.cubetiqs.graphql.demo.resolver.mutation
|
package com.cubetiqs.graphql.demo.resolver.mutation
|
||||||
|
|
||||||
import com.cubetiqs.graphql.demo.context.GMutation
|
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.User
|
||||||
import com.cubetiqs.graphql.demo.domain.user.UserInput
|
import com.cubetiqs.graphql.demo.domain.user.UserInput
|
||||||
import com.cubetiqs.graphql.demo.domain.user.UserMapper
|
import com.cubetiqs.graphql.demo.domain.user.UserMapper
|
||||||
@ -14,7 +15,7 @@ import org.springframework.transaction.annotation.Transactional
|
|||||||
class UserMutationResolver @Autowired constructor(
|
class UserMutationResolver @Autowired constructor(
|
||||||
private val userRepository: UserRepository,
|
private val userRepository: UserRepository,
|
||||||
) {
|
) {
|
||||||
@DgsMutation(field = "createUser")
|
@DgsMutation(field = DgsConstants.MUTATION.CreateUser)
|
||||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||||
fun createUser(input: UserInput): User {
|
fun createUser(input: UserInput): User {
|
||||||
if (userRepository.existsAllByUsername(input.username ?: "")) throw Exception("Username has been already existed!")
|
if (userRepository.existsAllByUsername(input.username ?: "")) throw Exception("Username has been already existed!")
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.cubetiqs.graphql.demo.resolver.query
|
package com.cubetiqs.graphql.demo.resolver.query
|
||||||
|
|
||||||
import com.cubetiqs.graphql.demo.context.GQuery
|
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.domain.account.Account
|
||||||
import com.cubetiqs.graphql.demo.repository.AccountRepository
|
import com.cubetiqs.graphql.demo.repository.AccountRepository
|
||||||
import com.netflix.graphql.dgs.DgsQuery
|
import com.netflix.graphql.dgs.DgsQuery
|
||||||
@ -11,7 +12,7 @@ import org.springframework.data.domain.Pageable
|
|||||||
class AccountQueryResolver @Autowired constructor(
|
class AccountQueryResolver @Autowired constructor(
|
||||||
private val accountRepository: AccountRepository,
|
private val accountRepository: AccountRepository,
|
||||||
) {
|
) {
|
||||||
@DgsQuery(field = "fetchAccounts")
|
@DgsQuery(field = DgsConstants.QUERY.FetchAccounts)
|
||||||
fun fetchAccounts(): Collection<Account> {
|
fun fetchAccounts(): Collection<Account> {
|
||||||
val accounts = accountRepository.findAll(Pageable.unpaged())
|
val accounts = accountRepository.findAll(Pageable.unpaged())
|
||||||
return accounts.content
|
return accounts.content
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.cubetiqs.graphql.demo.resolver.query
|
package com.cubetiqs.graphql.demo.resolver.query
|
||||||
|
|
||||||
import com.cubetiqs.graphql.demo.context.GQuery
|
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.domain.user.User
|
||||||
import com.cubetiqs.graphql.demo.repository.UserRepository
|
import com.cubetiqs.graphql.demo.repository.UserRepository
|
||||||
import com.netflix.graphql.dgs.DgsQuery
|
import com.netflix.graphql.dgs.DgsQuery
|
||||||
@ -11,7 +12,7 @@ import org.springframework.data.domain.Pageable
|
|||||||
class UserQueryResolver @Autowired constructor(
|
class UserQueryResolver @Autowired constructor(
|
||||||
private val userRepository: UserRepository,
|
private val userRepository: UserRepository,
|
||||||
) {
|
) {
|
||||||
@DgsQuery(field = "fetchUsers")
|
@DgsQuery(field = DgsConstants.QUERY.FetchUsers)
|
||||||
fun fetchUsers(): Collection<User> {
|
fun fetchUsers(): Collection<User> {
|
||||||
val users = userRepository.queryAllByEnabledIsTrue(Pageable.unpaged())
|
val users = userRepository.queryAllByEnabledIsTrue(Pageable.unpaged())
|
||||||
return users.content
|
return users.content
|
||||||
|
Loading…
Reference in New Issue
Block a user