|
1 | 1 | package com.introproventures.graphql.jpa.query.schema;
|
2 | 2 |
|
| 3 | +import java.util.Optional; |
| 4 | + |
3 | 5 | import static org.assertj.core.api.Assertions.assertThat;
|
4 | 6 | import static org.assertj.core.api.Assertions.tuple;
|
| 7 | +import static org.assertj.core.api.BDDAssertions.then; |
5 | 8 | import static org.assertj.core.util.Lists.list;
|
6 | 9 |
|
7 | 10 | import javax.persistence.EntityManager;
|
8 | 11 |
|
| 12 | +import graphql.schema.GraphQLFieldDefinition; |
| 13 | +import graphql.schema.GraphQLSchema; |
9 | 14 | import org.junit.Test;
|
10 | 15 | import org.junit.runner.RunWith;
|
11 | 16 | import org.springframework.beans.factory.annotation.Autowired;
|
@@ -46,6 +51,9 @@ public GraphQLSchemaBuilder graphQLSchemaBuilder(final EntityManager entityManag
|
46 | 51 | @Autowired
|
47 | 52 | private GraphQLExecutor executor;
|
48 | 53 |
|
| 54 | + @Autowired |
| 55 | + private GraphQLSchemaBuilder schemaBuilder; |
| 56 | + |
49 | 57 | @Test
|
50 | 58 | public void contextLoads() {
|
51 | 59 | Assert.isAssignable(GraphQLExecutor.class, executor.getClass());
|
@@ -117,4 +125,33 @@ public void testIgnoreFields() {
|
117 | 125 | );
|
118 | 126 | }
|
119 | 127 |
|
| 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 | + |
120 | 157 | }
|
0 commit comments