.\" 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::Execution 3pm" .TH GraphQL::Execution 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::Execution \- Execute GraphQL queries .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use GraphQL::Execution qw(execute); \& my $result = execute($schema, $doc, $root_value); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Executes a GraphQL query, returns results. .SH "METHODS" .IX Header "METHODS" .SS "execute" .IX Subsection "execute" .Vb 10 \& my $result = execute( \& $schema, \& $doc, # can also be AST \& $root_value, \& $context_value, \& $variable_values, \& $operation_name, \& $field_resolver, \& $promise_code, \& ); .Ve .ie n .IP "$schema" 4 .el .IP "\f(CW$schema\fR" 4 .IX Item "$schema" A GraphQL::Schema. .ie n .IP "$doc" 4 .el .IP "\f(CW$doc\fR" 4 .IX Item "$doc" Either a GraphQL query document to be fed in to \&\*(L"parse\*(R" in GraphQL::Language::Parser, or a return value from that. .ie n .IP "$root_value" 4 .el .IP "\f(CW$root_value\fR" 4 .IX Item "$root_value" A root value that can be used by field-resolvers. The default one needs a code-ref, a hash-ref or an object. .Sp For instance: .Sp .Vb 8 \& my $schema = GraphQL::Schema\->from_doc(<<\*(AqEOF\*(Aq); \& type Query { dateTimeNow: String, hi: String } \& EOF \& my $root_value = { \& dateTimeNow => sub { DateTime\->now\->ymd }, \& hi => "Bob", \& }; \& my $data = execute($schema, "{ dateTimeNow hi }", $root_value); .Ve .Sp will return: .Sp .Vb 6 \& { \& data => { \& dateTimeNow => { ymd => \*(Aq20190501\*(Aq }, \& hi => \*(AqBob\*(Aq, \& } \& } .Ve .Sp Be aware that with the default field-resolver, when it calls a method, that method will get called with \*(L"$args\*(R" in GraphQL::Type::Library \&\*(L"$context\*(R" in GraphQL::Type::Library, \*(L"$info\*(R" in GraphQL::Type::Library. To override that to pass no parameters, this is suitable as a \&\f(CW$field_resolver\fR parameters: .Sp .Vb 10 \& sub { \& my ($root_value, $args, $context, $info) = @_; \& my $field_name = $info\->{field_name}; \& my $property = ref($root_value) eq \*(AqHASH\*(Aq \& ? $root_value\->{$field_name} \& : $root_value; \& return $property\->($args, $context, $info) if ref $property eq \*(AqCODE\*(Aq; \& return $root_value\->$field_name if ref $property; # no args \& $property; \& } .Ve .ie n .IP "$context_value" 4 .el .IP "\f(CW$context_value\fR" 4 .IX Item "$context_value" A per-request scalar, that will be passed to field-resolvers. .ie n .IP "$variable_values" 4 .el .IP "\f(CW$variable_values\fR" 4 .IX Item "$variable_values" A hash-ref, typically the decoded \s-1JSON\s0 object supplied by a client. E.g. for this query: .Sp .Vb 3 \& query q($input: TestInputObject) { \& fieldWithObjectInput(input: $input) \& } .Ve .Sp The \f(CW$variable_values\fR will need to be a \s-1JSON\s0 object with a key \f(CW\*(C`input\*(C'\fR, whose value will need to conform to the input type \f(CW\*(C`TestInputObject\*(C'\fR. .Sp The purpose of this is to avoid needing to hard-code input values in your query. This aids in, among other things, being able to whitelist individual queries as acceptable, non-abusive queries to your system; and being able to generate client-side code for client-side validation rather than including the full GraphQL system in client code. .ie n .IP "$operation_name" 4 .el .IP "\f(CW$operation_name\fR" 4 .IX Item "$operation_name" A string (or \f(CW\*(C`undef\*(C'\fR) that if given will be the name of one of the operations in the query. .ie n .IP "$field_resolver" 4 .el .IP "\f(CW$field_resolver\fR" 4 .IX Item "$field_resolver" A code-ref to be used instead of the default field-resolver. .ie n .IP "$promise_code" 4 .el .IP "\f(CW$promise_code\fR" 4 .IX Item "$promise_code" If you need to return a promise, supply a hash-ref matching \&\*(L"PromiseCode\*(R" in GraphQL::Type::Library.