Grephql.ResponseDecoder (Grephql v0.10.1)

Copy Markdown View Source

Decodes GraphQL JSON response data into typed embedded schema structs.

Uses Ecto.embedded_load/3 to recursively convert plain maps (from Jason.decode!/1) into the generated embedded schema structs, automatically invoking custom Ecto.Type.cast/2 callbacks for scalars and enums.

Example

json = %{"name" => "Alice", "posts" => [%{"title" => "Hello"}]}
user = Grephql.ResponseDecoder.decode!(MyApp.GetUser.User, json)
user.name #=> "Alice"
hd(user.posts).title #=> "Hello"

Summary

Functions

Decodes a JSON map into the given embedded schema module.

Functions

decode!(module, data)

@spec decode!(module(), map()) :: struct()

Decodes a JSON map into the given embedded schema module.

Raises on failure.