predicate
Predicate and resolver helpers for decorators.
A decorator (see @graphql-markdown/types's DecoratorDefinition) is
selected by a predicate over the node being printed, rather than by a fixed
directive name. This module provides the common building blocks: matching a
directive, matching an entity kind, composing predicates, and reading a
directive's occurrences as decorator values.
always()β
function always(): DecoratorPredicate;
Defined in: packages/graphql/src/predicate.ts:191
A predicate that always matches, regardless of the node being printed.
Returnsβ
DecoratorPredicate
a DecoratorPredicate that is always true.
and()β
function and(...predicates): DecoratorPredicate;
Defined in: packages/graphql/src/predicate.ts:145
Combines predicates with logical AND. An empty list is vacuously true.
Parametersβ
predicatesβ
...DecoratorPredicate[]
the predicates to combine.
Returnsβ
DecoratorPredicate
a DecoratorPredicate true when every one of predicates is true.
directiveOccurrence()β
function directiveOccurrence(name): DecoratorResolver;
Defined in: packages/graphql/src/predicate.ts:277
Builds a resolver reading a single, non-repeatable directive's argument
values off the node being printed (see getTypeDirectiveValues,
which this delegates to). Use directiveOccurrences instead for a
repeatable directive, where more than one occurrence can carry values.
Parametersβ
nameβ
string
the schema directive name to read.
Returnsβ
DecoratorResolver
a DecoratorResolver resolving that directive's single occurrence as a one-record array, or an empty array when the schema, the directive, or that occurrence is absent.
directiveOccurrences()β
function directiveOccurrences(name): DecoratorResolver;
Defined in: packages/graphql/src/predicate.ts:260
Builds a resolver reading every occurrence of a directive off the node being printed, as one record of arguments per occurrence (see getTypeDirectiveValuesList, which this delegates to and which also covers repeatable directives).
Parametersβ
nameβ
string
the schema directive name to read.
Returnsβ
DecoratorResolver
a DecoratorResolver resolving that directive's occurrences, or an empty array when the schema or the directive is absent.
getDirectiveFromSchema()β
function getDirectiveFromSchema(name, options): Maybe<GraphQLDirective>;
Defined in: packages/graphql/src/predicate.ts:214
Resolves a schema directive definition by name.
Shared by directiveOccurrences (which reads a directive's argument
values off a node) and @graphql-markdown/printer-legacy's decorator
resolution (which also needs the directive definition itself, for a
decorator's render context) β both need "look up this named directive on
options.schema, safely", so it lives here once rather than being
reimplemented at each call site.
Parametersβ
nameβ
string
the schema directive name to resolve.
optionsβ
PrintTypeOptions
the print options in effect; options.schema is read.
Returnsβ
Maybe<GraphQLDirective>
the directive definition, or undefined when options.schema is
absent, not a GraphQLSchema, or does not declare a directive named name.
getSchemaEntity()β
function getSchemaEntity(type, options): Maybe<SchemaEntity>;
Defined in: packages/graphql/src/predicate.ts:52
Resolves the schema entity kind of the type being printed.
The kind is taken from the print options when the caller knows it, as only the caller can tell a query from a mutation. It falls back to the type guards otherwise, which cover every kind but the operations.
Parametersβ
typeβ
unknown
the GraphQL type being printed.
optionsβ
PrintTypeOptions
the print options in effect.
Returnsβ
Maybe<SchemaEntity>
the schema entity kind, or undefined when it cannot be determined.
hasAnyDirective()β
function hasAnyDirective(): DecoratorPredicate;
Defined in: packages/graphql/src/predicate.ts:115
Builds a predicate matching a node carrying any directive at all.
Returnsβ
DecoratorPredicate
a DecoratorPredicate true when the node carries at least one directive.
hasDirectiveNamed()β
function hasDirectiveNamed(name): DecoratorPredicate;
Defined in: packages/graphql/src/predicate.ts:97
Builds a predicate matching a node carrying a specific directive.
Parametersβ
nameβ
string
the schema directive name to match.
Returnsβ
DecoratorPredicate
a DecoratorPredicate true when the node carries @name.
Exampleβ
decorators: {
responses: {
predicate: hasDirectiveNamed("httpResponse"),
render: (values) => values.map((v) => `- ${v.code}`).join("\n"),
},
}
isEntity()β
function isEntity(...kinds): DecoratorPredicate;
Defined in: packages/graphql/src/predicate.ts:130
Builds a predicate matching one of the given schema entity kinds.
Parametersβ
kindsβ
...SchemaEntity[]
the schema entity kinds to match.
Returnsβ
DecoratorPredicate
a DecoratorPredicate true when the node's resolved entity kind is one of kinds.
not()β
function not(predicate): DecoratorPredicate;
Defined in: packages/graphql/src/predicate.ts:179
Negates a predicate.
Parametersβ
predicateβ
DecoratorPredicate
the predicate to negate.
Returnsβ
DecoratorPredicate
a DecoratorPredicate true when predicate is false.
or()β
function or(...predicates): DecoratorPredicate;
Defined in: packages/graphql/src/predicate.ts:163
Combines predicates with logical OR. An empty list is vacuously false.
Parametersβ
predicatesβ
...DecoratorPredicate[]
the predicates to combine.
Returnsβ
DecoratorPredicate
a DecoratorPredicate true when at least one of predicates is true.