33import graphql .ExecutionInput ;
44import graphql .ExecutionResult ;
55import graphql .GraphQL ;
6+ import graphql .GraphQLError ;
67import graphql .schema .GraphQLSchema ;
78import graphql .schema .idl .RuntimeWiring ;
89import graphql .schema .idl .SchemaGenerator ;
1516import java .io .InputStream ;
1617import java .io .InputStreamReader ;
1718import java .io .Reader ;
18- import java .util .HashMap ;
19+ import java .util .Arrays ;
20+ import java .util .Collections ;
1921import java .util .Map ;
2022
23+ import static graphql .validation .util .Util .mkMap ;
24+
2125@ SuppressWarnings ("UnnecessaryLocalVariable" )
2226public class SchemaWiringExample {
2327
@@ -27,17 +31,26 @@ public static void main(String[] args) {
2731 GraphQLSchema graphQLSchema = buildSchemaAndWiring ();
2832 GraphQL graphQL = GraphQL .newGraphQL (graphQLSchema ).build ();
2933
30- Map <String , Object > variables = new HashMap <>();
31- variables .put ("x" , "y" );
34+ Object applications = Arrays .asList (
35+ mkMap ("name" , "Brad" ),
36+ mkMap ("name" , "Andi" ),
37+ mkMap ("name" , "Bill" ),
38+ mkMap ("name" , repeatString ("x" , 200 )) // too long
39+ );
40+ Map <String , Object > variables = mkMap ("applications" , applications );
3241
3342 ExecutionInput ei = ExecutionInput .newExecutionInput ()
34- .query ("{field}" )
43+ .query ("query X($applications : [Application!]) {" +
44+ " hired(applications : $applications)" +
45+ "}" )
3546 .variables (variables )
3647 .build ();
3748
3849 ExecutionResult result = graphQL .execute (ei );
3950
40- System .out .println (result );
51+ for (GraphQLError error : result .getErrors ()) {
52+ System .out .println (error .getMessage ());
53+ }
4154 } catch (RuntimeException rte ) {
4255 rte .printStackTrace (System .out );
4356 }
@@ -62,10 +75,14 @@ private static GraphQLSchema buildSchemaAndWiring() {
6275 Reader sdl = buildSDL ();
6376 TypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser ().parse (sdl );
6477 GraphQLSchema graphQLSchema = new SchemaGenerator ().makeExecutableSchema (typeDefinitionRegistry , runtimeWiring );
65-
78+
6679 return graphQLSchema ;
6780 }
6881
82+ private static String repeatString (String s , int n ) {
83+ return String .join ("" , Collections .nCopies (n , s ));
84+ }
85+
6986 private static Reader buildSDL () {
7087 InputStream is = SchemaWiringExample .class .getResourceAsStream ("/examples/example.graphqls" );
7188 return new InputStreamReader (is );
0 commit comments