NAME
GraphQL::Client::http - GraphQL over HTTP
VERSION
version 0.605
SYNOPSIS
my $transport = GraphQL::Client::http->new(
url => 'http://localhost:5000/graphql',
method => 'POST',
);
my $request = {
query => 'query Greet($name: String) { hello(name: $name) }',
operationName => 'Greet',
variables => { name => 'Bob' },
};
my $options = {
headers => {
authorization => 'Bearer s3cr3t',
},
};
my $response = $transport->execute($request, $options);
DESCRIPTION
You probably shouldn't use this directly. Instead use GraphQL::Client.
GraphQL::Client::http
is a GraphQL transport for HTTP. GraphQL is not required to be transported via HTTP, but this is definitely the most common way.
This also serves as a reference implementation for GraphQL::Client
transports.
ATTRIBUTES
ua
A user agent, such as:
instance of a HTTP::Tiny (this is the default if no user agent is provided)
instance of a Mojo::UserAgent
the string
"AnyEvent::HTTP"
and more...
See "SUPPORTED USER AGENTS" in HTTP::AnyUA.
any_ua
The HTTP::AnyUA instance. Can be used to apply middleware if desired.
url
The http URL of a GraphQL endpoint, e.g. "http://myapiserver/graphql"
.
method
The HTTP method to use when querying the GraphQL server. Can be one of:
GET
POST
(default)
GraphQL servers should be able to handle both, but you can set this explicitly to one or the other if you're dealing with a server that is opinionated. You can also provide a different HTTP method, but anything other than GET
and POST
are less likely to work.
json
The JSON::XS (or compatible) object used for encoding and decoding data structures to and from the GraphQL server.
Defaults to a JSON::MaybeXS.
METHODS
new
$transport = GraphQL::Client::http->new(%attributes);
Construct a new GraphQL HTTP transport.
See "ATTRIBUTES".
execute
$response = $client->execute(\%request);
$response = $client->execute(\%request, \%options);
Get a response from the GraphQL server.
The %request
structure must have a query
key whose value is the query or mutation string. It may optionally have a variables
hashref and an operationName
string.
The %options
structure is optional and may contain options passed through to the user agent. The only useful options are headers
(which should have a hashref value) and method
and url
to override the attributes of the same names.
The response will either be a hashref with the following structure or a Future that resolves to such a hashref:
{
response => { # decoded response (may be undef if an error occurred)
data => {...},
errors => [...],
},
error => 'Something happened', # omitted if no error occurred
details => { # optional information which may aide troubleshooting
},
}
SEE ALSO
https://graphql.org/learn/serving-over-http/
BUGS
Please report any bugs or feature requests on the bugtracker website https://github.com/chazmcgarvey/graphql-client/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHOR
Charles McGarvey <ccm@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2020 by Charles McGarvey.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.