gqlgen で generate 時に「unable to open schema」となる場合の対処
事象
以下のように、schema.graphql が見つからない旨のエラーが出ることがある。
$ go run github.com/99designs/gqlgen generate unable to open schema: open schema.graphql: no such file or directory exit status 1
例えば、graphql スキーマは src/resources/graphql の中に入れたいんじゃ!と設定を変えていると見ることになると思われ。
解決方法
gqlgem.yml のスキーマファイルのパスは、go run ~ generate コマンドを実行したディレクトリからの相対パスとなっている模様。
(ここ以外のパス記述するところは gqlgen.yml のあるディレクトリが root となる。)
# Where are all the schema files located? globs are supported eg src/**/*.graphqls schema: - src/resources/graphql/*.graphqls # Where should the generated server code go? exec: filename: src/application/graph/generated.go package: graph
なので、gqlgen.yml を src のあるディレクトリに移動させることで対応できた。
もしくは、gqlgen.yml のあるディレクトリまで cd して go run ~ generate すれば OK。