Skip to content

Commit 868867f

Browse files
committed
When creating schema, relay PageInfo is now added as an additional type.
Notice that the client should also provide page info in order for it to work properly
1 parent 59f78b1 commit 868867f

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/main/java/graphql/annotations/AnnotationsSchemaCreator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import graphql.annotations.processor.GraphQLAnnotations;
1818
import graphql.annotations.processor.typeFunctions.TypeFunction;
19+
import graphql.relay.Relay;
1920
import graphql.schema.GraphQLDirective;
2021
import graphql.schema.GraphQLSchema;
2122
import graphql.schema.GraphQLType;
@@ -98,7 +99,7 @@ public GraphQLSchema build() {
9899
if (!this.directivesObjectList.isEmpty()) {
99100
builder.additionalDirectives(directives);
100101
}
101-
builder.additionalTypes(additionalTypes)
102+
builder.additionalTypes(additionalTypes).additionalType(Relay.pageInfoType)
102103
.codeRegistry(graphQLAnnotations.getContainer().getCodeRegistryBuilder().build());
103104
return builder.build();
104105
}

src/test/java/graphql/annotations/connection/GraphQLEnhancedConnectionTest.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,26 @@
2323
import graphql.annotations.processor.GraphQLAnnotations;
2424
import graphql.schema.DataFetcher;
2525
import graphql.schema.DataFetchingEnvironment;
26-
import graphql.schema.GraphQLObjectType;
2726
import graphql.schema.GraphQLSchema;
28-
import org.testng.annotations.BeforeClass;
27+
import org.testng.annotations.BeforeMethod;
2928
import org.testng.annotations.Test;
3029

31-
import java.util.Arrays;
32-
import java.util.Collections;
33-
import java.util.List;
34-
import java.util.Map;
30+
import java.util.*;
3531

36-
import static graphql.schema.GraphQLSchema.newSchema;
32+
import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema;
3733
import static org.testng.Assert.assertEquals;
3834

3935
@SuppressWarnings("ALL")
4036
public class GraphQLEnhancedConnectionTest {
4137

42-
private static GraphQL graphQL;
38+
private GraphQL graphQL;
4339
private GraphQLAnnotations graphQLAnnotations;
4440

4541

46-
@BeforeClass
42+
@BeforeMethod
4743
public void setUp() throws Exception {
4844
this.graphQLAnnotations = new GraphQLAnnotations();
49-
GraphQLObjectType object = this.graphQLAnnotations.object(TestListField.class);
50-
GraphQLSchema schema = newSchema().query(object).build();
51-
45+
GraphQLSchema schema = newAnnotationsSchema().query(TestListField.class).build();
5246
graphQL = GraphQL.newGraphQL(schema).build();
5347
}
5448

@@ -156,7 +150,7 @@ public void validDatafetcher_queryForCursors_getValidCursors() throws Exception
156150
public void fetchConnectionAsync() throws Exception {
157151
//Arrange
158152
ExecutionInput executionInput = new ExecutionInput("{ objsAsync(first:2) { edges { cursor } } }",
159-
null, "CONTEXT", null, null);
153+
null, "CONTEXT", null, new HashMap<>());
160154
//Act
161155
ExecutionResult result = graphQL.execute(executionInput);
162156
Map<String, Map<String, List<Map<String, Map<String, Object>>>>> data = result.getData();
@@ -171,7 +165,7 @@ public void fetchConnectionAsync() throws Exception {
171165
public void validDatafetcher_queryForValues_returnsValidValues() throws Exception {
172166
//Arrange
173167
ExecutionInput executionInput = new ExecutionInput("{ objs(first:2) { edges { cursor node { id, val } } } }",
174-
null, "CONTEXT", null, null);
168+
null, "CONTEXT", null, new HashMap<>());
175169

176170
//Act
177171
ExecutionResult result = graphQL.execute(executionInput);
@@ -188,7 +182,7 @@ public void validDatafetcher_queryForHasPreviousPage_returnsFalse() throws Excep
188182

189183
//Arrange
190184
ExecutionInput executionInput = new ExecutionInput("{ objs(first:2) { pageInfo { hasPreviousPage } } }",
191-
null, "CONTEXT", null, null);
185+
null, "CONTEXT", null, new HashMap<>());
192186

193187
//Act
194188
ExecutionResult result = graphQL.execute(executionInput);
@@ -203,7 +197,7 @@ public void validDatafetcher_queryForHasNextPage_returnsTrue() throws Exception
203197

204198
//Arrange
205199
ExecutionInput executionInput = new ExecutionInput("{ objs(first:2) { pageInfo { hasNextPage } } }",
206-
null, "CONTEXT", null, null);
200+
null, "CONTEXT", null, new HashMap<>());
207201

208202
//Act
209203
ExecutionResult result = graphQL.execute(executionInput);

0 commit comments

Comments
 (0)