graphql-docs 1.0.0.pre1 → 1.0.0.pre2
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 +4 -4
- data/README.md +20 -17
- data/lib/graphql-docs/generator.rb +38 -6
- data/lib/graphql-docs/helpers.rb +4 -8
- data/lib/graphql-docs/layouts/graphql_mutations.html +9 -8
- data/lib/graphql-docs/layouts/includes/arguments.html +1 -1
- data/lib/graphql-docs/layouts/includes/connections.html +1 -5
- data/lib/graphql-docs/layouts/includes/fields.html +4 -9
- data/lib/graphql-docs/layouts/includes/input_fields.html +2 -8
- data/lib/graphql-docs/layouts/includes/values.html +1 -1
- data/lib/graphql-docs/parser.rb +1 -1
- data/lib/graphql-docs/renderer.rb +7 -33
- data/lib/graphql-docs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9ace666d5ef2589da4991e236b929b2fd0ec58b
|
4
|
+
data.tar.gz: 5273fb7bf7bab9f9c5e9fbd36e92006822e1e18d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad3dd49c668b82de48707dd84905b4951ecfcbb16795c690eaccb4b74276fad4fa2140530becdb38045c351802e863bd9ff27509ddd497ee7f549b5c8d420d80
|
7
|
+
data.tar.gz: 98b5241afd6d9b9c0b8024a0bfcae9393b70cf51f88a50031ed3e812126bc8bd8e97d29c58c805eaa7672c664e664a8ac93b1b97ffbd25c6ef3a89c08b2f17b9
|
data/README.md
CHANGED
@@ -36,16 +36,15 @@ There are several phases going on the single `GraphQLDocs.build` call:
|
|
36
36
|
|
37
37
|
* The GraphQL IDL file is read (if you passed `filename`) through `GraphQL::Client` (or simply read if you passed a string through `schema`).
|
38
38
|
* `GraphQL::Parser` manipulates the IDL into a slightly saner format.
|
39
|
-
* `GraphQL::Generator` takes that saner format and
|
40
|
-
* `GraphQL::Renderer` technically runs as part of the generation phase. It passes the contents of each page
|
39
|
+
* `GraphQL::Generator` takes that saner format and begins the process of applying items to the HTML templates.
|
40
|
+
* `GraphQL::Renderer` technically runs as part of the generation phase. It passes the contents of each page and converts it into HTML.
|
41
41
|
|
42
42
|
If you wanted to, you could break these calls up individually. For example:
|
43
43
|
|
44
44
|
``` ruby
|
45
45
|
options = {}
|
46
46
|
options[:filename] = "#{File.dirname(__FILE__)}/../data/graphql/schema.idl"
|
47
|
-
|
48
|
-
options[:renderer] = my_renderer
|
47
|
+
options[:renderer] = MySuperCoolRenderer
|
49
48
|
|
50
49
|
options = GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS.merge(options)
|
51
50
|
|
@@ -63,17 +62,23 @@ generator.generate
|
|
63
62
|
|
64
63
|
By default, the HTML generation process uses ERB to layout the content. There are a bunch of default options provided for you, but feel free to override any of these. The *Configuration* section below has more information on what you can change.
|
65
64
|
|
66
|
-
It also uses [html-pipeline](https://github.com/jch/html-pipeline) to perform the
|
65
|
+
It also uses [html-pipeline](https://github.com/jch/html-pipeline) to perform the rendering by default. You can override this by providing a custom rendering class.You must implement two methods:
|
66
|
+
|
67
|
+
* `initialize` - Takes two arguments, the parsed `schema` and the configuration `options`.
|
68
|
+
* `render` Takes the contents of a template page. It also takes two optional kwargs, the GraphQL `type` and its `name`. For example:
|
67
69
|
|
68
70
|
``` ruby
|
69
71
|
class CustomRenderer
|
70
|
-
def initialize(
|
71
|
-
@options = options
|
72
|
+
def initialize(schema, options)
|
72
73
|
@parsed_schema = parsed_schema
|
74
|
+
@options = options
|
73
75
|
end
|
74
76
|
|
75
|
-
def render(type, name
|
76
|
-
contents.sub(/Repository/i, 'Meow Woof
|
77
|
+
def render(contents, type: nil, name: nil)
|
78
|
+
contents.sub(/Repository/i, '<strong>Meow Woof!</strong>')
|
79
|
+
|
80
|
+
opts[:content] = contents
|
81
|
+
@graphql_default_layout.result(OpenStruct.new(opts).instance_eval { binding })
|
77
82
|
end
|
78
83
|
end
|
79
84
|
|
@@ -83,13 +88,15 @@ options[:renderer] = CustomRenderer
|
|
83
88
|
GraphQLDocs.build(options)
|
84
89
|
```
|
85
90
|
|
91
|
+
If your `render` method returns `nil`, the `Generator` will not attempt to write any HTML file.
|
92
|
+
|
86
93
|
### Helper methods
|
87
94
|
|
88
95
|
In your ERB layouts, there are several helper methods you can use. The helper methods are:
|
89
96
|
|
90
97
|
* `slugify(str)` - This slugifies the given string.
|
91
98
|
* `include(filename, opts)` - This embeds a template from your `includes` folder, passing along the local options provided.
|
92
|
-
* `
|
99
|
+
* `markdownify(string)` - This converts a string into HTML via CommonMarker.
|
93
100
|
* `graphql_operation_types`, `graphql_mutation_types`, `graphql_object_types`, `graphql_interface_types`, `graphql_enum_types`, `graphql_union_types`, `graphql_input_object_types`, `graphql_scalar_types` - Collections of the various GraphQL types.
|
94
101
|
|
95
102
|
To call these methods within templates, you must use the dot notation, such as `<%= slugify.(text) %>`.
|
@@ -100,12 +107,8 @@ The following options are available:
|
|
100
107
|
|
101
108
|
| Option | Description | Default |
|
102
109
|
| :----- | :---------- | :------ |
|
103
|
-
| `
|
104
|
-
| `
|
105
|
-
| `login` | Uses this login while making requests through `GraphQLDocs::Client`. | `nil` |
|
106
|
-
| `password` | Uses this password while making requests through `GraphQLDocs::Client`. | `nil` |
|
107
|
-
| `path` | `GraphQLDocs::Client` loads a JSON file found at this location, representing the response from an introspection query. | `nil` |
|
108
|
-
| `url` | `GraphQLDocs::Client` makes a `POST` request to this URL, passing along the introspection query. | `nil` |
|
110
|
+
| `filename` | The location of your schema's IDL file. | `nil` |
|
111
|
+
| `schema` | A string representing a schema IDL file. | `nil` |
|
109
112
|
| `output_dir` | The location of the output HTML. | `./output/` |
|
110
113
|
| `use_default_styles` | Indicates if you want to use the default styles. | `true` |
|
111
114
|
| `base_url` | Indicates the base URL to prepend for assets and links. | `""` |
|
@@ -114,7 +117,7 @@ The following options are available:
|
|
114
117
|
| `renderer` | The rendering class to use. | `GraphQLDocs::Renderer`
|
115
118
|
| `templates` | The templates to use when generating HTML. You may override any of the following keys: `default`, `includes`, `operations`, `objects`, `mutations`, `interfaces`, `enums`, `unions`, `input_objects`, `scalars`. | The defaults are found in _lib/graphql-docs/layouts/_.
|
116
119
|
| `landing_pages` | The landing page to use when generating HTML for each type. You may override any of the following keys: `index`, `query`, `object`, `mutation`, `interface`, `enum`, `union`, `input_object`, `scalar`. | The defaults are found in _lib/graphql-docs/layouts/_.
|
117
|
-
| `classes` | Additional class names you can provide to certain elements. | The full list is
|
120
|
+
| `classes` | Additional class names you can provide to certain elements. | The full list is available in _lib/graphql-docs/configuration.rb/_.
|
118
121
|
|
119
122
|
## Development
|
120
123
|
|
@@ -11,7 +11,7 @@ module GraphQLDocs
|
|
11
11
|
@parsed_schema = parsed_schema
|
12
12
|
@options = options
|
13
13
|
|
14
|
-
@renderer = @options[:renderer].new(@
|
14
|
+
@renderer = @options[:renderer].new(@parsed_schema, @options)
|
15
15
|
|
16
16
|
@graphql_operation_template = ERB.new(File.read(@options[:templates][:operation]))
|
17
17
|
@graphql_object_template = ERB.new(File.read(@options[:templates][:objects]))
|
@@ -88,10 +88,8 @@ module GraphQLDocs
|
|
88
88
|
unless @options[:landing_pages][:query].nil?
|
89
89
|
query_landing_page = @options[:landing_pages][:query]
|
90
90
|
query_landing_page = File.read(query_landing_page)
|
91
|
-
if
|
92
|
-
|
93
|
-
@renderer.respond_to?(:yaml_split)
|
94
|
-
pieces = @renderer.yaml_split(query_landing_page)
|
91
|
+
if has_yaml?(query_landing_page)
|
92
|
+
pieces = yaml_split(query_landing_page)
|
95
93
|
pieces[2] = pieces[2].chomp
|
96
94
|
metadata = pieces[1, 3].join("\n")
|
97
95
|
query_landing_page = pieces[4]
|
@@ -108,6 +106,7 @@ module GraphQLDocs
|
|
108
106
|
def create_graphql_object_pages
|
109
107
|
graphql_object_types.each do |object_type|
|
110
108
|
opts = default_generator_options(type: object_type)
|
109
|
+
|
111
110
|
contents = @graphql_object_template.result(OpenStruct.new(opts).instance_eval { binding })
|
112
111
|
write_file('object', object_type[:name], contents)
|
113
112
|
end
|
@@ -186,10 +185,43 @@ module GraphQLDocs
|
|
186
185
|
FileUtils.mkdir_p(path)
|
187
186
|
end
|
188
187
|
|
188
|
+
if has_yaml?(contents)
|
189
|
+
# Split data
|
190
|
+
meta, contents = split_into_metadata_and_contents(contents)
|
191
|
+
@options = @options.merge(meta)
|
192
|
+
end
|
193
|
+
|
189
194
|
# normalize spacing so that CommonMarker doesn't treat it as `pre`
|
190
195
|
contents.gsub!(/^\s*$/, '')
|
191
|
-
contents
|
196
|
+
contents.gsub!(/^\s{4}/m, ' ')
|
197
|
+
|
198
|
+
contents = @renderer.render(contents, type: type, name: name)
|
192
199
|
File.write(File.join(path, 'index.html'), contents) unless contents.nil?
|
193
200
|
end
|
201
|
+
|
202
|
+
def split_into_metadata_and_contents(contents)
|
203
|
+
opts = {}
|
204
|
+
pieces = yaml_split(contents)
|
205
|
+
if pieces.size < 4
|
206
|
+
raise RuntimeError.new(
|
207
|
+
"The file '#{content_filename}' appears to start with a metadata section (three or five dashes at the top) but it does not seem to be in the correct format.",
|
208
|
+
)
|
209
|
+
end
|
210
|
+
# Parse
|
211
|
+
begin
|
212
|
+
meta = YAML.load(pieces[2]) || {}
|
213
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
214
|
+
raise "Could not parse YAML for #{name}: #{e.message}"
|
215
|
+
end
|
216
|
+
[meta, pieces[4]]
|
217
|
+
end
|
218
|
+
|
219
|
+
def has_yaml?(contents)
|
220
|
+
contents =~ /\A-{3,5}\s*$/
|
221
|
+
end
|
222
|
+
|
223
|
+
def yaml_split(contents)
|
224
|
+
contents.split(/^(-{5}|-{3})[ \t]*\r?\n?/, 3)
|
225
|
+
end
|
194
226
|
end
|
195
227
|
end
|
data/lib/graphql-docs/helpers.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'commonmarker'
|
2
|
-
|
3
1
|
module GraphQLDocs
|
4
2
|
module Helpers
|
5
3
|
SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze
|
@@ -18,9 +16,9 @@ module GraphQLDocs
|
|
18
16
|
template.result(OpenStruct.new(opts.merge(helper_methods)).instance_eval { binding })
|
19
17
|
end
|
20
18
|
|
21
|
-
def
|
19
|
+
def markdownify(string)
|
22
20
|
return '' if string.nil?
|
23
|
-
::CommonMarker.render_html(string, :DEFAULT)
|
21
|
+
::CommonMarker.render_html(string, :DEFAULT).strip
|
24
22
|
end
|
25
23
|
|
26
24
|
def graphql_operation_types
|
@@ -63,10 +61,8 @@ module GraphQLDocs
|
|
63
61
|
return @templates[filename] unless @templates[filename].nil?
|
64
62
|
|
65
63
|
contents = File.read(File.join(@options[:templates][:includes], filename))
|
66
|
-
|
67
|
-
|
68
|
-
@templates[filename] = ERB.new(template)
|
69
|
-
@templates[filename]
|
64
|
+
|
65
|
+
@templates[filename] = ERB.new(contents)
|
70
66
|
end
|
71
67
|
|
72
68
|
def helper_methods
|
@@ -2,18 +2,19 @@
|
|
2
2
|
|
3
3
|
<%= type[:description] %>
|
4
4
|
|
5
|
+
<% if !type[:input_fields].empty? %>
|
6
|
+
|
5
7
|
<h2>Input fields</h2>
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
<% else %>
|
10
|
-
<p>None</p>
|
9
|
+
<%= include.('fields.html', fields: type[:input_fields]) %>
|
10
|
+
|
11
11
|
<% end %>
|
12
12
|
|
13
|
-
<h2>Return fields</h2>
|
14
13
|
|
15
14
|
<% if !type[:return_fields].empty? %>
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
|
16
|
+
<h2>Return fields</h2>
|
17
|
+
|
18
|
+
<%= include.('fields.html', fields: type[:return_fields]) %>
|
19
|
+
|
19
20
|
<% end %>
|
@@ -6,11 +6,7 @@
|
|
6
6
|
<div class="description-wrapper">
|
7
7
|
<p><%= connection[:description] %></p>
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
<%= include.('arguments.html', args: connection[:arguments]) %>
|
12
|
-
|
13
|
-
<% end %>
|
9
|
+
<%= include.('arguments.html', args: connection[:arguments]) %>
|
14
10
|
</div>
|
15
11
|
</div>
|
16
12
|
|
@@ -1,25 +1,20 @@
|
|
1
1
|
<% fields.each do |field| %>
|
2
2
|
|
3
3
|
<div class="field-entry <%= classes[:field_entry] %>">
|
4
|
-
<% next if field[:name] == "id" || field[:name].blank? %>
|
5
|
-
|
6
4
|
<span class="field-name"><%= field[:name] %> (<code><a href="<%= base_url %>/<%= field[:type][:path] %>"><%= field[:type][:info] %></a></code>)</span>
|
7
5
|
|
8
6
|
<div class="description-wrapper">
|
9
7
|
<% if field[:is_deprecated] %>
|
10
8
|
<div class="deprecation-notice <%= classes[:deprecation_notice] %>">
|
11
9
|
<span class="deprecation-title">Deprecation notice</span>
|
12
|
-
<%=
|
10
|
+
<%= markdownify.(field[:deprecation_reason]) %>
|
13
11
|
</div>
|
14
12
|
<% end %>
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
<%= markdownify.(field[:description]) %>
|
15
|
+
|
16
|
+
<%= include.('arguments.html', args: field[:arguments]) %>
|
19
17
|
|
20
|
-
<% unless field[:arguments].blank? %>
|
21
|
-
<%= include.('arguments.html', args: field[:arguments]) %>
|
22
|
-
<% end %>
|
23
18
|
</div>
|
24
19
|
</div>
|
25
20
|
|
@@ -1,18 +1,12 @@
|
|
1
1
|
<% input_fields.each do |field| %>
|
2
2
|
|
3
3
|
<div class="field-entry <%= classes[:field_entry] %>">
|
4
|
-
<% next if field[:name] == "id" || field[:name].blank? %>
|
5
|
-
|
6
4
|
<span class="field-name"><%= field[:name] %> (<a href="<%= base_url %>/<%= field[:type][:path] %>"><code><%= field[:type][:info] %></code></a>)</span>
|
7
5
|
|
8
6
|
<div class="description-wrapper">
|
9
|
-
|
10
|
-
|
11
|
-
<% unless field[:args].nil? %>
|
12
|
-
|
13
|
-
<%= include.('arguments.html', args: field[:args]) %>
|
7
|
+
<%= field[:description] %>
|
14
8
|
|
15
|
-
|
9
|
+
<%= include.('arguments.html', args: field[:args]) %>
|
16
10
|
</div>
|
17
11
|
</div>
|
18
12
|
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<% if value[:is_deprecated] %>
|
9
9
|
<div class="deprecation-notice <%= classes[:deprecation_notice] %>">
|
10
10
|
<span class="deprecation-title">Deprecation notice</span>
|
11
|
-
<%=
|
11
|
+
<%= markdownify.(value[:deprecation_reason]) %>
|
12
12
|
</div>
|
13
13
|
<% end %>
|
14
14
|
|
data/lib/graphql-docs/parser.rb
CHANGED
@@ -6,9 +6,9 @@ module GraphQLDocs
|
|
6
6
|
class Renderer
|
7
7
|
include Helpers
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@options = options
|
9
|
+
def initialize(parsed_schema, options)
|
11
10
|
@parsed_schema = parsed_schema
|
11
|
+
@options = options
|
12
12
|
|
13
13
|
unless @options[:templates][:default].nil?
|
14
14
|
@graphql_default_layout = ERB.new(File.read(@options[:templates][:default]))
|
@@ -34,44 +34,18 @@ module GraphQLDocs
|
|
34
34
|
@pipeline = HTML::Pipeline.new(filters, @pipeline_config[:context])
|
35
35
|
end
|
36
36
|
|
37
|
-
def render(type, name
|
37
|
+
def render(contents, type: nil, name: nil)
|
38
38
|
opts = { base_url: @options[:base_url] }.merge({ type: type, name: name}).merge(helper_methods)
|
39
39
|
|
40
|
-
|
41
|
-
# Split data
|
42
|
-
meta, contents = split_into_metadata_and_contents(contents)
|
43
|
-
opts = opts.merge(meta)
|
44
|
-
end
|
45
|
-
|
46
|
-
contents = @pipeline.to_html(contents)
|
40
|
+
contents = to_html(contents)
|
47
41
|
return contents if @graphql_default_layout.nil?
|
48
42
|
opts[:content] = contents
|
49
43
|
@graphql_default_layout.result(OpenStruct.new(opts).instance_eval { binding })
|
50
44
|
end
|
51
45
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
def yaml_split(contents)
|
57
|
-
contents.split(/^(-{5}|-{3})[ \t]*\r?\n?/, 3)
|
58
|
-
end
|
59
|
-
|
60
|
-
def split_into_metadata_and_contents(contents)
|
61
|
-
opts = {}
|
62
|
-
pieces = yaml_split(contents)
|
63
|
-
if pieces.size < 4
|
64
|
-
raise RuntimeError.new(
|
65
|
-
"The file '#{content_filename}' appears to start with a metadata section (three or five dashes at the top) but it does not seem to be in the correct format.",
|
66
|
-
)
|
67
|
-
end
|
68
|
-
# Parse
|
69
|
-
begin
|
70
|
-
meta = YAML.load(pieces[2]) || {}
|
71
|
-
rescue Exception => e # rubocop:disable Lint/RescueException
|
72
|
-
raise "Could not parse YAML for #{name}: #{e.message}"
|
73
|
-
end
|
74
|
-
[meta, pieces[4]]
|
46
|
+
def to_html(string)
|
47
|
+
return '' if string.nil?
|
48
|
+
CommonMarker.render_html(string, :DEFAULT).strip
|
75
49
|
end
|
76
50
|
|
77
51
|
private
|
data/lib/graphql-docs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-docs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.pre2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|