Dancer2-Plugin-GraphQL
view release on metacpan or search on metacpan
my $test = Plack::Test->create( GraphQLApp->to_app );
subtest 'GraphQL with POST' => sub {
my $res = $test->request(
POST '/graphql',
Content_Type => 'application/json',
Content => '{"query":"{helloWorld}"}',
);
my $json = JSON::MaybeXS->new->allow_nonref;
is_deeply eval { $json->decode( $res->decoded_content ) },
{ 'data' => { 'helloWorld' => 'Hello, world!' } },
'Content as expected';
};
subtest 'GraphQL with route-handler' => sub {
my $res = $test->request(
POST '/graphql2',
Content_Type => 'application/json',
Content => '{"query":"{helloWorld}"}',
);
my $json = JSON::MaybeXS->new->allow_nonref;
is_deeply eval { $json->decode( $res->decoded_content ) },
{ 'data' => { 'helloWorld' => 'Hello, world!' } },
'Content as expected';
};
subtest 'GraphQL with die' => sub {
my $res = $test->request(
POST '/graphql-live-and-let-die',
Content_Type => 'application/json',
Content => '{"query":"{helloWorld}"}',
);
my $json = JSON::MaybeXS->new->allow_nonref;
is_deeply eval { $json->decode( $res->decoded_content ) },
{ errors => [ { message => "I died!\n" } ] },
'error as expected';
};
subtest 'GraphiQL' => sub {
my $res = $test->request(
GET '/graphql',
Accept => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
);
like $res->decoded_content, qr/React.createElement\(GraphiQL/, 'Content as expected';
};
done_testing;
( run in 0.322 second using v1.01-cache-2.11-cpan-26ccb49234f )