forked from graphql-java/graphql-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelaySchema.java
More file actions
84 lines (70 loc) · 2.91 KB
/
RelaySchema.java
File metadata and controls
84 lines (70 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package graphql;
import graphql.relay.Relay;
import graphql.schema.*;
import java.util.ArrayList;
import static graphql.Scalars.GraphQLString;
import static graphql.schema.GraphQLArgument.newArgument;
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
import static graphql.schema.GraphQLObjectType.newObject;
public class RelaySchema {
public static Relay relay = new Relay();
public static GraphQLObjectType StuffType = newObject()
.name("Stuff")
.field(newFieldDefinition()
.name("id")
.type(GraphQLString)
.fetchField()
.build())
.build();
public static GraphQLInterfaceType NodeInterface = relay.nodeInterface(new TypeResolver() {
@Override
public GraphQLObjectType getType(Object object) {
Relay.ResolvedGlobalId resolvedGlobalId = relay.fromGlobalId((String) object);
//TODO: implement
return null;
}
});
public static GraphQLObjectType StuffEdgeType = relay.edgeType("Stuff", StuffType, NodeInterface, new ArrayList<GraphQLFieldDefinition>());
public static GraphQLObjectType StuffConnectionType = relay.connectionType("Stuff", StuffEdgeType, new ArrayList<GraphQLFieldDefinition>());
public static GraphQLObjectType ThingType = newObject()
.name("Thing")
.field(newFieldDefinition()
.name("id")
.type(GraphQLString)
.fetchField()
.build())
.field(newFieldDefinition()
.name("stuffs")
.type(StuffConnectionType)
.build())
.build();
public static GraphQLObjectType RelayQueryType = newObject()
.name("RelayQuery")
.field(relay.nodeField(NodeInterface, new DataFetcher() {
@Override
public Object get(DataFetchingEnvironment environment) {
//TODO: implement
return null;
}
}))
.field(newFieldDefinition()
.name("thing")
.type(ThingType)
.argument(newArgument()
.name("id")
.description("id of the thing")
.type(new GraphQLNonNull(GraphQLString))
.build())
.dataFetcher(new DataFetcher() {
@Override
public Object get(DataFetchingEnvironment environment) {
//TODO: implement
return null;
}
})
.build())
.build();
public static GraphQLSchema Schema = GraphQLSchema.newSchema()
.query(RelayQueryType)
.build();
}