Giter VIP home page Giter VIP logo

graphql-perl-khrt's Introduction

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.

graphql-perl-khrt's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.