GraphQL::Client::http - GraphQL over HTTP
version 0.605
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);
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.
GraphQL::Client::http
This also serves as a reference implementation for GraphQL::Client transports.
GraphQL::Client
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"
"AnyEvent::HTTP"
and more...
See "SUPPORTED USER AGENTS" in HTTP::AnyUA.
The HTTP::AnyUA instance. Can be used to apply middleware if desired.
The http URL of a GraphQL endpoint, e.g. "http://myapiserver/graphql".
"http://myapiserver/graphql"
The HTTP method to use when querying the GraphQL server. Can be one of:
GET
POST (default)
POST
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.
The JSON::XS (or compatible) object used for encoding and decoding data structures to and from the GraphQL server.
Defaults to a JSON::MaybeXS.
$transport = GraphQL::Client::http->new(%attributes);
Construct a new GraphQL HTTP transport.
See "ATTRIBUTES".
$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.
%request
query
variables
operationName
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.
%options
headers
method
url
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 }, }
https://graphql.org/learn/serving-over-http/
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.
Charles McGarvey <ccm@cpan.org>
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.
To install GraphQL::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GraphQL::Client
CPAN shell
perl -MCPAN -e shell install GraphQL::Client
For more information on module installation, please visit the detailed CPAN module installation guide.