|
1 | | -//package graphql; |
2 | | -// |
3 | | -// |
4 | | -//import graphql.schema.GraphQLObjectType; |
5 | | -//import graphql.schema.GraphQLSchema; |
6 | | -// |
7 | | -//import java.util.Map; |
8 | | -// |
9 | | -//import static graphql.Scalars.GraphQLString; |
10 | | -//import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; |
11 | | -//import static graphql.schema.GraphQLObjectType.newObject; |
12 | | -// |
13 | | -//public class HelloWorld { |
14 | | -// |
15 | | -// public static void main(String[] args) { |
16 | | -// GraphQLObjectType queryType = newObject() |
17 | | -// .name("helloWorldQuery") |
18 | | -// .field(newFieldDefinition() |
19 | | -// .type(GraphQLString) |
20 | | -// .name("hello") |
21 | | -// .staticValue("world")) |
22 | | -// .build(); |
23 | | -// |
24 | | -// GraphQLSchema schema = GraphQLSchema.newSchema() |
25 | | -// .query(queryType) |
26 | | -// .build(); |
27 | | -// |
28 | | -// GraphQL graphQL = GraphQL.newGraphQL(schema).build(); |
29 | | -// |
30 | | -// Map<String, Object> result = graphQL.execute("{hello}").getData(); |
31 | | -// System.out.println(result); |
32 | | -// // Prints: {hello=world} |
33 | | -// } |
34 | | -// |
35 | | -// @Test |
36 | | -// public void helloWorldTest() { |
37 | | -// GraphQLObjectType queryType = newObject() |
38 | | -// .name("helloWorldQuery") |
39 | | -// .field(newFieldDefinition() |
40 | | -// .type(GraphQLString) |
41 | | -// .name("hello") |
42 | | -// .staticValue("world")) |
43 | | -// .build(); |
44 | | -// |
45 | | -// GraphQLSchema schema = GraphQLSchema.newSchema() |
46 | | -// .query(queryType) |
47 | | -// .build(); |
48 | | -// GraphQL graphQL = GraphQL.newGraphQL(schema).build(); |
49 | | -// Map<String, Object> result = graphQL.execute("{hello}").getData(); |
50 | | -// assertEquals("world", result.get("hello")); |
51 | | -// } |
52 | | -//} |
| 1 | +package graphql; |
| 2 | + |
| 3 | + |
| 4 | +import graphql.schema.GraphQLObjectType; |
| 5 | +import graphql.schema.GraphQLSchema; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +import java.util.Map; |
| 9 | + |
| 10 | +import static graphql.Scalars.GraphQLString; |
| 11 | +import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; |
| 12 | +import static graphql.schema.GraphQLObjectType.newObject; |
| 13 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 14 | + |
| 15 | +public class HelloWorld { |
| 16 | + |
| 17 | + public static void main(String[] args) { |
| 18 | + GraphQLObjectType queryType = newObject() |
| 19 | + .name("helloWorldQuery") |
| 20 | + .field(newFieldDefinition() |
| 21 | + .type(GraphQLString) |
| 22 | + .name("hello") |
| 23 | + .staticValue("world")) |
| 24 | + .build(); |
| 25 | + |
| 26 | + GraphQLSchema schema = GraphQLSchema.newSchema() |
| 27 | + .query(queryType) |
| 28 | + .build(); |
| 29 | + |
| 30 | + GraphQL graphQL = GraphQL.newGraphQL(schema).build(); |
| 31 | + |
| 32 | + Map<String, Object> result = graphQL.execute("{hello}").getData(); |
| 33 | + System.out.println(result); |
| 34 | + // Prints: {hello=world} |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void helloWorldTest() { |
| 39 | + GraphQLObjectType queryType = newObject() |
| 40 | + .name("helloWorldQuery") |
| 41 | + .field(newFieldDefinition() |
| 42 | + .type(GraphQLString) |
| 43 | + .name("hello") |
| 44 | + .staticValue("world")) |
| 45 | + .build(); |
| 46 | + |
| 47 | + GraphQLSchema schema = GraphQLSchema.newSchema() |
| 48 | + .query(queryType) |
| 49 | + .build(); |
| 50 | + GraphQL graphQL = GraphQL.newGraphQL(schema).build(); |
| 51 | + Map<String, Object> result = graphQL.execute("{hello}").getData(); |
| 52 | + assertEquals("world", result.get("hello")); |
| 53 | + } |
| 54 | +} |
0 commit comments