Skip to content

Commit

Permalink
Fix quarkusio#20802 CustomDirective for smallrye-graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
robp94 authored and michelle-purcell committed Jul 20, 2022
1 parent 8dc30de commit 1af2287
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import io.smallrye.graphql.schema.Annotations;
import io.smallrye.graphql.schema.SchemaBuilder;
import io.smallrye.graphql.schema.model.Argument;
import io.smallrye.graphql.schema.model.DirectiveType;
import io.smallrye.graphql.schema.model.Field;
import io.smallrye.graphql.schema.model.Group;
import io.smallrye.graphql.schema.model.InputType;
Expand Down Expand Up @@ -403,6 +404,7 @@ private String[] getSchemaJavaClasses(Schema schema) {
classes.addAll(getTypeClassNames(schema.getTypes().values()));
classes.addAll(getInputClassNames(schema.getInputs().values()));
classes.addAll(getInterfaceClassNames(schema.getInterfaces().values()));
classes.addAll(getDirectiveTypeClassNames(schema.getDirectiveTypes()));

return classes.toArray(String[]::new);
}
Expand Down Expand Up @@ -460,6 +462,16 @@ private Set<String> getTypeClassNames(Collection<Type> complexGraphQLTypes) {
return classes;
}

private Set<String> getDirectiveTypeClassNames(Collection<DirectiveType> complexGraphQLDirectiveTypes) {
Set<String> classes = new HashSet<>();
for (DirectiveType complexGraphQLDirectiveType : complexGraphQLDirectiveTypes) {
if (complexGraphQLDirectiveType.getClassName() != null) {
classes.add(complexGraphQLDirectiveType.getClassName());
}
}
return classes;
}

private Set<String> getInputClassNames(Collection<InputType> complexGraphQLTypes) {
Set<String> classes = new HashSet<>();
for (InputType complexGraphQLType : complexGraphQLTypes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.smallrye.graphql.deployment;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import org.eclipse.microprofile.graphql.Description;
import org.eclipse.microprofile.graphql.NonNull;

import io.smallrye.graphql.api.Directive;
import io.smallrye.graphql.api.DirectiveLocation;

@Directive(on = { DirectiveLocation.OBJECT, DirectiveLocation.INTERFACE, DirectiveLocation.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Description("test-description")
public @interface CustomDirective {
@NonNull
String[] fields();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkus.smallrye.graphql.deployment;

import static io.quarkus.smallrye.graphql.deployment.AbstractGraphQLTest.MEDIATYPE_JSON;

import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -30,7 +28,7 @@ public class GraphQLTest extends AbstractGraphQLTest {
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestResource.class, TestPojo.class, TestRandom.class, TestGenericsPojo.class,
BusinessException.class)
CustomDirective.class, BusinessException.class)
.addAsResource(new StringAsset(getPropertyAsString(configuration())), "application.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

Expand All @@ -51,6 +49,8 @@ public void testSchema() {
Assertions.assertTrue(body.contains("type TestGenericsPojo_String {"));
Assertions.assertTrue(body.contains("enum SomeEnum {"));
Assertions.assertTrue(body.contains("enum Number {"));
Assertions.assertTrue(body.contains("type TestPojo @customDirective(fields : [\"test-pojo\"])"));
Assertions.assertTrue(body.contains("message: String @customDirective(fields : [\"message\"])"));
}

@Test
Expand Down Expand Up @@ -253,6 +253,7 @@ public void testContext() {
private static Map<String, String> configuration() {
Map<String, String> m = new HashMap<>();
m.put("quarkus.smallrye-graphql.events.enabled", "true");
m.put("quarkus.smallrye-graphql.schema-include-directives", "true");
return m;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class HotReloadTest extends AbstractGraphQLTest {
final static QuarkusDevModeTest TEST = new QuarkusDevModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestResource.class, TestPojo.class, TestRandom.class, TestGenericsPojo.class,
BusinessException.class)
CustomDirective.class, BusinessException.class)
.addAsResource(new StringAsset(getPropertyAsString()), "application.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
/**
* Just a test pojo
*/
@CustomDirective(fields = "test-pojo")
public class TestPojo {
@CustomDirective(fields = "message")
private String message;
private List<String> list = Arrays.asList("a", "b", "c");

Expand Down

0 comments on commit 1af2287

Please sign in to comment.