|
1 | 1 | package graphql.kickstart.tools
|
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder |
3 | 4 | import graphql.*
|
4 | 5 | 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 |
7 | 9 | import org.junit.Test
|
8 | 10 | import org.reactivestreams.Publisher
|
9 | 11 | import org.reactivestreams.Subscriber
|
@@ -670,4 +672,40 @@ class EndToEndTest {
|
670 | 672 | val exceptionWhileDataFetching = result.errors[0] as ExceptionWhileDataFetching
|
671 | 673 | assert(exceptionWhileDataFetching.exception is IllegalArgumentException)
|
672 | 674 | }
|
| 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 | + } |
673 | 711 | }
|
0 commit comments