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 directives building #2188

Closed
wants to merge 1 commit into from
Closed
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
@@ -0,0 +1,73 @@
package io.smallrye.graphql.schema;

import java.io.IOException;

import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;

import io.smallrye.graphql.api.OneOf;
import io.smallrye.graphql.api.federation.Authenticated;
import io.smallrye.graphql.api.federation.ComposeDirective;
import io.smallrye.graphql.api.federation.Extends;
import io.smallrye.graphql.api.federation.External;
import io.smallrye.graphql.api.federation.FieldSet;
import io.smallrye.graphql.api.federation.Inaccessible;
import io.smallrye.graphql.api.federation.InterfaceObject;
import io.smallrye.graphql.api.federation.Key;
import io.smallrye.graphql.api.federation.Override;
import io.smallrye.graphql.api.federation.Provides;
import io.smallrye.graphql.api.federation.Requires;
import io.smallrye.graphql.api.federation.Shareable;
import io.smallrye.graphql.api.federation.Tag;
import io.smallrye.graphql.api.federation.link.Import;
import io.smallrye.graphql.api.federation.link.Link;
import io.smallrye.graphql.api.federation.link.Purpose;
import io.smallrye.graphql.api.federation.policy.Policy;
import io.smallrye.graphql.api.federation.policy.PolicyGroup;
import io.smallrye.graphql.api.federation.policy.PolicyItem;
import io.smallrye.graphql.api.federation.requiresscopes.RequiresScopes;
import io.smallrye.graphql.api.federation.requiresscopes.ScopeGroup;
import io.smallrye.graphql.api.federation.requiresscopes.ScopeItem;

class DirectiveIndexer {
static IndexView directiveIndex() {
Indexer indexer = new Indexer();

try {
// directives from the API module
indexer.indexClass(io.smallrye.graphql.api.Deprecated.class);
indexer.indexClass(java.lang.Deprecated.class);
indexer.indexClass(OneOf.class);

indexer.indexClass(Authenticated.class);
indexer.indexClass(ComposeDirective.class);
indexer.indexClass(Extends.class);
indexer.indexClass(External.class);
indexer.indexClass(FieldSet.class);
indexer.indexClass(Inaccessible.class);
indexer.indexClass(InterfaceObject.class);
indexer.indexClass(Key.class);
indexer.indexClass(Override.class);
indexer.indexClass(Provides.class);
indexer.indexClass(Requires.class);
indexer.indexClass(Shareable.class);
indexer.indexClass(Tag.class);

indexer.indexClass(Link.class);
indexer.indexClass(Import.class);
indexer.indexClass(Purpose.class);

indexer.indexClass(Policy.class);
indexer.indexClass(PolicyGroup.class);
indexer.indexClass(PolicyItem.class);

indexer.indexClass(RequiresScopes.class);
indexer.indexClass(ScopeGroup.class);
indexer.indexClass(ScopeItem.class);
} catch (IOException e) {
throw new RuntimeException(e);
}

return indexer.complete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.CompositeIndex;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.MethodInfo;
Expand Down Expand Up @@ -100,7 +101,7 @@ public static Schema build(IndexView index) {
* @return the Schema
*/
public static Schema build(IndexView index, TypeAutoNameStrategy autoNameStrategy) {
ScanningContext.register(index);
ScanningContext.register(CompositeIndex.create(index, DirectiveIndexer.directiveIndex()));
return new SchemaBuilder(autoNameStrategy).generateSchema();
}

Expand Down Expand Up @@ -185,6 +186,8 @@ private List<MethodInfo> getAllMethodsIncludingFromSuperClasses(ClassInfo classI
}

private void addDirectiveTypes(Schema schema) {
Set<DirectiveType> directiveTypes = new HashSet<>();

// custom directives from annotations
for (AnnotationInstance annotationInstance : ScanningContext.getIndex().getAnnotations(DIRECTIVE)) {
ClassInfo classInfo = annotationInstance.target().asClass();
Expand All @@ -193,10 +196,11 @@ private void addDirectiveTypes(Schema schema) {
DotName packageName = classInfo.name().packagePrefixName();
if ((packageName == null || !packageName.toString().startsWith(FEDERATION_ANNOTATIONS_PACKAGE.toString())
|| federationEnabled) && !isGraphQLJavaDirective(classInfo)) {
schema.addDirectiveType(directiveTypeCreator.create(classInfo));
directiveTypes.add(directiveTypeCreator.create(classInfo));
}

}
directiveTypes.forEach(schema::addDirectiveType);
// bean validation directives
schema.addDirectiveType(BeanValidationDirectivesHelper.CONSTRAINT_DIRECTIVE_TYPE);
// rolesAllowed directive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -90,6 +91,23 @@ public void addArgumentType(DirectiveArgument type) {
this.argumentTypes.add(type);
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
DirectiveType that = (DirectiveType) o;
return repeatable == that.repeatable && Objects.equals(className, that.className) && Objects.equals(name, that.name)
&& Objects.equals(description, that.description) && Objects.equals(locations, that.locations)
&& Objects.equals(argumentTypes, that.argumentTypes);
}

@Override
public int hashCode() {
return Objects.hash(className, name, description, locations, argumentTypes, repeatable);
}

@Override
public String toString() {
return "DirectiveType(" +
Expand Down
Loading