Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CustomDirective for smallrye-graphql #26638

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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