elasticgraph-graphiql 1.0.0.rc3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 385d5969cb0ffe906b559de2c50c9182f45f814341b072da7052e4e3f28ab115
4
+ data.tar.gz: e11e3c79fe25bf0482a4c942cee73f5cfb57eac317fa889f40518b50485ec337
5
+ SHA512:
6
+ metadata.gz: 00e94e01fbfccf322438494b9a1e7faf4bfafca1e7646193e97f21ee583c6266c24ffec70f615add6baec437d9d57922efdf7a38f0d2d7a993c7a9db931fff8c
7
+ data.tar.gz: 79ce29f7e96f13295562aa4389c60913cf1aac9fd9064f66103ebeaa291620bb56edd151edeb7f1380c0ffb54635621a1cb5c96d3f13930b052528d1afbe9a30
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 - 2025 Block, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # ElasticGraph::GraphiQL
2
+
3
+ Provides a GraphiQL IDE for ElasticGraph projects.
4
+
5
+ Here's an example `config.ru`:
6
+
7
+ ``` ruby
8
+ require 'elastic_graph/graphql'
9
+ require 'elastic_graph/graphiql'
10
+
11
+ graphql = ElasticGraph::GraphQL.from_yaml_file("path/to/config.yaml")
12
+ run ElasticGraph::GraphiQL.new(graphql)
13
+ ```
14
+
15
+ Run this with `rackup` (after installing the `rackup` gem) or any other rack-compatible server.
16
+
17
+ ## Dependency Diagram
18
+
19
+ ```mermaid
20
+ graph LR;
21
+ classDef targetGemStyle fill:#FADBD8,stroke:#EC7063,color:#000,stroke-width:2px;
22
+ classDef otherEgGemStyle fill:#A9DFBF,stroke:#2ECC71,color:#000;
23
+ classDef externalGemStyle fill:#E0EFFF,stroke:#70A1D7,color:#2980B9;
24
+ elasticgraph-graphiql["elasticgraph-graphiql"];
25
+ class elasticgraph-graphiql targetGemStyle;
26
+ elasticgraph-rack["elasticgraph-rack"];
27
+ elasticgraph-graphiql --> elasticgraph-rack;
28
+ class elasticgraph-rack otherEgGemStyle;
29
+ elasticgraph-local["elasticgraph-local"];
30
+ elasticgraph-local --> elasticgraph-graphiql;
31
+ class elasticgraph-local otherEgGemStyle;
32
+ ```
33
+
34
+ ## License
35
+
36
+ elasticgraph-graphiql is released under the [MIT License](https://opensource.org/licenses/MIT).
37
+
38
+ Part of the distributed code comes from the [GraphiQL project](https://github.com/graphql/graphiql),
39
+ also licensed under the MIT License, Copyright (c) GraphQL Contributors.
@@ -0,0 +1,6 @@
1
+ The `assets.tar.gz` tarball was built using the `elasticgraph-graphiql/scripts/update_graphiql` script, which
2
+ also updates this file.
3
+
4
+ It was last run using git ref `graphiql@5.0.4` and it sourced GraphiQL from:
5
+
6
+ https://github.com/graphql/graphiql/tree/graphiql@5.0.4/examples/graphiql-vite
@@ -0,0 +1,64 @@
1
+ # Copyright 2024 - 2025 Block, Inc.
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+ #
7
+ # frozen_string_literal: true
8
+
9
+ require "elastic_graph/rack/graphql_endpoint"
10
+ require "open3"
11
+ require "rack/builder"
12
+ require "rack/static"
13
+ require "shellwords"
14
+ require "tmpdir"
15
+
16
+ module ElasticGraph
17
+ # A [Rack](https://github.com/rack/rack) application that serves both an ElasticGraph GraphQL endpoint
18
+ # and a [GraphiQL IDE](https://github.com/graphql/graphiql). This can be used for local development,
19
+ # mounted in a [Rails](https://rubyonrails.org/) application, or run in any other Rack-compatible context.
20
+ #
21
+ # @example Simple config.ru to serve an ElasticGraph GraphiQL IDE
22
+ # require "elastic_graph/graphql"
23
+ # require "elastic_graph/graphiql"
24
+ #
25
+ # graphql = ElasticGraph::GraphQL.from_yaml_file("config/settings/development.yaml")
26
+ # run ElasticGraph::GraphiQL.new(graphql)
27
+ module GraphiQL
28
+ # Builds a [Rack](https://github.com/rack/rack) application that serves both an ElasticGraph GraphQL endpoint
29
+ # and a [GraphiQL IDE](https://github.com/graphql/graphiql).
30
+ #
31
+ # @param graphql [ElasticGraph::GraphQL] ElasticGraph GraphQL instance
32
+ # @return [Rack::Builder] built Rack application
33
+ def self.new(graphql, output: $stdout)
34
+ tarball_path = ::File.join(__dir__.to_s, "graphiql/assets.tar.gz")
35
+ static_content_root = ::Dir.mktmpdir("elasticgraph_graphiql")
36
+ output.puts "Extracting GraphiQL assets from #{tarball_path} to #{static_content_root}..."
37
+
38
+ tar_command = "tar -xzf #{::Shellwords.escape(tarball_path)} -C #{::Shellwords.escape(static_content_root)}"
39
+ tar_output, status = ::Open3.capture2e(tar_command)
40
+
41
+ unless status.success?
42
+ error_message = "Failed to extract GraphiQL assets from #{tarball_path}.\n"
43
+ error_message += "Command: '#{tar_command}'\n"
44
+ error_message += "Exit Status: #{status.exitstatus}\n"
45
+ error_message += "Output: #{tar_output}"
46
+
47
+ raise error_message
48
+ end
49
+
50
+ output.puts "GraphiQL assets extracted successfully to #{static_content_root}."
51
+ graphql_endpoint = Rack::GraphQLEndpoint.new(graphql)
52
+
53
+ ::Rack::Builder.new do
54
+ # @type self: ::Rack::Builder
55
+ use ::Rack::Static, urls: ["/assets", "/favicon.svg", "/monacoeditorwork"], root: static_content_root
56
+ use ::Rack::Static, urls: {"/" => "index.html"}, root: static_content_root
57
+
58
+ map "/graphql" do
59
+ run graphql_endpoint
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,187 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2024 - 2025 Block, Inc.
4
+ #
5
+ # Use of this source code is governed by an MIT-style
6
+ # license that can be found in the LICENSE file or at
7
+ # https://opensource.org/licenses/MIT.
8
+ #
9
+ # frozen_string_literal: true
10
+
11
+ require "fileutils"
12
+ require "open3"
13
+ require "optparse"
14
+ require "shellwords"
15
+ require "tmpdir"
16
+
17
+ # --- Configuration Constants ---
18
+ GRAPHIQL_REPO_URL = "https://github.com/graphql/graphiql"
19
+ VITE_EXAMPLE_SUBPATH = File.join("examples", "graphiql-vite")
20
+ VITE_EXAMPLE_PACKAGE_NAME = "example-graphiql-vite"
21
+ TARGET_ASSETS_TARBALL_PATH = File.expand_path("../lib/elastic_graph/graphiql/assets.tar.gz", __dir__)
22
+ ELASTICGRAPH_FAVICONS_SOURCE_DIR = File.expand_path("../../config/site/src/assets/favicons", __dir__)
23
+
24
+ # --- Options Parsing ---
25
+ git_ref = nil
26
+
27
+ OptionParser.new do |opts|
28
+ opts.banner = "Usage: #{$PROGRAM_NAME} [options]"
29
+ opts.separator ""
30
+ opts.separator "Specific options:"
31
+
32
+ opts.on("-r REF", "--ref REF", String, "Git ref (tag, branch, commit SHA) of the graphql/graphiql repository to use") do |ref|
33
+ git_ref = ref
34
+ end
35
+
36
+ opts.on_tail("-h", "--help", "Show this message") do
37
+ puts opts
38
+ exit
39
+ end
40
+ end.parse!
41
+
42
+ unless git_ref
43
+ raise "Must provide a `--ref`."
44
+ end
45
+
46
+ def run_command(command, in_dir: nil, env_vars: {})
47
+ puts "Executing: #{command} #{"(in dir: #{in_dir})" if in_dir}"
48
+
49
+ full_command_env = ENV.to_h.merge(env_vars)
50
+ stdout_str, stderr_str, status = Open3.capture3(full_command_env, command, chdir: in_dir || Dir.pwd)
51
+
52
+ unless status.success?
53
+ puts "Error executing command: #{command}"
54
+ puts "STDOUT:\n#{stdout_str}" unless stdout_str.empty?
55
+ puts "STDERR:\n#{stderr_str}" unless stderr_str.empty?
56
+ puts "Exit status: #{status.exitstatus}"
57
+
58
+ raise "Command failed: #{command}"
59
+ end
60
+
61
+ stdout_str
62
+ end
63
+
64
+ # --- Main Script Logic ---
65
+ puts "Script update_graphiql started."
66
+ puts "Configuration:"
67
+ puts " GraphiQL Repo URL: #{GRAPHIQL_REPO_URL}"
68
+ puts " GraphiQL Git Ref: #{git_ref}"
69
+ puts " Target Example Subpath: #{VITE_EXAMPLE_SUBPATH}"
70
+ puts " Target Example Package Name: #{VITE_EXAMPLE_PACKAGE_NAME}"
71
+ puts " Target Archive Path: #{TARGET_ASSETS_TARBALL_PATH}"
72
+ puts " ElasticGraph Favicons Source: #{ELASTICGRAPH_FAVICONS_SOURCE_DIR}"
73
+
74
+ puts "\nStarting main operations..."
75
+ Dir.mktmpdir("graphiql_build") do |temp_dir|
76
+ puts "Created temporary directory for build: #{temp_dir}"
77
+
78
+ repo_clone_subdir = "graphiql_repo"
79
+ repo_clone_path = File.join(temp_dir, repo_clone_subdir)
80
+ FileUtils.mkdir_p(repo_clone_path)
81
+
82
+ puts "\nCloning graphql/graphiql repository (ref: #{git_ref}) into #{repo_clone_path}..."
83
+ run_command("git clone #{GRAPHIQL_REPO_URL}.git .", in_dir: repo_clone_path)
84
+ puts "Checking out git ref: #{git_ref}..."
85
+ run_command("git checkout #{Shellwords.escape(git_ref)}", in_dir: repo_clone_path)
86
+ puts "Successfully cloned and checked out ref: #{git_ref}."
87
+
88
+ example_dir = File.join(repo_clone_path, VITE_EXAMPLE_SUBPATH)
89
+ unless Dir.exist?(example_dir)
90
+ raise "Example path #{VITE_EXAMPLE_SUBPATH} not found after clone and checkout in #{repo_clone_path}."
91
+ end
92
+ puts "Found example path: #{example_dir}"
93
+
94
+ app_jsx_path = File.join(example_dir, "src", "App.jsx")
95
+ unless File.exist?(app_jsx_path)
96
+ raise "#{app_jsx_path} not found. Skipping fetcher URL modification."
97
+ end
98
+
99
+ puts "\nModifying #{app_jsx_path} to use local /graphql endpoint..."
100
+ app_content = File.read(app_jsx_path)
101
+ original_fetch_url = "https://graphql.earthdata.nasa.gov/api"
102
+ target_fetch_url = "/graphql"
103
+ if app_content.gsub!(original_fetch_url, target_fetch_url)
104
+ File.write(app_jsx_path, app_content)
105
+ puts "Successfully updated fetch URL in #{app_jsx_path} to '#{target_fetch_url}'."
106
+ else
107
+ raise "Could not find expected remote fetch URL ('#{original_fetch_url}') in #{app_jsx_path}."
108
+ end
109
+
110
+ puts "\nInstalling dependencies from root (#{repo_clone_path}) using Yarn..."
111
+ run_command("yarn install --frozen-lockfile", in_dir: repo_clone_path, env_vars: {"NODE_OPTIONS" => "--max-old-space-size=4096"})
112
+
113
+ puts "\nBuilding packages using Yarn..."
114
+ run_command("yarn build", in_dir: repo_clone_path, env_vars: {"NODE_OPTIONS" => "--max-old-space-size=4096"})
115
+
116
+ puts "\nBuilding GraphiQL example (#{VITE_EXAMPLE_PACKAGE_NAME}) using Yarn workspace..."
117
+ run_command("yarn workspace #{VITE_EXAMPLE_PACKAGE_NAME} build", in_dir: repo_clone_path, env_vars: {"NODE_OPTIONS" => "--max-old-space-size=4096"})
118
+
119
+ dist_path = File.join(example_dir, "dist")
120
+ index_html_in_dist_path = File.join(dist_path, "index.html")
121
+ unless Dir.exist?(dist_path) && File.exist?(index_html_in_dist_path)
122
+ raise "Build output directory '#{dist_path}' or 'index.html' not found after build."
123
+ end
124
+ puts "Build successful. Assets found in: #{dist_path}"
125
+
126
+ # Modify dist/index.html (title) BEFORE archiving
127
+ puts "\nModifying #{index_html_in_dist_path} for title..."
128
+ index_html_content = File.read(index_html_in_dist_path)
129
+
130
+ # Update Title
131
+ original_title_pattern = /<title>GraphiQL Vite Example<\/title>/i
132
+ target_title = "<title>ElasticGraph GraphiQL</title>"
133
+ if index_html_content.gsub!(original_title_pattern, target_title)
134
+ puts "Successfully updated title in HTML content buffer."
135
+ else
136
+ raise "Could not find original title ('GraphiQL Vite Example') in HTML content buffer."
137
+ end
138
+
139
+ # Favicon Replacement: Replace the example's favicon.svg with ElasticGraph's version.
140
+ # The graphiql-vite example's index.html already links to /favicon.svg.
141
+ puts "\nProcessing favicon replacement..."
142
+ elasticgraph_favicon_svg_source = File.join(ELASTICGRAPH_FAVICONS_SOURCE_DIR, "favicon.svg")
143
+ target_favicon_in_dist = File.join(dist_path, "favicon.svg")
144
+
145
+ puts " Source ElasticGraph favicon path: #{elasticgraph_favicon_svg_source}"
146
+ puts " Target favicon path in dist: #{target_favicon_in_dist}"
147
+
148
+ unless File.exist?(elasticgraph_favicon_svg_source)
149
+ raise "ElasticGraph favicon.svg NOT FOUND at source (#{elasticgraph_favicon_svg_source})."
150
+ end
151
+
152
+ FileUtils.cp(elasticgraph_favicon_svg_source, target_favicon_in_dist)
153
+ puts " SUCCESS: Copied ElasticGraph favicon.svg to #{target_favicon_in_dist}."
154
+
155
+ # Write all accumulated HTML changes (title)
156
+ File.write(index_html_in_dist_path, index_html_content)
157
+ puts "Finished HTML modifications and favicon replacement."
158
+
159
+ # Create tar.gz archive
160
+ archive_parent_dir = File.dirname(TARGET_ASSETS_TARBALL_PATH)
161
+ FileUtils.mkdir_p(archive_parent_dir)
162
+ archive_filename = File.basename(TARGET_ASSETS_TARBALL_PATH)
163
+ temp_archive_file_path = File.join(temp_dir, archive_filename)
164
+
165
+ puts "\nCreating tarball: #{temp_archive_file_path} from contents of #{dist_path}..."
166
+ tar_command = "tar -czvf #{Shellwords.escape(temp_archive_file_path)} -C #{Shellwords.escape(dist_path)} ."
167
+ run_command(tar_command)
168
+
169
+ puts "Moving tarball from #{temp_archive_file_path} to #{TARGET_ASSETS_TARBALL_PATH}..."
170
+ FileUtils.mv(temp_archive_file_path, TARGET_ASSETS_TARBALL_PATH)
171
+ puts "Tarball successfully created at #{TARGET_ASSETS_TARBALL_PATH}"
172
+
173
+ # Record the GraphiQL git ref we used so there's a record of it.
174
+ ::File.write(::File.expand_path("../assets_info.md", TARGET_ASSETS_TARBALL_PATH), <<~EOS)
175
+ The `assets.tar.gz` tarball was built using the `elasticgraph-graphiql/scripts/update_graphiql` script, which
176
+ also updates this file.
177
+
178
+ It was last run using git ref `#{git_ref}` and it sourced GraphiQL from:
179
+
180
+ #{GRAPHIQL_REPO_URL}/tree/#{git_ref}/#{VITE_EXAMPLE_SUBPATH}
181
+ EOS
182
+
183
+ puts "\nOperations in temporary directory completed."
184
+ end
185
+
186
+ puts "Temporary directory cleaned up."
187
+ puts "\nScript completed successfully."
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elasticgraph-graphiql
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.rc3
5
+ platform: ruby
6
+ authors:
7
+ - Myron Marston
8
+ - Ben VandenBos
9
+ - Block Engineering
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 1980-01-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: elasticgraph-rack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.0.0.rc3
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.0.0.rc3
28
+ - !ruby/object:Gem::Dependency
29
+ name: elasticgraph-elasticsearch
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '='
33
+ - !ruby/object:Gem::Version
34
+ version: 1.0.0.rc3
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.0.0.rc3
42
+ - !ruby/object:Gem::Dependency
43
+ name: elasticgraph-opensearch
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 1.0.0.rc3
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.0.rc3
56
+ email:
57
+ - myron@squareup.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - README.md
64
+ - lib/elastic_graph/graphiql.rb
65
+ - lib/elastic_graph/graphiql/assets.tar.gz
66
+ - lib/elastic_graph/graphiql/assets_info.md
67
+ - script/update_graphiql
68
+ homepage: https://block.github.io/elasticgraph/
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ bug_tracker_uri: https://github.com/block/elasticgraph/issues
73
+ changelog_uri: https://github.com/block/elasticgraph/releases/tag/v1.0.0.rc3
74
+ documentation_uri: https://block.github.io/elasticgraph/api-docs/v1.0.0.rc3/
75
+ homepage_uri: https://block.github.io/elasticgraph/
76
+ source_code_uri: https://github.com/block/elasticgraph/tree/v1.0.0.rc3/elasticgraph-graphiql
77
+ gem_category: local
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '3.4'
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.5'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.6.7
96
+ specification_version: 4
97
+ summary: Provides a GraphiQL IDE for ElasticGraph projects.
98
+ test_files: []