GraphQL における N+1 問題の解決の機構として Dataloder と呼ばれるものがあるが、Go でこれを行うときは gqlgen + graph-gophers/dataloader という組み合わせがよく使われるようだ。後者は gqlgen の公式ドキュメントからも参照されているので、gqlgen を使っていれば自然とそうなりそう。 このへんの話は 【GraphQL × Go】 N+1問題を解決するgqlgen + dataloaderの実装方法とCacheの実装オプション - LayerX エンジニアブログ などに詳しい。 さて、この dataloaders ってのを普通に使ってコードを書いてみるとわかるのだけど、ロードのためのキーとして string を、ロードされた結果として interface{} を返すような実装になっている。つまり実際にデータベースにアクセスするよ