Skip to content

Commit 156da41

Browse files
committed
relay tests fixed
1 parent 69460c9 commit 156da41

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public Builder typeFunction(TypeFunction typeFunction) {
8282
return this;
8383
}
8484

85+
public Builder setAlwaysPrettify(Boolean shouldAlwaysPrettify) {
86+
this.graphQLAnnotations.getObjectHandler().getTypeRetriever().getGraphQLFieldRetriever().setAlwaysPrettify(shouldAlwaysPrettify);
87+
return this;
88+
}
89+
90+
public GraphQLAnnotations getGraphQLAnnotations() {
91+
return this.graphQLAnnotations;
92+
}
93+
8594
public GraphQLSchema build() {
8695
assert this.queryObject != null;
8796

src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import graphql.annotations.processor.retrievers.fieldBuilders.method.MethodNameBuilder;
3232
import graphql.annotations.processor.retrievers.fieldBuilders.method.MethodTypeBuilder;
3333
import graphql.annotations.processor.typeFunctions.TypeFunction;
34+
import graphql.annotations.processor.util.CodeRegistryUtil;
3435
import graphql.annotations.processor.util.ConnectionUtil;
3536
import graphql.annotations.processor.util.DataFetcherConstructor;
3637
import graphql.relay.Relay;
@@ -151,6 +152,14 @@ private GraphQLFieldDefinition handleRelayArguments(Method method, ProcessingEle
151152
GraphQLFieldDefinition relayFieldDefinition = null;
152153
if (method.isAnnotationPresent(GraphQLRelayMutation.class)) {
153154
relayFieldDefinition = buildRelayMutation(method, container, builder, outputType, args);
155+
156+
// Getting the data fetcher from the old field type and putting it as the new type
157+
String newParentType = relayFieldDefinition.getType().getName();
158+
relayFieldDefinition.getType().getChildren().forEach(field -> {
159+
DataFetcher dataFetcher = CodeRegistryUtil.getDataFetcher(container.getCodeRegistryBuilder(), outputType.getName(), (GraphQLFieldDefinition) field);
160+
container.getCodeRegistryBuilder().dataFetcher(coordinates(newParentType, field.getName()), dataFetcher);
161+
});
162+
154163
} else {
155164
builder.arguments(args);
156165
}

src/test/java/graphql/annotations/RelayTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.HashMap;
3131
import java.util.Map;
3232

33+
import static graphql.annotations.AnnotationsSchemaCreator.newAnnotationsSchema;
3334
import static org.testng.Assert.*;
3435

3536
@SuppressWarnings("unchecked")
@@ -69,7 +70,6 @@ public Result(int i) {
6970
this.i = i;
7071
}
7172

72-
@GraphQLField
7373
public int getI() {
7474
return i;
7575
}
@@ -129,7 +129,7 @@ public void noArgMutation() {
129129
assertNotNull(returnType.getFieldDefinition("getI"));
130130
assertNotNull(returnType.getFieldDefinition("clientMutationId"));
131131

132-
GraphQLSchema schema = GraphQLSchema.newSchema().query(object).mutation(object).build();
132+
GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).mutation(TestObject.class).build();
133133

134134
GraphQL graphQL = GraphQL.newGraphQL(schema).queryExecutionStrategy(new EnhancedExecutionStrategy()).build();
135135

@@ -151,7 +151,7 @@ public void interfaceReturningMutation() {
151151

152152
assertNotNull(doSomething);
153153

154-
GraphQLSchema schema = GraphQLSchema.newSchema().query(object).mutation(object).build();
154+
GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).mutation(TestObject.class).build();
155155

156156
GraphQL graphQL = GraphQL.newGraphQL(schema).queryExecutionStrategy(new EnhancedExecutionStrategy()).build();
157157

@@ -190,7 +190,7 @@ public void argMutation() {
190190
assertNotNull(returnType.getFieldDefinition("getI"));
191191
assertNotNull(returnType.getFieldDefinition("clientMutationId"));
192192

193-
GraphQLSchema schema = GraphQLSchema.newSchema().query(object).mutation(object).codeRegistry(this.graphQLAnnotations.getContainer().getCodeRegistryBuilder().build()).build();
193+
GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).mutation(TestObject.class).build();
194194

195195
GraphQL graphQL = GraphQL.newGraphQL(schema).queryExecutionStrategy(new EnhancedExecutionStrategy()).build();
196196

@@ -227,7 +227,7 @@ public void argVariableMutation() {
227227
assertNotNull(returnType.getFieldDefinition("getI"));
228228
assertNotNull(returnType.getFieldDefinition("clientMutationId"));
229229

230-
GraphQLSchema schema = GraphQLSchema.newSchema().query(object).mutation(object).build();
230+
GraphQLSchema schema = newAnnotationsSchema().query(TestObject.class).mutation(TestObject.class).build();
231231

232232
GraphQL graphQL = GraphQL.newGraphQL(schema).queryExecutionStrategy(new EnhancedExecutionStrategy()).build();
233233

0 commit comments

Comments
 (0)