Skip to content

Commit 28194bd

Browse files
committed
Add test to validate schema transformation
1 parent 3e41329 commit 28194bd

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

src/test/kotlin/graphql/kickstart/tools/EndToEndTest.kt

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package graphql.kickstart.tools
22

3+
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
34
import graphql.*
45
import graphql.execution.AsyncExecutionStrategy
5-
import graphql.schema.GraphQLEnumType
6-
import graphql.schema.GraphQLSchema
6+
import graphql.schema.*
7+
import graphql.util.TraversalControl
8+
import graphql.util.TraverserContext
79
import org.junit.Test
810
import org.reactivestreams.Publisher
911
import org.reactivestreams.Subscriber
@@ -670,4 +672,40 @@ class EndToEndTest {
670672
val exceptionWhileDataFetching = result.errors[0] as ExceptionWhileDataFetching
671673
assert(exceptionWhileDataFetching.exception is IllegalArgumentException)
672674
}
675+
676+
class Transformer : GraphQLTypeVisitorStub() {
677+
override fun visitGraphQLObjectType(node: GraphQLObjectType?, context: TraverserContext<GraphQLSchemaElement>?): TraversalControl {
678+
val newNode = node?.transform { builder -> builder.description(node.description + " [MODIFIED]") }
679+
return changeNode(context, newNode)
680+
}
681+
}
682+
683+
@Test
684+
fun `transformed schema should execute query`() {
685+
val transformedSchema = SchemaTransformer().transform(schema, Transformer())
686+
val transformedGql: GraphQL = GraphQL.newGraphQL(transformedSchema)
687+
.queryExecutionStrategy(AsyncExecutionStrategy())
688+
.build()
689+
690+
val data = assertNoGraphQlErrors(transformedGql) {
691+
"""
692+
{
693+
otherUnionItems {
694+
... on Item {
695+
itemId: id
696+
}
697+
... on ThirdItem {
698+
thirdItemId: id
699+
}
700+
}
701+
}
702+
"""
703+
}
704+
705+
assertEquals(data["otherUnionItems"], listOf(
706+
mapOf("itemId" to 0),
707+
mapOf("itemId" to 1),
708+
mapOf("thirdItemId" to 100)
709+
))
710+
}
673711
}

0 commit comments

Comments
 (0)