rack-graphiql 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rack/graphiql/version.rb +5 -0
- data/lib/rack/graphiql.rb +182 -0
- data/lib/rack-graphiql.rb +1 -0
- data/rack-graphiql.gemspec +26 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 94daf14bf5c41d69f6cde7a5965961bd86f89aae
|
4
|
+
data.tar.gz: 0ae4d31cbf3fe0a075490b482cefa38249d620f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 96289af12de19c0d976723da7e46333c0c90a9a1072f33f871be3d18799b4d4a3d5d8c6daae6949c3f7476e2c6290bb5f78f943f103db231c8d509413ec8ab01
|
7
|
+
data.tar.gz: b61329e644e33a3453455f8a660047a62f77bcc00e9bb4a8029938bc5eb325e3ac60181300800cc3a8f373943f05cdf43b6ac51039cc545e3b634a5015f201ef
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Yuya Takeyama
|
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,43 @@
|
|
1
|
+
# Rack::GraphiQL
|
2
|
+
|
3
|
+
[GraphiQL](https://github.com/graphql/graphiql) as Rack application.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rack-graphiql'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rack-graphiql
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In your `config.ru`:
|
24
|
+
|
25
|
+
```rb
|
26
|
+
map '/graphiql' do
|
27
|
+
run Rack::GraphiQL.new(endpoint: '/graphql')
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
|
+
|
35
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yuya-takeyama/rack-graphiql.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rack/graphiql"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'rack/graphiql/version'
|
2
|
+
require 'erb'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
class GraphiQL
|
7
|
+
GRAPHIQL_VERSION = '0.10.2'
|
8
|
+
FETCH_VERSION = '2.0.1'
|
9
|
+
REACT_VERSION = '15.5.4'
|
10
|
+
REACT_DOM_VERSION = '15.5.4'
|
11
|
+
|
12
|
+
include ERB::Util
|
13
|
+
|
14
|
+
def initialize(endpoint:)
|
15
|
+
@endpoint = endpoint
|
16
|
+
@template = ERB.new(open(__FILE__).read.split("__END__\n").last)
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
req = Rack::Request.new(env)
|
21
|
+
graphiql_query = req.params['query']
|
22
|
+
graphiql_variables = begin
|
23
|
+
JSON.pretty_generate(JSON.parse(req.params['variables']))
|
24
|
+
rescue JSON::ParserError
|
25
|
+
''
|
26
|
+
end
|
27
|
+
graphiql_operation_name = req.params['operationName']
|
28
|
+
[200, {'Content-Type' => 'text/html'}, [@template.result(binding)]]
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def endpoint
|
34
|
+
@endpoint
|
35
|
+
end
|
36
|
+
|
37
|
+
def graphiql_version
|
38
|
+
GRAPHIQL_VERSION
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch_version
|
42
|
+
FETCH_VERSION
|
43
|
+
end
|
44
|
+
|
45
|
+
def react_version
|
46
|
+
REACT_VERSION
|
47
|
+
end
|
48
|
+
|
49
|
+
def react_dom_version
|
50
|
+
REACT_DOM_VERSION
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
__END__
|
56
|
+
<!DOCTYPE html>
|
57
|
+
<html>
|
58
|
+
<head>
|
59
|
+
<meta charset="utf-8" />
|
60
|
+
<title>GraphiQL</title>
|
61
|
+
<meta name="robots" content="noindex" />
|
62
|
+
<meta name="graphiql-endpoint" content="<%=h endpoint %>" />
|
63
|
+
<meta name="graphiql-query" content="<%=h graphiql_query %>" />
|
64
|
+
<meta name="graphiql-variables" content="<%=h graphiql_variables %>" />
|
65
|
+
<meta name="graphiql-operation-name" content="<%=h graphiql_operation_name %>" />
|
66
|
+
<style>
|
67
|
+
html, body {
|
68
|
+
height: 100%;
|
69
|
+
margin: 0;
|
70
|
+
overflow: hidden;
|
71
|
+
width: 100%;
|
72
|
+
}
|
73
|
+
</style>
|
74
|
+
<link href="//cdn.jsdelivr.net/graphiql/<%=h graphiql_version %>/graphiql.css" rel="stylesheet" />
|
75
|
+
<script src="//cdn.jsdelivr.net/fetch/<%=h fetch_version %>/fetch.min.js"></script>
|
76
|
+
<script src="//cdn.jsdelivr.net/react/<%=h react_version %>/react.min.js"></script>
|
77
|
+
<script src="//cdn.jsdelivr.net/react/<%=h react_dom_version %>/react-dom.min.js"></script>
|
78
|
+
<script src="//cdn.jsdelivr.net/graphiql/<%=h graphiql_version %>/graphiql.min.js"></script>
|
79
|
+
</head>
|
80
|
+
<body>
|
81
|
+
<script>
|
82
|
+
// Collect the URL parameters
|
83
|
+
var parameters = {};
|
84
|
+
window.location.search.substr(1).split('&').forEach(function (entry) {
|
85
|
+
var eq = entry.indexOf('=');
|
86
|
+
if (eq >= 0) {
|
87
|
+
parameters[decodeURIComponent(entry.slice(0, eq))] =
|
88
|
+
decodeURIComponent(entry.slice(eq + 1));
|
89
|
+
}
|
90
|
+
});
|
91
|
+
|
92
|
+
var endpoint = document.querySelector('meta[name=graphiql-endpoint]').attributes.content.value;
|
93
|
+
|
94
|
+
function locationURL(params) {
|
95
|
+
return endpoint + locationQuery(params);
|
96
|
+
}
|
97
|
+
|
98
|
+
// Produce a Location query string from a parameter object.
|
99
|
+
function locationQuery(params) {
|
100
|
+
return '?' + Object.keys(params).map(function (key) {
|
101
|
+
return encodeURIComponent(key) + '=' +
|
102
|
+
encodeURIComponent(params[key]);
|
103
|
+
}).join('&');
|
104
|
+
}
|
105
|
+
|
106
|
+
// Derive a fetch URL from the current URL, sans the GraphQL parameters.
|
107
|
+
var graphqlParamNames = {
|
108
|
+
query: true,
|
109
|
+
variables: true,
|
110
|
+
operationName: true
|
111
|
+
};
|
112
|
+
|
113
|
+
var otherParams = {};
|
114
|
+
for (var k in parameters) {
|
115
|
+
if (parameters.hasOwnProperty(k) && graphqlParamNames[k] !== true) {
|
116
|
+
otherParams[k] = parameters[k];
|
117
|
+
}
|
118
|
+
}
|
119
|
+
var fetchURL = locationURL(otherParams);
|
120
|
+
|
121
|
+
// Defines a GraphQL fetcher using the fetch API.
|
122
|
+
function graphQLFetcher(graphQLParams) {
|
123
|
+
return fetch(fetchURL, {
|
124
|
+
method: 'post',
|
125
|
+
headers: {
|
126
|
+
'Accept': 'application/json',
|
127
|
+
'Content-Type': 'application/json'
|
128
|
+
},
|
129
|
+
body: JSON.stringify(graphQLParams),
|
130
|
+
credentials: 'include',
|
131
|
+
}).then(function (response) {
|
132
|
+
return response.text();
|
133
|
+
}).then(function (responseBody) {
|
134
|
+
try {
|
135
|
+
return JSON.parse(responseBody);
|
136
|
+
} catch (error) {
|
137
|
+
return responseBody;
|
138
|
+
}
|
139
|
+
});
|
140
|
+
}
|
141
|
+
|
142
|
+
// When the query and variables string is edited, update the URL bar so
|
143
|
+
// that it can be easily shared.
|
144
|
+
function onEditQuery(newQuery) {
|
145
|
+
parameters.query = newQuery;
|
146
|
+
updateURL();
|
147
|
+
}
|
148
|
+
|
149
|
+
function onEditVariables(newVariables) {
|
150
|
+
parameters.variables = newVariables;
|
151
|
+
updateURL();
|
152
|
+
}
|
153
|
+
|
154
|
+
function onEditOperationName(newOperationName) {
|
155
|
+
parameters.operationName = newOperationName || '';
|
156
|
+
updateURL();
|
157
|
+
}
|
158
|
+
|
159
|
+
function updateURL() {
|
160
|
+
history.replaceState(null, null, locationQuery(parameters));
|
161
|
+
}
|
162
|
+
|
163
|
+
var query = document.querySelector('meta[name=graphiql-query]').attributes.content.value;
|
164
|
+
var variables = document.querySelector('meta[name=graphiql-variables]').attributes.content.value;
|
165
|
+
var operationName = document.querySelector('meta[name=graphiql-operation-name]').attributes.content.value;
|
166
|
+
|
167
|
+
// Render <GraphiQL /> into the body.
|
168
|
+
ReactDOM.render(
|
169
|
+
React.createElement(GraphiQL, {
|
170
|
+
fetcher: graphQLFetcher,
|
171
|
+
onEditQuery: onEditQuery,
|
172
|
+
onEditVariables: onEditVariables,
|
173
|
+
onEditOperationName: onEditOperationName,
|
174
|
+
query: query || undefined,
|
175
|
+
variables: variables,
|
176
|
+
operationName: operationName,
|
177
|
+
}),
|
178
|
+
document.body
|
179
|
+
);
|
180
|
+
</script>
|
181
|
+
</body>
|
182
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/graphiql'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rack/graphiql/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-graphiql"
|
8
|
+
spec.version = Rack::GraphiQL::VERSION
|
9
|
+
spec.authors = ["Yuya Takeyama"]
|
10
|
+
spec.email = ["sign.of.the.wolf.pentagram@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{GraphiQL as Rack application.}
|
13
|
+
spec.description = %q{GraphiQL as Rack application.}
|
14
|
+
spec.homepage = "https://github.com/yuya-takeyama/rack-graphiql"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-graphiql
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuya Takeyama
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: GraphiQL as Rack application.
|
42
|
+
email:
|
43
|
+
- sign.of.the.wolf.pentagram@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/rack-graphiql.rb
|
56
|
+
- lib/rack/graphiql.rb
|
57
|
+
- lib/rack/graphiql/version.rb
|
58
|
+
- rack-graphiql.gemspec
|
59
|
+
homepage: https://github.com/yuya-takeyama/rack-graphiql
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.6.8
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: GraphiQL as Rack application.
|
83
|
+
test_files: []
|