| 1 | package Plack::App::GraphQL; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Plack::Util; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Plack::Request; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use GraphQL::Execution; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Safe::Isa; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | extends 'Plack::Component'; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | has convert => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | isa => sub { ref($_[0]) ? 1:0 }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | predicate => 'has_convert', | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | coerce => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | if(ref($_[0]) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my ($class_proto, @args) = @{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | return normalize_convert_class($class_proto)->to_graphql(@args); | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | return $_[0]; # assume its a hashref already. | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub normalize_convert_class { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_convert_class: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $class_proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my $class = $class_proto =~m/^\+(.+)$/ ? | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | $1 : "GraphQL::Plugin::Convert::$class_proto"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | return Plack::Util::load_class($class); | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | has schema => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | builder => '_build_schema', | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | coerce => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $schema_proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | return ( ref($schema_proto) =~m/GraphQL::Schema/) ? | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | $schema_proto : | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | coerce_schema($schema_proto); | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | sub coerce_schema { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
coerce_schema: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | my $source = Plack::Util::is_real_fh($_[0]) ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | do { local $/ = undef; <$_[0]> } : | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.5
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | return Plack::Util::load_class("GraphQL::Schema") | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | ->from_doc($source); | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub _build_schema { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_schema: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | return $self->has_convert ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | $self->convert->{schema} : | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | has root_value => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | builder => '_build_root_value', | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub _build_root_value { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_root_value: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | return $self->has_convert ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | $self->convert->{root_value} : | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | has resolver => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | builder => '_build_resolver', | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | sub _build_resolver { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_resolver: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | return $self->has_convert ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | $self->convert->{resolver} : | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | has promise_code => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | required => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ); # TODO waiting on GraphQL | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | has endpoint => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | builder => 'DEFAULT_ENDPOINT', | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | sub DEFAULT_ENDPOINT { our $DEFAULT_ENDPOINT ||= '/' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEFAULT_ENDPOINT: called CC=2 SCAR=7.6
Pod
undocumented
Condition50%1/2
our $DEFAULT_ENDPOINT ||= "/"
MC/DC0%0/1
our $DEFAULT_ENDPOINT ||= "/"
our $DEFAULT_ENDPOINT
Truth table50%1/2
A
A= our $DEFAULT_ENDPOINT
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | has context_class => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | builder => 'DEFAULT_CONTEXT_CLASS', | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | coerce => sub { Plack::Util::load_class($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | sub DEFAULT_CONTEXT_CLASS { our $DEFAULT_CONTEXT_CLASS ||= 'Plack::App::GraphQL::Context' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEFAULT_CONTEXT_CLASS: called CC=2 SCAR=7.6
Pod
undocumented
Condition50%1/2
our $DEFAULT_CONTEXT_CLASS ||= "Plack::App::GraphQL::Context"
MC/DC0%0/1
our $DEFAULT_CONTEXT_CLASS ||= "Plack::App::GraphQL::Context"
our $DEFAULT_CONTEXT_CLASS
Truth table50%1/2
A
A= our $DEFAULT_CONTEXT_CLASS
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | has ui_template_class => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | builder => 'DEFAULT_UI_TEMPLATE_CLASS', | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | coerce => sub { Plack::Util::load_class(shift) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | ▶ | sub DEFAULT_UI_TEMPLATE_CLASS { our $DEFAULT_UI_TEMPLATE_CLASS ||= 'Plack::App::GraphQL::UITemplate' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEFAULT_UI_TEMPLATE_CLASS: called CC=2 SCAR=7.6
Pod
undocumented
Condition50%1/2
our $DEFAULT_UI_TEMPLATE_CLASS ||= "Plack::App::GraphQL::UITemplate"
MC/DC0%0/1
our $DEFAULT_UI_TEMPLATE_CLASS ||= "Plack::App::GraphQL::UITemplate"
our $DEFAULT_UI_TEMPLATE_CLASS
Truth table50%1/2
A
A= our $DEFAULT_UI_TEMPLATE_CLASS
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | has ui_template => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | builder => '_build_ui_template', | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub _build_ui_template { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_ui_template: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $self->ui_template_class->new(json_encoder => $self->json_encoder, graphiql_version => $self->graphiql_version); | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | has graphiql => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | builder => 'DEFAULT_GRAPHIQL', | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | ▶ | sub DEFAULT_GRAPHIQL { our $DEFAULT_GRAPHIQL ||= 0 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEFAULT_GRAPHIQL: called CC=2 SCAR=7.6
Pod
undocumented
Condition50%1/2
our $DEFAULT_GRAPHIQL ||= 0
MC/DC0%0/1
our $DEFAULT_GRAPHIQL ||= 0
our $DEFAULT_GRAPHIQL
Truth table50%1/2
A
A= our $DEFAULT_GRAPHIQL
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | has graphiql_version => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | builder => 'DEFAULT_GRAPHIQL_VERSION', | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | sub DEFAULT_GRAPHIQL_VERSION { our $DEFAULT_GRAPHIQL_VERSION ||= 'latest' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEFAULT_GRAPHIQL_VERSION: called CC=2 SCAR=7.6
Pod
undocumented
Condition50%1/2
our $DEFAULT_GRAPHIQL_VERSION ||= "latest"
MC/DC0%0/1
our $DEFAULT_GRAPHIQL_VERSION ||= "latest"
our $DEFAULT_GRAPHIQL_VERSION
Truth table50%1/2
A
A= our $DEFAULT_GRAPHIQL_VERSION
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | has json_encoder => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | json_encode => 'encode', | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | json_decode => 'decode', | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | builder => '_build_json_encoder', | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | our $DEFAULT_JSON_CLASS = 'JSON::MaybeXS'; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | ▶ | sub _build_json_encoder { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_json_encoder: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | return our $JSON_ENCODER ||= Plack::Util::load_class($DEFAULT_JSON_CLASS) | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
our $JSON_ENCODER ||= Plack::Util::load_class($Plack::App::GraphQL::DEFAULT_JSON_CLASS)->new->utf8->allow_nonref
MC/DC0%0/2
our $JSON_ENCODER ||= Plack::Util::load_class($Plack::App::GraphQL::DEFAULT_JSON_CLASS)->new->utf8->allow_nonref
our $JSON_ENCODER
Plack::Util::load_class($Plack::App::GraphQL::DEFAULT_JSON_CLASS)->new->utf8->allow_nonref
Truth table33%1/3
A ||= B
A= our $JSON_ENCODERB= Plack::Util::load_class($Plack::App::GraphQL::DEFAULT_JSON_CLASS)->new->utf8->allow_nonref
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | ->new | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | ->utf8 | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ->allow_nonref; | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | has exceptions_class => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | builder => 'DEFAULT_EXCEPTIONS_CLASS', | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | ▶ | coerce => sub { Plack::Util::load_class(shift) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | our $DEFAULT_EXCEPTIONS_CLASS = 'Plack::App::GraphQL::Exceptions'; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | ▶ | sub DEFAULT_EXCEPTIONS_CLASS { $DEFAULT_EXCEPTIONS_CLASS } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DEFAULT_EXCEPTIONS_CLASS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | has exceptions => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | handles => [qw(respond_415 respond_404 respond_400)], | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | builder => '_build_exceptions', | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub _build_exceptions { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_exceptions: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return $self->exceptions_class->new(psgi_app=>$self); | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | ▶ | sub call { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | my ($self, $env) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | my $req = Plack::Request->new($env); | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | ▶ | return $self->respond($req) if $self->matches_endpoint($req); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | return $self->respond_404($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | ▶ | sub matches_endpoint { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
matches_endpoint: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | my ($self, $req) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | return $req->env->{PATH_INFO} eq $self->endpoint ? 1:0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | ▶ | sub respond { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
respond: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | my ($self, $req) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | return sub { $self->respond_graphiql($req, @_) } if $self->accepts_graphiql($req); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | ▶ | return sub { $self->respond_graphql($req, @_) } if $self->accepts_graphql($req); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | return $self->respond_415($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | ▶ | sub accepts_graphiql { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accepts_graphiql: called CC=5 SCAR=21.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | my ($self, $req) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | return 1 if $self->graphiql | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | and (($req->env->{HTTP_ACCEPT}||'') =~ /^text\/html\b/) | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | and (!defined($req->body_parameters->{'raw'})); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%2/8
$self->graphiql and ($req->env->{"HTTP_ACCEPT"} || "") =~ m[^text/html\b] and not defined $req->body_parameters->{"raw"}
$self->graphiql and ($req->env->{"HTTP_ACCEPT"} || "") =~ m[^text/html\b]
$req->env->{'HTTP_ACCEPT'} || ''
MC/DC0%0/3
$self->graphiql and ($req->env->{"HTTP_ACCEPT"} || "") =~ m[^text/html\b] and not defined $req->body_parameters->{"raw"}
$self->graphiql
$req->env->{'HTTP_ACCEPT'}
not defined $req->body_parameters->{"raw"}
Truth table25%1/4
A and B and not(C)
A= $self->graphiqlB= $req->env->{'HTTP_ACCEPT'}C= not defined $req->body_parameters->{"raw"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | sub accepts_graphql { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accepts_graphql: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | my ($self, $req) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | ▶ | return (($req->env->{HTTP_ACCEPT}||'') =~ /^application\/json\b/) ? 1:0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$req->env->{'HTTP_ACCEPT'} || ''
MC/DC0%0/1
$req->env->{'HTTP_ACCEPT'} || ''
$req->env->{'HTTP_ACCEPT'}
Truth table50%1/2
A
A= $req->env->{'HTTP_ACCEPT'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | sub respond_graphiql { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
respond_graphiql: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my ($self, $req, $responder) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my $body = $self->ui_template->process($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | return $responder->( | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 200, | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 'Content-Type' => 'text/html', | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 'Content-Length' => Plack::Util::content_length([$body]), | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | [$body], | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | ▶ | sub respond_graphql { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
respond_graphql: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | my ($self, $req, $responder) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | my ($results, $context) = $self->prepare_results($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 1 | my $writer = $self->prepare_writer($context, $responder); | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # This is ugly; its just a placeholder until GraphQL allows Futures. | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | ▶ | if(ref($results)=~m/Future/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | $results->on_done(sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return $self->write_results($context, shift, $writer); | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | }); # needs on_fail... | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | return $self->write_results($context, $results, $writer) | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | ▶ | sub prepare_writer { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_writer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | my ($self, $context, $responder) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | my @headers = $self->prepare_headers($context); | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | return my $writer = $responder->([200, \@headers]); | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | ▶ | sub prepare_headers { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_headers: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | my ($self, $context) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | return my @headers = ('Content-Type' => 'application/json'); | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | ▶ | sub write_results { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_results: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | my ($self, $context, $results, $writer) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | my $body = $self->json_encode($results); | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | $writer->write($body); | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | $writer->close; | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | ▶ | sub prepare_results { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_results: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | my ($self, $req) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | my $data = $self->prepare_body($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | my $context = $self->prepare_context($req, $data); | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | my $root_value = $self->prepare_root_value($context); | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | my $results = $self->execute( | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | $self->schema, | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | $data, | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | $root_value, | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | $context, | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | $self->resolver, | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | $self->promise_code, | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | return ($results, $context); | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | ▶ | sub prepare_body { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_body: called CC=2 SCAR=7.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | my ($self, $req) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 292 | my $json_body = eval { | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | $self->json_decode($req->raw_body()); | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | ▶ | } || do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
eval {
do {
$self->json_decode($req->raw_body)
}
} || do {
$self->respond_400($req)
}
MC/DC0%0/2
eval {
do {
$self->json_decode($req->raw_body)
}
} || do {
$self->respond_400($req)
}
eval {
do {
$self->json_decode($req->raw_body)
}
}
do {
$self->respond_400($req)
}
Truth table33%1/3
A || B
A= eval {
do {
$self->json_decode($req->raw_body)
}
}B= do {
$self->respond_400($req)
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $self->respond_400($req); | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | return $json_body; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | sub prepare_context { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_context: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | my ($self, $req) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | ▶ | return my $context = $req->env->{'plack.graphql.context'} ||= $self->build_context($req); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$req->env->{"plack.graphql.context"} ||= $self->build_context($req)
MC/DC0%0/2
$req->env->{"plack.graphql.context"} ||= $self->build_context($req)
$req->env->{"plack.graphql.context"}
$self->build_context($req)
Truth table33%1/3
A ||= B
A= $req->env->{"plack.graphql.context"}B= $self->build_context($req)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 1 | ▶ | sub build_context { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_context: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | my ($self, $req, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | my $context_class = $self->context_class; | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | return $context_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | request => $req, | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | data => $data, | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | app => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | log => $req->env->{'psgix.logger'}, | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | ▶ | sub prepare_root_value { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_root_value: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | my ($self, $context) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | ▶ | return my $root_value = $context->req->env->{'plack.graphql.root_value'} ||= $self->root_value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$context->req->env->{"plack.graphql.root_value"} ||= $self->root_value
MC/DC0%0/2
$context->req->env->{"plack.graphql.root_value"} ||= $self->root_value
$context->req->env->{"plack.graphql.root_value"}
$self->root_value
Truth table33%1/3
A ||= B
A= $context->req->env->{"plack.graphql.root_value"}B= $self->root_value
| |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | my ($self, $schema, $data, $root_value, $context, $resolver, $promise_code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | return my $results = GraphQL::Execution::execute( | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | $schema, | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | $data->{query}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | $root_value, | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | $context, | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | $data->{variables}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | $data->{operationName}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | $resolver, | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | $promise_code, | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | Plack::App::GraphQL - Serve GraphQL from Plack / PSGI | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | =begin markdown | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | https://travis-ci.org/jjn1056/Plack-App-GraphQL | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # PROJECT STATUS | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | [](https://travis-ci.org/jjn1056/Plack-App-GraphQL) | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | [](https://metacpan.org/pod/Plack-App-GraphQL) | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | =end markdown | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | use Plack::App::GraphQL; | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | my $schema = q| | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | type Query { | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | hello: String | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |; | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | my %root_value = ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | hello => 'Hello World!', | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | my $app = Plack::App::GraphQL | ||||||||||||||||||||||||||||||||||||||||||||||
| 368 | ->new(schema => $schema, root_value => \%root_value) | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | ->to_app; | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | Or mount under a given URL: | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | use Plack::Builder; | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | use Plack::App::GraphQL; | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # $schema and %root_value as above | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | my $app = Plack::App::GraphQL | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | ->new(schema => $schema, root_value => \%root_value) | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | ->to_app; | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | builder { | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | mount "/graphql" => $app; | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | You can also use the 'endpoint' configuration option to set a root path to match. | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | This is the most simple option if you application is not serving other endpoints | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | or applications (See documentation below). | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | Serve L<GraphQL> with L<Plack>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | Please note this is an early access / minimal documentation release. You should already | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | be familiar with L<GraphQL>. There's some examples in C</examples> but few real test | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | cases. If you are not comfortable using this based on reading the source code and | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | can't accept the possibility that the underlying code might change (although I expect | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | the configuration options are pretty set now) then you shouldn't use this. I recommend | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | looking at official plugins for Dancer and Mojolicious: L<Dancer2::Plugin::GraphQL>, | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | L<Mojolicious::Plugin::GraphQL> instead (or you can send me patches :) ). | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||
| 402 | This currently doesn't support an asychronous responses until updates are made in | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | core L<GraphQL>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | This L<Plack> applications supports the following configuration arguments: | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||
| 409 | =head2 schema | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||
| 411 | The L<GraphQL::Schema>. Canonically this should be an instance of L<GraphQL::Schema> | ||||||||||||||||||||||||||||||||||||||||||||||
| 412 | but if you pass a string or a filehandle, we will assume that it is a parse-able | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | graphql SDL document that we can build a schema object from. Makes for easy demos. | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | =head2 root_value | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | An object, hashref or coderef that field resolvers can use to look up requests. Generally | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | the method or hash keys will match the query or mutation keys. See the examples for | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | more. | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | You can override this at runtime (with for example a bit of middleware) by using the | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 'plack.graphql.root_value' key in the PSGI $env. This may or my not be considered a | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | good practice :) Some examples suggest always using the $context for stuff like this | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | while other examples seem to think its a good idea. I choose to rather enable this | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | ability and let you decide what is right for your application. | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||
| 427 | =head2 resolver | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||
| 429 | Used to change how field resolvers work. See L<GraphQL> (or ignore this since its likely | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | something you really don't need for normal work. | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | =head2 convert | ||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | This takes a sub class of L<GraphQL::Plugin::Convert>, such as L<GraphQL::Plugin::Convert::DBIC>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | Providing this will automatically provide L</schema>, L</root_value> and L</resolver>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||
| 437 | You can shortcut the value of this with a '+' and we will assume the default namespace. For | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | example '+DBIC' is the same as 'GraphQL::Plugin::Convert::DBIC'. | ||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | =head2 endpoint | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | The URI path part that is associated with the graphql API endpoint. Often this is set to | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 'graphql'. The default is '/'. You might prefer to use a custom or alternative router | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | (for example L<Plack::Builder>). | ||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | =head2 context_class | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||
| 448 | Default is L<Plack::App::GraphQL::Context>. This is an object that is passed as the 'context' | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | argument to your field resolvers. You might wish to subclass this to add additional useful | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | methods such as simple access to a user object (if you you authentication for example). | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||
| 452 | =head2 graphiql_version | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | String that defaults to 'latest'. This allows you to specify the graphiql version to use. | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | B<NOTE> Setting this does not enable GraphiQL. | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | =head2 graphiql | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | Boolean that defaults to FALSE. Turn this on to enable the HTML Interactive GraphQL query | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | screen. Useful for leaning and debugging but you probably want it off in production. | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | B<NOTE> If you want to use this you should also install L<Template::Tiny> which is needed. We | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | don't make L<Template::Tiny> a dependency here so that you are not forced to install it where | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | you don't want the interactive screens (such as production). | ||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | =head2 json_encoder | ||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | Lets you specify the instance of the class used for JSON encoding / decoding. The default is an | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | instance of L<JSON::MaybeXS> so you will want to be sure install a fast JSON de/encoder in production, | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | such as L<Cpanel::JSON::XS> (it will default to a pure Perl one which might not need your speed | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | requirements). | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||
| 474 | =head2 exceptions_class | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | Class that provides the exception responses. Override the default (L<Plack::App::GraphQL::Exceptions>) | ||||||||||||||||||||||||||||||||||||||||||||||
| 477 | if you want complete control over how your errors look. | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||
| 481 | TBD | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | John Napiorkowski <jnapiork@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | L<GraphQL>, L<Plack> | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||
| 491 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | Copyright (c) 2019 by "AUTHOR" as listed above. | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||
| 497 | This library is free software and may be distributed under the same terms as perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||
| 499 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||