use of io.smallrye.graphql.client.impl.typesafe.reflection.TypeInfo in project smallrye-graphql by smallrye.
the class QueryBuilder method field.
private String field(FieldInfo field) {
TypeInfo type = field.getType();
StringBuilder expression = new StringBuilder();
field.getAlias().ifPresent(alias -> expression.append(alias).append(":"));
expression.append(field.getName());
String path = nestedExpressionPrefix() + field.getRawName();
List<ParameterInfo> nestedParameters = method.nestedParameters(path);
if (!nestedParameters.isEmpty())
expression.append(nestedParameters.stream().map(this::bind).collect(joining(", ", "(", ")")));
expressionStack.push(path);
// appends the empty string, if the type is scalar, etc.
expression.append(fields(type));
expressionStack.pop();
return expression.toString();
}
use of io.smallrye.graphql.client.impl.typesafe.reflection.TypeInfo in project smallrye-graphql by smallrye.
the class ResponseImpl method getList.
public <T> List<T> getList(Class<T> dataType, String rootField) {
if (data == null || data.equals(JsonValue.NULL) || data.keySet().isEmpty()) {
throw SmallRyeGraphQLClientMessages.msg.noDataInResponse();
}
JsonValue item = data.get(rootField);
if (item == null) {
throw SmallRyeGraphQLClientMessages.msg.fieldNotFoundInResponse(rootField, data.keySet());
}
if (item.getValueType().equals(JsonValue.ValueType.NULL)) {
// field is present in the response, but is null
return null;
}
if (item instanceof JsonObject) {
throw SmallRyeGraphQLClientMessages.msg.responseContainsSingleObject(rootField);
}
if (item instanceof JsonArray) {
List<T> result = new ArrayList<T>();
JsonArray jsonArray = (JsonArray) item;
TypeInfo type = TypeInfo.of(dataType);
jsonArray.forEach(o -> {
if (o.getValueType().equals(JsonValue.ValueType.OBJECT)) {
result.add((T) JsonReader.readJson(rootField, type, o, null));
} else {
result.add((T) getScalarValue(o));
}
});
return result;
}
throw SmallRyeGraphQLClientMessages.msg.unexpectedValueInResponse(rootField, item.getValueType().toString());
}
use of io.smallrye.graphql.client.impl.typesafe.reflection.TypeInfo in project smallrye-graphql by smallrye.
the class JsonArrayReader method readItem.
private Object readItem(IndexedLocationBuilder locationBuilder, JsonValue itemValue) {
Location itemLocation = locationBuilder.nextLocation();
TypeInfo itemType = getItemType();
if (itemValue.getValueType() == ValueType.NULL && itemType.isNonNull())
throw new InvalidResponseException("invalid null " + itemLocation);
return JsonReader.readJson(itemLocation, itemType, itemValue, field);
}
use of io.smallrye.graphql.client.impl.typesafe.reflection.TypeInfo in project smallrye-graphql by smallrye.
the class HeaderBuilder method resolveHeaderMethod.
private HeaderDescriptor resolveHeaderMethod(Header header) {
TypeInfo declaringType = method.getDeclaringType();
MethodInvocation method = new MethodResolver(declaringType, header.method()).resolve();
if (!method.isStatic())
throw new RuntimeException("referenced header method '" + header.method() + "'" + " in " + declaringType.getTypeName() + " is not static");
String value = callMethod(method);
return new HeaderDescriptor(value, header.name(), toHeaderName(method));
}
Aggregations