# `Grephql.TypeMapper`
[🔗](https://github.com/fahchen/grephql/blob/v0.10.1/lib/grephql/type_mapper.ex#L1)

Maps GraphQL type references to Ecto schema types.

Resolves the corresponding Ecto type (for embedded schema field definitions)
and nullability from a parsed GraphQL type reference.

## Scalar mapping

Built-in GraphQL scalars map to Ecto primitives:

  - `String` → `:string`
  - `Int` → `:integer`
  - `Float` → `:float`
  - `Boolean` → `:boolean`
  - `ID` → `:string`
  - `DateTime` → `Grephql.Types.DateTime`
  - `Date` → `:date`
  - `JSON` / `JSONObject` → `:map`
  - `URI` / `URL` → `:string`
  - `BigInt` / `Long` → `:integer`
  - `HTML` → `:string`
  - `UnsignedInt64` → `:integer`
  - `Base64String` → `:string`

Custom scalars map to user-provided `Ecto.Type` modules via the `scalar_types` config.
Custom scalars override built-in defaults. Unknown scalars raise `CompileError`.

## Enum mapping

Enum types are automatically resolved using `Grephql.Types.Enum` (a parameterized
Ecto type). No user configuration is needed — enum values are read from the schema
at compile time. Users can still override enum types via `scalar_types` if custom
serialization is needed.

# `ecto_type`

```elixir
@type ecto_type() ::
  :string
  | :integer
  | :float
  | :boolean
  | :date
  | :map
  | {:array, ecto_type()}
  | {:object, String.t()}
  | module()
```

# `resolve_result`

```elixir
@type resolve_result() :: %{
  ecto_type: ecto_type(),
  nullable: boolean(),
  enum_values: [String.t()] | nil,
  inner_nullable: boolean() | nil
}
```

# `scalar_types`

```elixir
@type scalar_types() :: %{required(String.t()) =&gt; module()}
```

# `resolve`

```elixir
@spec resolve(Grephql.Schema.TypeRef.t(), Grephql.Schema.t(), scalar_types()) ::
  resolve_result()
```

Resolves a GraphQL type reference to its Ecto type and nullability.

Returns a map with:
  - `:ecto_type` — the Ecto type for schema field definition
  - `:nullable` — whether the field allows nil
  - `:enum_values` — enum value strings when type is `Grephql.Types.Enum`, nil otherwise

## Parameters

  - `type_ref` — the GraphQL type reference to resolve
  - `schema` — the parsed GraphQL schema (for enum value lookup)
  - `scalar_types` — user-provided custom scalar mappings (default: `%{}`)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
