X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fgraphql-client;a=blobdiff_plain;f=lib%2FGraphQL%2FClient.pm;h=d2dd652b4dbc75bdc69a259641107eb66b81cc35;hp=edbb64e4ddc05c6c9e185cdcfc46503bd5e2e3ae;hb=HEAD;hpb=c9d0cfde05aac5f3ec38b908e570311545f29d11 diff --git a/lib/GraphQL/Client.pm b/lib/GraphQL/Client.pm index edbb64e..d2dd652 100644 --- a/lib/GraphQL/Client.pm +++ b/lib/GraphQL/Client.pm @@ -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); @@ -247,31 +248,32 @@ Note: Setting the L attribute affects the response shape. The URL of a GraphQL endpoint, e.g. C<"http://myapiserver/graphql">. -=attr class +=attr 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. -=attr transport +See L. -The transport object. +=attr transport_class -By default this is automatically constructed based on the L. +The package name of a transport. -=attr 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. +=attr transport -Default is 0. +The transport object. -See L. +By default this is automatically constructed based on L or L. =head1 ERROR HANDLING 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 => {...}, @@ -297,6 +299,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 {