View on
Ed J > GraphQL-0.13 > GraphQL



Annotate this POD

View/Report Bugs
Module Version: 0.13   Source   Latest Release: GraphQL-0.24


GraphQL - Perl implementation of GraphQL


  use GraphQL::Schema;
  use GraphQL::Type::Object;
  use GraphQL::Type::Scalar qw($String);
  use GraphQL::Execution;

  my $schema = GraphQL::Schema->new(query => GraphQL::Type::Object->new(
    name => 'QueryRoot',
    fields => {
      helloWorld => { type => $String, resolve => sub { 'Hello world!' } },
  post '/graphql' => sub {
    send_as JSON => GraphQL::Execution->execute(

The above is from the sample Dancer 2 applet.


This module is a port of the GraphQL reference implementation, graphql-js, to Perl 5.

See GraphQL::Type for description of how to create GraphQL types.

Introduction to GraphQL

GraphQL is a technology that lets clients talk to APIs via a single endpoint, which acts as a single "source of the truth". This means clients do not need to seek the whole picture from several APIs. Additionally, it makes this efficient in network traffic, time, and programming effort:

Network traffic

The request asks for exactly what it wants, which it gets, and no more. No wasted traffic.


It gets all the things it needs in one go, including any connected resources, so it does not need to make several requests to fill its information requirement.

Programming effort

With "fragments" that can be attached to user-interface components, keeping track of what information a whole page needs to request can be automated. See Relay or Apollo for more on this.

Basic concepts

GraphQL implements a system featuring a schema, which features various classes of types, some of which are objects. Special objects provide the roots of queries (mandatory), and mutations and subscriptions (both optional).

Objects have fields, each of which can be specified to take arguments, and which have a return type. These are effectively the properties and/or methods on the type. If they return an object, then a query can specify subfields of that object, and so on - as alluded to in the "time-saving" point above.

For more, see the JavaScript tutorial in "SEE ALSO".

Hooking your system up to GraphQL

You will need to decide how to model your system in GraphQL terms. This will involve deciding on what output object types you have, what fields they have, and what arguments and return-types those fields have.

Additionally, you will need to design mutations if you want to be able to update/create/delete data. This requires some thought for return types, to ensure you can get all the information you need to proceed to avoid extra round-trips.

Finally, you should consider whether you need "subscriptions". These are designed to hook into WebSockets. Apollo has a JavaScript module for this.

Specifying types and fields is straightforward. See the document for how to make resolvers.


To debug, set environment variable GRAPHQL_DEBUG to a true value.


None yet.

SEE ALSO ^ - GraphQL specification - Tutorial on the JavaScript version, highly recommended.


Ed J, <etj at>


Please report any bugs or feature requests on

Or, if you prefer email and/or RT: to bug-graphql at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


The creation of this work has been sponsored by Perl Careers:


Copyright 2017 Ed J.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

syntax highlighting: