|
44 | 44 | import java.lang.reflect.Parameter; |
45 | 45 | import java.util.Arrays; |
46 | 46 | import java.util.Collections; |
| 47 | +import java.util.Comparator; |
47 | 48 | import java.util.HashMap; |
48 | 49 | import java.util.List; |
49 | 50 | import java.util.Map; |
50 | 51 | import java.util.Optional; |
| 52 | +import java.util.TreeMap; |
51 | 53 | import java.util.function.Function; |
52 | 54 | import java.util.stream.Collectors; |
53 | 55 |
|
@@ -149,7 +151,7 @@ public GraphQLInterfaceType.Builder getIfaceBuilder(Class<?> iface) throws Graph |
149 | 151 | if (description != null) { |
150 | 152 | builder.description(description.value()); |
151 | 153 | } |
152 | | - for (Method method : iface.getMethods()) { |
| 154 | + for (Method method : getOrderedMethods(iface)) { |
153 | 155 | boolean valid = !Modifier.isStatic(method.getModifiers()) && |
154 | 156 | method.getAnnotation(GraphQLField.class) != null; |
155 | 157 | if (valid) { |
@@ -222,7 +224,7 @@ public GraphQLObjectType.Builder getObjectBuilder(Class<?> object) throws GraphQ |
222 | 224 | if (description != null) { |
223 | 225 | builder.description(description.value()); |
224 | 226 | } |
225 | | - for (Method method : object.getMethods()) { |
| 227 | + for (Method method : getOrderedMethods(object)) { |
226 | 228 |
|
227 | 229 | Class<?> declaringClass = getDeclaringClass(method); |
228 | 230 |
|
@@ -261,13 +263,19 @@ public static GraphQLObjectType.Builder objectBuilder(Class<?> object) throws Gr |
261 | 263 | } |
262 | 264 |
|
263 | 265 |
|
| 266 | + protected List<Method> getOrderedMethods(Class c) { |
| 267 | + return Arrays.stream(c.getMethods()) |
| 268 | + .sorted(Comparator.comparing(Method::getName)) |
| 269 | + .collect(Collectors.toList()); |
| 270 | + } |
| 271 | + |
264 | 272 | protected Map<String, Field> getAllFields(Class c) { |
265 | 273 | Map<String, Field> fields; |
266 | 274 |
|
267 | 275 | if (c.getSuperclass() != null) { |
268 | 276 | fields = getAllFields(c.getSuperclass()); |
269 | 277 | } else { |
270 | | - fields = new HashMap<>(); |
| 278 | + fields = new TreeMap<>(); |
271 | 279 | } |
272 | 280 |
|
273 | 281 | for (Field f : c.getDeclaredFields()) { |
|
0 commit comments