Skip to content

Commit ff0e12b

Browse files
author
Johan Rouve
committed
Prevent to add PageInfo definition if not needed
1 parent 0b2a3a5 commit ff0e12b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/main/kotlin/graphql/kickstart/tools/relay/RelayConnectionFactory.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ import graphql.language.*
66
class RelayConnectionFactory : TypeDefinitionFactory {
77

88
override fun create(existing: MutableList<Definition<*>>): List<Definition<*>> {
9+
val connectionDirectives = findConnectionDirectives(existing)
10+
if (connectionDirectives.isEmpty()) {
11+
return emptyList()
12+
}
13+
914
val definitions = mutableListOf<Definition<*>>()
1015
val definitionsByName = existing.filterIsInstance<TypeDefinition<*>>()
1116
.associateBy { it.name }
1217
.toMutableMap()
1318

14-
findConnectionDirectives(existing)
19+
connectionDirectives
1520
.flatMap { createDefinitions(it) }
1621
.forEach {
1722
if (!definitionsByName.containsKey(it.name)) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package graphql.kickstart.tools.relay
2+
3+
import graphql.language.Definition
4+
import org.junit.Assert
5+
import org.junit.Test
6+
7+
class RelayConnectionFactoryTest {
8+
9+
@Test
10+
fun `should not add new definition when no @connection directive`() {
11+
// setup
12+
val factory = RelayConnectionFactory()
13+
val existing = mutableListOf<Definition<*>>()
14+
15+
val newDefinitions = factory.create(existing)
16+
17+
// expect
18+
Assert.assertEquals(newDefinitions.size, 0)
19+
}
20+
}

0 commit comments

Comments
 (0)