Grephql.Types.Union (Grephql v0.10.1)

Copy Markdown View Source

Dynamic parameterized Ecto Type for GraphQL union/interface types.

Dispatches to the correct embedded schema module based on the __typename field in the JSON map.

The generated module implements Ecto.ParameterizedType and uses embed_as: :dump so that Ecto.embedded_load/3 calls load/3, which reads __typename and delegates to the matched module via Ecto.embedded_load/3.

Summary

Functions

Defines a parameterized Ecto Type module for a GraphQL union/interface.

Functions

define(module_name, typename_to_module)

@spec define(module(), %{required(String.t()) => module()}) ::
  {:module, module(), binary(), term()}

Defines a parameterized Ecto Type module for a GraphQL union/interface.

Called by the type generator at compile time. typename_to_module maps GraphQL __typename strings to their corresponding embedded schema modules.