TypedGql.Generation.Plugin behaviour (TypedGql v0.13.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 — currently TypedGql.Generation.Plugins.SkipInclude for @include/@skip — before the ones given in the :generation_plugins option, in order, at each juncture.

TypedGql.TypeGenerator describes what each step does.

Summary

Types

What Module.create/3 is handed to record where a generated module came from: the caller's Macro.Env, or a keyword list carrying :file/:line.

Callbacks

Runs on the {module, quoted_ast, create_opts} triples produced by lowering, where create_opts is what Module.create/3 is handed to record where the generated module came from.

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

module_create_opts()

@type module_create_opts() :: Macro.Env.t() | keyword()

What Module.create/3 is handed to record where a generated module came from: the caller's Macro.Env, or a keyword list carrying :file/:line.

selection()

Callbacks

after_lower(list, t)

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

Runs on the {module, quoted_ast, create_opts} triples produced by lowering, where create_opts is what Module.create/3 is handed to record where the generated module came from.

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.