GraphQ...ibrary(3pm)
π GraphQ...ibrary(3pm) β GraphQL::Type::Library π
okay bestie, you found it β this is the GraphQL::Type::Library page, straight out of the User Contributed Perl Documentation manual π«Ά it's a whole bag of Type::Tiny types you can yeet into your Moo classes so your GraphQL stuff type-checks itself. no cap. let's go β¨
β¨ NAME β¨
GraphQL::Type::Library β the GraphQL type library π¦
β¨ SYNOPSIS β¨
use GraphQL::Type::Library -all;
has name => (is => 'ro', isa => StrNameValid, required => 1);
β¨ DESCRIPTION β¨
It provides Type::Tiny types. that's the whole description. iconic, honestly. π
π TYPES π
π StrNameValid
If you call it with a string that is not a valid GraphQL name, it will throw an exception at you π. Perfectly suited for passing to an isa constraint in Moo. she's strict and we love her for it π
π ValuesMatchTypes
A subtype of HashRef in Types::Standard, whose values are hash-refs. It takes two parameters:
valuekeyname β optional within the second-level hashes.typekeyname β values will be aGraphQL::Type. Mandatory within the second-level hashes.
In the second-level hashes, the values (if given) must pass the GraphQL type constraint. no skips, no shortcuts β¨
π FieldsGot
A data item describing the fields found in a particular object in a query. It preserves their order β because order is everything bestie, we are NOT shuffling anything around πΈ
π FieldMapInput
A hash-ref mapping field names to a hash-ref description. The 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 thetype(implemented with typeValuesMatchTypes. NB this is a Perl value, not a JSON/GraphQL value.)descriptionβ description.
π FieldMapOutput
A hash-ref mapping field names to a hash-ref description. Description keys, all optional except type:
typeβ GraphQL output type for the field.argsβ aFieldMapInput.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 ofis_deprecatedto 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. live your truth π¦
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. iykyk π
Here's 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. very main character energy π₯
$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::Schemaobject.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. tiny but mighty π§
π ArrayRefNonEmpty
Like ArrayRef in Types::Standard but it requires at least one entry. empty arrays? not on her watch π
π UniqueByProperty
An ArrayRef, its members' property (the one in the parameter) can occur only once. no duplicates allowed, periodt π
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". dramatic? yes. helpful? also yes π
π DocumentLocation
A hash-ref that has keys line and column which are Int.
π JSONable
A value that will be JSON-able. β¨
π ErrorResult
A hash-ref that has keys message, location, path, extensions.
π ExecutionResult
A 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
A 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. she'll get there when she gets there π«Ά
π 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>" β thank you king π«Ά
and that's the whole page bestie! this one was generated for perl v5.34.0 and dated 2022-03-27 π now go forth and type-check your GraphQL, you absolute legend. slay. β¨ππ¦
π¦ where this page comes from
- debian bookworm: libgraphql-perl 0.54-1 Β· Artistic-2.0
- debian trixie: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu noble: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu resolute: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu stonking: libgraphql-perl 0.54-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms