};
my $JSON = JSON::MaybeXS->new->utf8->allow_nonref;
sub _safe_serialize {
my $data = shift or return 'undefined';
my $json = $JSON->encode( $data );
$json =~ s#/#\\/#g;
return $json;
}
# D
my $body = $JSON->decode($app->request->body);
my $data = eval { $handler->($app, $body, $EXECUTE) };
$data = { errors => [ { message => $@ } ] } if $@;
$app->send_as(JSON => $data);
ntly:
graphql '/graphql' => $schema => sub {
my ($app, $body, $execute) = @_;
# returns JSON-able Perl data
$execute->(
$schema,
$body->{query},
undef, # $root_value