Skip to content

Commit f1d0977

Browse files
committed
Added unit test to reproduce #114
1 parent ce4bffe commit f1d0977

File tree

3 files changed

+66
-10
lines changed

3 files changed

+66
-10
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ data class SchemaObjects(val query: GraphQLObjectType, val mutation: GraphQLObje
1313
* Makes a GraphQLSchema with query, mutation and subscription.
1414
*/
1515
fun toSchema(): GraphQLSchema = GraphQLSchema.newSchema()
16-
.query(query)
17-
.mutation(mutation)
18-
.subscription(subscription)
19-
.build(dictionary)
16+
.query(query)
17+
.mutation(mutation)
18+
.subscription(subscription)
19+
.additionalTypes(dictionary)
20+
.build()
2021

2122
/**
2223
* Makes a GraphQLSchema with query but without mutation and subscription.
2324
*/
2425
fun toReadOnlySchema(): GraphQLSchema = GraphQLSchema.newSchema()
25-
.query(query)
26-
.build(dictionary)
27-
}
26+
.query(query)
27+
.additionalTypes(dictionary)
28+
.build()
29+
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ class SchemaParser internal constructor(scanResult: ScannedSchemaObjects) {
5050
const val DEFAULT_DEPRECATION_MESSAGE = "No longer supported"
5151

5252
@JvmStatic fun newParser() = SchemaParserBuilder()
53-
internal fun getDocumentation(node: AbstractNode<*>): String? = node.comments?.filter {
54-
!it.content.startsWith("#")
55-
}?.map { it.content.trimEnd() }?.joinToString("\n")?.trimIndent()
53+
internal fun getDocumentation(node: AbstractNode<*>): String? = node.comments?.asSequence()
54+
?.filter {!it.content.startsWith("#")}
55+
?.joinToString("\n") { it.content.trimEnd() }
56+
?.trimIndent()
5657
}
5758

5859
private val dictionary = scanResult.dictionary
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.coxautodev.graphql.tools
2+
3+
import graphql.relay.Connection
4+
import graphql.relay.SimpleListConnection
5+
import graphql.schema.DataFetchingEnvironment
6+
import spock.lang.Specification
7+
8+
class RelayConnectionSpec extends Specification {
9+
10+
def "relay connection types are compatible"() {
11+
when:
12+
SchemaParser.newParser().schemaString('''\
13+
type Query {
14+
users(first: Int, after: String): UserConnection
15+
}
16+
17+
type UserConnection {
18+
edges: [UserEdge!]!
19+
pageInfo: PageInfo!
20+
}
21+
22+
type UserEdge {
23+
cursor: String!
24+
node: User!
25+
}
26+
27+
type User {
28+
id: ID!
29+
name: String
30+
}
31+
''')
32+
.resolvers(new QueryResolver())
33+
.dictionary(User.class)
34+
.build()
35+
.makeExecutableSchema()
36+
37+
then:
38+
noExceptionThrown()
39+
}
40+
41+
static class QueryResolver implements GraphQLQueryResolver {
42+
Connection<User> users(int first, String after, DataFetchingEnvironment env) {
43+
new SimpleListConnection<User>(new ArrayList()).get(env)
44+
}
45+
}
46+
47+
static class User {
48+
Long id
49+
String name
50+
}
51+
52+
53+
}

0 commit comments

Comments
 (0)