directive
Library supporting customDirective
for directive based customization.
Seeβ
WILDCARD_DIRECTIVEβ
const WILDCARD_DIRECTIVE: "*";
Wildcard *
character for matching any directive name.
See getCustomDirectiveOptions, isCustomDirective
Defined inβ
packages/graphql/src/directive.ts:31
executableDirectiveLocation()β
function executableDirectiveLocation(directive): boolean
Checks if a directive is executable (related to operations).
Parametersβ
β’ directive: GraphQLDirective
Returnsβ
boolean
Defined inβ
packages/graphql/src/directive.ts:286
getConstDirectiveMap()β
function getConstDirectiveMap(entity, customDirectiveMap): Maybe<CustomDirectiveMap>
Returns a map of custom directives for a schema entity.
Parametersβ
β’ entity: unknown
a GraphQL schema entity.
β’ customDirectiveMap: Maybe
<CustomDirectiveMap
>
a custom directive map (see getCustomDirectives).
Returnsβ
Maybe
<CustomDirectiveMap
>
a map of GraphQL directives matching the custom directives defined, else undefined
.
Exampleβ
import { buildSchema } from "graphql";
import { getConstDirectiveMap } from "@graphql-markdown/utils/directive";
const schema = buildSchema(`
directive @testA(
arg: ArgEnum = ARGA
) on OBJECT | FIELD_DEFINITION
directive @testB(
argA: Int!,
argB: [String!]
) on FIELD_DEFINITION
enum ArgEnum {
ARGA
ARGB
ARGC
}
type Test @testA {
id: ID!
fieldA: [String!]
@testA(arg: ARGC)
@testB(argA: 10, argB: ["testArgB"])
}
type TestWithoutDirective {
id: ID!
}
`);
const customDirectives = {
testA: {
type: schema.getDirective("testA"),
descriptor: (_, constDirectiveType) => `${constDirectiveType.name}`;
},
};
const map = getConstDirectiveMap(schema.getType("Test"), customDirectives);
// Expected result: {
// "descriptor": (_, constDirectiveType) => `${constDirectiveType.name}`,
// "type": schema.getDirective("testA"),
// }
Defined inβ
packages/graphql/src/directive.ts:251
getCustomDirectiveOptions()β
function getCustomDirectiveOptions(schemaDirectiveName, customDirectiveOptions): Maybe<CustomDirectiveOptions>
Returns a record set of custom handlers from a directive by name.
Parametersβ
β’ schemaDirectiveName: DirectiveName
the GraphQL directive name.
β’ customDirectiveOptions: CustomDirective
the customDirective
option.
Returnsβ
Maybe
<CustomDirectiveOptions
>
a record set of custom handlers for the matching directive (or if *
is declared), or undefined if no match.
Exampleβ
import { getCustomDirectiveOptions } from "@graphql-markdown/utils/directive";
const customDirectiveOptions = {
"*": {
descriptor: (_, constDirectiveType) => `Wildcard ${constDirectiveType.name}`;
},
};
const customDirectives = getCustomDirectiveOptions("testB", customDirectiveOptions);
// Expected result: {
// "descriptor": (_, constDirectiveType) => `Wildcard ${constDirectiveType.name}`,
// "type": "@testB",
// }
Defined inβ
packages/graphql/src/directive.ts:79
getCustomDirectives()β
function getCustomDirectives(schemaMap, customDirectiveOptions?): Maybe<CustomDirectiveMap>
Returns a custom directives map with custom handlers from customDirective
.
Parametersβ
β’ schemaMap: Pick
<SchemaMap
, "directives"
>
the GraphQL schema map returned by introspection!getSchemaMap
β’ customDirectiveOptions?: Maybe
<CustomDirective
>
the customDirective
option.
Returnsβ
Maybe
<CustomDirectiveMap
>
a custom directive map, or undefined if no match.
Exampleβ
import { buildSchema } from "graphql";
import { getCustomDirectives } from "@graphql-markdown/utils/directive";
const schema = buildSchema(`
directive @testA(
arg: ArgEnum = ARGA
) on OBJECT | FIELD_DEFINITION
directive @testB(
argA: Int!,
argB: [String!]
) on FIELD_DEFINITION
enum ArgEnum {
ARGA
ARGB
ARGC
}
`);
const schemaMap = {
directives: {
testA: schema.getDirective("testA"),
testB: schema.getDirective("testB"),
},
};
const customDirectiveOptions = {
testA: {
descriptor: (_, constDirectiveType) => `Named directive ${constDirectiveType.name}`;
},
"*": {
descriptor: (_, constDirectiveType) => `Wildcard ${constDirectiveType.name}`;
},
};
const customDirectives = getCustomDirectives(schemaMap, customDirectiveOptions);
// Expected result: {
// "testA": {
// "descriptor": (_, constDirectiveType) => `Named directive ${constDirectiveType.name}`,
// "type": "@testA",
// },
// "testB": {
// "descriptor": (_, constDirectiveType) => `Wildcard ${constDirectiveType.name}`,
// "type": "@testB",
// },
// }
Defined inβ
packages/graphql/src/directive.ts:153
isCustomDirective()β
function isCustomDirective(schemaDirectiveName, customDirectiveOptions): boolean
Checks if a directive name is referenced in customDirective
option.
Parametersβ
β’ schemaDirectiveName: DirectiveName
the GraphQL directive name.
β’ customDirectiveOptions: CustomDirective
the customDirective
option.
Returnsβ
boolean
true
if the directive is declared or *
is declared in customDirective
option, else false
.
Defined inβ
packages/graphql/src/directive.ts:42
typeSystemDirectiveLocation()β
function typeSystemDirectiveLocation(directive): boolean
Checks if a directive is system (related to schema definition).
Parametersβ
β’ directive: GraphQLDirective
Returnsβ
boolean
Defined inβ
packages/graphql/src/directive.ts:309