.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "GraphQL::Type::Library 3pm" .TH GraphQL::Type::Library 3pm "2022-03-27" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" GraphQL::Type::Library \- GraphQL type library .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use GraphQL::Type::Library \-all; \& has name => (is => \*(Aqro\*(Aq, isa => StrNameValid, required => 1); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Provides Type::Tiny types. .SH "TYPES" .IX Header "TYPES" .SS "StrNameValid" .IX Subsection "StrNameValid" If called with a string that is not a valid GraphQL name, will throw an exception. Suitable for passing to an \f(CW\*(C`isa\*(C'\fR constraint in Moo. .SS "ValuesMatchTypes" .IX Subsection "ValuesMatchTypes" Subtype of \*(L"HashRef\*(R" in Types::Standard, whose values are hash-refs. Takes two parameters: .IP "value keyname" 4 .IX Item "value keyname" Optional within the second-level hashes. .IP "type keyname" 4 .IX Item "type keyname" Values will be a GraphQL::Type. Mandatory within the second-level hashes. .PP In the second-level hashes, the values (if given) must pass the GraphQL type constraint. .SS "FieldsGot" .IX Subsection "FieldsGot" Data item describing the fields found in a particular object in a query. Preserves their order. .SS "FieldMapInput" .IX Subsection "FieldMapInput" Hash-ref mapping field names to a hash-ref description. Description keys, all optional except \f(CW\*(C`type\*(C'\fR: .IP "type" 4 .IX Item "type" GraphQL input type for the field. .IP "default_value" 4 .IX Item "default_value" Default value for this argument if none supplied. Must be same type as the \f(CW\*(C`type\*(C'\fR (implemented with type \*(L"ValuesMatchTypes\*(R". \&\fB\s-1NB\s0\fR this is a Perl value, not a JSON/GraphQL value. .IP "description" 4 .IX Item "description" Description. .SS "FieldMapOutput" .IX Subsection "FieldMapOutput" Hash-ref mapping field names to a hash-ref description. Description keys, all optional except \f(CW\*(C`type\*(C'\fR: .PP \fItype\fR .IX Subsection "type" .PP GraphQL output type for the field. .PP \fIargs\fR .IX Subsection "args" .PP A \*(L"FieldMapInput\*(R". .PP \fIsubscribe\fR .IX Subsection "subscribe" .PP Code-ref to return a subscription to the field from a given source-object. See \*(L"subscribe\*(R" in GraphQL::Subscription. .PP \fIdeprecation_reason\fR .IX Subsection "deprecation_reason" .PP Reason if deprecated. If given, also sets a boolean key of \&\f(CW\*(C`is_deprecated\*(C'\fR to true. .PP \fIdescription\fR .IX Subsection "description" .PP Description. .PP \fIresolve\fR .IX Subsection "resolve" .PP Code-ref to return a given property from a given source-object. A key concept is to remember that the \*(L"object\*(R" on which these fields exist, were themselves returned by other fields. .PP 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. .PP 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. .PP 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: .PP .Vb 10 \& 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), \& }, \& # ... .Ve .PP The code-ref will be called with these parameters: .PP \f(CW$source\fR .IX Subsection "$source" .PP The Perl entity (possibly a blessed object) returned by the resolver that conjured up this GraphQL object. .PP \f(CW$args\fR .IX Subsection "$args" .PP Hash-ref of the arguments passed to the field. The values will be Perl values. .PP \f(CW$context\fR .IX Subsection "$context" .PP The \*(L"context\*(R" value supplied to the call to \&\*(L"execute\*(R" in GraphQL::Execution. Can be used for authenticated user information, or a per-request cache. .PP \f(CW$info\fR .IX Subsection "$info" .PP A hash-ref describing this node of the request; see \*(L"info hash\*(R" below. .PP \fIinfo hash\fR .IX Subsection "info hash" .PP field_name .IX Subsection "field_name" .PP The real name of this field. .PP field_nodes .IX Subsection "field_nodes" .PP The array of Abstract Syntax Tree (\s-1AST\s0) nodes that refer to this field in this \*(L"selection set\*(R" (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. .PP return_type .IX Subsection "return_type" .PP The return type. .PP parent_type .IX Subsection "parent_type" .PP The type of which this field is part. .PP path .IX Subsection "path" .PP The hierarchy of fields from the query root to this field-resolution. .PP schema .IX Subsection "schema" .PP GraphQL::Schema object. .PP fragments .IX Subsection "fragments" .PP Any fragments applying to this request. .PP root_value .IX Subsection "root_value" .PP The \*(L"root value\*(R" given to \f(CW\*(C`execute\*(C'\fR. .PP operation .IX Subsection "operation" .PP A hash-ref describing the operation (\f(CW\*(C`query\*(C'\fR, etc) being executed. .PP variable_values .IX Subsection "variable_values" .PP the operation's arguments, filled out with the variables hash supplied to the request. .PP promise_code .IX Subsection "promise_code" .PP A hash-ref. The relevant value supplied to the \f(CW\*(C`execute\*(C'\fR function. .SS "Int32Signed" .IX Subsection "Int32Signed" 32\-bit signed integer. .SS "ArrayRefNonEmpty" .IX Subsection "ArrayRefNonEmpty" Like \*(L"ArrayRef\*(R" in Types::Standard but requires at least one entry. .SS "UniqueByProperty" .IX Subsection "UniqueByProperty" An ArrayRef, its members' property (the one in the parameter) can occur only once. .PP .Vb 7 \& use Moo; \& use GraphQL::Type::Library \-all; \& has types => ( \& is => \*(Aqro\*(Aq, \& isa => UniqueByProperty[\*(Aqname\*(Aq] & ArrayRef[InstanceOf[\*(AqGraphQL::Type::Object\*(Aq]], \& required => 1, \& ); .Ve .SS "ExpectObject" .IX Subsection "ExpectObject" A \f(CW\*(C`Maybe[HashRef]\*(C'\fR that produces a GraphQL-like message if it fails, saying \*(L"found not an object\*(R". .SS "DocumentLocation" .IX Subsection "DocumentLocation" Hash-ref that has keys \f(CW\*(C`line\*(C'\fR and \f(CW\*(C`column\*(C'\fR which are \f(CW\*(C`Int\*(C'\fR. .SS "JSONable" .IX Subsection "JSONable" A value that will be JSON-able. .SS "ErrorResult" .IX Subsection "ErrorResult" Hash-ref that has keys \f(CW\*(C`message\*(C'\fR, \f(CW\*(C`location\*(C'\fR, \f(CW\*(C`path\*(C'\fR, \f(CW\*(C`extensions\*(C'\fR. .SS "ExecutionResult" .IX Subsection "ExecutionResult" Hash-ref that has keys \f(CW\*(C`data\*(C'\fR and/or \f(CW\*(C`errors\*(C'\fR. .PP The \f(CW\*(C`errors\*(C'\fR, if present, will be an array-ref of \f(CW\*(C`ErrorResult\*(C'\fR. .PP The \f(CW\*(C`data\*(C'\fR 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. .SS "ExecutionPartialResult" .IX Subsection "ExecutionPartialResult" Hash-ref that has keys \f(CW\*(C`data\*(C'\fR and/or \f(CW\*(C`errors\*(C'\fR. Like \*(L"ExecutionResult\*(R" above, but the \f(CW\*(C`errors\*(C'\fR, if present, will be an array-ref of GraphQL::Error objects. .SS "Promise" .IX Subsection "Promise" An object that has a \f(CW\*(C`then\*(C'\fR method. .SS "PromiseCode" .IX Subsection "PromiseCode" A hash-ref with three keys: \f(CW\*(C`resolve\*(C'\fR, \f(CW\*(C`all\*(C'\fR, \f(CW\*(C`reject\*(C'\fR. The values are all code-refs that take one value (for \f(CW\*(C`all\*(C'\fR, an array-ref), and create the given kind of Promise. .PP An example, enabling interoperation with Promises: .PP .Vb 6 \& use Promises qw(collect resolved rejected); \& { \& all => \e&collect, \& resolve => \e&resolved, \& reject => \e&rejected, \& }, .Ve .PP Must also have a \f(CW\*(C`new\*(C'\fR key for use with GraphQL::Subscription, with code returning a promise that can then have \f(CW\*(C`resolve\*(C'\fR or \f(CW\*(C`reject\*(C'\fR called on it. .SS "AsyncIterator" .IX Subsection "AsyncIterator" An instance of GraphQL::AsyncIterator. .SH "AUTHOR" .IX Header "AUTHOR" Ed J, \f(CW\*(C`\*(C'\fR