ECのウェブ担当者のメモ

ECサイトを運営管理している、WEB担当プログラマのメモ

スポンサーリンク

Rails の graphql を サブディレクトリのパスで運用する

f:id:jun9632:20220113220705p:plain

/api/graphql とか /admin/graphql とか /api/graphiql とか

のパスでgraphqlするための router.rbの設定です。

Rails.application.routes.draw do
  namespace :api do
    if Rails.env.development?
      mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: '/api/graphql'
    end

    post '/graphql', to: 'graphql#execute'
  end
end

コントローラーも下記においています。

app/controllers/api/graphql_controller.rb

関連記事

marketing-web.hatenablog.com

marketing-web.hatenablog.com