Open3
graphqlをrailsで開発

gemfileに追加しても反映されないバグ
gemファイルに
gem 'graphql'
group :development do
gem 'graphiql-rails'
end
を追加したが、bundle installをしなさいとエラーが出た。
解決策
docker-compose build --no-cache
でキャッシュを消したら解決した
dockerfile 参考記事

http://localhost:3000/graphiqlに移動しても loading...がずっと出る
エラー原因の推測
rails7でassetsファイルが作成が作成されず、cssが反映されていないのが原因ではないか?
assetsファイルが作成されなかったので、自分でファイルを作成し、
app/assets/config/manifest.js
/= link graphiql/rails/application.css
//= link graphiql/rails/application.js
上記を記入したがダメだった。
プロジェクトを削除して1から作成後
docker-compose run web rails g graphql:install
とコマンド打った後
But did not, please create this file and use it to link any assets that need
to be rendered by your app:
Example:
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
and restart your server
とエラーが出たので
app/assets/config/manifest.jsを作成し、
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
を記述したところ成功した。

rails-graphqlの使い方
rails g graphql:install
でGraphQL関連のファイルが自動生成させる
次にgraphqlのルーティングを追加する
Rails.application.routes.draw do
+ if Rails.env.development?
+ mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "graphql#execute"
+ end
post "/graphql", to: "graphql#execute"
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Defines the root path route ("/")
# root "articles#index"
end
app/assets/config/manifest.jsに
//= link graphiql/rails/application.css
//= link graphiql/rails/application.js
を追加する。
config/application.rbに次の1行を追加
require_relative "boot"
require "rails/all"
Bundler.require(*Rails.groups)
module RailsReactGraphql
class Application < Rails::Application
config.load_defaults 7.0
config.api_only = true
config.middleware.use ActionDispatch::Session::CookieStore <=追加
end
end