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 support for union directives #1889

Merged
merged 1 commit into from
Aug 9, 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 @@ -211,6 +211,7 @@ private void setupDirectives(Directives directives) {
fieldCreator.setDirectives(directives);
argumentCreator.setDirectives(directives);
operationCreator.setDirectives(directives);
unionCreator.setDirectives(directives);
}

private void addTypesToSchema(Schema schema) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.smallrye.graphql.schema.creator.type;

import java.util.List;
import java.util.Optional;

import org.jboss.jandex.ClassInfo;
Expand All @@ -8,7 +9,9 @@
import io.smallrye.graphql.schema.Annotations;
import io.smallrye.graphql.schema.creator.ReferenceCreator;
import io.smallrye.graphql.schema.helper.DescriptionHelper;
import io.smallrye.graphql.schema.helper.Directives;
import io.smallrye.graphql.schema.helper.TypeNameHelper;
import io.smallrye.graphql.schema.model.DirectiveInstance;
import io.smallrye.graphql.schema.model.Reference;
import io.smallrye.graphql.schema.model.ReferenceType;
import io.smallrye.graphql.schema.model.UnionType;
Expand All @@ -18,6 +21,7 @@ public class UnionCreator implements Creator<UnionType> {
private static final Logger LOG = Logger.getLogger(UnionCreator.class.getName());

private final ReferenceCreator referenceCreator;
private Directives directives;

public UnionCreator(ReferenceCreator referenceCreator) {
this.referenceCreator = referenceCreator;
Expand All @@ -39,7 +43,13 @@ public UnionType create(ClassInfo classInfo, Reference reference) {
// Description
Optional<String> maybeDescription = DescriptionHelper.getDescriptionForType(annotations);

return new UnionType(classInfo.name().toString(), name, maybeDescription.orElse(null));
UnionType unionType = new UnionType(classInfo.name().toString(), name, maybeDescription.orElse(null));

// Directives
unionType.setDirectiveInstances(getDirectiveInstances(annotations));

return unionType;

}

// TODO: create feature that allows adding UNION directives (graphql.schema)
Expand All @@ -48,4 +58,11 @@ public String getDirectiveLocation() {
return "UNION";
}

private List<DirectiveInstance> getDirectiveInstances(Annotations annotations) {
return directives.buildDirectiveInstances(annotations, getDirectiveLocation());
}

public void setDirectives(Directives directives) {
this.directives = directives;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,18 @@ private void createGraphQLUnionType(UnionType unionType) {
}
}

// Directives
if (unionType.hasDirectiveInstances()) {
for (DirectiveInstance directiveInstance : unionType.getDirectiveInstances()) {
unionTypeBuilder.withDirective(createGraphQLDirectiveFrom(directiveInstance));
}
}

GraphQLUnionType graphQLUnionType = unionTypeBuilder.build();
// To resolve the concrete class
this.codeRegistryBuilder.typeResolver(graphQLUnionType, new UnionResolver(unionType));
this.unionMap.put(unionType.getName(), graphQLUnionType);

}

private void createGraphQLInputObjectTypes() {
Expand Down
Loading