Skip to content

khrt/graphql-perl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

GraphQL - A Perl port of the reference implementation of GraphQL.

SYNOPSIS

use GraphQL qw/:types graphql/;

my $schema = GraphQLSchema(
    query => $Query,
    mutation => $Mutation;
);

my $result = graphql($schema, $query);

DESCRIPTION

GraphQL is a port of the reference GraphQL implementation implements GraphQL types, parser, validation, execution, and introspection.

TYPES

To import all available GraphQL types use :types tag from GraphQL class.

Object Types and Fields

Object

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;

Fields

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

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::Language::Object

Scalar Types

GraphQL provides a number of built‐in scalars, but type systems can add additional scalars with semantic meaning.

  • GraphQLBoolean
  • GraphQLFloat
  • GraphQLInt
  • GraphQLID
  • GraphQLString

GraphQL::Language::Scalar

Enumeration Types

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 },
    },
);

GraphQL::Language::Enum

Lists

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!]

GraphQL::Language::List

Non-Null

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]!

GraphQL::Language::NonNull

Interfaces

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) = @_; ... } );

GraphQL::Language::Interface

Union Types

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],
);

GraphQL::Language::Union

Schema

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,
);

GraphQL::Type::Schema.

INTROSPECTION

GraphQL::Type::Introspection.

LIMITATIONS

Boolean, NULL.

EXAMPLES

See examples directory.

GITHUB

https://github.com/khrt/graphql-perl

AUTHOR

Artur Khabibullin - [email protected]

LICENSE

This module and all the modules in this package are governed by the same license as Perl itself.

About

A Perl implementation of GraphQL

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages