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