4
4
import graphql .execution .AsyncExecutionStrategy ;
5
5
import graphql .relay .Connection ;
6
6
import graphql .relay .SimpleListConnection ;
7
- import graphql .schema .*;
8
- import graphql .schema .idl .SchemaDirectiveWiring ;
9
- import graphql .schema .idl .SchemaDirectiveWiringEnvironment ;
7
+ import graphql .schema .DataFetchingEnvironment ;
8
+ import graphql .schema .GraphQLSchema ;
10
9
import groovy .lang .Closure ;
11
10
import org .junit .Test ;
12
- import org .slf4j .Logger ;
13
- import org .slf4j .LoggerFactory ;
14
11
15
- import java .util .*;
12
+ import java .util .Collections ;
13
+ import java .util .HashMap ;
14
+ import java .util .Map ;
16
15
17
16
public class RelayConnectionTest {
18
17
19
- private static final Logger log = LoggerFactory .getLogger (RelayConnectionTest .class );
20
-
21
18
@ Test
22
19
public void compiles () {
23
- SchemaParserOptions options = SchemaParserOptions .newOptions ()
24
-
25
- .build ();
26
20
GraphQLSchema schema = SchemaParser .newParser ().file ("RelayConnection.graphqls" )
27
21
.resolvers (new QueryResolver ())
28
22
.dictionary (User .class )
29
- .directive ("connection" , new ConnectionDirective ())
30
- .options (options )
31
23
.build ()
32
24
.makeExecutableSchema ();
33
25
34
26
GraphQL gql = GraphQL .newGraphQL (schema )
35
27
.queryExecutionStrategy (new AsyncExecutionStrategy ())
36
28
.build ();
37
29
38
- Map <String ,Object > variables = new HashMap <>();
30
+ Map <String , Object > variables = new HashMap <>();
39
31
variables .put ("limit" , 10 );
40
32
Utils .assertNoGraphQlErrors (gql , variables , new Closure <String >(null ) {
41
33
@ Override
42
34
public String call () {
43
- return "query {\n " +
35
+ return "query {\n " +
44
36
" users {\n " +
45
37
" edges {\n " +
46
38
" cursor\n " +
@@ -60,7 +52,6 @@ public String call() {
60
52
}
61
53
62
54
static class QueryResolver implements GraphQLQueryResolver {
63
- // fixme #114: desired return type to use: Connection<User>
64
55
public Connection <User > users (int first , String after , DataFetchingEnvironment env ) {
65
56
return new SimpleListConnection <>(Collections .singletonList (new User (1L , "Luke" ))).get (env );
66
57
}
@@ -76,16 +67,5 @@ public User(Long id, String name) {
76
67
}
77
68
}
78
69
79
- static class ConnectionDirective implements SchemaDirectiveWiring {
80
-
81
- @ Override
82
- public GraphQLFieldDefinition onField (SchemaDirectiveWiringEnvironment <GraphQLFieldDefinition > environment ) {
83
- GraphQLFieldDefinition field = environment .getElement ();
84
- log .info ("Transforming field" );
85
- return field ;
86
- }
87
-
88
- }
89
-
90
70
91
71
}
0 commit comments