3
3
import graphql .ExecutionInput ;
4
4
import graphql .ExecutionResult ;
5
5
import graphql .GraphQL ;
6
+ import graphql .GraphQLError ;
6
7
import graphql .schema .GraphQLSchema ;
7
8
import graphql .schema .idl .RuntimeWiring ;
8
9
import graphql .schema .idl .SchemaGenerator ;
15
16
import java .io .InputStream ;
16
17
import java .io .InputStreamReader ;
17
18
import java .io .Reader ;
18
- import java .util .HashMap ;
19
+ import java .util .Arrays ;
20
+ import java .util .Collections ;
19
21
import java .util .Map ;
20
22
23
+ import static graphql .validation .util .Util .mkMap ;
24
+
21
25
@ SuppressWarnings ("UnnecessaryLocalVariable" )
22
26
public class SchemaWiringExample {
23
27
@@ -27,17 +31,26 @@ public static void main(String[] args) {
27
31
GraphQLSchema graphQLSchema = buildSchemaAndWiring ();
28
32
GraphQL graphQL = GraphQL .newGraphQL (graphQLSchema ).build ();
29
33
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 );
32
41
33
42
ExecutionInput ei = ExecutionInput .newExecutionInput ()
34
- .query ("{field}" )
43
+ .query ("query X($applications : [Application!]) {" +
44
+ " hired(applications : $applications)" +
45
+ "}" )
35
46
.variables (variables )
36
47
.build ();
37
48
38
49
ExecutionResult result = graphQL .execute (ei );
39
50
40
- System .out .println (result );
51
+ for (GraphQLError error : result .getErrors ()) {
52
+ System .out .println (error .getMessage ());
53
+ }
41
54
} catch (RuntimeException rte ) {
42
55
rte .printStackTrace (System .out );
43
56
}
@@ -62,10 +75,14 @@ private static GraphQLSchema buildSchemaAndWiring() {
62
75
Reader sdl = buildSDL ();
63
76
TypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser ().parse (sdl );
64
77
GraphQLSchema graphQLSchema = new SchemaGenerator ().makeExecutableSchema (typeDefinitionRegistry , runtimeWiring );
65
-
78
+
66
79
return graphQLSchema ;
67
80
}
68
81
82
+ private static String repeatString (String s , int n ) {
83
+ return String .join ("" , Collections .nCopies (n , s ));
84
+ }
85
+
69
86
private static Reader buildSDL () {
70
87
InputStream is = SchemaWiringExample .class .getResourceAsStream ("/examples/example.graphqls" );
71
88
return new InputStreamReader (is );
0 commit comments