use
5.014;
with
qw(
GraphQL::Role::FieldsEither
)
;
our
$VERSION
=
'0.02'
;
use
constant
DEBUG
=>
$ENV
{GRAPHQL_DEBUG};
my
@LOCATIONS
=
qw(
QUERY
MUTATION
SUBSCRIPTION
FIELD
FRAGMENT_DEFINITION
FRAGMENT_SPREAD
INLINE_FRAGMENT
SCHEMA
SCALAR
OBJECT
FIELD_DEFINITION
ARGUMENT_DEFINITION
INTERFACE
UNION
ENUM
ENUM_VALUE
INPUT_OBJECT
INPUT_FIELD_DEFINITION
)
;
has
locations
=> (
is
=>
'ro'
,
isa
=> ArrayRef[Enum[
@LOCATIONS
]],
required
=> 1);
has
args
=> (
is
=>
'thunked'
,
isa
=> FieldMapInput,
required
=> 1);
method from_ast(
HashRef
$name2type
,
HashRef
$ast_node
,
) :ReturnType(InstanceOf[__PACKAGE__]) {
DEBUG and _debug(
'Directive.from_ast'
,
$ast_node
);
$self
->new(
$self
->_from_ast_named(
$ast_node
),
locations
=>
$ast_node
->{locations},
$self
->_from_ast_fields(
$name2type
,
$ast_node
,
'args'
),
);
}
has
to_doc
=> (
is
=>
'lazy'
,
isa
=> Str);
sub
_build_to_doc {
my
(
$self
) =
@_
;
DEBUG and _debug(
'Directive.to_doc'
,
$self
);
my
@start
= (
$self
->_description_doc_lines(
$self
->description),
"directive \@@{[$self->name]}("
,
);
my
@argtuples
=
$self
->_make_fieldtuples(
$self
->args);
DEBUG and _debug(
'Directive.to_doc(args)'
, \
@argtuples
);
my
$end
=
") on "
.
join
(
' | '
, @{
$self
->locations});
return
join
(
"\n"
,
@start
).
join
(
', '
,
map
$_
->[0],
@argtuples
).
$end
.
"\n"
if
!
grep
$_
->[1],
@argtuples
;
join
''
,
map
"$_\n"
,
@start
,
(
map
{
my
(
$main
,
@description
) =
@$_
;
(
map
length
() ?
" $_"
:
""
,
@description
,
$main
,
)
}
@argtuples
),
$end
;
}
$GraphQL::Directive::DEPRECATED
= GraphQL::Directive->new(
name
=>
'deprecated'
,
description
=>
'Marks an element of a GraphQL schema as no longer supported.'
,
locations
=> [
qw(FIELD_DEFINITION ENUM_VALUE)
],
args
=> {
reason
=> {
type
=>
$String
,
description
=>
'Explains why this element was deprecated, usually also including '
.
'a suggestion for how to access supported similar data. Formatted '
.
default_value
=>
'No longer supported'
,
},
},
);
$GraphQL::Directive::INCLUDE
= GraphQL::Directive->new(
name
=>
'include'
,
description
=>
'Directs the executor to include this field or fragment only when the `if` argument is true.'
,
locations
=> [
qw(FIELD FRAGMENT_SPREAD INLINE_FRAGMENT)
],
args
=> {
if
=> {
type
=>
$Boolean
->non_null,
description
=>
'Included when true.'
,
},
},
);
$GraphQL::Directive::SKIP
= GraphQL::Directive->new(
name
=>
'skip'
,
description
=>
'Directs the executor to skip this field or fragment when the `if` argument is true.'
,
locations
=> [
qw(FIELD FRAGMENT_SPREAD INLINE_FRAGMENT)
],
args
=> {
if
=> {
type
=>
$Boolean
->non_null,
description
=>
'Skipped when true.'
,
},
},
);
@GraphQL::Directive::SPECIFIED_DIRECTIVES
= (
$GraphQL::Directive::INCLUDE
,
$GraphQL::Directive::SKIP
,
$GraphQL::Directive::DEPRECATED
,
);
method _get_directive_values(
HashRef
$node
,
HashRef
$variables
,
) {
DEBUG and _debug(
'_get_directive_values'
,
$self
->name,
$node
,
$variables
);
my
(
$d
) =
grep
$_
->{name} eq
$self
->name, @{
$node
->{directives} || []};
return
if
!
$d
;
GraphQL::Execution::_get_argument_values(
$self
,
$d
,
$variables
);
}
__PACKAGE__->meta->make_immutable();
1;