Module: ElasticGraph::GraphiQL
- Defined in:
- lib/elastic_graph/graphiql.rb
Overview
A [Rack](github.com/rack/rack) application that serves both an ElasticGraph GraphQL endpoint and a [GraphiQL IDE](github.com/graphql/graphiql). This can be used for local development, mounted in a [Rails](rubyonrails.org/) application, or run in any other Rack-compatible context.
Class Method Summary collapse
-
.new(graphql, output: $stdout) ⇒ Rack::Builder
Builds a [Rack](github.com/rack/rack) application that serves both an ElasticGraph GraphQL endpoint and a [GraphiQL IDE](github.com/graphql/graphiql).
Class Method Details
.new(graphql, output: $stdout) ⇒ Rack::Builder
Builds a [Rack](github.com/rack/rack) application that serves both an ElasticGraph GraphQL endpoint and a [GraphiQL IDE](github.com/graphql/graphiql).
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/elastic_graph/graphiql.rb', line 33 def self.new(graphql, output: $stdout) tarball_path = ::File.join(__dir__.to_s, "graphiql/assets.tar.gz") static_content_root = ::Dir.mktmpdir("elasticgraph_graphiql") output.puts "Extracting GraphiQL assets from #{tarball_path} to #{static_content_root}..." tar_command = "tar -xzf #{::Shellwords.escape(tarball_path)} -C #{::Shellwords.escape(static_content_root)}" tar_output, status = ::Open3.capture2e(tar_command) unless status.success? = "Failed to extract GraphiQL assets from #{tarball_path}.\n" += "Command: '#{tar_command}'\n" += "Exit Status: #{status.exitstatus}\n" += "Output: #{tar_output}" raise end output.puts "GraphiQL assets extracted successfully to #{static_content_root}." graphql_endpoint = Rack::GraphQLEndpoint.new(graphql) ::Rack::Builder.new do # @type self: ::Rack::Builder use ::Rack::Static, urls: ["/assets", "/favicon.svg", "/monacoeditorwork"], root: static_content_root use ::Rack::Static, urls: {"/" => "index.html"}, root: static_content_root map "/graphql" do run graphql_endpoint end end end |