GreenFairy.Adapters.Ecto (GreenFairy v0.3.0)

View Source

Backing adapter for Ecto schemas.

This adapter automatically detects Ecto schemas and provides:

  • CQL Support: Extracts field metadata for filtering, infers operators from Ecto types
  • DataLoader Support: Configures batched loading using Dataloader.Ecto

Supported Ecto Types

  • :string - text operations (eq, neq, contains, starts_with, ends_with, in, is_nil)
  • :integer, :float, :decimal - numeric comparisons (eq, neq, gt, lt, gte, lte, in, is_nil)
  • :boolean - equality only (eq, is_nil)
  • :id, :binary_id - id operations (eq, neq, in, is_nil)
  • :naive_datetime, :utc_datetime, :date, :time - temporal comparisons
  • {:parameterized, Ecto.Enum, _} - enum operations (eq, neq, in, is_nil)
  • :map, :array - equality only (eq, is_nil)

Usage

The Ecto adapter is the default adapter and is auto-detected:

type "User", struct: MyApp.Accounts.User do
  use GreenFairy.Extensions.CQL

  field :id, non_null(:id)
  field :name, :string
  field :posts, list_of(:post) do
    dataload :posts
  end
end

CQL will automatically detect that MyApp.Accounts.User is an Ecto schema and the adapter will be used for both CQL filtering and DataLoader.

Summary

Functions

Returns the association struct for a given association name.

Returns associations defined on an Ecto schema.

Returns the CQL type prefix for this adapter.

Detects the CQL sub-adapter for an Ecto schema module.

Checks if a module is an Ecto schema.

Gets the Ecto repo for a given schema module.

Returns the primary key fields for an Ecto schema.

Returns the complete type-to-operators mapping.

Functions

apply_operator(module, query, field, operator, value, opts)

association(module, name)

Returns the association struct for a given association name.

associations(module)

Returns associations defined on an Ecto schema.

cql_capabilities(module)

cql_type_prefix()

Returns the CQL type prefix for this adapter.

This prefix is used when generating CQL filter/operator type names in the GraphQL schema.

detect_cql_subadapter(module)

Detects the CQL sub-adapter for an Ecto schema module.

Looks up the schema's repo and detects the database adapter from it, then returns the corresponding CQL sub-adapter module.

ecto_schema?(module)

Checks if a module is an Ecto schema.

Convenience function that delegates to handles?/1.

get_repo_for_schema(module)

Gets the Ecto repo for a given schema module.

The repo is determined by:

  1. Checking if the module defines __repo__/0
  2. Checking the :green_fairy, :repo application config
  3. Inferring from the module name (e.g., MyApp.Accounts.User -> MyApp.Repo)

operator_inputs(module)

operator_type_for(module, ecto_type)

primary_key(module)

Returns the primary key fields for an Ecto schema.

sort_direction_enum(module, repo_namespace)

sort_directions(module)

supported_operators(module, category, field_type)

supports_geo_ordering?(module)

supports_priority_ordering?(module)

type_operators()

Returns the complete type-to-operators mapping.

Useful for introspection and documentation.