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

Added union directive tests #1893

Merged
merged 1 commit into from
Aug 10, 2023
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 @@ -52,7 +52,6 @@ public UnionType create(ClassInfo classInfo, Reference reference) {

}

// TODO: create feature that allows adding UNION directives (graphql.schema)
@Override
public String getDirectiveLocation() {
return "UNION";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static java.util.Objects.requireNonNull;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -20,6 +21,7 @@
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -124,6 +126,24 @@ void schemaWithEnumDirectives() {
"Enum value EnumWithDirectives.B should not have directive @enumDirective");
}

@Test
void schemaWithUnionDirectives() {
GraphQLSchema graphQLSchema = createGraphQLSchema(UnionDirective.class, UnionTestApi.class,
UnionTestApi.SomeUnion.class, UnionTestApi.SomeClass.class);

GraphQLUnionType unionWithDirectives = graphQLSchema.getTypeAs("SomeUnion");
List<GraphQLDirective> unionDirectives = unionWithDirectives.getDirectives("unionDirective");
assertFalse(unionDirectives.isEmpty(),
"Union SomeUnion should have directive @unionDirective");
assertEquals(3, unionDirectives.size(), "Union SomeUnion should have 3 @unionDirective instances");
Set<String> expectedDirectivesArgValues = new HashSet<>(Arrays.asList("A", "B", "C"));
unionDirectives.forEach(directive -> directive.getArguments()
.forEach(argument -> assertFalse(expectedDirectivesArgValues.add(argument.toAppliedArgument().getValue()),
"Unexpected directive argument value")));
assertTrue(unionWithDirectives.getDirectives("InputDirective").isEmpty(),
"Union SomeUnion should not have a directive @inputDirective");
}

@Test
void schemaWithInputDirectives() {
GraphQLSchema graphQLSchema = createGraphQLSchema(InputDirective.class, OutputDirective.class, InputTestApi.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.smallrye.graphql.schema;

import static io.smallrye.graphql.api.DirectiveLocation.UNION;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;

import io.smallrye.graphql.api.Directive;

@Retention(RUNTIME)
@Directive(on = { UNION })
@Repeatable(UnionDirective.UnionDirectives.class)
public @interface UnionDirective {
String value();

@Retention(RUNTIME)
@interface UnionDirectives {
UnionDirective[] value();
}

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

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

import io.smallrye.graphql.api.Union;

@GraphQLApi
public class UnionTestApi {

@Query
public SomeUnion query() {
return null;
}

static class SomeClass implements SomeUnion {
private int number;

public int getNumber() {
return number;
}

}

@Union
@UnionDirective(value = "C")
@UnionDirective(value = "A")
@InputDirective // should be ignored
@UnionDirective(value = "B")
interface SomeUnion {
}

}
Loading