Adapters

Absinthe supports an adapter mechanism that allows developers to define their schema using one code convention (eg, snake_cased fields and arguments), but accept query documents and return results (including names in errors) in another (eg, camelCase). This is useful in allowing both client and server to use conventions most natural to them.

Absinthe ships with two adapters:

To set the adapter, you can set an application configuration value:

config :absinthe,
  adapter: Absinthe.Adapter.TheAdapterName

Or, you can provide it as an option to Absinthe.run/3:

Absinthe.run(query, MyApp.Schema,
             adapter: Absinthe.Adapter.TheAdapterName)

Notably, this means you’re able to switch adapters on case-by-case basis. In a Phoenix application, this means you could even support using different adapters for different clients.

A custom adapter module must merely implement the Absinthe.Adapter protocol, in many cases with use Absinthe.Adapter and only overriding the desired functions.

Note that types that are defined external to your application (including the introspection types) may not be compatible if you’re using a different adapter.