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());
}
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;
}
Aggregations