From: Charles McGarvey Date: Mon, 16 Mar 2020 02:39:58 +0000 (-0600) Subject: Version 0.601 X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fgraphql-client;a=commitdiff_plain;h=afe2bc3fe09e80cea209312408159ed83f1bfc91 Version 0.601 --- diff --git a/Changes b/Changes index c54d2b5..81a7db9 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ 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. diff --git a/META.json b/META.json index 737e3ed..7139b38 100644 --- a/META.json +++ b/META.json @@ -114,19 +114,19 @@ "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", @@ -141,7 +141,7 @@ "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", diff --git a/META.yml b/META.yml index ef5ab68..727e00d 100644 --- a/META.yml +++ b/META.yml @@ -33,16 +33,16 @@ no_index: 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' @@ -64,7 +64,7 @@ resources: 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' diff --git a/Makefile.PL b/Makefile.PL index 491a896..7d75ca6 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -46,7 +46,7 @@ my %WriteMakefileArgs = ( "Test::More" => 0, "lib" => 0 }, - "VERSION" => "0.600", + "VERSION" => "0.601", "test" => { "TESTS" => "t/*.t" } diff --git a/README b/README index ba5570e..ae64d68 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ NAME VERSION - version 0.600 + version 0.601 SYNOPSIS @@ -52,7 +52,8 @@ DESCRIPTION GraphQL::Client provides a simple way to execute GraphQL 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 @@ -65,27 +66,28 @@ ATTRIBUTES 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 @@ -126,8 +128,8 @@ ERROR HANDLING 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 => {...}, @@ -156,6 +158,7 @@ ERROR HANDLING my $data = eval { $graphql->execute(...) }; if (my $error = $@) { + my $resp = $error->{response}; # handle errors } else { diff --git a/bin/graphql b/bin/graphql index 31c48ae..6825edc 100755 --- a/bin/graphql +++ b/bin/graphql @@ -11,7 +11,7 @@ use Getopt::Long; use GraphQL::Client; use JSON::MaybeXS; -our $VERSION = '0.600'; # VERSION +our $VERSION = '0.601'; # VERSION my $version; my $help; @@ -228,7 +228,7 @@ graphql - Command-line GraphQL client =head1 VERSION -version 0.600 +version 0.601 =head1 SYNOPSIS diff --git a/lib/GraphQL/Client.pm b/lib/GraphQL/Client.pm index 2f844fe..8b93e4b 100644 --- a/lib/GraphQL/Client.pm +++ b/lib/GraphQL/Client.pm @@ -8,7 +8,7 @@ use Module::Load qw(load); 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(@_) } @@ -83,15 +83,15 @@ sub url { $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"; @@ -116,15 +116,16 @@ sub _url_protocol { 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); @@ -170,7 +171,7 @@ GraphQL::Client - A GraphQL client =head1 VERSION -version 0.600 +version 0.601 =head1 SYNOPSIS @@ -218,7 +219,7 @@ version 0.600 C provides a simple way to execute L queries and mutations on a server. -This module is the programmatic interface. There is also a L. +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, lets you plug in your own user agent, so this client works naturally with L, @@ -230,25 +231,25 @@ L, and more. You can also use L middleware. 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. +Default is 0. -=head2 transport +See L. -The transport object. +=head2 transport_class -By default this is automatically constructed based on the L. +The package name of a transport. -=head2 unpack +This is optional if the correct transport can be correctly determined from the L. -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. +By default this is automatically constructed based on L or L. =head1 METHODS @@ -288,7 +289,8 @@ Note: Setting the L attribute affects the response shape. There are two different styles for handling errors. -If L is 0 (off), every response -- whether success or failure -- is enveloped like this: +If L is 0 (off, the default), every response -- whether success or failure -- is enveloped +like this: { data => {...}, @@ -314,6 +316,7 @@ otherwise it will throw an exception. So your code would instead look like this: my $data = eval { $graphql->execute(...) }; if (my $error = $@) { + my $resp = $error->{response}; # handle errors } else { diff --git a/lib/GraphQL/Client/http.pm b/lib/GraphQL/Client/http.pm index 7adf4a4..a53228a 100644 --- a/lib/GraphQL/Client/http.pm +++ b/lib/GraphQL/Client/http.pm @@ -9,7 +9,7 @@ use HTTP::AnyUA::Util qw(www_form_urlencode); use HTTP::AnyUA; use namespace::clean; -our $VERSION = '0.600'; # VERSION +our $VERSION = '0.601'; # VERSION sub _croak { require Carp; goto &Carp::croak } @@ -169,7 +169,7 @@ GraphQL::Client::http - GraphQL over HTTP =head1 VERSION -version 0.600 +version 0.601 =head1 SYNOPSIS @@ -188,7 +188,7 @@ version 0.600 authorization => 'Bearer s3cr3t', }, }; - my $response = $client->execute($request, $options); + my $response = $transport->execute($request, $options); =head1 DESCRIPTION diff --git a/lib/GraphQL/Client/https.pm b/lib/GraphQL/Client/https.pm index 6467664..f73b48f 100644 --- a/lib/GraphQL/Client/https.pm +++ b/lib/GraphQL/Client/https.pm @@ -6,7 +6,7 @@ use strict; use parent 'GraphQL::Client::http'; -our $VERSION = '0.600'; # VERSION +our $VERSION = '0.601'; # VERSION sub new { my $class = shift; @@ -27,7 +27,7 @@ GraphQL::Client::https - GraphQL over HTTPS =head1 VERSION -version 0.600 +version 0.601 =head1 DESCRIPTION diff --git a/t/client.t b/t/client.t index 4775b70..1dd0cd4 100755 --- a/t/client.t +++ b/t/client.t @@ -14,14 +14,14 @@ use GraphQL::Client; 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'; };