Skip to content

Commit

Permalink
chore: fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hantsy committed Nov 25, 2024
1 parent 4a09159 commit 43737da
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ val beans = beans {
if (!passwordEncoder.matches(password, user.password)) {
throw BadCredentialsException("username or password was not matched.")
}
if (!user.isEnabled()) {
if (!user.isEnabled) {
throw DisabledException("user is not enabled.")
}
AuthenticationTokenWithId(user.id, username, user.authorities)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExceptionHandlers : DataFetcherExceptionHandler {
return when (val exception = handlerParameters.exception) {
is PostNotFoundException, is AuthorNotFoundException -> {
val graphqlError = TypedGraphQLError.newNotFoundBuilder()
.message(exception.message)
.message(exception.message?: "Not found")
.path(handlerParameters.path)
.build();
val result = DataFetcherExceptionHandlerResult.newResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AuthDataFetcher(

@DgsMutation
fun signIn(@InputArgument credentials: Credentials, dfe: DgsDataFetchingEnvironment): Map<String, Any> {
var auth = authenticationManager.authenticate(
val auth = authenticationManager.authenticate(
UsernamePasswordAuthenticationToken(
credentials.username,
credentials.password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.demo.gql.datafetchers

import com.example.demo.gql.DgsConstants
import com.example.demo.gql.types.*
import com.example.demo.service.AuthorNotFoundException
import com.example.demo.service.AuthorService
import com.example.demo.service.PostService
import com.netflix.graphql.dgs.*
Expand All @@ -19,7 +20,7 @@ class AuthorsDataFetcher(

@DgsData(parentType = DgsConstants.AUTHOR.TYPE_NAME, field = DgsConstants.AUTHOR.Posts)
fun posts(dfe: DgsDataFetchingEnvironment): List<Post> {
val a: Author = dfe.getSource()
val a: Author = dfe.getSource()!!
return postService.getPostsByAuthorId(a.id)
}

Expand All @@ -30,7 +31,7 @@ class AuthorsDataFetcher(

@DgsData(parentType = DgsConstants.AUTHOR.TYPE_NAME, field = DgsConstants.AUTHOR.Profile)
fun profile(dfe: DgsDataFetchingEnvironment): Profile? {
val a: Author = dfe.getSource()
val a: Author = dfe.getSource()!!
return authorService.getProfileByUserId(a.id)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ class PostsDataFetcher(val postService: PostService) {
@DgsData(parentType = DgsConstants.POST.TYPE_NAME, field = DgsConstants.POST.Author)
fun author(dfe: DgsDataFetchingEnvironment): CompletableFuture<Author> {
val dataLoader = dfe.getDataLoader<String, Author>("authorsLoader")
val post = dfe.getSource<Post>()
return dataLoader.load(post.authorId)
val post = dfe.getSource<Post>()!!
return dataLoader!!.load(post.authorId)
}

@DgsData(parentType = DgsConstants.POST.TYPE_NAME, field = DgsConstants.POST.Comments)
fun comments(dfe: DgsDataFetchingEnvironment): CompletableFuture<List<Comment>> {
val dataLoader = dfe.getDataLoader<String, List<Comment>>(
CommentsDataLoader::class.java
)
val (id) = dfe.getSource<Post>()
val (id) = dfe.getSource<Post>()!!
return dataLoader.load(id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import com.example.demo.gql.types.Author
import com.example.demo.service.AuthorService
import com.netflix.graphql.dgs.DgsDataLoader
import org.dataloader.BatchLoader
import java.util.concurrent.CompletableFuture.completedFuture
import java.util.concurrent.CompletableFuture.supplyAsync
import java.util.concurrent.CompletionStage

@DgsDataLoader(name = "authorsLoader")
class AuthorsDataLoader(val authorService: AuthorService) : BatchLoader<String, Author> {
override fun load(keys: List<String>): CompletionStage<List<Author>> = supplyAsync {
override fun load(keys: List<String>): CompletionStage<List<Author>> = completedFuture(
authorService.getAuthorByIdIn(keys)
}
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CommentsDataLoader(val postService: PostService) : MappedBatchLoader<Strin
mappedComments[it] = comments.filter { (_, _, postId) -> postId == it }
}
log.info("mapped comments: {}", mappedComments)
return CompletableFuture.supplyAsync { mappedComments }
return CompletableFuture.completedFuture(mappedComments)
}

companion object {
Expand Down

0 comments on commit 43737da

Please sign in to comment.