GraphQL::Type::Library - GraphQL type library
use GraphQL::Type::Library -all; has name => (is => 'ro', isa => StrNameValid, required => 1);
Provides Type::Tiny types.
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.
isa
Subtype of "HashRef" in Types::Standard, whose values are hash-refs. Takes two parameters:
Optional within the second-level hashes.
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.
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 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.
GraphQL output type for the field.
A "FieldMapInput".
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.
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:
The Perl entity (possibly a blessed object) returned by the resolver that conjured up this GraphQL object.
Hash-ref of the arguments passed to the field. The values will be Perl values.
The "context" value supplied to the call to "execute" in GraphQL::Execution. Can be used for authenticated user information, or a per-request cache.
A hash-ref with these keys:
The real name of this field.
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 with more than one name - i.e. with an alias.
The return type.
The type of which this field is part.
The hierarchy of fields from the query root to this field-resolution.
GraphQL::Schema object.
Any fragments applying to this request.
The "root value" given to execute.
execute
A hash-ref describing the operation (query, etc) being executed.
query
the operation's arguments, filled out with the variables hash supplied to the request.
A hash-ref. The relevant value supplied to the execute function.
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.
Code-ref to return a given property from a given source-object.
Reason if deprecated. If given, also sets a boolean key of is_deprecated to true.
is_deprecated
32-bit signed integer.
Like "ArrayRef" in Types::Standard but requires at least one entry.
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, );
A Maybe[HashRef] that produces a GraphQL-like message if it fails, saying "found not an object".
Maybe[HashRef]
Hash-ref that has keys line and column which are Int.
line
column
Int
Hash-ref that has keys message, location, path.
message
location
path
Hash-ref that has keys data and/or errors.
data
errors
The errors, if present, will be an array-ref of ErrorResult.
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.
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.
An object that has a then method.
then
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.
resolve
all
reject
Ed J, <etj at cpan.org>
<etj at cpan.org>
To install GraphQL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GraphQL
CPAN shell
perl -MCPAN -e shell install GraphQL
For more information on module installation, please visit the detailed CPAN module installation guide.