]> Dogcows Code - chaz/graphql-client/commitdiff
Version 0.603
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 22 Mar 2020 08:03:00 +0000 (02:03 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 22 Mar 2020 08:03:00 +0000 (02:03 -0600)
12 files changed:
Changes
META.json
META.yml
Makefile.PL
README
bin/graphql
lib/GraphQL/Client.pm
lib/GraphQL/Client/CLI.pm
lib/GraphQL/Client/http.pm
lib/GraphQL/Client/https.pm
t/00-report-prereqs.dd
t/http.t

diff --git a/Changes b/Changes
index 24d318937e93ac6a3fe471edb30cd5571b3a094a..b20f2a96e043cec596de6a380448464881473531 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 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.
index c98c070429220aba8a0c8a86ea190016b2363789..b8bb85f0cd7f95e4dabb4000a7e1560e7c6f5253 100644 (file)
--- a/META.json
+++ b/META.json
@@ -72,6 +72,7 @@
          },
          "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",
index 95a95186666c8257d6d0c53ae39b7765897bcb24..1c5959c9cf7255520edbaa05b6483c53628c8913 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -33,24 +33,25 @@ no_index:
 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'
@@ -68,7 +69,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.602'
+version: '0.603'
 x_authority: cpan:CCM
 x_generated_by_perl: v5.28.0
 x_serialization_backend: 'YAML::Tiny version 1.73'
index 2c7c27a4b517365427fc50e943ede579ae5508a6..3524dadced3e51b4d7f7ac94d1b7946246721c94 100644 (file)
@@ -21,6 +21,7 @@ my %WriteMakefileArgs = (
   "NAME" => "GraphQL::Client",
   "PREREQ_PM" => {
     "Carp" => 0,
+    "Encode" => 0,
     "Getopt::Long" => "2.39",
     "HTTP::AnyUA" => 0,
     "HTTP::AnyUA::Util" => 0,
@@ -47,7 +48,7 @@ my %WriteMakefileArgs = (
     "Test::More" => 0,
     "lib" => 0
   },
-  "VERSION" => "0.602",
+  "VERSION" => "0.603",
   "test" => {
     "TESTS" => "t/*.t"
   }
@@ -56,6 +57,7 @@ my %WriteMakefileArgs = (
 
 my %FallbackPrereqs = (
   "Carp" => 0,
+  "Encode" => 0,
   "ExtUtils::MakeMaker" => 0,
   "File::Spec" => 0,
   "FindBin" => 0,
diff --git a/README b/README
index 8d892553238c915cc9eda0523e0199495cbb514b..6129b243d46e70617a880910acde732eaf309f09 100644 (file)
--- a/README
+++ b/README
@@ -4,7 +4,7 @@ NAME
 
 VERSION
 
-    version 0.602
+    version 0.603
 
 SYNOPSIS
 
@@ -122,9 +122,11 @@ OPTIONS
     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
 
index e5c6784dceb77ce70eb4ee848413233eec19a968..00bc95962c33ac3e4d28431a93205a46ddfbdd72 100755 (executable)
@@ -10,7 +10,7 @@ use strict;
 
 use GraphQL::Client::CLI;
 
-our $VERSION = '0.602'; # VERSION
+our $VERSION = '0.603'; # VERSION
 
 GraphQL::Client::CLI->main(@ARGV);
 
@@ -26,7 +26,7 @@ graphql - Command-line GraphQL client
 
 =head1 VERSION
 
-version 0.602
+version 0.603
 
 =head1 SYNOPSIS
 
@@ -138,9 +138,10 @@ By default, the response structure is printed as-is from the server, and the pro
 
 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
 
index c4a61192950bfa4d5c9d9f077def3ec232cf07e2..32c41f8b52f1a42ee52a67dcf78e2264fd559e15 100644 (file)
@@ -8,7 +8,7 @@ use Module::Load qw(load);
 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(@_) }
@@ -171,7 +171,7 @@ GraphQL::Client - A GraphQL client
 
 =head1 VERSION
 
-version 0.602
+version 0.603
 
 =head1 SYNOPSIS
 
index bb2ab030b89c70597d955e824e8b8406afa41f59..d28634cf17d26c364ac8b5be2bd842674b52412b 100644 (file)
@@ -4,13 +4,16 @@ package GraphQL::Client::CLI;
 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 }
 
@@ -67,6 +70,7 @@ sub main {
     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> };
     }
 
@@ -80,6 +84,7 @@ sub main {
         *STDOUT = $out;
     }
 
+    binmode(STDOUT, 'encoding(UTF-8)');
     _print_data($data, $format);
 
     exit($unpack && $err ? 1 : 0);
@@ -91,6 +96,9 @@ sub _get_options {
 
     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,
@@ -124,18 +132,29 @@ sub _get_options {
         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);
     }
@@ -160,12 +179,12 @@ sub _print_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];
                 }
             }
         }
@@ -309,7 +328,7 @@ GraphQL::Client::CLI - Implementation of the graphql CLI program
 
 =head1 VERSION
 
-version 0.602
+version 0.603
 
 =head1 DESCRIPTION
 
index 667e44ebc5ac2f8e0389078b1003c9d0159ff0d3..48f68e8243aa2bac0764c9816adedc44ac76b6a7 100644 (file)
@@ -9,7 +9,7 @@ use HTTP::AnyUA::Util qw(www_form_urlencode);
 use HTTP::AnyUA;
 use namespace::clean;
 
-our $VERSION = '0.602'; # VERSION
+our $VERSION = '0.603'; # VERSION
 
 sub _croak { require Carp; goto &Carp::croak }
 
@@ -42,7 +42,7 @@ sub execute {
         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));
@@ -171,7 +171,7 @@ GraphQL::Client::http - GraphQL over HTTP
 
 =head1 VERSION
 
-version 0.602
+version 0.603
 
 =head1 SYNOPSIS
 
index 6df0df98fd1cec4999fdf8c9b2c3aee53d142848..54d2acf75128a058e0664931d51f04fe0dc3a00f 100644 (file)
@@ -6,7 +6,7 @@ use strict;
 
 use parent 'GraphQL::Client::http';
 
-our $VERSION = '0.602'; # VERSION
+our $VERSION = '0.603'; # VERSION
 
 sub new {
     my $class = shift;
@@ -27,7 +27,7 @@ GraphQL::Client::https - GraphQL over HTTPS
 
 =head1 VERSION
 
-version 0.602
+version 0.603
 
 =head1 DESCRIPTION
 
index fa4b2196e38dcdf7aae13a3e9d358c08f0fff783..82d5ee631580a6fa35581690a893f88339c2ae31 100644 (file)
@@ -48,6 +48,7 @@ do { my $x = {
                                       },
                       'requires' => {
                                       'Carp' => '0',
+                                      'Encode' => '0',
                                       'Getopt::Long' => '2.39',
                                       'HTTP::AnyUA' => '0',
                                       'HTTP::AnyUA::Util' => '0',
index 61a9ccf63cceac74932990dc642e35393d359302..cad84fdaa800119b37f8ae331ce779abb36c41c8 100755 (executable)
--- a/t/http.t
+++ b/t/http.t
@@ -57,7 +57,7 @@ subtest 'POST request' => sub {
 
     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 {
This page took 0.034754 seconds and 4 git commands to generate.