Closed evbo closed 6 years ago
Circe type-class based JSON deserialization is quite similar to spray-json. Circe uses Encoder
and Decoder
type-classes for this. Sungria supports these via:
sangria.marshalling.circe.{circeEncoderToInput, circeDecoderFromInput}
Circe provides various mechanisms to define the decoders, for example you can write them manually or you can derive them from the case classes (similar to what spray-json provides). Here is an example of how you can take advantage of fully automatic derivation:
import io.circe.generic.auto._
import io.circe.syntax._
import sangria.marshalling.circe._
val MetricType = deriveInputObjectType[Metric]()
val MetricArg = Argument("metric", OptionInputType(ListInputType(MetricType)))
val QueryType = ObjectType("Query", "Required root object that contains all types",
fields[Context, Unit](
Field("getMetrics", ListType(MetricsType),
arguments = MetricArg :: Nil,
resolve = c ⇒ c.ctx.dao.getMetrics(c arg MetricArg))))
Thank you and sorry for the late response. So it appears that with circe I needed the following import that was missing:
import sangria.marshalling.circe._
That's all the magic it took! Now it's compiling, thank you!
It took me also quite some time to find out that this line was what was missing. Thanks for sharing it!
Hi,
What is the equivalent import for circe for the following sprayJson?:
import sangria.marshalling.sprayJson.sprayJsonReaderFromInput
In migrating from sprayJson to circe, I've tried using
import sangria.marshalling.circe.circeFromInput
But I still get error:
Here is how my spray implementation worked: