diff --git a/CHANGELOG.md b/CHANGELOG.md index 57a8b32..0ef5f1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,12 @@ -## v1.0.2 (2018-05-11) +## v1.0.3 (2018-05-11) The release should be compatible with v1.0.0, so no update to the downstream libraries is necessary. +* Removed new helpers methods in `ResultMarshaller` (otherwise all downstream libraries need to recompiled, at least for scala 2.11) +* Re-added helpers as a part of `MarshallingUtil` + +## v1.0.2 (2018-05-11) + * Added several helper methods in `ResultMarshaller` for easy value creation * Moved `SimpleResultMarshallerForType` and `SymmetricMarshaller` from sangria diff --git a/src/main/scala/sangria/marshalling/MarshallingUtil.scala b/src/main/scala/sangria/marshalling/MarshallingUtil.scala index 66ac07b..a42b6f9 100644 --- a/src/main/scala/sangria/marshalling/MarshallingUtil.scala +++ b/src/main/scala/sangria/marshalling/MarshallingUtil.scala @@ -36,4 +36,45 @@ object MarshallingUtil { implicit class MarshaledConverter[In : InputUnmarshaller](in: In) { def convertMarshaled[Out : ResultMarshallerForType] = convert(in) } + + implicit class ResultMarshallerOps(val m: ResultMarshaller) extends AnyVal { + def list(elements: ResultMarshaller#Node*): m.Node = + m.arrayNode(elements.asInstanceOf[Seq[m.Node]].toVector) + + def map(elements: (String, ResultMarshaller#Node)*): m.Node = + m.mapNode(elements.foldLeft(m.emptyMapNode(elements.map(_._1))) { + case (acc, (name, value)) ⇒ m.addMapNodeElem(acc, name, value.asInstanceOf[m.Node], optional = false) + }) + + def fromString(value: String): m.Node = + m.scalarNode(value, "String", Set.empty) + + def fromEnumString(value: String): m.Node = + m.enumNode(value, "") + + def fromInt(value: Int): m.Node = + m.scalarNode(value, "Int", Set.empty) + + def fromLong(value: Long): m.Node = + m.scalarNode(value, "Long", Set.empty) + + def fromBoolean(value: Boolean): m.Node = + m.scalarNode(value, "Long", Set.empty) + + def fromFloat(value: Float): m.Node = + m.scalarNode(value, "Float", Set.empty) + + def fromDouble(value: Double): m.Node = + m.scalarNode(value, "Float", Set.empty) + + def fromBigInt(value: BigInt): m.Node = + m.scalarNode(value, "BigInt", Set.empty) + + def fromBigInt(value: BigDecimal): m.Node = + m.scalarNode(value, "BigDecimal", Set.empty) + + def fromInput[Input : InputUnmarshaller](value: Input): m.Node = { + value.convertMarshaled(SimpleResultMarshallerForType[m.Node](m)) + } + } } diff --git a/src/main/scala/sangria/marshalling/ResultMarshaller.scala b/src/main/scala/sangria/marshalling/ResultMarshaller.scala index f9c88a3..5bed185 100644 --- a/src/main/scala/sangria/marshalling/ResultMarshaller.scala +++ b/src/main/scala/sangria/marshalling/ResultMarshaller.scala @@ -55,47 +55,6 @@ trait ResultMarshaller { } def capabilities: Set[MarshallerCapability] = Set.empty - - // Helpers for easy value creation - - def list(elements: Node*): Node = - arrayNode(elements.toVector) - - def map(elements: (String, Node)*): Node = - mapNode(elements) - - def fromString(value: String): Node = - scalarNode(value, "String", Set.empty) - - def fromEnumString(value: String): Node = - enumNode(value, "") - - def fromInt(value: Int): Node = - scalarNode(value, "Int", Set.empty) - - def fromLong(value: Long): Node = - scalarNode(value, "Long", Set.empty) - - def fromBoolean(value: Boolean): Node = - scalarNode(value, "Long", Set.empty) - - def fromFloat(value: Float): Node = - scalarNode(value, "Float", Set.empty) - - def fromDouble(value: Double): Node = - scalarNode(value, "Float", Set.empty) - - def fromBigInt(value: BigInt): Node = - scalarNode(value, "BigInt", Set.empty) - - def fromBigDecimal(value: BigDecimal): Node = - scalarNode(value, "BigDecimal", Set.empty) - - def fromInput[Input : InputUnmarshaller](value: Input): Node = { - import MarshallingUtil._ - - value.convertMarshaled(SimpleResultMarshallerForType[Node](this)) - } } object ResultMarshaller {