graphql-perl - Dancer2::Plugin::GraphQL - Dancer2 GraphQL endpoint
The porting of GraphQL to Perl 5 (sponsored by Perl Careers) continues. With v0.12, released 10 Oct, it is possible to run queries and return results. This includes the introspection query built in to GraphQL.
Now there is a Dancer 2 plugin: Dancer2::Plugin::GraphQL. This allows you to make a Dancer2 app that serves GraphQL, and - if configured suitably - serve the superb GraphiQL interface to interactively explore and query your schema, with type-ahead.
There is also a sample Dancer2 app (as revamped by Nick Tonkin). Here is the heart of the code (see it on GitHub):
use Dancer2; use GraphQL::Schema; use GraphQL::Type::Object; use GraphQL::Type::Scalar qw/ $String /; use Dancer2::Plugin::GraphQL; # ... my $schema = GraphQL::Schema->new( query => GraphQL::Type::Object->new( name => 'QueryRoot', fields => { helloWorld => { type => $String, resolve => sub { 'Hello, world!' }, }, }, ), ); graphql '/graphql' => $schema;
Leave a comment