GraphQL - A Perl port of the reference implementation of GraphQL.
use GraphQL qw/:types graphql/;
my $schema = GraphQLSchema(
query => $Query,
mutation => $Mutation;
);
my $result = graphql($schema, $query);
GraphQL is a port of the reference GraphQL implementation implements GraphQL types, parser, validation, execution, and introspection.
To import all available GraphQL types use :types
tag from GraphQL class.
Object represents a list of named fields, each of which yield a value of a specific type.
GraphQLObjectType(
name => '',
fields => {
...
},
);
Possible parameters of an object:
- name;
- fields - see "Fields";
- description - optional;
- interfaces - optional;
- is_type_of - optional;
List of named fields.
{
args => {
...
},
type => GraphQLString,
resolve => sub {
my ($obj, $args) = @_;
...
},
}
Possible argument of a field:
- type;
- args - see "Arguments";
- resolve - must a code ref if passed;
- description - optional;
- deprecation_reason - optional;
Arguments are applicable to fields and should defined like a HASH ref of arguments of HASH ref with type.
{
arg_name => {
type => GraphQL,
description => 'Argument description',
},
}
Possible parameters of an argument:
- type;
- description - optional;
- default_value - optional;
GraphQL provides a number of built‐in scalars, but type systems can add additional scalars with semantic meaning.
- GraphQLBoolean
- GraphQLFloat
- GraphQLInt
- GraphQLID
- GraphQLString
Enumeration types are a special kind of scalar that is restricted to a particular set of allowed values.
GraphQLEnumType(
name => 'Color',
values => {
RED => { value => 0 },
GREEN => { value => 1 },
BLUE => { value => 2 },
},
);
List modifier marks type as List, which indicates that this field will return an array of that type.
GraphQLList($Type);
The "Non-Null" and "List" modifiers can be combined.
GraphQLList(GraphQLNonNull($Type)); # [$Type!]
The Non-Null type modifier means that server always expects to return a non-null value for a field. Getting a null value will trigger a GraphQL execution error, letting the client know that something has gone wrong.
GraphQLList($Type);
The "Non-Null" and "List" modifiers can be combined.
GraphQLNonNull(GraphQLList($Type)); # [$Type]!
Like many type systems, GraphQL supports interfaces. An Interface is an abstract type that includes a certain set of fields that a type must include to implement the interface.
-
name;
-
fields - see "Fields";
-
description - optional;
-
resolve_type - must be a CODE ref, optional;
GraphQLInterfaceType( name => 'Interface', fields => { ... }, resolve_type => { my ($obj, $context, $info) = @_; ... } );
Union types are very similar to interfaces, but they don't get to specify any common fields between the types.
GraphQLUnionType(
name => 'Union',
types => [$Type0, $Type1],
);
Every GraphQL service has a query type and may or may not have a mutation type. These types are the same as a regular object type, but they are special because they define the entry point of every GraphQL query.
GraphQLSchema(
query => $Query,
mutation => $Mutation,
);
Boolean
, NULL
.
See examples directory.
https://github.com/khrt/graphql-perl
Artur Khabibullin - [email protected]
This module and all the modules in this package are governed by the same license as Perl itself.