44import graphql .execution .AsyncExecutionStrategy ;
55import graphql .relay .Connection ;
66import 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 ;
109import groovy .lang .Closure ;
1110import org .junit .Test ;
12- import org .slf4j .Logger ;
13- import org .slf4j .LoggerFactory ;
1411
15- import java .util .*;
12+ import java .util .Collections ;
13+ import java .util .HashMap ;
14+ import java .util .Map ;
1615
1716public class RelayConnectionTest {
1817
19- private static final Logger log = LoggerFactory .getLogger (RelayConnectionTest .class );
20-
2118 @ Test
2219 public void compiles () {
23- SchemaParserOptions options = SchemaParserOptions .newOptions ()
24-
25- .build ();
2620 GraphQLSchema schema = SchemaParser .newParser ().file ("RelayConnection.graphqls" )
2721 .resolvers (new QueryResolver ())
2822 .dictionary (User .class )
29- .directive ("connection" , new ConnectionDirective ())
30- .options (options )
3123 .build ()
3224 .makeExecutableSchema ();
3325
3426 GraphQL gql = GraphQL .newGraphQL (schema )
3527 .queryExecutionStrategy (new AsyncExecutionStrategy ())
3628 .build ();
3729
38- Map <String ,Object > variables = new HashMap <>();
30+ Map <String , Object > variables = new HashMap <>();
3931 variables .put ("limit" , 10 );
4032 Utils .assertNoGraphQlErrors (gql , variables , new Closure <String >(null ) {
4133 @ Override
4234 public String call () {
43- return "query {\n " +
35+ return "query {\n " +
4436 " users {\n " +
4537 " edges {\n " +
4638 " cursor\n " +
@@ -60,7 +52,6 @@ public String call() {
6052 }
6153
6254 static class QueryResolver implements GraphQLQueryResolver {
63- // fixme #114: desired return type to use: Connection<User>
6455 public Connection <User > users (int first , String after , DataFetchingEnvironment env ) {
6556 return new SimpleListConnection <>(Collections .singletonList (new User (1L , "Luke" ))).get (env );
6657 }
@@ -76,16 +67,5 @@ public User(Long id, String name) {
7667 }
7768 }
7869
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-
9070
9171}
0 commit comments