Grephql.TypeGenerator (Grephql v0.10.1)

Copy Markdown View Source

Generates EctoTypedSchema embedded schema modules from GraphQL query AST.

Given an operation definition and a schema, generates per-query output type modules with proper nesting, nullability, and field alias support.

Naming convention

Output types follow per-query path naming under a Result namespace:

ClientModule.FunctionName.Result.FieldName.NestedField...

Field aliases override both struct field names and module path segments.

Union/Interface support

When a field's type is a union or interface, inline fragments determine which concrete types to generate. Shared fields (outside fragments) are merged into each concrete type's struct. A parameterized Grephql.Types.Union Ecto Type handles __typename-based dispatch during deserialization.

Summary

Functions

Generates embedded schema modules for an operation's output types.

Generates an embedded schema module for a named fragment under ClientModule.Fragments.FragmentName.

Types

option()

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

Functions

generate(operation, schema, opts)

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

Generates embedded schema modules for an operation's output types.

Returns a list of generated module names.

Options

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

generate_fragment(fragment, schema, client_module, scalar_types)

@spec generate_fragment(
  Grephql.Language.Fragment.t(),
  Grephql.Schema.t(),
  module(),
  map()
) :: module()

Generates an embedded schema module for a named fragment under ClientModule.Fragments.FragmentName.