use of graphql.language.Value in project structr by structr.
the class QueryConfig method handleTypeArguments.
public void handleTypeArguments(final SecurityContext securityContext, final Class type, final List<Argument> arguments) throws FrameworkException {
// parse arguments
for (final Argument argument : arguments) {
final String name = argument.getName();
final Value value = argument.getValue();
switch(name) {
case "_page":
this.page = getIntegerValue(value, 1);
break;
case "_pageSize":
case "_first":
this.pageSize = getIntegerValue(value, Integer.MAX_VALUE);
break;
case "_sort":
this.sortKeySource = getStringValue(value, "name");
this.sortKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, sortKeySource, false);
break;
case "_desc":
this.sortDescending = getBooleanValue(value, false);
break;
default:
// handle simple selections like an _equals on the field
final PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, name, false);
if (key != null) {
addAttribute(key, key.getSearchAttribute(securityContext, Occurrence.REQUIRED, castValue(securityContext, type, key, value), true, null), Occurrence.REQUIRED);
}
break;
}
}
}
use of graphql.language.Value in project graphql-java by graphql-java.
the class ValuesResolver method coerceValueAstForList.
private Object coerceValueAstForList(GraphqlFieldVisibility fieldVisibility, GraphQLList graphQLList, Value value, Map<String, Object> variables) {
if (value instanceof ArrayValue) {
ArrayValue arrayValue = (ArrayValue) value;
List<Object> result = new ArrayList<>();
for (Value singleValue : arrayValue.getValues()) {
result.add(coerceValueAst(fieldVisibility, graphQLList.getWrappedType(), singleValue, variables));
}
return result;
} else {
return Collections.singletonList(coerceValueAst(fieldVisibility, graphQLList.getWrappedType(), value, variables));
}
}
use of graphql.language.Value in project graphql-java by graphql-java.
the class SchemaGenerator method buildInputField.
private GraphQLInputObjectField buildInputField(BuildContext buildCtx, InputValueDefinition fieldDef) {
GraphQLInputObjectField.Builder fieldBuilder = GraphQLInputObjectField.newInputObjectField();
fieldBuilder.definition(fieldDef);
fieldBuilder.name(fieldDef.getName());
fieldBuilder.description(schemaGeneratorHelper.buildDescription(fieldDef, fieldDef.getDescription()));
// currently the spec doesnt allow deprecations on InputValueDefinitions but it should!
// fieldBuilder.deprecate(buildDeprecationReason(fieldDef.getDirectives()));
GraphQLInputType inputType = buildInputType(buildCtx, fieldDef.getType());
fieldBuilder.type(inputType);
Value defaultValue = fieldDef.getDefaultValue();
if (defaultValue != null) {
fieldBuilder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType));
}
fieldBuilder.withDirectives(buildDirectives(fieldDef.getDirectives(), emptyList(), INPUT_FIELD_DEFINITION));
return fieldBuilder.build();
}
use of graphql.language.Value in project graphql-java by graphql-java.
the class SchemaGenerator method buildArgument.
private GraphQLArgument buildArgument(BuildContext buildCtx, InputValueDefinition valueDefinition) {
GraphQLArgument.Builder builder = GraphQLArgument.newArgument();
builder.definition(valueDefinition);
builder.name(valueDefinition.getName());
builder.description(schemaGeneratorHelper.buildDescription(valueDefinition, valueDefinition.getDescription()));
GraphQLInputType inputType = buildInputType(buildCtx, valueDefinition.getType());
builder.type(inputType);
Value defaultValue = valueDefinition.getDefaultValue();
if (defaultValue != null) {
builder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType));
}
return builder.build();
}
use of graphql.language.Value in project graphql-java by graphql-java.
the class SchemaDiff method checkFieldArg.
private void checkFieldArg(DiffCtx ctx, TypeDefinition oldDef, FieldDefinition oldField, InputValueDefinition oldArg, InputValueDefinition newArg) {
Type oldArgType = oldArg.getType();
Type newArgType = newArg.getType();
DiffCategory category = checkTypeWithNonNullAndList(oldArgType, newArgType);
if (category != null) {
ctx.report(DiffEvent.apiBreakage().category(category).typeName(oldDef.getName()).typeKind(getTypeKind(oldDef)).fieldName(oldField.getName()).components(getAstDesc(oldArgType), getAstDesc(newArgType)).reasonMsg("The new API has changed field '%s' argument '%s' from type '%s' to '%s'", mkDotName(oldDef.getName(), oldField.getName()), oldArg.getName(), getAstDesc(oldArgType), getAstDesc(newArgType)).build());
} else {
//
// and down we go again recursively via arg types
//
checkType(ctx, oldArgType, newArgType);
}
boolean changedDefaultValue = false;
Value oldValue = oldArg.getDefaultValue();
Value newValue = newArg.getDefaultValue();
if (oldValue != null && newValue != null) {
if (!oldValue.getClass().equals(newValue.getClass())) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.INVALID).typeName(oldDef.getName()).typeKind(getTypeKind(oldDef)).fieldName(oldField.getName()).components(oldArg.getName()).reasonMsg("The new API has changed default value types on argument named '%s' on field '%s' of type '%s", oldArg.getName(), mkDotName(oldDef.getName(), oldField.getName()), oldDef.getName()).build());
}
if (!oldValue.isEqualTo(newValue)) {
changedDefaultValue = true;
}
}
if (oldValue == null && newValue != null) {
changedDefaultValue = true;
}
if (oldValue != null && newValue == null) {
changedDefaultValue = true;
}
if (changedDefaultValue) {
ctx.report(DiffEvent.apiDanger().category(DiffCategory.DIFFERENT).typeName(oldDef.getName()).typeKind(getTypeKind(oldDef)).fieldName(oldField.getName()).components(oldArg.getName()).reasonMsg("The new API has changed default value on argument named '%s' on field '%s' of type '%s", oldArg.getName(), mkDotName(oldDef.getName(), oldField.getName()), oldDef.getName()).build());
}
checkDirectives(ctx, oldDef, oldArg.getDirectives(), newArg.getDirectives());
}
Aggregations