Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/maven/org.apache.maven.plugins-ma…
Browse files Browse the repository at this point in the history
…ven-enforcer-plugin-3.1.0
  • Loading branch information
phillip-kruger authored Aug 9, 2022
2 parents 4dff1d4 + 8dda0e7 commit 075c66d
Show file tree
Hide file tree
Showing 105 changed files with 712 additions and 4,776 deletions.
2 changes: 1 addition & 1 deletion .github/project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: SmallRye GraphQL
release:
current-version: 2.0.0.RC4
current-version: 2.0.0.RC6
next-version: 2.0.0-SNAPSHOT
4 changes: 4 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ SmallRye GraphQL is an implementation of
mvn clean install
----

Note that some tests perform locale-sensitive assertions.
If you use non-English locale, you need to adjust the command above.
For example: `LANG=C mvn clean install`

=== Testing against the unreleased v 2.1-SNAPSHOT of MicroProfile GraphQL

(You need to build that version of MicroProfile GraphQL locally first to make the snapshot versions available in your repository)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.smallrye.graphql.client.vertx.dynamic;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.*;

import org.jboss.logging.Logger;

Expand Down Expand Up @@ -61,6 +58,11 @@ public VertxDynamicGraphQLClientBuilder header(String name, String value) {
return this;
}

public VertxDynamicGraphQLClientBuilder headers(Map<String, String> headers) {
headersMap.setAll(headers);
return this;
}

public VertxDynamicGraphQLClientBuilder options(WebClientOptions options) {
this.options = options;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ Object invoke(MethodInvocation method) {

private Object executeSingleResultOperationOverHttpSync(MethodInvocation method, JsonObject request, MultiMap headers) {
HttpResponse<Buffer> response = postSync(request.toString(), headers);
log.debugf("response graphql: %s", response);
if (log.isTraceEnabled() && response != null) {
log.tracef("response graphql: %s", response.bodyAsString());
}
return new ResultBuilder(method, response.bodyAsString(),
response.statusCode(), response.statusMessage()).read();
}
Expand Down Expand Up @@ -251,9 +253,8 @@ private JsonObject request(MethodInvocation method) {
request.add("query", query);
request.add("variables", variables(method));
request.add("operationName", method.getName());
log.debugf("request graphql: %s", query);
JsonObject result = request.build();
log.debugf("full graphql request: %s", result.toString());
log.tracef("full graphql request: %s", result.toString());
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ public boolean isPrimitive() {
}

public boolean isEnum() {
return ifClass(Class::isEnum);
if (type instanceof TypeVariable) {
Class<?> resolved = resolveTypeVariable();
return resolved.isEnum();
} else {
return ifClass(Class::isEnum);
}
}

public Optional<ConstructionInfo> scalarConstructor() {
Expand Down
42 changes: 42 additions & 0 deletions client/tck/src/main/java/tck/graphql/typesafe/EnumBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@
class EnumBehavior {
private final TypesafeGraphQLClientFixture fixture = TypesafeGraphQLClientFixture.load();

public static class DescribedValue<T> {

public DescribedValue() {
}

T value;
String description;

public T getValue() {
return value;
}

public void setValue(T value) {
this.value = value;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}

enum Episode {
NEWHOPE,
EMPIRE,
Expand Down Expand Up @@ -68,4 +93,21 @@ void shouldCallEnumFilterQuery() {
then(fixture.variables()).isEqualTo("{'episode':'JEDI'}");
then(characters).containsExactly("Luke", "Darth");
}

@GraphQLClientApi
interface EpisodeGenericApi {
DescribedValue<Episode> describedEpisode();
}

@Test
void shouldCallGenericQuery() {
fixture.returnsData("'describedEpisode':{'value':'NEWHOPE','description':'Episode 4'}");
EpisodeGenericApi api = fixture.build(EpisodeGenericApi.class);

DescribedValue<Episode> episode = api.describedEpisode();

then(fixture.query()).isEqualTo("query describedEpisode { describedEpisode {value description} }");
then(episode.description).isEqualTo("Episode 4");
then(episode.value).isEqualTo(NEWHOPE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static Annotations getAnnotationsForArray(org.jboss.jandex.Type typeInCol
return new Annotations(annotationMap);
}

//
//

/**
* Used when we are creating operation and arguments for these operations
Expand All @@ -217,12 +217,12 @@ public static Annotations getAnnotationsForArray(org.jboss.jandex.Type typeInCol
* @return annotation for this argument
*/
public static Annotations getAnnotationsForArgument(MethodInfo methodInfo, short pos) {
if (pos >= methodInfo.parameters().size()) {
if (pos >= methodInfo.parametersCount()) {
throw new IndexOutOfBoundsException(
"Parameter at position " + pos + " not found on method " + methodInfo.name());
}

final org.jboss.jandex.Type parameterType = methodInfo.parameters().get(pos);
final org.jboss.jandex.Type parameterType = methodInfo.parameterType(pos);

Map<DotName, AnnotationInstance> annotationMap = getAnnotations(parameterType);

Expand Down Expand Up @@ -451,7 +451,7 @@ private static Annotations getAnnotationsForInputField(FieldInfo fieldInfo, Meth
annotationsForField.putAll(getTypeUseAnnotations(fieldInfo.type()));
}
if (methodInfo != null) {
List<org.jboss.jandex.Type> parameters = methodInfo.parameters();
List<org.jboss.jandex.Type> parameters = methodInfo.parameterTypes();
if (!parameters.isEmpty()) {
org.jboss.jandex.Type param = parameters.get(ZERO);
annotationsForField.putAll(getTypeUseAnnotations(param));
Expand Down Expand Up @@ -580,6 +580,7 @@ private static Map<DotName, AnnotationInstance> getAnnotationsWithFilter(org.jbo
public static final DotName INPUT = DotName.createSimple("org.eclipse.microprofile.graphql.Input");
public static final DotName TYPE = DotName.createSimple("org.eclipse.microprofile.graphql.Type");
public static final DotName INTERFACE = DotName.createSimple("org.eclipse.microprofile.graphql.Interface");
public static final DotName UNION = DotName.createSimple("io.smallrye.graphql.api.Union");
public static final DotName ENUM = DotName.createSimple("org.eclipse.microprofile.graphql.Enum");
public static final DotName ID = DotName.createSimple("org.eclipse.microprofile.graphql.Id");
public static final DotName DESCRIPTION = DotName.createSimple("org.eclipse.microprofile.graphql.Description");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,23 @@ public static boolean isUnwrappedType(Type type) {
// Validation
public static final DotName JAVAX_VALIDATION_ANNOTATION_EMAIL = DotName.createSimple("javax.validation.constraints.Email");
public static final DotName JAVAX_VALIDATION_ANNOTATION_MAX = DotName.createSimple("javax.validation.constraints.Max");
public static final DotName JAVAX_VALIDATION_ANNOTATION_DECIMAL_MAX = DotName
.createSimple("javax.validation.constraints.DecimalMax");
public static final DotName JAVAX_VALIDATION_ANNOTATION_MIN = DotName.createSimple("javax.validation.constraints.Min");
public static final DotName JAVAX_VALIDATION_ANNOTATION_DECIMAL_MIN = DotName
.createSimple("javax.validation.constraints.DecimalMin");
public static final DotName JAVAX_VALIDATION_ANNOTATION_PATTERN = DotName
.createSimple("javax.validation.constraints.Pattern");
public static final DotName JAVAX_VALIDATION_ANNOTATION_SIZE = DotName.createSimple("javax.validation.constraints.Size");

public static final DotName JAKARTA_VALIDATION_ANNOTATION_EMAIL = DotName
.createSimple("jakarta.validation.constraints.Email");
public static final DotName JAKARTA_VALIDATION_ANNOTATION_MAX = DotName.createSimple("jakarta.validation.constraints.Max");
public static final DotName JAKARTA_VALIDATION_ANNOTATION_DECIMAL_MAX = DotName
.createSimple("jakarta.validation.constraints.DecimalMax");
public static final DotName JAKARTA_VALIDATION_ANNOTATION_MIN = DotName.createSimple("jakarta.validation.constraints.Min");
public static final DotName JAKARTA_VALIDATION_ANNOTATION_DECIMAL_MIN = DotName
.createSimple("jakarta.validation.constraints.DecimalMin");
public static final DotName JAKARTA_VALIDATION_ANNOTATION_PATTERN = DotName
.createSimple("jakarta.validation.constraints.Pattern");
public static final DotName JAKARTA_VALIDATION_ANNOTATION_SIZE = DotName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.smallrye.graphql.schema.creator.type.InputTypeCreator;
import io.smallrye.graphql.schema.creator.type.InterfaceCreator;
import io.smallrye.graphql.schema.creator.type.TypeCreator;
import io.smallrye.graphql.schema.creator.type.UnionCreator;
import io.smallrye.graphql.schema.helper.BeanValidationDirectivesHelper;
import io.smallrye.graphql.schema.helper.Directives;
import io.smallrye.graphql.schema.helper.GroupHelper;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class SchemaBuilder {
private final ReferenceCreator referenceCreator;
private final OperationCreator operationCreator;
private final DirectiveTypeCreator directiveTypeCreator;
private final UnionCreator unionCreator;

/**
* This builds the Schema from Jandex
Expand Down Expand Up @@ -98,6 +100,7 @@ private SchemaBuilder(TypeAutoNameStrategy autoNameStrategy) {
typeCreator = new TypeCreator(referenceCreator, fieldCreator, operationCreator);
interfaceCreator = new InterfaceCreator(referenceCreator, fieldCreator, operationCreator);
directiveTypeCreator = new DirectiveTypeCreator(referenceCreator);
unionCreator = new UnionCreator(referenceCreator);
}

private Schema generateSchema() {
Expand Down Expand Up @@ -130,7 +133,7 @@ private Schema generateSchema() {
// Add all custom datafetchers
addDataFetchers(schema);

// Reset the maps.
// Reset the maps.
referenceCreator.clear();

return schema;
Expand Down Expand Up @@ -162,6 +165,9 @@ private void addTypesToSchema(Schema schema) {
// Add the interface types
createAndAddToSchema(ReferenceType.INTERFACE, interfaceCreator, schema::addInterface);

// Add the union types
createAndAddToSchema(ReferenceType.UNION, unionCreator, schema::addUnion);

// Add the enum types
createAndAddToSchema(ReferenceType.ENUM, enumCreator, schema::addEnum);
}
Expand All @@ -185,6 +191,11 @@ private void addOutstandingTypesToSchema(Schema schema) {
keepGoing = true;
}

// See if there is any unions we missed
if (findOutstandingAndAddToSchema(ReferenceType.UNION, unionCreator, schema::containsUnion, schema::addUnion)) {
keepGoing = true;
}

// See if there is any enums we missed
if (findOutstandingAndAddToSchema(ReferenceType.ENUM, enumCreator, schema::containsEnum,
schema::addEnum)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public ArgumentCreator(ReferenceCreator referenceCreator) {
* @return an Argument
*/
public Optional<Argument> createArgument(Operation operation, MethodInfo methodInfo, short position) {
if (position >= methodInfo.parameters().size()) {
if (position >= methodInfo.parametersCount()) {
throw new SchemaBuilderException(
"Can not create argument for parameter [" + position + "] "
+ "on method [" + methodInfo.declaringClass().name() + "#" + methodInfo.name() + "]: "
+ "method has only " + methodInfo.parameters().size() + " parameters");
+ "method has only " + methodInfo.parametersCount() + " parameters");
}

Annotations annotationsForThisArgument = Annotations.getAnnotationsForArgument(methodInfo, position);
Expand All @@ -59,7 +59,7 @@ public Optional<Argument> createArgument(Operation operation, MethodInfo methodI
}

// Argument Type
Type argumentType = methodInfo.parameters().get(position);
Type argumentType = methodInfo.parameterType(position);

// Name
String defaultName = methodInfo.parameterName(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ public Optional<Field> createFieldForParameter(MethodInfo method, short position
String name = getFieldName(Direction.IN, annotationsForPojo, method.parameterName(position));

// Field Type
Type fieldType = getFieldType(fieldInfo, method.parameters().get(position));
Type fieldType = getFieldType(fieldInfo, method.parameterType(position));

Reference reference = referenceCreator.createReferenceForPojoField(fieldType,
method.parameters().get(position), annotationsForPojo, Direction.IN, parentObjectReference);
method.parameterType(position), annotationsForPojo, Direction.IN, parentObjectReference);

String fieldName = fieldInfo != null ? fieldInfo.name() : null;
Field field = new Field(null, fieldName, name, reference);
addDirectivesForBeanValidationConstraints(annotationsForPojo, field, parentObjectReference);
populateField(Direction.IN, field, fieldType, method.parameters().get(position), annotationsForPojo);
populateField(Direction.IN, field, fieldType, method.parameterType(position), annotationsForPojo);

return Optional.of(field);

Expand Down Expand Up @@ -249,7 +249,7 @@ private static void validateFieldType(Direction direction, MethodInfo methodInfo

private static Type getMethodType(MethodInfo method, Direction direction) {
if (direction.equals(Direction.IN)) {
return method.parameters().get(0);
return method.parameterType(0);
}
return getReturnType(method);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Operation createOperation(MethodInfo methodInfo, OperationType operationT
}

// Arguments
List<Type> parameters = methodInfo.parameters();
List<Type> parameters = methodInfo.parameterTypes();
for (short i = 0; i < parameters.size(); i++) {
Optional<Argument> maybeArgument = argumentCreator.createArgument(operation, methodInfo, i);
maybeArgument.ifPresent(operation::addArgument);
Expand Down
Loading

0 comments on commit 075c66d

Please sign in to comment.