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

Make sure to not create adapted types in the schema #1346

Merged
merged 1 commit into from
Apr 8, 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 @@ -261,6 +261,14 @@ public Set<DotName> getAnnotationNames() {
return annotationsMap.keySet();
}

public Annotations removeAnnotations(DotName... annotations) {
Map<DotName, AnnotationInstance> newAnnotationsMap = new HashMap<>(annotationsMap);
for (DotName annotation : annotations) {
newAnnotationsMap.remove(annotation);
}
return new Annotations(newAnnotationsMap, this.parentAnnotations);
}

/**
* Get a specific annotation
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,23 +247,19 @@ public Reference createReference(Direction direction, ClassInfo classInfo, boole
Reference reference = new Reference(className, name, referenceType, parametrizedTypeArgumentsReferences,
addParametrizedTypeNameExtension);

// Adapt to Scalar
boolean shouldCreateAdapedToType = AdaptToHelper.shouldCreateTypeInSchema(annotationsForClass);
// Adaptation
Optional<AdaptTo> adaptTo = AdaptToHelper.getAdaptTo(reference, annotationsForClass);
reference.setAdaptTo(adaptTo.orElse(null));

// Now add it to the correct map
if (shouldCreateAdapedToType && createAdapedToType) {
putIfAbsent(name, reference, referenceType);
}

// Adapt with adapter
boolean shouldCreateAdapedWithType = AdaptWithHelper.shouldCreateTypeInSchema(annotationsForClass);
Optional<AdaptWith> adaptWith = AdaptWithHelper.getAdaptWith(direction, this, reference, annotationsForClass);
reference.setAdaptWith(adaptWith.orElse(null));

// Now add it to the correct map
if (shouldCreateAdapedWithType && createAdapedWithType) {
boolean shouldCreateAdapedToType = AdaptToHelper.shouldCreateTypeInSchema(annotationsForClass);
boolean shouldCreateAdapedWithType = AdaptWithHelper.shouldCreateTypeInSchema(annotationsForClass);

// We ignore the field that is being adapted
if (shouldCreateAdapedToType && createAdapedToType && shouldCreateAdapedWithType && createAdapedWithType) {
putIfAbsent(name, reference, referenceType);
}
return reference;
Expand Down Expand Up @@ -298,7 +294,7 @@ private Reference getReference(Direction direction,
Annotations annotations,
Reference parentObjectReference) {

// In some case, like operations and interfaces, there is not fieldType
// In some case, like operations and interfaces, there is no fieldType
if (fieldType == null) {
fieldType = methodType;
}
Expand All @@ -315,7 +311,7 @@ private Reference getReference(Direction direction,
}
return Scalars.getScalar(fieldTypeName);
} else if (fieldType.kind().equals(Type.Kind.ARRAY)) {
// java Array
// Java Array
Type typeInArray = fieldType.asArrayType().component();
Type typeInMethodArray = methodType.asArrayType().component();
return getReference(direction, typeInArray, typeInMethodArray, annotations, parentObjectReference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ public static Optional<AdaptWith> getAdaptWith(Direction direction, ReferenceCre
if (Scalars.isScalar(to.name().toString())) {
adaptWith.setToReference(Scalars.getScalar(to.name().toString()));
} else {
Reference toRef = referenceCreator.createReferenceForAdapter(direction, to, annotations);
Annotations annotationsAplicableToMe = annotations.removeAnnotations(Annotations.ADAPT_WITH,
Annotations.JSONB_TYPE_ADAPTER);

// Remove the adaption annotation, as this is the type being adapted to
Reference toRef = referenceCreator.createReferenceForAdapter(direction, to,
annotationsAplicableToMe);
toRef.setWrapper(WrapperCreator.createWrapper(to).orElse(null));

adaptWith.setToReference(toRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ private Bootstrap(Schema schema, boolean skipInjectionValidation) {
*/
private void verifyInjectionIsAvailable() {
LookupService lookupService = LookupService.get();
ClassloadingService classloadingService = ClassloadingService.get();
// This crazy stream operation basically collects all class names where we need to verify that
// it belongs to an injectable bean
Stream.of(
Expand Down
2 changes: 1 addition & 1 deletion server/runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>3.0.0.Final</version>
<version>2.1.0.Final</version>
jmartisk marked this conversation as resolved.
Show resolved Hide resolved
<configuration>
<version>${version.wildfly}</version>
<server-config>standalone-microprofile.xml</server-config>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.smallrye.graphql.test.apps.adapt.to.api;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.eclipse.microprofile.graphql.GraphQLApi;
Expand Down Expand Up @@ -47,6 +48,19 @@ public AdaptToData updateAdaptToData(AdaptToData adaptToData) {
return adaptToData;
}

@Mutation
public Dummy addDummy(Dummy dummy) {
return dummy;
}

@Query
public Dummy getDummy() {
Dummy d = new Dummy();
d.id = new DummyId(new Date());
d.name = "foo";
return d;
}

public static class AdaptToData {
public Long id;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.smallrye.graphql.test.apps.adapt.to.api;

import io.smallrye.graphql.api.AdaptToScalar;
import io.smallrye.graphql.api.Scalar;

public class Dummy {

public String name;
@AdaptToScalar(Scalar.String.class)
public DummyId id;

}
Loading