|
| 1 | +package graphql.annotations; |
| 2 | + |
| 3 | +import graphql.ExecutionResult; |
| 4 | +import graphql.GraphQL; |
| 5 | +import graphql.annotations.annotationTypes.GraphQLField; |
| 6 | +import graphql.annotations.annotationTypes.GraphQLName; |
| 7 | +import graphql.annotations.annotationTypes.directives.activation.Directive; |
| 8 | +import graphql.annotations.annotationTypes.directives.activation.GraphQLDirectives; |
| 9 | +import graphql.annotations.annotationTypes.directives.definition.DirectiveLocations; |
| 10 | +import graphql.annotations.annotationTypes.directives.definition.GraphQLDirectiveDefinition; |
| 11 | +import graphql.annotations.processor.GraphQLAnnotations; |
| 12 | +import graphql.introspection.Introspection; |
| 13 | +import graphql.schema.GraphQLCodeRegistry; |
| 14 | +import graphql.schema.GraphQLObjectType; |
| 15 | +import graphql.schema.GraphQLSchema; |
| 16 | +import org.testng.annotations.BeforeMethod; |
| 17 | +import org.testng.annotations.Test; |
| 18 | + |
| 19 | +import java.util.Map; |
| 20 | + |
| 21 | +import static graphql.schema.GraphQLSchema.newSchema; |
| 22 | +import static org.testng.Assert.assertEquals; |
| 23 | +import static org.testng.Assert.assertTrue; |
| 24 | + |
| 25 | +public class GraphQLDirectivesViaMethodDefinitionTest { |
| 26 | + private GraphQLAnnotations graphQLAnnotations; |
| 27 | + private GraphQLSchema schema; |
| 28 | + |
| 29 | + public static class DirectivesContainer { |
| 30 | + @GraphQLName("suffix") |
| 31 | + @GraphQLDirectiveDefinition(wiring = GraphQLDirectivesViaClassDefinitionTest.SuffixWiring.class) |
| 32 | + @DirectiveLocations({Introspection.DirectiveLocation.FIELD_DEFINITION, Introspection.DirectiveLocation.ARGUMENT_DEFINITION}) |
| 33 | + public static void suffixDirective(@GraphQLName("suffix") String suffix) { |
| 34 | + |
| 35 | + } |
| 36 | + |
| 37 | + @GraphQLField |
| 38 | + @GraphQLDirectives({ |
| 39 | + @Directive(name = "suffix", argumentsValues = {"coolSuffix"})}) |
| 40 | + public static String name() { |
| 41 | + return "yarin"; |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | + @BeforeMethod |
| 47 | + public void setUp() { |
| 48 | + this.graphQLAnnotations = new GraphQLAnnotations(); |
| 49 | + this.graphQLAnnotations.directives(DirectivesContainer.class); |
| 50 | + GraphQLObjectType object = this.graphQLAnnotations.object(DirectivesContainer.class); |
| 51 | + GraphQLCodeRegistry codeRegistry = graphQLAnnotations.getContainer().getCodeRegistryBuilder().build(); |
| 52 | + this.schema = newSchema().query(object).codeRegistry(codeRegistry).build(); |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void queryName_directivesInAlternativeWayCreation_wiringIsActivated() throws Exception { |
| 58 | + // Act |
| 59 | + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("query { name }"); |
| 60 | + // Assert |
| 61 | + assertTrue(result.getErrors().isEmpty()); |
| 62 | + assertEquals(((Map<String, String>) result.getData()).get("name").toString(), "yarincoolSuffix"); |
| 63 | + } |
| 64 | +} |
0 commit comments