-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/kotlin/com/expedia/graphql/integration/NodeGraphTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.expedia.graphql.integration | ||
|
||
import com.expedia.graphql.TopLevelObject | ||
import com.expedia.graphql.testSchemaConfig | ||
import com.expedia.graphql.toSchema | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class NodeGraphTest { | ||
|
||
@Test | ||
fun nodeGraph() { | ||
val root = Node(id = 0, value = "root", parent = null, children = emptyList()) | ||
val nodeA = Node(id = 1, value = "A", parent = root, children = emptyList()) | ||
val nodeB = Node(id = 2, value = "B", parent = root, children = emptyList()) | ||
val nodeC = Node(id = 3, value = "C", parent = nodeB, children = emptyList()) | ||
|
||
root.children = listOf(nodeA, nodeB) | ||
nodeB.children = listOf(nodeC) | ||
|
||
val queries = listOf(TopLevelObject(NodeQuery())) | ||
|
||
val schema = toSchema(queries = queries, config = testSchemaConfig) | ||
|
||
assertEquals(expected = 1, actual = schema.queryType.fieldDefinitions.size) | ||
assertEquals(expected = "nodeGraph", actual = schema.queryType.fieldDefinitions.first().name) | ||
} | ||
} | ||
|
||
/** | ||
* Represents a recursive type that references itself, | ||
* similar to a tree node structure. | ||
*/ | ||
data class Node( | ||
val id: Int, | ||
val value: String, | ||
val parent: Node?, | ||
var children: List<Node> | ||
) | ||
|
||
class NodeQuery { | ||
|
||
private val root = Node(id = 0, value = "root", parent = null, children = emptyList()) | ||
private val nodeA = Node(id = 1, value = "A", parent = root, children = emptyList()) | ||
private val nodeB = Node(id = 2, value = "B", parent = root, children = emptyList()) | ||
private val nodeC = Node(id = 3, value = "C", parent = nodeB, children = emptyList()) | ||
|
||
init { | ||
root.children = listOf(nodeA, nodeB) | ||
nodeB.children = listOf(nodeC) | ||
} | ||
|
||
fun nodeGraph() = root | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/kotlin/com/expedia/graphql/integration/RecursiveInterfaceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.expedia.graphql.integration | ||
|
||
import com.expedia.graphql.TopLevelObject | ||
import com.expedia.graphql.testSchemaConfig | ||
import com.expedia.graphql.toSchema | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class RecursiveInterfaceTest { | ||
|
||
@Test | ||
fun recursiveInterface() { | ||
val queries = listOf(TopLevelObject(RecursiveInterfaceQuery())) | ||
val schema = toSchema(queries = queries, config = testSchemaConfig) | ||
assertEquals(1, schema.queryType.fieldDefinitions.size) | ||
val field = schema.queryType.fieldDefinitions.first() | ||
assertEquals("getRoot", field.name) | ||
} | ||
} | ||
|
||
class RecursiveInterfaceQuery { | ||
fun getRoot() = RecursiveInterfaceA() | ||
} | ||
|
||
interface SomeInterface { | ||
val id: String | ||
} | ||
|
||
class RecursiveInterfaceA : SomeInterface { | ||
override val id = "A" | ||
fun getB() = RecursiveInterfaceB() | ||
} | ||
|
||
class RecursiveInterfaceB : SomeInterface { | ||
override val id = "B" | ||
fun getA() = RecursiveInterfaceA() | ||
} |
33 changes: 33 additions & 0 deletions
33
src/test/kotlin/com/expedia/graphql/integration/RecursiveUnionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.expedia.graphql.integration | ||
|
||
import com.expedia.graphql.TopLevelObject | ||
import com.expedia.graphql.testSchemaConfig | ||
import com.expedia.graphql.toSchema | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class RecursiveUnionTest { | ||
|
||
@Test | ||
fun recursiveUnion() { | ||
val queries = listOf(TopLevelObject(RecursiveUnionQuery())) | ||
val schema = toSchema(queries = queries, config = testSchemaConfig) | ||
assertEquals(1, schema.queryType.fieldDefinitions.size) | ||
val field = schema.queryType.fieldDefinitions.first() | ||
assertEquals("getRoot", field.name) | ||
} | ||
} | ||
|
||
class RecursiveUnionQuery { | ||
fun getRoot() = RecursiveUnionA() | ||
} | ||
|
||
interface SomeUnion | ||
|
||
class RecursiveUnionA : SomeUnion { | ||
fun getB() = RecursiveUnionB() | ||
} | ||
|
||
class RecursiveUnionB : SomeUnion { | ||
fun getA() = RecursiveUnionA() | ||
} |