/kavo-skills:graphql-bindingfrom Kavo Developer Skills
Reference for @kavo/graphql and its Nest binding — building a GraphQL schema over an existing createCrud service, including raw-AST filter/sort args, multi-entity merging, and the zero-code KavoModule option.
Ships in Kavo Developer Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
@kavo/graphql (packages/protocols/graphql) builds a GraphQLSchema over
an existing createCrud service. Every resolver calls directly into the
same DefaultKavoService/engine pipeline REST binds to — no parallel
request path, no second copy of filter/sort/pagination validation, no
separate error handling. Full detail:
docs/internals/architecture/13-graphql-binding.md (and ADR-0016 for the
package-boundary rationale).
@kavo/graphql is host-framework-agnostic: it imports @kavo/core and the
graphql peer only, never @kavo/nest. @kavo/nest depends on
@kavo/graphql, not the other way around.
import { createKavoGraphQLSchema } from "@kavo/graphql";
const schema = createKavoGraphQLSchema({
name: "Owner",
service: ownerService, // whatever createCrud(Owner, ...) returned
itemType: OwnerType, // hand-written GraphQLObjectType
createInputType: CreateOwnerInput, // optional — omit to skip the mutation
updateInputType: UpdateOwnerInput,
patchInputType: PatchOwnerInput,
deleteOne: true,
restoreOne: true, // meaningful only if Owner declared soft delete
purgeOne: true,
});
| Field | Enabled by |
|---|---|
Query.owner(id) | always |
Query.owners(limit, offset, sort, filter) | always |
Mutation.createOwner | createInputType |
Mutation.updateOwner | updateInputType |
Mutation.patchOwner | patchInputType |
Mutation.deleteOwner: Boolean | deleteOne: true |
Mutation.restoreOwner: Owner | restoreOne: true |
Mutation.purgeOwner: Boolean | purgeOne: true |
These flags do not cross-check REST's @Kavo config. Setting
restoreOne: true here for an entity whose @Kavo config disables
restoreOne still adds the field to the schema — it throws
OperationDisabledException at resolve time instead, same as calling the
REST route would. Keeping the two declarations in sync is your job today.
Query.<entity>ssort: [String!] — REST's own -field convention
(["-createdAt", "name"]), translated to Sort[] locally.filter: JSON — a custom GraphQLJSON scalar carrying Kavo's raw
filter AST directly, not REST's wire grammar:
{ kind: "condition", field, operator, value }{ kind: "group", operator: "AND"|"OR"|"NOT", children: [...] }SCREAMING_SNAKE (EQ, GTE, IN, …) — REST's camelCase
wire tokens (eq, gte, in) do not work here. This is the raw-AST
escape hatch, not the REST grammar re-encoded as JSON.import { mergeKavoGraphQLSchemas } from "@kavo/graphql";
const schema = mergeKavoGraphQLSchemas([
{ name: "Owner", service: ownerService, itemType: OwnerType, createInputType: CreateOwnerInput },
{ name: "Cat", service: catService, itemType: CatType, createInputType: CreateCatInput },
]);
Field names are namespaced per entity's own name — no collisions. An
empty binding list throws ConfigurationException at schema-build time
(an empty Query type is invalid GraphQL either way; this fails with a
message naming the actual fix instead of a deep graphql-js validation
error on first request).
Hand-listing every entity doesn't scale. Register each entity's GraphQL types once, next to its DTOs:
// owner.graphql-types.ts
registerKavoGraphQLTypes(Owner, { itemType: OwnerType, createInputType: CreateOwnerInput });
resolveKavoGraphQLSchema (host-agnostic) then takes a list of { entity }
refs and a resolveService(entity) callback, looks up each entity's
registered types (skipping any with none — opt-in, not implied by @Kavo
alone), and merges the rest.
Two ways to mount it, pick one per app/path — never both:
Concrete controller (full control):
@Controller("graphql")
export class GraphQLController extends BaseKavoGraphQLController {
constructor(moduleRef: ModuleRef) {
super(moduleRef);
} // must be declared
@Post()
@HttpCode(200) // GraphQL-over-HTTP convention: 200 even for mutations
handle(@Body() body: { query: string; variables?: Record<string, unknown> }) {
return this.execute(body.query, body.variables);
}
}
Zero-code path: KavoModule.forRoot({ infrastructure, graphql: true })
mounts POST /graphql; { graphql: { path: "api/graphql" } } mounts it
elsewhere. Setting graphql implies provideServices (the merged
schema's resolvers need every entity's service as a DI provider), even
if provideServices itself is left unset.
⚠️ The route is unguarded unless you give it guards, mutations
included; a guard on an entity's REST controller does not extend to it.
{ graphql: { guards: [GraphQLAuthGuard] } } puts guards on it with
@UseGuards (a denial stops the request before any resolver runs, 403 when the guard returns false). Guards must stay singleton-scoped. A guard
class's own dependencies must come from a global module or from
forRootAsync({ imports }). Either way context.app is {} over
GraphQL, so per-caller policy/filter.apply rules see no caller.
graphql is an optional peer of @kavo/nest — it's lazy-loaded
(loadGraphQL(), dynamic import()) so an app that never touches GraphQL
never needs it installed, and import { Kavo } from "@kavo/nest" never
crashes on a missing graphql package regardless of whether KavoModule's
graphql option is set.
EntityMetadata — itemType/createInputType/etc.
are hand-written per entity.OperationRegistry.itemType fields
exist; a relation needs a hand-added field + resolver.<Entity>FilterInput per entity instead of the raw-AST JSON
scalar.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
15 skills in this plugin
/composite-primary-keysReference for composite primary key support in @kavo/typeorm — the compositeIdFields metadata field, the ~-delimited route-id encoding, the creatable/updatable split, and every place composite keys don't yet work (other ORM adapters, many-to-many array-mutation, @kavo/graphql). Use when an entity has more than one @PrimaryColumn, or when a route id, association, or array-mutation write on such an entity behaves unexpectedly./dto-slotsReference for Kavo's six optional schema slots (create/update/patch/query/item/list) — entity-derived defaults, the schemaShapeKeys narrowing rule, and serialization order. Use when configuring a DTO class or validator on @Kavo's schema option, or answering "why isn't my field showing/hiding" or "what shape does this response have" questions./npx claudepluginhub kavo-labs/kavo --plugin kavo-skillsOther plugins' skills for the same job