1717public class Relay {
1818
1919 public static final String NODE = "Node" ;
20+
2021 private GraphQLObjectType pageInfoType = newObject ()
2122 .name ("PageInfo" )
2223 .description ("Information about pagination in a connection." )
@@ -39,7 +40,7 @@ public class Relay {
3940 .build ();
4041
4142 public GraphQLInterfaceType nodeInterface (TypeResolver typeResolver ) {
42- GraphQLInterfaceType node = newInterface ()
43+ return newInterface ()
4344 .name (NODE )
4445 .description ("An object with an ID" )
4546 .typeResolver (typeResolver )
@@ -48,11 +49,10 @@ public GraphQLInterfaceType nodeInterface(TypeResolver typeResolver) {
4849 .description ("The ID of an object" )
4950 .type (new GraphQLNonNull (GraphQLID )))
5051 .build ();
51- return node ;
5252 }
5353
5454 public GraphQLFieldDefinition nodeField (GraphQLInterfaceType nodeInterface , DataFetcher nodeDataFetcher ) {
55- GraphQLFieldDefinition fieldDefinition = newFieldDefinition ()
55+ return newFieldDefinition ()
5656 .name ("node" )
5757 .description ("Fetches an object given its ID" )
5858 .type (nodeInterface )
@@ -62,91 +62,93 @@ public GraphQLFieldDefinition nodeField(GraphQLInterfaceType nodeInterface, Data
6262 .description ("The ID of an object" )
6363 .type (new GraphQLNonNull (GraphQLID )))
6464 .build ();
65- return fieldDefinition ;
6665 }
6766
6867 public List <GraphQLArgument > getConnectionFieldArguments () {
6968 List <GraphQLArgument > args = new ArrayList <GraphQLArgument >();
70-
7169 args .add (newArgument ()
7270 .name ("before" )
71+ .description ("fetching only nodes before this node (exclusive)" )
7372 .type (GraphQLString )
7473 .build ());
7574 args .add (newArgument ()
7675 .name ("after" )
76+ .description ("fetching only nodes after this node (exclusive)" )
7777 .type (GraphQLString )
7878 .build ());
7979 args .add (newArgument ()
8080 .name ("first" )
81+ .description ("fetching only the first certain number of nodes" )
8182 .type (GraphQLInt )
8283 .build ());
8384 args .add (newArgument ()
8485 .name ("last" )
86+ .description ("fetching only the last certain number of nodes" )
8587 .type (GraphQLInt )
8688 .build ());
8789 return args ;
8890 }
8991
9092 public List <GraphQLArgument > getBackwardPaginationConnectionFieldArguments () {
9193 List <GraphQLArgument > args = new ArrayList <GraphQLArgument >();
92-
9394 args .add (newArgument ()
9495 .name ("before" )
96+ .description ("fetching only nodes before this node (exclusive)" )
9597 .type (GraphQLString )
9698 .build ());
9799 args .add (newArgument ()
98100 .name ("last" )
101+ .description ("fetching only the last certain number of nodes" )
99102 .type (GraphQLInt )
100103 .build ());
101104 return args ;
102105 }
103106
104107 public List <GraphQLArgument > getForwardPaginationConnectionFieldArguments () {
105108 List <GraphQLArgument > args = new ArrayList <GraphQLArgument >();
106-
107109 args .add (newArgument ()
108110 .name ("after" )
111+ .description ("fetching only nodes after this node (exclusive)" )
109112 .type (GraphQLString )
110113 .build ());
111114 args .add (newArgument ()
112115 .name ("first" )
116+ .description ("fetching only the first certain number of nodes" )
113117 .type (GraphQLInt )
114118 .build ());
115119 return args ;
116120 }
117121
118122 public GraphQLObjectType edgeType (String name , GraphQLOutputType nodeType , GraphQLInterfaceType nodeInterface , List <GraphQLFieldDefinition > edgeFields ) {
119-
120- GraphQLObjectType edgeType = newObject ()
123+ return newObject ()
121124 .name (name + "Edge" )
122- .description ("An edge in a connection. " )
125+ .description ("An edge in a connection" )
123126 .field (newFieldDefinition ()
124127 .name ("node" )
125128 .type (nodeType )
126129 .description ("The item at the end of the edge" ))
127130 .field (newFieldDefinition ()
128131 .name ("cursor" )
129132 .type (new GraphQLNonNull (GraphQLString ))
130- .description ("" ))
133+ .description ("cursor marks a unique position or index into the connection " ))
131134 .fields (edgeFields )
132135 .build ();
133- return edgeType ;
134136 }
135137
136138 public GraphQLObjectType connectionType (String name , GraphQLObjectType edgeType , List <GraphQLFieldDefinition > connectionFields ) {
137-
138- GraphQLObjectType connectionType = newObject ()
139+ return newObject ()
139140 .name (name + "Connection" )
140141 .description ("A connection to a list of items." )
141142 .field (newFieldDefinition ()
142143 .name ("edges" )
144+ .description ("a list of edges" )
143145 .type (new GraphQLList (edgeType )))
144146 .field (newFieldDefinition ()
145147 .name ("pageInfo" )
148+ .description ("details about this specific page" )
146149 .type (new GraphQLNonNull (pageInfoType )))
147150 .fields (connectionFields )
148151 .build ();
149- return connectionType ;
150152 }
151153
152154
0 commit comments