File tree 4 files changed +89
-3
lines changed
spring-graphql-webflux/src/main/java/com/example/demo/gql
4 files changed +89
-3
lines changed Original file line number Diff line number Diff line change
1
+ # This workflow will build a Java project with Gradle
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
3
+
4
+ name : spring-graphql-webflux
5
+
6
+ on :
7
+ push :
8
+ paths :
9
+ - " spring-graphql-webflux/**"
10
+ branches : [ master ]
11
+ pull_request :
12
+ paths :
13
+ - " spring-graphql-webflux/**"
14
+ types :
15
+ - opened
16
+ - synchronize
17
+ - reopened
18
+
19
+ jobs :
20
+ build :
21
+
22
+ runs-on : ubuntu-latest
23
+
24
+ steps :
25
+ - uses : actions/checkout@v2
26
+ - name : Set up JDK
27
+ uses : actions/setup-java@v2
28
+ with :
29
+ java-version : ' 17'
30
+ distribution : ' zulu'
31
+ - name : Setup Postgres in Docker
32
+ run : |
33
+ docker-compose up -d postgres
34
+ docker ps -a
35
+ - name : Build with Gradle
36
+ run : |
37
+ cd spring-graphql-webflux
38
+ chmod +x gradlew
39
+ ./gradlew build
40
+
Original file line number Diff line number Diff line change 27
27
HELP.md
28
28
.gradle
29
29
build /
30
- ! gradle /wrapper /gradle-wrapper.jar
31
- ! ** /src /main /** /build /
32
- ! ** /src /test /** /build /
33
30
34
31
# ## STS ###
35
32
.apt_generated
Original file line number Diff line number Diff line change
1
+ package com .example .demo .gql ;
2
+
3
+ import com .example .demo .service .AuthorNotFoundException ;
4
+ import com .example .demo .service .PostNotFoundException ;
5
+ import graphql .GraphQLError ;
6
+ import graphql .GraphqlErrorBuilder ;
7
+ import graphql .schema .DataFetchingEnvironment ;
8
+ import org .springframework .graphql .execution .DataFetcherExceptionResolver ;
9
+ import org .springframework .graphql .execution .ErrorType ;
10
+ import org .springframework .stereotype .Component ;
11
+ import reactor .core .publisher .Mono ;
12
+
13
+ import java .util .Arrays ;
14
+ import java .util .List ;
15
+
16
+ @ Component
17
+ public class ExceptionHandlers implements DataFetcherExceptionResolver {
18
+ @ Override
19
+ public Mono <List <GraphQLError >> resolveException (Throwable exception , DataFetchingEnvironment environment ) {
20
+ if (exception instanceof PostNotFoundException || exception instanceof AuthorNotFoundException ) {
21
+ return Mono .fromCallable (() -> Arrays .asList (
22
+ GraphqlErrorBuilder .newError (environment )
23
+ .errorType (ErrorType .NOT_FOUND )
24
+ .message (exception .getMessage ())
25
+ .build ()));
26
+ }
27
+ return Mono .empty ();
28
+ }
29
+ }
Original file line number Diff line number Diff line change
1
+ package com .example .demo .gql .dataloaders ;
2
+
3
+ import lombok .RequiredArgsConstructor ;
4
+ import org .dataloader .DataLoaderFactory ;
5
+ import org .dataloader .DataLoaderRegistry ;
6
+ import org .springframework .graphql .execution .DataLoaderRegistrar ;
7
+ import org .springframework .stereotype .Component ;
8
+
9
+ @ Component
10
+ @ RequiredArgsConstructor
11
+ public class DataLoaderConfig implements DataLoaderRegistrar {
12
+ private final AuthorsDataLoader authorsDataLoader ;
13
+ private final CommentsDataLoader commentsDataLoader ;
14
+
15
+ @ Override
16
+ public void registerDataLoaders (DataLoaderRegistry registry ) {
17
+ registry .register ("commentsLoader" , DataLoaderFactory .newMappedDataLoader (commentsDataLoader ));
18
+ registry .register ("authorsLoader" , DataLoaderFactory .newDataLoader (authorsDataLoader ));
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments