astFromUntypedValue function

ValueNode astFromUntypedValue(
  1. Object? value
)

Implementation

ast.ValueNode astFromUntypedValue(Object? value) {
  if (value == null) {
    return const ast.NullValueNode();
  } else if (value is String) {
    return ast.StringValueNode(
      value: value,
      isBlock: value.length > 100,
    );
  } else if (value is int) {
    return ast.IntValueNode(value: value.toString());
  } else if (value is double) {
    return ast.FloatValueNode(value: value.toString());
  } else if (value is bool) {
    return ast.BooleanValueNode(value: value);
  } else if (value is Map<String, Object?>) {
    return ast.ObjectValueNode(fields: [
      ...value.entries.map(
        (e) {
          return ast.ObjectFieldNode(
            name: ast.NameNode(
              value: e.key,
            ),
            value: astFromUntypedValue(e.value),
          );
        },
      ),
    ]);
  } else if (value is List<Object?>) {
    return ast.ListValueNode(values: [
      ...value.map(astFromUntypedValue),
    ]);
  }
  throw Error();
}