Skip to content

Commit db103a1

Browse files
committed
Support generics (fix #114)
1 parent 94fa444 commit db103a1

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.graphql-java</groupId>
66
<artifactId>graphql-java-tools</artifactId>
7-
<version>5.2.5-SNAPSHOT</version>
7+
<version>5.3.0-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>GraphQL Java Tools</name>

src/test/groovy/com/coxautodev/graphql/tools/RelayConnectionSpec.groovy

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package com.coxautodev.graphql.tools
22

3+
import graphql.GraphQL
4+
import graphql.execution.AsyncExecutionStrategy
35
import graphql.relay.Connection
46
import graphql.relay.DefaultConnection
57
import graphql.relay.Edge
68
import graphql.relay.SimpleListConnection
79
import graphql.schema.DataFetchingEnvironment
10+
import graphql.schema.GraphQLSchema
11+
import spock.lang.Shared
812
import spock.lang.Specification
913

1014
class RelayConnectionSpec extends Specification {
1115

1216
def "relay connection types are compatible"() {
1317
when:
14-
SchemaParser.newParser().schemaString('''\
18+
GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
1519
type Query {
1620
users(first: Int, after: String): UserConnection
1721
otherTypes: AnotherTypeConnection
@@ -43,34 +47,72 @@ class RelayConnectionSpec extends Specification {
4347
}
4448
4549
type AnotherType {
46-
50+
echo: String
4751
}
4852
''')
4953
.resolvers(new QueryResolver())
5054
.build()
5155
.makeExecutableSchema()
56+
GraphQL gql = GraphQL.newGraphQL(schema)
57+
.queryExecutionStrategy(new AsyncExecutionStrategy())
58+
.build()
59+
def data = Utils.assertNoGraphQlErrors(gql, [limit: 10]) {
60+
'''
61+
query {
62+
users {
63+
edges {
64+
node {
65+
id
66+
name
67+
}
68+
}
69+
}
70+
otherTypes {
71+
edges {
72+
node {
73+
echo
74+
}
75+
}
76+
}
77+
}
78+
'''
79+
}
5280

5381
then:
5482
noExceptionThrown()
83+
data.users.edges.size == 1
84+
data.users.edges[0].node.id == "1"
85+
data.users.edges[0].node.name == "name"
86+
data.otherTypes.edges.size == 1
87+
data.otherTypes.edges[0].node.echo == "echo"
5588
}
5689

5790
static class QueryResolver implements GraphQLQueryResolver {
5891
Connection<User> users(int first, String after, DataFetchingEnvironment env) {
59-
new SimpleListConnection<User>(new ArrayList()).get(env)
92+
new SimpleListConnection<User>(new ArrayList([new User(1L, "name")])).get(env)
6093
}
6194

6295
Connection<AnotherType> otherTypes(DataFetchingEnvironment env) {
63-
new SimpleListConnection<AnotherType>(new ArrayList()).get(env)
96+
new SimpleListConnection<AnotherType>(new ArrayList([new AnotherType("echo")])).get(env)
6497
}
6598
}
6699

67100
static class User {
68101
Long id
69102
String name
103+
104+
User(Long id, String name) {
105+
this.id = id
106+
this.name = name
107+
}
70108
}
71109

72110
private static class AnotherType {
111+
String echo
73112

113+
AnotherType(String echo) {
114+
this.echo = echo
115+
}
74116
}
75117

76118

0 commit comments

Comments
 (0)