|
16 | 16 |
|
17 | 17 | package com.expediagroup.graphql.examples.server.spring.query |
18 | 18 |
|
19 | | -import com.expediagroup.graphql.server.exception.KotlinGraphQLError |
20 | 19 | import com.expediagroup.graphql.server.operations.Query |
| 20 | +import graphql.GraphQLError |
| 21 | +import graphql.GraphqlErrorException |
21 | 22 | import graphql.execution.DataFetcherResult |
22 | | -import graphql.execution.ResultPath |
23 | | -import graphql.language.SourceLocation |
24 | 23 | import org.springframework.stereotype.Component |
25 | 24 | import java.util.concurrent.CompletableFuture |
26 | 25 |
|
27 | 26 | @Component |
28 | 27 | class DataAndErrorsQuery : Query { |
29 | 28 |
|
30 | 29 | fun returnDataAndErrors(): DataFetcherResult<String?> { |
31 | | - val error = KotlinGraphQLError(RuntimeException("data and errors"), listOf(SourceLocation(1, 1)), ResultPath.rootPath().toList()) |
32 | 30 | return DataFetcherResult.newResult<String>() |
33 | 31 | .data("Hello from data fetcher") |
34 | | - .error(error) |
| 32 | + .error(getError()) |
35 | 33 | .build() |
36 | 34 | } |
37 | 35 |
|
38 | 36 | fun completableFutureDataAndErrors(): CompletableFuture<DataFetcherResult<String?>> { |
39 | | - val error = KotlinGraphQLError(RuntimeException("data and errors"), listOf(SourceLocation(1, 1)), ResultPath.rootPath().toList()) |
40 | 37 | val dataFetcherResult = DataFetcherResult.newResult<String>() |
41 | 38 | .data("Hello from data fetcher") |
42 | | - .error(error) |
| 39 | + .error(getError()) |
43 | 40 | .build() |
44 | 41 | return CompletableFuture.completedFuture(dataFetcherResult) |
45 | 42 | } |
| 43 | + |
| 44 | + private fun getError(): GraphQLError = GraphqlErrorException.newErrorException() |
| 45 | + .cause(RuntimeException("data and errors")) |
| 46 | + .message("data and errors") |
| 47 | + .build() |
46 | 48 | } |
0 commit comments