Grephql.InputTypeGenerator (Grephql v0.9.0)

Copy Markdown View Source

Generates Ecto embedded schema modules for GraphQL input types.

Unlike Grephql.TypeGenerator (per-query output types), input types are schema-level and shared across queries. Each input object type generates one module under ClientModule.Inputs.InputTypeName.

Generated modules include a build/1 function that validates parameters via Ecto changeset and returns {:ok, struct} or {:error, changeset}.

Summary

Functions

Generates input type modules for all input types referenced by an operation's variable definitions.

Generates a Variables struct for an operation's variable definitions.

Types

option()

@type option() ::
  {:client_module, module()} | {:function_name, atom()} | {:scalar_types, map()}

Functions

generate(operation, schema, opts)

@spec generate(Grephql.Language.OperationDefinition.t(), Grephql.Schema.t(), [
  option()
]) :: [module()]

Generates input type modules for all input types referenced by an operation's variable definitions.

Returns a list of generated module names.

Options

  • :client_module — the parent client module (e.g., MyApp.UserService)
  • :scalar_types — custom scalar type mappings (default: %{})

generate_variables(operation, schema, opts)

@spec generate_variables(
  Grephql.Language.OperationDefinition.t(),
  Grephql.Schema.t(),
  [option()]
) :: module() | nil

Generates a Variables struct for an operation's variable definitions.

Returns the Variables module name, or nil if the operation has no variables. Variable field names are snake_cased with source: mapping to the original GraphQL variable name for correct serialization via Ecto.embedded_dump/2.

Options

  • :client_module — the parent client module
  • :function_name — the defgql function name (for module path)
  • :scalar_types — custom scalar type mappings (default: %{})