mirror of
https://github.com/ash-project/ash_graphql.git
synced 2024-09-21 13:53:20 +12:00
33 lines
769 B
Markdown
33 lines
769 B
Markdown
# Use Maps with GraphQL
|
|
|
|
If you define an `Ash.Type.NewType` that is a subtype of `:map`, _and_ you add the `fields` constraint which specifies field names and their types, `AshGraphql` will automatically derive an appropriate GraphQL type for it.
|
|
|
|
For example:
|
|
|
|
```elixir
|
|
defmodule MyApp.Types.Metadata do
|
|
@moduledoc false
|
|
use Ash.Type.NewType, subtype_of: :map, constraints: [
|
|
fields: [
|
|
title: [
|
|
type: :string
|
|
],
|
|
description: [
|
|
type: :string
|
|
]
|
|
]
|
|
]
|
|
|
|
def graphql_type, do: :metadata
|
|
end
|
|
|
|
```
|
|
|
|
## Bypassing type generation for an map
|
|
|
|
Add the `graphql_define_type?/1` callback, like so, to skip Ash's generation (i.e if you're defining it yourself)
|
|
|
|
```elixir
|
|
@impl true
|
|
def graphql_define_type?(_), do: false
|
|
```
|