Skip to main content

tag

Custom directive tag helper.

See​

Option customDirective.[directive].tag

directiveTag()​

function directiveTag(
directive,
type?,
classname?): Badge

Helper for rendering custom description from schema directive on type. This is an example on how to build a custom tag callback.

Parameters​

β€’ directive: GraphQLDirective

the schema directive to parse.

β€’ type?: unknown

the type being processed.

β€’ classname?: string = "badge--secondary"

optional CSS classname, "badge--secondary" by default.

Returns​

Badge

a custom description based on directive value.

Example​

import { GraphQLDirective, GraphQLScalarType } from "graphql";
import { directiveTag } from "@graphql-markdown/helpers/directives/tag";

const directive = new GraphQLDirective({
name: "auth",
description: "Authentication required",
locations: [],
});

const type = new GraphQLScalarType<string>({
name: "FooBar",
astNode: {
kind: Kind.SCALAR_TYPE_DEFINITION,
name: { kind: Kind.NAME, value: "FooBar" },
directives: [
{
kind: Kind.DIRECTIVE,
name: { kind: Kind.NAME, value: "auth" },
},
],
},
});

directiveTag(directive, type);
// Expected result: { text: "@auth", classname: "badge--secondary" }

Defined in​

directives/tag.ts:51