Skip to content

Commit 3c545a8

Browse files
anotenderigdianov
authored andcommitted
Add test case that validates schema after it is created (#170)
1 parent a8889da commit 3c545a8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/CalculatedEntityTests.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.introproventures.graphql.jpa.query.schema;
22

3+
import java.util.Optional;
4+
35
import static org.assertj.core.api.Assertions.assertThat;
46
import static org.assertj.core.api.Assertions.tuple;
7+
import static org.assertj.core.api.BDDAssertions.then;
58
import static org.assertj.core.util.Lists.list;
69

710
import javax.persistence.EntityManager;
811

12+
import graphql.schema.GraphQLFieldDefinition;
13+
import graphql.schema.GraphQLSchema;
914
import org.junit.Test;
1015
import org.junit.runner.RunWith;
1116
import org.springframework.beans.factory.annotation.Autowired;
@@ -46,6 +51,9 @@ public GraphQLSchemaBuilder graphQLSchemaBuilder(final EntityManager entityManag
4651
@Autowired
4752
private GraphQLExecutor executor;
4853

54+
@Autowired
55+
private GraphQLSchemaBuilder schemaBuilder;
56+
4957
@Test
5058
public void contextLoads() {
5159
Assert.isAssignable(GraphQLExecutor.class, executor.getClass());
@@ -117,4 +125,33 @@ public void testIgnoreFields() {
117125
);
118126
}
119127

128+
@Test
129+
public void shouldInheritMethodDescriptionFromBaseClass() {
130+
//when
131+
GraphQLSchema schema = schemaBuilder.build();
132+
133+
//then
134+
Optional<GraphQLFieldDefinition> field = getFieldForType("parentTransientGetter",
135+
"CalculatedEntity",
136+
schema);
137+
then(field)
138+
.isPresent().get()
139+
.extracting("description")
140+
.isNotNull()
141+
.containsExactly("getParentTransientGetter");
142+
}
143+
144+
private Optional<GraphQLFieldDefinition> getFieldForType(String fieldName,
145+
String type,
146+
GraphQLSchema schema) {
147+
return schema.getQueryType()
148+
.getFieldDefinition(type)
149+
.getType()
150+
.getChildren()
151+
.stream()
152+
.map(GraphQLFieldDefinition.class::cast)
153+
.filter(graphQLFieldDefinition -> graphQLFieldDefinition.getName().equals(fieldName))
154+
.findFirst();
155+
}
156+
120157
}

0 commit comments

Comments
 (0)