with-directive
decorators render helper for directive-definition-only content.
See
Migrating from customDirective
withDirective()
function withDirective(name, render): DecoratorRenderer;
Defined in: directives/with-directive.ts:49
Builds a decorator render for content derived from a directive's own
definition — not per-occurrence argument values, so no resolve is
needed. Looks the directive up once and skips the decorator (renders
nothing) when it is absent from the schema, sparing render its own
getDirectiveFromSchema call and null check.
Parameters
name
string
the schema directive name to resolve.
render
(directive, options, context) => Maybe<string>
called with the resolved directive, the print options, and the decorator's context, only when the directive is present in the schema.
Returns
DecoratorRenderer
a DecoratorRenderer for use as a decorator's render.
Example
import { withDirective } from "@graphql-markdown/helpers/directives/with-directive";
import { directiveDescriptor } from "@graphql-markdown/helpers/directives/descriptor";
import { hasDirectiveNamed } from "@graphql-markdown/graphql";
decorators: {
authDescription: {
predicate: hasDirectiveNamed("auth"),
position: { into: "description" },
render: withDirective("auth", (directive, options, { type }) =>
directiveDescriptor(directive, type, "Requires the `${requires}` role."),
),
},
}