Skip to content

Commit

Permalink
[#1655]: quickfix for fetches attribute from an EntityViewInheritance…
Browse files Browse the repository at this point in the history
… annotated entity view

If the viewType is a supertype then some of the given `fetches` might actually
belong to one of its subtypes. This was mishandled by the current implementation
and lead to an NPE.
  • Loading branch information
david-kubecka authored and beikov committed Feb 8, 2023
1 parent 016a7e7 commit 9778610
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ private static NavigableSet<String> getFetches(Collection<String> fetches, Manag
// Fetch a specific attribute
sb.append(parts[i]);
MethodAttribute<?, ?> attribute = viewType.getAttribute(parts[i]);
if (attribute == null) {
// fallback for viewType with @EntityViewInheritance
attribute = viewType.getRecursiveAttributes().get(parts[i]);
}
if (attribute instanceof PluralAttribute<?, ?, ?>) {
t = ((PluralAttribute<?, ?, ?>) attribute).getElementType();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void run() {
for (int i = 0; i < 4; i++) {
Boy b = new Boy("Boy " + i);
em.persist(b);
Girl g = new Girl("Girl " + i);
Girl g = new Girl("Girl " + i, "Doll " + i);
em.persist(g);
Person p = new Person("Person " + i, new HashSet<>(Arrays.asList(b, g)));
people.add(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,22 @@

@Entity
public class Girl extends Child {
public Girl(String name) {

private String dollName;

public Girl(String name, String dollName) {
super(name);
this.dollName = dollName;
}

public Girl() {
}

public String getDollName() {
return dollName;
}

public void setDollName(String dollName) {
this.dollName = dollName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
@GraphQLType(name = "Girl")
@EntityView(Girl.class)
public interface GirlView extends ChildView {
String getDollName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void init() {
for (int i = 0; i < 4; i++) {
Boy b = new Boy("Boy " + i);
em.persist(b);
Girl g = new Girl("Girl " + i);
Girl g = new Girl("Girl " + i, "Doll " + i);
em.persist(g);
Person p = new Person("Person " + i, new HashSet<>(Arrays.asList(b, g)));
people.add(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void testRequestScope() {
assertEquals("Person 0", nodes.get(0).get("owner").get("name").asText());
assertEquals("Boy 0", nodes.get(0).get("owner").get("children").get(0).get("name").asText());
assertEquals("Girl 0", nodes.get(0).get("owner").get("children").get(1).get("name").asText());
assertEquals("Doll 0", nodes.get(0).get("owner").get("children").get(1).get("dollName").asText());

requestGraphQL = request(5, connection.get("pageInfo").get("endCursor").asText());
response = this.restTemplate.postForEntity("/graphql", new HttpEntity<>(requestGraphQL, headers), JsonNode.class);
Expand Down Expand Up @@ -122,7 +123,8 @@ static String request(int first, String after) {
" name\n" +
" children {\n" +
" ... on Boy { name }\n" +
" ... on Girl { name }\n" +
" ... on Girl { name dollName }\n" +
" __typename\n" +
" }\n" +
" }\n" +
" }\n" +
Expand Down

0 comments on commit 9778610

Please sign in to comment.