HTTPie で GraphQL を使う

https://countries.trevorblades.com/
にアクセスしてみます。

## 日本

```bash:get_jp.sh
URL="https://countries.trevorblades.com/"
#
http $URL query='query {country (code: "JP") {name native currency phone }}'
```

実行結果

```text
$ ./get_jp.sh 
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 103
accept-ranges: bytes
access-control-allow-credentials: true
access-control-allow-headers: *
access-control-allow-methods: POST, GET, HEAD, OPTIONS
access-control-allow-origin: *
access-control-expose-headers: *
access-control-max-age: 600
age: 275
cache-control: public, s-maxage=2628000, stale-while-revalidate=2628000
content-encoding: gzip
content-type: application/json; charset=utf-8
date: Sat, 15 Apr 2023 00:34:21 GMT
gcdn-cache: HIT
vary: Accept-Encoding
via: 1.1 varnish
x-cache: HIT
x-cache-hits: 2
x-powered-by: Stellate
x-served-by: cache-hnd18738-HND
x-timer: S1681518861.280412,VS0,VE0

{
    "data": {
        "country": {
            "currency": "JPY",
            "name": "Japan",
            "native": "日本",
            "phone": "81"
        }
    }
}

```

## 韓国

```bash:get_kr.sh
URL="https://countries.trevorblades.com/"
#
http $URL query='query {country (code: "KR") {name native currency phone }}'
```

実行結果

```text
$ ./get_kr.sh 
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 118
accept-ranges: bytes
access-control-allow-credentials: true
access-control-allow-headers: *
access-control-allow-methods: POST, GET, HEAD, OPTIONS
access-control-allow-origin: *
access-control-expose-headers: *
access-control-max-age: 600
age: 205
cache-control: public, s-maxage=2628000, stale-while-revalidate=2628000
content-encoding: gzip
content-type: application/json; charset=utf-8
date: Sat, 15 Apr 2023 00:35:23 GMT
gcdn-cache: HIT
vary: Accept-Encoding
via: 1.1 varnish
x-cache: HIT
x-cache-hits: 1
x-powered-by: Stellate
x-served-by: cache-hnd18742-HND
x-timer: S1681518923.446620,VS0,VE1

{
    "data": {
        "country": {
            "currency": "KRW",
            "name": "South Korea",
            "native": "대한민국",
            "phone": "82"
        }
    }
}
```

## ウクライナ

```bash:get_ua.sh
URL="https://countries.trevorblades.com/"
#
http $URL query='query {country (code: "UA") {name native currency phone }}'
```

実行結果

```text
$ ./get_ua.sh 
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 115
accept-ranges: bytes
access-control-allow-credentials: true
access-control-allow-headers: *
access-control-allow-methods: POST, GET, HEAD, OPTIONS
access-control-allow-origin: *
access-control-expose-headers: *
access-control-max-age: 600
age: 156
cache-control: public, s-maxage=2628000, stale-while-revalidate=2628000
content-encoding: gzip
content-type: application/json; charset=utf-8
date: Sat, 15 Apr 2023 00:35:53 GMT
gcdn-cache: HIT
vary: Accept-Encoding
via: 1.1 varnish
x-cache: HIT
x-cache-hits: 1
x-powered-by: Stellate
x-served-by: cache-hnd18747-HND
x-timer: S1681518953.456675,VS0,VE1

{
    "data": {
        "country": {
            "currency": "UAH",
            "name": "Ukraine",
            "native": "Україна",
            "phone": "380"
        }
    }
}
```

## query を別ファイルにする

```json:query_jp.json
{"query": "query {country (code: \"JP\") {name native currency phone }}"}
```

```bash:get_jp_a.sh
URL="https://countries.trevorblades.com/"
#
http $URL < query_jp.json
```

```bash:get_jp_b.sh
URL="https://countries.trevorblades.com/"
#
http $URL @query_jp.json
```

## 確認したバージョン ##

```text
$ http --version
3.2.1
```