Revision history for GraphQL-Client.
+0.601 2020-03-15 20:38:38-06:00 MST7MDT
+ * Rename "class" attribute to "transport_class".
+ * Minor pod fixups.
+
0.600 2020-03-15 18:08:57-06:00 MST7MDT
- * Initial public release
+ * Initial public release.
"provides" : {
"GraphQL::Client" : {
"file" : "lib/GraphQL/Client.pm",
- "version" : "0.600"
+ "version" : "0.601"
},
"GraphQL::Client::Error" : {
"file" : "lib/GraphQL/Client.pm",
- "version" : "0.600"
+ "version" : "0.601"
},
"GraphQL::Client::http" : {
"file" : "lib/GraphQL/Client/http.pm",
- "version" : "0.600"
+ "version" : "0.601"
},
"GraphQL::Client::https" : {
"file" : "lib/GraphQL/Client/https.pm",
- "version" : "0.600"
+ "version" : "0.601"
}
},
"release_status" : "stable",
"web" : "https://github.com/chazmcgarvey/graphql-client"
}
},
- "version" : "0.600",
+ "version" : "0.601",
"x_authority" : "cpan:CCM",
"x_generated_by_perl" : "v5.28.0",
"x_serialization_backend" : "Cpanel::JSON::XS version 4.15",
provides:
GraphQL::Client:
file: lib/GraphQL/Client.pm
- version: '0.600'
+ version: '0.601'
GraphQL::Client::Error:
file: lib/GraphQL/Client.pm
- version: '0.600'
+ version: '0.601'
GraphQL::Client::http:
file: lib/GraphQL/Client/http.pm
- version: '0.600'
+ version: '0.601'
GraphQL::Client::https:
file: lib/GraphQL/Client/https.pm
- version: '0.600'
+ version: '0.601'
recommends:
HTTP::Tiny: '0'
Pod::Usage: '0'
bugtracker: https://github.com/chazmcgarvey/graphql-client/issues
homepage: https://github.com/chazmcgarvey/graphql-client
repository: https://github.com/chazmcgarvey/graphql-client.git
-version: '0.600'
+version: '0.601'
x_authority: cpan:CCM
x_generated_by_perl: v5.28.0
x_serialization_backend: 'YAML::Tiny version 1.73'
"Test::More" => 0,
"lib" => 0
},
- "VERSION" => "0.600",
+ "VERSION" => "0.601",
"test" => {
"TESTS" => "t/*.t"
}
VERSION
- version 0.600
+ version 0.601
SYNOPSIS
GraphQL::Client provides a simple way to execute GraphQL
<https://graphql.org/> queries and mutations on a server.
- This module is the programmatic interface. There is also a graphql.
+ This module is the programmatic interface. There is also a "CLI
+ program".
GraphQL servers are usually served over HTTP. The provided transport,
GraphQL::Client::http, lets you plug in your own user agent, so this
The URL of a GraphQL endpoint, e.g. "http://myapiserver/graphql".
- class
+ unpack
- The package name of a transport.
+ Whether or not to "unpack" the response, which enables a different
+ style for error-handling.
- By default this is automatically determined from the protocol portion
- of the "url".
+ Default is 0.
- transport
+ See "ERROR HANDLING".
- The transport object.
+ transport_class
- By default this is automatically constructed based on the "class".
+ The package name of a transport.
- unpack
+ This is optional if the correct transport can be correctly determined
+ from the "url".
- Whether or not to "unpack" the response, which enables a different
- style for error-handling.
+ transport
- Default is 0.
+ The transport object.
- See "ERROR HANDLING".
+ By default this is automatically constructed based on "transport_class"
+ or "url".
METHODS
There are two different styles for handling errors.
- If "unpack" is 0 (off), every response -- whether success or failure --
- is enveloped like this:
+ If "unpack" is 0 (off, the default), every response -- whether success
+ or failure -- is enveloped like this:
{
data => {...},
my $data = eval { $graphql->execute(...) };
if (my $error = $@) {
+ my $resp = $error->{response};
# handle errors
}
else {
use GraphQL::Client;
use JSON::MaybeXS;
-our $VERSION = '0.600'; # VERSION
+our $VERSION = '0.601'; # VERSION
my $version;
my $help;
=head1 VERSION
-version 0.600
+version 0.601
=head1 SYNOPSIS
use Scalar::Util qw(reftype);
use namespace::clean;
-our $VERSION = '0.600'; # VERSION
+our $VERSION = '0.601'; # VERSION
sub _croak { require Carp; goto &Carp::croak }
sub _throw { GraphQL::Client::Error->throw(@_) }
$self->{url};
}
-sub class {
+sub transport_class {
my $self = shift;
- $self->{class};
+ $self->{transport_class};
}
sub transport {
my $self = shift;
$self->{transport} //= do {
- my $class = $self->_transport_class;
+ my $class = $self->_autodetermine_transport_class;
eval { load $class };
if ((my $err = $@) || !$class->can('execute')) {
$err ||= "Loaded $class, but it doesn't look like a proper transport.\n";
return $protocol;
}
-sub _transport_class {
+sub _autodetermine_transport_class {
my $self = shift;
- return _expand_class($self->{class}) if $self->{class};
+ my $class = $self->transport_class;
+ return _expand_class($class) if $class;
my $protocol = $self->_url_protocol;
_croak 'Failed to determine transport from URL' if !$protocol;
- my $class = lc($protocol);
+ $class = lc($protocol);
$class =~ s/[^a-z]/_/g;
return _expand_class($class);
=head1 VERSION
-version 0.600
+version 0.601
=head1 SYNOPSIS
C<GraphQL::Client> provides a simple way to execute L<GraphQL|https://graphql.org/> queries and
mutations on a server.
-This module is the programmatic interface. There is also a L<graphql|"CLI program">.
+This module is the programmatic interface. There is also a L<"CLI program"|graphql>.
GraphQL servers are usually served over HTTP. The provided transport, L<GraphQL::Client::http>, lets
you plug in your own user agent, so this client works naturally with L<HTTP::Tiny>,
The URL of a GraphQL endpoint, e.g. C<"http://myapiserver/graphql">.
-=head2 class
+=head2 unpack
-The package name of a transport.
+Whether or not to "unpack" the response, which enables a different style for error-handling.
-By default this is automatically determined from the protocol portion of the L</url>.
+Default is 0.
-=head2 transport
+See L</ERROR HANDLING>.
-The transport object.
+=head2 transport_class
-By default this is automatically constructed based on the L</class>.
+The package name of a transport.
-=head2 unpack
+This is optional if the correct transport can be correctly determined from the L</url>.
-Whether or not to "unpack" the response, which enables a different style for error-handling.
+=head2 transport
-Default is 0.
+The transport object.
-See L</ERROR HANDLING>.
+By default this is automatically constructed based on L</transport_class> or L</url>.
=head1 METHODS
There are two different styles for handling errors.
-If L</unpack> is 0 (off), every response -- whether success or failure -- is enveloped like this:
+If L</unpack> is 0 (off, the default), every response -- whether success or failure -- is enveloped
+like this:
{
data => {...},
my $data = eval { $graphql->execute(...) };
if (my $error = $@) {
+ my $resp = $error->{response};
# handle errors
}
else {
use HTTP::AnyUA;
use namespace::clean;
-our $VERSION = '0.600'; # VERSION
+our $VERSION = '0.601'; # VERSION
sub _croak { require Carp; goto &Carp::croak }
=head1 VERSION
-version 0.600
+version 0.601
=head1 SYNOPSIS
authorization => 'Bearer s3cr3t',
},
};
- my $response = $client->execute($request, $options);
+ my $response = $transport->execute($request, $options);
=head1 DESCRIPTION
use parent 'GraphQL::Client::http';
-our $VERSION = '0.600'; # VERSION
+our $VERSION = '0.601'; # VERSION
sub new {
my $class = shift;
=head1 VERSION
-version 0.600
+version 0.601
=head1 DESCRIPTION
use MockTransport;
subtest 'transport' => sub {
- my $client = GraphQL::Client->new(class => 'http');
- isa_ok($client->transport, 'GraphQL::Client::http', 'decide transport from class');
+ my $client = GraphQL::Client->new(transport_class => 'http');
+ isa_ok($client->transport, 'GraphQL::Client::http', 'decide transport from transport_class');
$client = GraphQL::Client->new(url => 'https://localhost:4000/graphql');
isa_ok($client->transport, 'GraphQL::Client::http', 'decide transport from url');
- $client = GraphQL::Client->new(class => 'not a real class');
- is($client->class, 'not a real class', 'class constructor works');
+ $client = GraphQL::Client->new(transport_class => 'not a real class');
+ is($client->transport_class, 'not a real class', 'transport_class constructor works');
throws_ok { $client->transport } qr/^Failed to load transport/, 'throws if invalid transport';
};