Serialisation & Atoms

Absinthe only expects atom keys in your data in the sense that that’s the default way to look up data. You can change that default either by specifying a different way to get data for a field, or by setting a different default middleware.

The reason that Absinthe defaults to using atom key lookups is because most people are using accessing structured data in their resolvers. This would be data like an Ecto schema. Ecto schemas and ecto embedded schemas have well defined fields so atoms are an easy choice. They also handle decoding database information into these fields for you.

If you have particular graphql objects in Absinthe that you always want to load using data with string keys, you can do this trivially via the middleware/3 callback in your schema. For example, suppose you had an object named :config that you wanted to have use stringified defaults.

def middleware([], %{identifier: field_identifier}, %{identifier: :config}) do
  [{Absinthe.Middleware.MapGet, Atom.to_string(field_identifier)}]
end
def middleware(middleware, _, _) do
  middleware
end