Skip to content

Commit

Permalink
Fixed a problem where during the scanning of InputTypes it included s…
Browse files Browse the repository at this point in the history
…ynthetic methods, added a filter + test
  • Loading branch information
mskacelik authored and jmartisk committed Nov 22, 2023
1 parent 7d87fcf commit a696c14
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void addFields(InputType inputType, ClassInfo classInfo, Reference refer
// Find all methods and properties up the tree
for (ClassInfo c = classInfo; c != null; c = ScanningContext.getIndex().getClassByName(c.superName())) {
if (!c.toString().startsWith(JAVA_DOT)) { // Not java objects
allMethods.addAll(c.methods());
c.methods().stream().filter(methodInfo -> !methodInfo.isSynthetic()).forEach(allMethods::add);
for (final FieldInfo fieldInfo : c.fields()) {
allFields.putIfAbsent(fieldInfo.name(), fieldInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ public void testGenericSchemaBuilding() {
Set<Operation> mutations = schema.getMutations();
Map<String, Type> outputTypes = schema.getTypes();

assertEquals(queries.size(), 2);
assertEquals(mutations.size(), 4);
assertEquals(queries.size(), 3);
assertEquals(mutations.size(), 5);

Operation firstQuery = queries.stream()
.filter(q -> q.getName().equals("heroes"))
Expand All @@ -221,6 +221,12 @@ public void testGenericSchemaBuilding() {
Type greetingType = outputTypes.get("Greet");
assertNotNull(greetingType);

Operation thirdQuery = queries.stream()
.filter(q -> q.getName().equals("saySome")).findFirst().orElseThrow(AssertionError::new);
assertEquals(thirdQuery.getArguments().size(), 1);
assertEquals(thirdQuery.getArguments().get(0).getReference().getName(), "SomeInput");
assertEquals(thirdQuery.getReference().getName(), "Some");

// ------------------------------------------------------------------
// MUTATIONS
Operation firstMutation = mutations.stream()
Expand Down Expand Up @@ -281,6 +287,17 @@ public void testGenericSchemaBuilding() {
// return type
assertEquals(fourthMutation.getReference().getName(), "Hero");

Operation fifthMutation = mutations.stream()
.filter(q -> q.getName().equals("updateSome"))
.findFirst()
.orElseThrow(AssertionError::new);

// arguments
assertEquals(fifthMutation.getArguments().size(), 1);
assertEquals(fifthMutation.getArguments().get(0).getReference().getName(), "SomeInput");
// return type
assertEquals(fifthMutation.getReference().getName(), "Some");

}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.smallrye.graphql.index.generic;

public interface Attribute<T> {
T getValue();

void setValue(T value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ public ResponseComposite sayHello(String name) {
return null;
}

@Query
public Some saySome(Some value) {
return null;
}

@Mutation
public Some updateSome(Some some) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.smallrye.graphql.index.generic;

public class Some implements Attribute<Long> {
Long some;

public Some() {
}

public Some(Long some) {
this.some = some;
}

@Override
public Long getValue() {
return some;
}

@Override
public void setValue(Long value) {
this.some = value;
}
}

0 comments on commit a696c14

Please sign in to comment.