|
NAMEGraphQL::Type::Library - GraphQL type librarySYNOPSISuse GraphQL::Type::Library -all; has name => (is => 'ro', isa => StrNameValid, required => 1); DESCRIPTIONProvides Type::Tiny types.TYPESStrNameValidIf called with a string that is not a valid GraphQL name, will throw an exception. Suitable for passing to an "isa" constraint in Moo.ValuesMatchTypesSubtype of "HashRef" in Types::Standard, whose values are hash-refs. Takes two parameters:
In the second-level hashes, the values (if given) must pass the GraphQL type constraint. FieldsGotData item describing the fields found in a particular object in a query. Preserves their order.FieldMapInputHash-ref mapping field names to a hash-ref description. Description keys, all optional except "type":
FieldMapOutputHash-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. Int32Signed32-bit signed integer.ArrayRefNonEmptyLike "ArrayRef" in Types::Standard but requires at least one entry.UniqueByPropertyAn 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, ); ExpectObjectA "Maybe[HashRef]" that produces a GraphQL-like message if it fails, saying "found not an object".DocumentLocationHash-ref that has keys "line" and "column" which are "Int".JSONableA value that will be JSON-able.ErrorResultHash-ref that has keys "message", "location", "path", "extensions".ExecutionResultHash-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. ExecutionPartialResultHash-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.PromiseAn object that has a "then" method.PromiseCodeA 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. AsyncIteratorAn instance of GraphQL::AsyncIterator.AUTHOREd J, "<etj at cpan.org>"
Visit the GSP FreeBSD Man Page Interface. |