Search in sources :

Example 11 with Type

use of graphql.language.Type 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)

Example 12 with Type

use of graphql.language.Type in project graphql-java by graphql-java.

the class IntrospectionResultToSchema method createInputValueDefinitions.

@SuppressWarnings("unchecked")
private List<InputValueDefinition> createInputValueDefinitions(List<Map<String, Object>> args) {
    List<InputValueDefinition> result = new ArrayList<>();
    for (Map<String, Object> arg : args) {
        Type argType = createTypeIndirection((Map<String, Object>) arg.get("type"));
        InputValueDefinition inputValueDefinition = new InputValueDefinition((String) arg.get("name"), argType);
        inputValueDefinition.setComments(toComment((String) arg.get("description")));
        String valueLiteral = (String) arg.get("defaultValue");
        if (valueLiteral != null) {
            Value defaultValue = AstValueHelper.valueFromAst(valueLiteral);
            inputValueDefinition.setDefaultValue(defaultValue);
        }
        result.add(inputValueDefinition);
    }
    return result;
}
Also used : Type(graphql.language.Type) NonNullType(graphql.language.NonNullType) ListType(graphql.language.ListType) ArrayList(java.util.ArrayList) Value(graphql.language.Value) StringValue(graphql.language.StringValue) InputValueDefinition(graphql.language.InputValueDefinition)

Aggregations

Type (graphql.language.Type)12 InterfaceTypeDefinition (graphql.language.InterfaceTypeDefinition)9 ObjectTypeDefinition (graphql.language.ObjectTypeDefinition)8 ScalarTypeDefinition (graphql.language.ScalarTypeDefinition)8 TypeDefinition (graphql.language.TypeDefinition)8 UnionTypeDefinition (graphql.language.UnionTypeDefinition)8 EnumTypeDefinition (graphql.language.EnumTypeDefinition)7 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)7 InputValueDefinition (graphql.language.InputValueDefinition)7 Map (java.util.Map)7 GraphQLError (graphql.GraphQLError)6 Directive (graphql.language.Directive)6 EnumValueDefinition (graphql.language.EnumValueDefinition)6 FieldDefinition (graphql.language.FieldDefinition)6 InputObjectTypeExtensionDefinition (graphql.language.InputObjectTypeExtensionDefinition)6 TypeName (graphql.language.TypeName)6 List (java.util.List)6 Optional (java.util.Optional)6 Collectors (java.util.stream.Collectors)6 Internal (graphql.Internal)4