Reputation: 43
I'm running a GraphQL server using Rails with the graphql-ruby
and graphiql-rails
gems. I can access the GraphiQL interface successfully. I've set up a POST route at /graphql
that maps to graphql#execute
. However, when I try to connect to it using the Apollo GraphQL Sandbox by typing the URL http://localhost:3000/graphql
into the endpoint address, it fails to establish a connection to my local server.
I have no problem connecting to it using GraphiQl however. I just enter the url "localhost:3000/graphiql" in to the server and it works
I've ensured that CORS is properly configured and that the server is running. What could be causing this issue? Any suggestions would be appreciated!
My Gemfile
source "https://rubygems.org"
ruby "3.0.0"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.1.3", ">= 7.1.3.4"
# Use mysql as the database for Active Record
gem "mysql2", "~> 0.5"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
# gem "jbuilder"
# Use Redis adapter to run Action Cable in production
gem "redis", ">= 4.0.1"
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mswin mswin64 mingw x64_mingw jruby ]
# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin Ajax possible
gem "rack-cors"
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mswin mswin64 mingw x64_mingw ]
end
group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
gem "annotate", "~> 3.2"
end
gem 'figaro', '~> 1.2'
gem 'devise_token_auth'
gem "kaminari", "~> 1.2"
gem "sidekiq", "~> 7.3"
gem "faraday", "~> 2.12"
gem "solargraph", "~> 0.50.0", group: :development
gem "graphql", "~> 2.3"
gem "graphiql-rails", "~> 1.10"
gem "sprockets-rails", "~> 3.5"
I verified that the GraphQL server is running and accessible through the GraphiQL interface. I also checked the endpoint URL, ensured CORS settings are configured correctly, and confirmed the POST route to graphql#execute
is set up. I expected Apollo GraphQL Sandbox to connect to the server and allow me to run queries, but it fails to connect.
Upvotes: 0
Views: 61