Closed14

relay 13.2.0 から relay-compiler が panic する

ピン留めされたアイテム
Masayuki IzumiMasayuki Izumi

TL;DR

  • relay-compiler 13.0.0 or 13.0.1 から 13.0.2 にあげると、デフォルトの言語設定が TypeScript から Flow に変わる
    • TypeScript を使ってるプロジェクトでは relay-compiler が thread 'main' panicked at 'Expect GraphQLAsts to exist.', というエラーを吐くようになる
  • 設定ファイルで language: "typescript" を書くと、いままでと同じ動作になる
  • 設定ファイルは以下のいずれかが有効
    • relay.config.js or relay.config.json として、引数無しで relay-compiler を実行
    • JSON で書いて relay-compiler の第1引数に渡す
Masayuki IzumiMasayuki Izumi
:) % yarn generate
[INFO] querying files to compile...
[INFO] [default] compiling...
thread 'main' panicked at 'Expect GraphQLAsts to exist.', /Users/runner/work/relay/relay/compiler/crates/relay-compiler/src/compiler.rs:333:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
ERROR: "generate:relay" exited with 1.
Masayuki IzumiMasayuki Izumi

thread 'main' panicked at 'Expect GraphQLAsts to exist.',

何らかの要因でコード中から document を抜き出すのに失敗したか

Masayuki IzumiMasayuki Izumi

thread 'main' panicked at 'Expect GraphQLAsts to exist.', で雑に issue 検索すると、なんか訴えてる issue が見つかる
https://github.com/facebook/relay/issues/3815

Masayuki IzumiMasayuki Izumi

この issue 自体は Relay のいろんなところが使いにくいからなんとかしてくれ〜 的なのを example 出しながら訴えかけてるもので、関係なさそう

…と見せかけて、最初の example がまさに今困ってるやつと同じ

I attempted to set up Relay and then starred at this error for about 30 minutes: "thread 'main' panicked at 'Expect GraphQLAsts to exist.', /Users/runner/work/relay/relay/compiler/crates/relay-compiler/src/compiler.rs:333:18".

Masayuki IzumiMasayuki Izumi

v13.2.0 にめちゃめちゃ怪しい変更があった
https://github.com/facebook/relay/commit/4801f2b6660d8e3a5e2c7741688cb554d9d32f1e

language の初期値が TypeScript だったのを消している

Masayuki IzumiMasayuki Izumi

Rust 版 relay-compiler では設定ファイルからのみ言語を変更できる
https://github.com/facebook/relay/blob/v13.2.0/packages/relay-compiler/README.md

(なぜ CLI オプションから落とした…)

Masayuki IzumiMasayuki Izumi
$ cat relay.config.js 
module.exports = {
  language: "typescript",
  schema: "schema.graphql",
  src: "./src/",
};
Masayuki IzumiMasayuki Izumi

README のとおりに yarn relay すると yarn に怒られた

$ yarn relay --config ./relay.config.js 
Usage Error: Couldn't find a script named "relay".

$ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ...

yarn relay-compiler にしたら relay に怒られた
--config ないのか

$ yarn relay-compiler --config ./relay.config.js
error: Found argument '--config' which wasn't expected, or isn't valid in this context

        If you tried to supply `--config` as a value rather than a flag, use `-- --config`

USAGE:
    relay [OPTIONS] [CONFIG]

For more information try --help
Masayuki IzumiMasayuki Izumi

--config flag ではなく普通に引数で渡してみる

$ yarn relay-compiler relay.config.js 
[ERROR] Failed to parse config file `relay.config.js`: expected value at line 1 column 1

syntax error :thinking:

Masayuki IzumiMasayuki Izumi

json にしたら怒られない(??????)

$ yarn relay-compiler relay.config.json 
[INFO] querying files to compile...
[INFO] [default] compiling...
[INFO] [default] compiled documents: 15 reader, 6 normalization, 15 operation text
[INFO] Done
Masayuki IzumiMasayuki Izumi

relay.config.js{,on} なら引数省略できると書いてたので、それで試したら JS でもいけた

$ cat relay.config.js
module.exports = {
  language: "typescript",
  schema: "schema.graphql",
  src: "./src/",
};

$ yarn relay-compiler relay.config.json
[ERROR] Failed to read config file `relay.config.json`.

$ yarn relay-compiler                  
[INFO] querying files to compile...
[INFO] [default] compiling...
[INFO] [default] compiled documents: 15 reader, 6 normalization, 15 operation text
[INFO] Done

なんでや!!!

このスクラップは2022/03/19にクローズされました