Skip to content

Commit 18eec21

Browse files
committed
Find protected methods as well again in scan (fix #182, fix #184)
1 parent 023f28f commit 18eec21

File tree

5 files changed

+89
-6
lines changed

5 files changed

+89
-6
lines changed

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<groupId>com.graphql-java</groupId>
@@ -259,6 +260,6 @@
259260
<connection>scm:git:git://github.com/graphql-java/graphql-java-tools.git</connection>
260261
<developerConnection>scm:git:git@github.com:graphql-java/graphql-java-tools.git</developerConnection>
261262
<url>http://github.com/graphql-java/graphql-java-tools</url>
262-
<tag>HEAD</tag>
263-
</scm>
263+
<tag>HEAD</tag>
264+
</scm>
264265
</project>

src/main/kotlin/com/coxautodev/graphql/tools/FieldResolverScanner.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import org.apache.commons.lang3.reflect.FieldUtils
99
import org.slf4j.LoggerFactory
1010
import java.lang.reflect.Modifier
1111
import java.lang.reflect.ParameterizedType
12-
import java.lang.reflect.TypeVariable
1312

1413
/**
1514
* @author Andrew Potter
@@ -22,7 +21,7 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) {
2221
private val log = LoggerFactory.getLogger(FieldResolverScanner::class.java)
2322

2423
fun getAllMethods(type: Class<*>) =
25-
(type.methods.toList() + ClassUtils.getAllSuperclasses(type).flatMap { it.methods.toList() })
24+
(type.declaredMethods.toList() + ClassUtils.getAllSuperclasses(type).flatMap { it.methods.toList() })
2625
.asSequence()
2726
.filter { !it.isSynthetic }
2827
.filter { !Modifier.isPrivate(it.modifiers) }
@@ -74,7 +73,6 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) {
7473
private fun isBoolean(type: GraphQLLangType) = type.unwrap().let { it is TypeName && it.name == Scalars.GraphQLBoolean.name }
7574

7675
private fun findResolverMethod(field: FieldDefinition, search: Search): java.lang.reflect.Method? {
77-
7876
val methods = getAllMethods(search.type)
7977
val argumentCount = field.inputValueDefinitions.size + if (search.requiredFirstParameterType != null) 1 else 0
8078
val name = field.name

src/main/kotlin/com/coxautodev/graphql/tools/SchemaObjects.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.coxautodev.graphql.tools
33
import graphql.schema.GraphQLObjectType
44
import graphql.schema.GraphQLSchema
55
import graphql.schema.GraphQLType
6+
import graphql.schema.visibility.NoIntrospectionGraphqlFieldVisibility
67

78
/**
89
* @author Andrew Potter
@@ -17,6 +18,7 @@ data class SchemaObjects(val query: GraphQLObjectType, val mutation: GraphQLObje
1718
.mutation(mutation)
1819
.subscription(subscription)
1920
.additionalTypes(dictionary)
21+
// .fieldVisibility(NoIntrospectionGraphqlFieldVisibility.NO_INTROSPECTION_FIELD_VISIBILITY)
2022
.build()
2123

2224
/**
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.coxautodev.graphql.tools;
2+
3+
import graphql.relay.*;
4+
import graphql.schema.DataFetchingEnvironment;
5+
import org.junit.Test;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
import java.util.stream.Collectors;
10+
11+
public class RelayConnectionTest {
12+
13+
@Test
14+
public void compiles() {
15+
SchemaParser.newParser().file("RelayConnection.graphqls")
16+
.resolvers(new QueryResolver())
17+
.dictionary(User.class)
18+
.build()
19+
.makeExecutableSchema();
20+
}
21+
22+
static class QueryResolver implements GraphQLQueryResolver {
23+
// fixme #114: desired return type to use: Connection<User>
24+
public UserConnection users(int first, String after, DataFetchingEnvironment env) {
25+
return (UserConnection) new SimpleListConnection<User>(new ArrayList()).get(env);
26+
}
27+
}
28+
29+
// fixme #114: remove this implementation
30+
static class UserConnection extends DefaultConnection<User> {
31+
32+
UserConnection(List<Edge<User>> edges, PageInfo pageInfo) {
33+
super(edges, pageInfo);
34+
}
35+
36+
public List<UserEdge> edges() {
37+
return super.getEdges().stream()
38+
.map(UserEdge.class::cast)
39+
.collect(Collectors.toList());
40+
}
41+
42+
public PageInfo getPageInfo() {
43+
return super.getPageInfo();
44+
}
45+
}
46+
47+
// fixme #114: remove this implementation
48+
static class UserEdge extends DefaultEdge<User> {
49+
50+
UserEdge(User node, ConnectionCursor cursor) {
51+
super(node, cursor);
52+
}
53+
54+
}
55+
56+
static class User {
57+
Long id;
58+
String name;
59+
}
60+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
type Query {
2+
users(first: Int, after: String): UserConnection
3+
}
4+
5+
type UserConnection {
6+
edges: [UserEdge!]!
7+
pageInfo: PageInfo!
8+
}
9+
10+
type UserEdge {
11+
cursor: String!
12+
node: User!
13+
}
14+
15+
type User {
16+
id: ID!
17+
name: String
18+
}
19+
20+
type PageInfo {
21+
22+
}

0 commit comments

Comments
 (0)