Search in sources :

Example 6 with Value

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;
        }
    }
}
Also used : Argument(graphql.language.Argument) ObjectValue(graphql.language.ObjectValue) Value(graphql.language.Value) StringValue(graphql.language.StringValue) IntValue(graphql.language.IntValue) BooleanValue(graphql.language.BooleanValue) PropertyKey(org.structr.core.property.PropertyKey)

Example 7 with Value

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));
    }
}
Also used : ArrayList(java.util.ArrayList) NullValue(graphql.language.NullValue) ObjectValue(graphql.language.ObjectValue) Value(graphql.language.Value) ArrayValue(graphql.language.ArrayValue) ArrayValue(graphql.language.ArrayValue)

Example 8 with Value

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();
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) Value(graphql.language.Value)

Example 9 with Value

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();
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) Value(graphql.language.Value) GraphQLArgument(graphql.schema.GraphQLArgument)

Example 10 with Value

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());
}
Also used : Type(graphql.language.Type) Value(graphql.language.Value)

Aggregations

Value (graphql.language.Value)11 ObjectValue (graphql.language.ObjectValue)6 ArrayValue (graphql.language.ArrayValue)4 StringValue (graphql.language.StringValue)4 Argument (graphql.language.Argument)3 BooleanValue (graphql.language.BooleanValue)3 IntValue (graphql.language.IntValue)3 NullValue (graphql.language.NullValue)3 Type (graphql.language.Type)2 VariableDefinition (graphql.language.VariableDefinition)2 GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)2 GraphQLInputType (graphql.schema.GraphQLInputType)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 PropertyKey (org.structr.core.property.PropertyKey)2 Directive (graphql.language.Directive)1 EnumValue (graphql.language.EnumValue)1 FloatValue (graphql.language.FloatValue)1 InputValueDefinition (graphql.language.InputValueDefinition)1 ListType (graphql.language.ListType)1