Skip to content

Commit

Permalink
Switching createGraphQLEnumTypes and createGraphQLDirectiveTypes to a…
Browse files Browse the repository at this point in the history
…llow EnumTypes directive arguments
  • Loading branch information
mskacelik authored and jmartisk committed Nov 24, 2023
1 parent a696c14 commit 2871a2a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ private void verifyInjectionIsAvailable() {
private void generateGraphQLSchema() {
GraphQLSchema.Builder schemaBuilder = GraphQLSchema.newSchema();

createGraphQLDirectiveTypes();
createGraphQLEnumTypes();
createGraphQLDirectiveTypes();

createGraphQLInterfaceTypes();
createGraphQLUnionTypes();
createGraphQLObjectTypes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
import io.smallrye.graphql.bootstrap.Bootstrap;
import io.smallrye.graphql.execution.SchemaPrinter;
import io.smallrye.graphql.execution.TestConfig;
import io.smallrye.graphql.schema.directiveswithenumvalues.MyEnum;
import io.smallrye.graphql.schema.directiveswithenumvalues.MyEnumValueDirective;
import io.smallrye.graphql.schema.directiveswithenumvalues.MyObject;
import io.smallrye.graphql.schema.directiveswithenumvalues.SomeApi;
import io.smallrye.graphql.schema.model.Schema;
import io.smallrye.graphql.schema.rolesallowedschemas.Customer;
import io.smallrye.graphql.schema.rolesallowedschemas.RolesSchema1;
Expand Down Expand Up @@ -112,6 +116,31 @@ void testSchemaWithDirectives() throws URISyntaxException, IOException {
Assertions.assertEquals(expectedSchema, actualSchema);
}

@Test
void testSchemaWithEnumValueDirectives() throws URISyntaxException, IOException {
GraphQLSchema graphQLSchema = createGraphQLSchema(MyEnum.class, MyEnumValueDirective.class, EnumDirective.class,
MyObject.class, SomeApi.class);

GraphQLDirective typeDirective = graphQLSchema.getDirective("myEnumValueDirective");
assertEquals("myEnumValueDirective", typeDirective.getName());
assertEquals(1, typeDirective.getArguments().size());
assertEquals("MyEnum!", typeDirective.getArgument("value").getType().toString());

GraphQLFieldDefinition fieldWithEnumValueDirective = graphQLSchema
.getObjectType("MyObject")
.getFieldDefinition("name");

GraphQLDirective enumValueDirectiveInstance = fieldWithEnumValueDirective.getDirective("myEnumValueDirective");
assertEquals("myEnumValueDirective", enumValueDirectiveInstance.getName());
GraphQLArgument argument = enumValueDirectiveInstance.getArgument("value");
assertEquals("value", argument.getName());
assertEquals(MyEnum.SOME.toString(), argument.toAppliedArgument().getValue());

GraphQLEnumType enumType = graphQLSchema.getTypeAs("MyEnum");
assertNotNull(enumType.getDirective("enumDirective"),
"Enum MyEnum should have directive @enumDirective");
}

@Test
void schemaWithEnumDirectives() {
GraphQLSchema graphQLSchema = createGraphQLSchema(EnumDirective.class, EnumTestApi.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.smallrye.graphql.schema.directiveswithenumvalues;

import io.smallrye.graphql.schema.EnumDirective;

@EnumDirective
public enum MyEnum {
SOME,
THING
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.smallrye.graphql.schema.directiveswithenumvalues;

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

import org.eclipse.microprofile.graphql.NonNull;

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

@Retention(RetentionPolicy.RUNTIME)
@Directive(on = DirectiveLocation.FIELD_DEFINITION)
public @interface MyEnumValueDirective {

@NonNull
MyEnum value();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.smallrye.graphql.schema.directiveswithenumvalues;

import java.util.Objects;

import org.eclipse.microprofile.graphql.NonNull;

public class MyObject {

@NonNull
@MyEnumValueDirective(MyEnum.SOME)
String name;

public MyObject(String name) {
this.name = Objects.requireNonNull(name);
}

public String getName() {
return name;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.smallrye.graphql.schema.directiveswithenumvalues;

import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Query;

@GraphQLApi
public class SomeApi {
@Query
public MyObject getMyObject() {
return new MyObject("Test");
}
}

0 comments on commit 2871a2a

Please sign in to comment.