Revision history for GraphQL-Client.
+0.603 2020-03-22 02:01:32-06:00 MST7MDT
+ * Allow deep formatting with csv,tsv,table.
+ * Fix Unicode issues.
+
0.602 2020-03-17 18:27:46-06:00 MST7MDT
* Add support for GRAPHQL_CLIENT_OPTIONS environment variable.
* Fix a slew of CLI option problems.
},
"requires" : {
"Carp" : "0",
+ "Encode" : "0",
"Getopt::Long" : "2.39",
"HTTP::AnyUA" : "0",
"HTTP::AnyUA::Util" : "0",
"provides" : {
"GraphQL::Client" : {
"file" : "lib/GraphQL/Client.pm",
- "version" : "0.602"
+ "version" : "0.603"
},
"GraphQL::Client::CLI" : {
"file" : "lib/GraphQL/Client/CLI.pm",
- "version" : "0.602"
+ "version" : "0.603"
},
"GraphQL::Client::Error" : {
"file" : "lib/GraphQL/Client.pm",
- "version" : "0.602"
+ "version" : "0.603"
},
"GraphQL::Client::http" : {
"file" : "lib/GraphQL/Client/http.pm",
- "version" : "0.602"
+ "version" : "0.603"
},
"GraphQL::Client::https" : {
"file" : "lib/GraphQL/Client/https.pm",
- "version" : "0.602"
+ "version" : "0.603"
}
},
"release_status" : "stable",
"web" : "https://github.com/chazmcgarvey/graphql-client"
}
},
- "version" : "0.602",
+ "version" : "0.603",
"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.602'
+ version: '0.603'
GraphQL::Client::CLI:
file: lib/GraphQL/Client/CLI.pm
- version: '0.602'
+ version: '0.603'
GraphQL::Client::Error:
file: lib/GraphQL/Client.pm
- version: '0.602'
+ version: '0.603'
GraphQL::Client::http:
file: lib/GraphQL/Client/http.pm
- version: '0.602'
+ version: '0.603'
GraphQL::Client::https:
file: lib/GraphQL/Client/https.pm
- version: '0.602'
+ version: '0.603'
recommends:
HTTP::Tiny: '0'
Pod::Usage: '0'
requires:
Carp: '0'
+ Encode: '0'
Getopt::Long: '2.39'
HTTP::AnyUA: '0'
HTTP::AnyUA::Util: '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.602'
+version: '0.603'
x_authority: cpan:CCM
x_generated_by_perl: v5.28.0
x_serialization_backend: 'YAML::Tiny version 1.73'
"NAME" => "GraphQL::Client",
"PREREQ_PM" => {
"Carp" => 0,
+ "Encode" => 0,
"Getopt::Long" => "2.39",
"HTTP::AnyUA" => 0,
"HTTP::AnyUA::Util" => 0,
"Test::More" => 0,
"lib" => 0
},
- "VERSION" => "0.602",
+ "VERSION" => "0.603",
"test" => {
"TESTS" => "t/*.t"
}
my %FallbackPrereqs = (
"Carp" => 0,
+ "Encode" => 0,
"ExtUtils::MakeMaker" => 0,
"File::Spec" => 0,
"FindBin" => 0,
VERSION
- version 0.602
+ version 0.603
SYNOPSIS
When unpack mode is enabled, if the response completes with no errors,
only the data section of the response is printed and the program exits
0. If the response has errors, the whole response structure is printed
- as-is and the program exits 1.
+ as-is and the program exits 1. See "EXAMPLES" to see what this looks
+ like in practice.
- See "EXAMPLES".
+ Use --no-unpack to disable if unpack mode was enabled via
+ GRAPHQL_CLIENT_OPTIONS.
FORMAT
use GraphQL::Client::CLI;
-our $VERSION = '0.602'; # VERSION
+our $VERSION = '0.603'; # VERSION
GraphQL::Client::CLI->main(@ARGV);
=head1 VERSION
-version 0.602
+version 0.603
=head1 SYNOPSIS
When unpack mode is enabled, if the response completes with no errors, only the data section of
the response is printed and the program exits 0. If the response has errors, the whole response
-structure is printed as-is and the program exits 1.
+structure is printed as-is and the program exits 1. See L</EXAMPLES> to see what this looks like in
+practice.
-See L</EXAMPLES>.
+Use C<--no-unpack> to disable if unpack mode was enabled via C<GRAPHQL_CLIENT_OPTIONS>.
=head1 FORMAT
use Scalar::Util qw(reftype);
use namespace::clean;
-our $VERSION = '0.602'; # VERSION
+our $VERSION = '0.603'; # VERSION
sub _croak { require Carp; goto &Carp::croak }
sub _throw { GraphQL::Client::Error->throw(@_) }
=head1 VERSION
-version 0.602
+version 0.603
=head1 SYNOPSIS
use warnings;
use strict;
-use Text::ParseWords;
+use Encode qw(decode);
use Getopt::Long 2.39 qw(GetOptionsFromArray);
use GraphQL::Client;
use JSON::MaybeXS;
+use Text::ParseWords;
use namespace::clean;
-our $VERSION = '0.602'; # VERSION
+our $VERSION = '0.603'; # VERSION
+
+my $JSON = JSON::MaybeXS->new(canonical => 1);
sub _croak { require Carp; goto &Carp::croak }
if ($query eq '-') {
print STDERR "Interactive mode engaged! Waiting for a query on <STDIN>...\n"
if -t STDIN; ## no critic (InputOutput::ProhibitInteractiveTest)
+ binmode(STDIN, 'encoding(UTF-8)');
$query = do { local $/; <STDIN> };
}
*STDOUT = $out;
}
+ binmode(STDOUT, 'encoding(UTF-8)');
_print_data($data, $format);
exit($unpack && $err ? 1 : 0);
unshift @args, shellwords($ENV{GRAPHQL_CLIENT_OPTIONS} || '');
+ # assume UTF-8 args if non-ASCII
+ @args = map { decode('UTF-8', $_) } @args if grep { /\P{ASCII}/ } @args;
+
my %options = (
format => 'json:pretty',
unpack => 0,
die "Two or more --variable keys are incompatible.\n" if $@;
}
elsif ($options{variables}) {
- $options{variables} = eval { JSON::MaybeXS->new->decode($options{variables}) };
+ $options{variables} = eval { $JSON->decode($options{variables}) };
die "The --variables JSON does not parse.\n" if $@;
}
return \%options;
}
+sub _stringify {
+ my ($item) = @_;
+ if (ref($item) eq 'ARRAY') {
+ my $first = @$item && $item->[0];
+ return join(',', @$item) if !ref($first);
+ return join(',', map { $JSON->encode($_) } @$item);
+ }
+ return $JSON->encode($item) if ref($item) eq 'HASH';
+ return $item;
+}
+
sub _print_data {
my ($data, $format) = @_;
$format = lc($format || 'json:pretty');
if ($format eq 'json' || $format eq 'json:pretty') {
- my %opts = (allow_nonref => 1, canonical => 1, utf8 => 1);
+ my %opts = (allow_nonref => 1, canonical => 1);
$opts{pretty} = 1 if $format eq 'json:pretty';
print JSON::MaybeXS->new(%opts)->encode($data);
}
if ($first && ref $first eq 'HASH') {
@columns = sort keys %$first;
$rows = [
- map { [@{$_}{@columns}] } @$val
+ map { [map { _stringify($_) } @{$_}{@columns}] } @$val
];
}
elsif ($first) {
@columns = keys %$unpacked;
- $rows = [map { [$_] } @$val];
+ $rows = [map { [map { _stringify($_) } $_] } @$val];
}
}
}
=head1 VERSION
-version 0.602
+version 0.603
=head1 DESCRIPTION
use HTTP::AnyUA;
use namespace::clean;
-our $VERSION = '0.602'; # VERSION
+our $VERSION = '0.603'; # VERSION
sub _croak { require Carp; goto &Carp::croak }
my $encoded_data = $self->json->encode($data);
$options->{content} = $encoded_data;
$options->{headers}{'content-length'} = length $encoded_data;
- $options->{headers}{'content-type'} = 'application/json';
+ $options->{headers}{'content-type'} = 'application/json;charset=UTF-8';
}
return $self->_handle_response($self->any_ua->request($method, $url, $options));
=head1 VERSION
-version 0.602
+version 0.603
=head1 SYNOPSIS
use parent 'GraphQL::Client::http';
-our $VERSION = '0.602'; # VERSION
+our $VERSION = '0.603'; # VERSION
sub new {
my $class = shift;
=head1 VERSION
-version 0.602
+version 0.603
=head1 DESCRIPTION
},
'requires' => {
'Carp' => '0',
+ 'Encode' => '0',
'Getopt::Long' => '2.39',
'HTTP::AnyUA' => '0',
'HTTP::AnyUA::Util' => '0',
is($req->[0], 'POST', 'method is POST');
is($req->[2]{content}, '{"query":"{hello}"}', 'encoded body as JSON');
- is($req->[2]{headers}{'content-type'}, 'application/json', 'set content-type to json');
+ is($req->[2]{headers}{'content-type'}, 'application/json;charset=UTF-8', 'set content-type to json');
};
subtest 'GET request' => sub {