Skip to content

Commit 576353e

Browse files
authored
Merge pull request #476 from ooga/not-add-pageinfo-definition
Prevent to add PageInfo definition if not needed
2 parents f989690 + fabdb3d commit 576353e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ 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+
// do not add Relay definitions unless needed
12+
return emptyList()
13+
}
14+
915
val definitions = mutableListOf<Definition<*>>()
1016
val definitionsByName = existing.filterIsInstance<TypeDefinition<*>>()
1117
.associateBy { it.name }
1218
.toMutableMap()
1319

14-
findConnectionDirectives(existing)
20+
connectionDirectives
1521
.flatMap { createDefinitions(it) }
1622
.forEach {
1723
if (!definitionsByName.containsKey(it.name)) {
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.assertEquals
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+
assertEquals(newDefinitions.size, 0)
19+
}
20+
}

0 commit comments

Comments
 (0)