TypedGql.Generation.Plugin behaviour (typedGql v0.11.0)

Copy Markdown View Source

Behaviour for hooking into the response-type generation pipeline.

Generation runs as four named steps — normalize, resolve, lower, create. Plugins observe/transform the output of the first three via after_normalize, after_resolve, and after_lower (plus before_normalize for the raw entry). Adjacent before_X equals after_prev, so only the after_* family and before_normalize are exposed. The terminal create step compiles modules and is not hookable.

All callbacks are optional. use TypedGql.Generation.Plugin provides identity defaults and defoverridable, so a plugin only implements the hooks it cares about (the built-in @include/@skip plugin implements only after_resolve).

TypedGql always runs its built-in plugins before user plugins, in order, at each juncture.

Summary

Callbacks

Runs on the {module, quoted_ast} pairs produced by lowering.

Runs on the canonical selections produced by normalization (fragment spreads expanded, inline fragments flattened, ancestor directives propagated onto each field).

Runs on the generated-schema tree produced by resolution.

Runs on the raw selections before normalization.

Types

selection()

@type selection() ::
  TypedGql.Language.Field.t()
  | TypedGql.Language.InlineFragment.t()
  | TypedGql.Language.FragmentSpread.t()

Callbacks

after_lower(list, t)

(optional)
@callback after_lower([{module(), Macro.t()}], TypedGql.Generation.Context.t()) :: [
  {module(), Macro.t()}
]

Runs on the {module, quoted_ast} pairs produced by lowering.

after_normalize(list, t)

(optional)
@callback after_normalize([selection()], TypedGql.Generation.Context.t()) :: [selection()]

Runs on the canonical selections produced by normalization (fragment spreads expanded, inline fragments flattened, ancestor directives propagated onto each field).

after_resolve(t, t)

(optional)

Runs on the generated-schema tree produced by resolution.

This is where directive plugins like @include/@skip operate, since it is the last juncture before field types are lowered.

before_normalize(list, t)

(optional)
@callback before_normalize([selection()], TypedGql.Generation.Context.t()) :: [
  selection()
]

Runs on the raw selections before normalization.