GraphQL
view release on metacpan or search on metacpan
lib/GraphQL/Directive.pm view on Meta::CPAN
FIELD
FRAGMENT_DEFINITION
FRAGMENT_SPREAD
INLINE_FRAGMENT
SCHEMA
SCALAR
OBJECT
FIELD_DEFINITION
ARGUMENT_DEFINITION
INTERFACE
UNION
ENUM
ENUM_VALUE
INPUT_OBJECT
INPUT_FIELD_DEFINITION
);
=head1 NAME
GraphQL::Directive - GraphQL directive
=head1 SYNOPSIS
use GraphQL::Directive;
my $directive = GraphQL::Directive->new(
name => 'Object',
interfaces => [ $interfaceType ],
fields => { field_name => { type => $scalar_type, resolve => sub { '' } }},
);
=head1 ATTRIBUTES
Has C<name>, C<description> from L<GraphQL::Role::Named>.
=head2 locations
Array-ref of locations where the directive can occur. Must be one of
these strings:
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
=cut
has locations => (is => 'ro', isa => ArrayRef[Enum[@LOCATIONS]], required => 1);
=head2 args
Hash-ref of arguments. See L<GraphQL::Type::Library/FieldMapInput>.
=cut
has args => (is => 'thunked', isa => FieldMapInput, required => 1);
=head1 METHODS
=head2 from_ast
See L<GraphQL::Type/from_ast>.
=cut
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; # no descriptions
# if descriptions
join '', map "$_\n",
@start,
(map {
my ($main, @description) = @$_;
(
map length() ? " $_" : "", @description, $main,
)
} @argtuples),
$end;
}
=head1 PACKAGE VARIABLES
=head2 $GraphQL::Directive::DEPRECATED
=cut
( run in 0.864 second using v1.01-cache-2.11-cpan-39bf76dae61 )