File tree 2 files changed +27
-1
lines changed
main/kotlin/graphql/kickstart/tools/relay
test/kotlin/graphql/kickstart/tools/relay
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -6,12 +6,18 @@ import graphql.language.*
6
6
class RelayConnectionFactory : TypeDefinitionFactory {
7
7
8
8
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
+
9
15
val definitions = mutableListOf<Definition <* >>()
10
16
val definitionsByName = existing.filterIsInstance<TypeDefinition <* >>()
11
17
.associateBy { it.name }
12
18
.toMutableMap()
13
19
14
- findConnectionDirectives(existing)
20
+ connectionDirectives
15
21
.flatMap { createDefinitions(it) }
16
22
.forEach {
17
23
if (! definitionsByName.containsKey(it.name)) {
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments