---
name: "GraphQL::Type::Library"
section: "3pm"
platform: "linux"
package: "libgraphql-perl"
version: "0.54-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/GraphQL::Type::Library"
---

# GraphQL::Type::Library(3pm)

GraphQL type library

## NAME

GraphQL::Type::Library - GraphQL type library

## SYNOPSIS

```
    use GraphQL::Type::Library -all;
    has name => (is => 'ro', isa => StrNameValid, required => 1);
```

## DESCRIPTION

Provides Type::Tiny types.

## TYPES

### StrNameValid

If called with a string that is not a valid GraphQL name, will throw an exception. Suitable for passing to an `"isa"` constraint in Moo.

### ValuesMatchTypes

Subtype of "HashRef" in Types::Standard, whose values are hash-refs. Takes two parameters:

- value keyname

  Optional within the second-level hashes.

- type keyname

  Values will be a GraphQL::Type. Mandatory within the second-level hashes.

In the second-level hashes, the values (if given) must pass the GraphQL type constraint.

### FieldsGot

Data item describing the fields found in a particular object in a query. Preserves their order.

### FieldMapInput

Hash-ref mapping field names to a hash-ref description. Description keys, all optional except `"type"`:

- type

  GraphQL input type for the field.

- default\_value

  Default value for this argument if none supplied. Must be same type as the `"type"` (implemented with type "ValuesMatchTypes". **NB** this is a Perl value, not a JSON/GraphQL value.

- description

  Description.

### FieldMapOutput

Hash-ref mapping field names to a hash-ref description. Description keys, all optional except `"type"`:

*type*

GraphQL output type for the field.

*args*

A "FieldMapInput".

*subscribe*

Code-ref to return a subscription to the field from a given source-object. See "subscribe" in GraphQL::Subscription.

*deprecation\_reason*

Reason if deprecated. If given, also sets a boolean key of `"is_deprecated"` to true.

*description*

Description.

*resolve*

Code-ref to return a given property from a given source-object. A key concept is to remember that the "object" on which these fields exist, were themselves returned by other fields.

There are no restrictions on what you can return, so long as it is a scalar, and if your return type is a list, that scalar is an array-ref.

Emphasis has been put on there being Perl values here. Conversion between Perl and GraphQL values is taken care of by scalar types, and it is only scalar information that will be returned to the client, albeit in the shape dictated by the object types.

An example function that takes a name and GraphQL type, and returns a field definition, with a resolver that calls read-only Moo accessors, suitable for placing (several of) inside the hash-ref defining a type's fields:

```
  sub _make_moo_field {
    my ($field_name, $type) = @_;
    ($field_name => { resolve => sub {
      my ($root_value, $args, $context, $info) = @_;
      my @passon = %$args ? ($args) : ();
      return undef unless $root_value->can($field_name);
      $root_value->$field_name(@passon);
    }, type => $type });
  }
  # ...
    fields => {
      _make_moo_field(name => $String),
      _make_moo_field(description => $String),
    },
  # ...
```

The code-ref will be called with these parameters:

`$source`

The Perl entity (possibly a blessed object) returned by the resolver that conjured up this GraphQL object.

`$args`

Hash-ref of the arguments passed to the field. The values will be Perl values.

`$context`

The "context" value supplied to the call to "execute" in GraphQL::Execution. Can be used for authenticated user information, or a per-request cache.

`$info`

A hash-ref describing this node of the request; see "info hash" below.

*info hash*

field\_name

The real name of this field.

field\_nodes

The array of Abstract Syntax Tree (AST) nodes that refer to this field in this "selection set" (set of fields) on this object. There may be more than one such set for a given field, if it is requested more than once with a given name (not with an alias) - the results will be combined into one reply.

return\_type

The return type.

parent\_type

The type of which this field is part.

path

The hierarchy of fields from the query root to this field-resolution.

schema

GraphQL::Schema object.

fragments

Any fragments applying to this request.

root\_value

The "root value" given to `"execute"`.

operation

A hash-ref describing the operation (`"query"`, etc) being executed.

variable\_values

the operation's arguments, filled out with the variables hash supplied to the request.

promise\_code

A hash-ref. The relevant value supplied to the `"execute"` function.

### Int32Signed

32-bit signed integer.

### ArrayRefNonEmpty

Like "ArrayRef" in Types::Standard but requires at least one entry.

### UniqueByProperty

An ArrayRef, its members' property (the one in the parameter) can occur only once.

```
  use Moo;
  use GraphQL::Type::Library -all;
  has types => (
    is => 'ro',
    isa => UniqueByProperty['name'] & ArrayRef[InstanceOf['GraphQL::Type::Object']],
    required => 1,
  );
```

### ExpectObject

A `"Maybe[HashRef]"` that produces a GraphQL-like message if it fails, saying "found not an object".

### DocumentLocation

Hash-ref that has keys `"line"` and `"column"` which are `"Int"`.

### JSONable

A value that will be JSON-able.

### ErrorResult

Hash-ref that has keys `"message"`, `"location"`, `"path"`, `"extensions"`.

### ExecutionResult

Hash-ref that has keys `"data"` and/or `"errors"`.

The `"errors"`, if present, will be an array-ref of `"ErrorResult"`.

The `"data"` if present will be the return data, being a hash-ref whose values are either further hashes, array-refs, or scalars. It will be JSON-able.

### ExecutionPartialResult

Hash-ref that has keys `"data"` and/or `"errors"`. Like "ExecutionResult" above, but the `"errors"`, if present, will be an array-ref of GraphQL::Error objects.

### Promise

An object that has a `"then"` method.

### PromiseCode

A hash-ref with three keys: `"resolve"`, `"all"`, `"reject"`. The values are all code-refs that take one value (for `"all"`, an array-ref), and create the given kind of Promise.

An example, enabling interoperation with Promises:

```
  use Promises qw(collect resolved rejected);
  {
    all     => \&collect,
    resolve => \&resolved,
    reject  => \&rejected,
  },
```

Must also have a `"new"` key for use with GraphQL::Subscription, with code returning a promise that can then have `"resolve"` or `"reject"` called on it.

### AsyncIterator

An instance of GraphQL::AsyncIterator.

## AUTHOR

Ed J, `"<etj at cpan.org>"`
