Introduce self-describing hooks#91
Merged
Merged
Conversation
`@hook(input: ["creator.id"])` forced every call site to know and select the exact fields a hook reads internally. Updating a hook's needs meant touching every query that used it — the call site was coupled to the hook's implementation. A hook now declares the data it needs as a named GraphQL fragment via `#[Hook(name: ..., requires: ...)]`. The call site shrinks to a bare `@hook(name: ...)`. The generator builds a typed data class from the `requires` fragment (emitted into `Generated/Hook/`), validates that the `@hook` field sits on a type the fragment's `on Type` condition allows — an object type, or an interface, in which case any implementer — and injects the required selection into the operation sent to the server. The hook receives the typed object. Fields a hook needs but the caller did not select are merged into the raw payload only, never surfacing as properties on the caller's generated classes, so the typed API stays free of hook internals. Batched hooks (`batched: true`) carry over: the `HookLoader` collects the typed data objects instead of scalar tuples. This is a breaking change — the `@hook(input:)` argument is removed; `DirectiveProcessor` raises a migration error if it is still used. Hooks must move their field list into a `requires` fragment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@hook(input: ["creator.id"])forced every call site to know and select the exact fields a hook reads internally. Updating a hook's needs meant touching every query that used it — the call site was coupled to the hook's implementation.A hook now declares the data it needs as a named GraphQL fragment via
#[Hook(name: ..., requires: ...)]. The call site shrinks to a bare@hook(name: ...). The generator builds a typed data class from therequiresfragment (emitted intoGenerated/Hook/), validates that the@hookfield sits on a type the fragment'son Typecondition allows — an object type, or an interface, in which case any implementer — and injects the required selection into the operation sent to the server. The hook receives the typed object.Fields a hook needs but the caller did not select are merged into the raw payload only, never surfacing as properties on the caller's generated classes, so the typed API stays free of hook internals. Batched hooks (
batched: true) carry over: theHookLoadercollects the typed data objects instead of scalar tuples.This is a breaking change — the
@hook(input:)argument is removed;DirectiveProcessorraises a migration error if it is still used. Hooks must move their field list into arequiresfragment.