graphql-docs 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -1
- data/lib/graphql-docs/configuration.rb +3 -1
- data/lib/graphql-docs/layouts/graphql_enums.html +3 -5
- data/lib/graphql-docs/layouts/graphql_input_objects.html +2 -0
- data/lib/graphql-docs/layouts/graphql_interfaces.html +2 -0
- data/lib/graphql-docs/layouts/graphql_mutations.html +2 -0
- data/lib/graphql-docs/layouts/graphql_objects.html +2 -0
- data/lib/graphql-docs/layouts/graphql_unions.html +3 -5
- data/lib/graphql-docs/layouts/includes/connections.html +1 -0
- data/lib/graphql-docs/layouts/includes/fields.html +2 -0
- data/lib/graphql-docs/layouts/includes/input_fields.html +2 -0
- data/lib/graphql-docs/layouts/includes/notices.html +8 -0
- data/lib/graphql-docs/layouts/includes/values.html +2 -0
- data/lib/graphql-docs/parser.rb +17 -8
- data/lib/graphql-docs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0779515b3313c00ee5bf7ba9a57592bd90a79d13'
|
4
|
+
data.tar.gz: 18b9ce93fc442cdf8c851dd0be0c6facf91f0d6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03dc4d16f2aa0c8000015a74a715429b8d8d4992fa8a3838d693d5d2bb90473435b3a22dadecb24642f6a620d8d53a35c37625021950a220278006f354051bb0
|
7
|
+
data.tar.gz: c5cb0870d13d1838fd199fd24da03cb84e88a6fe014fe251c17477e28e6910481182cd823a29edfa9d55fd091116fe36bd9ee4af9083ea73dba3db92942e915b
|
data/README.md
CHANGED
@@ -102,6 +102,7 @@ In your ERB layouts, there are several helper methods you can use. The helper me
|
|
102
102
|
To call these methods within templates, you must use the dot notation, such as `<%= slugify.(text) %>`.
|
103
103
|
|
104
104
|
For `markdownify`, `CommonMarker` is not enabled by default (because it relies on native code). You will need to add `require 'commonmarker'` if you wish to use it.
|
105
|
+
|
105
106
|
## Configuration
|
106
107
|
|
107
108
|
The following options are available:
|
@@ -118,7 +119,57 @@ The following options are available:
|
|
118
119
|
| `renderer` | The rendering class to use. | `GraphQLDocs::Renderer`
|
119
120
|
| `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/_.
|
120
121
|
| `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/_.
|
121
|
-
| `classes` | Additional class names you can provide to certain elements. | The full list is available in _lib/graphql-docs/configuration.
|
122
|
+
| `classes` | Additional class names you can provide to certain elements. | The full list is available in _lib/graphql-docs/configuration.rb_.
|
123
|
+
| `notices` | A proc used to add notices to schema members. See *Customizing Notices* section below. | `nil` |
|
124
|
+
|
125
|
+
### Customizing Notices
|
126
|
+
|
127
|
+
A notice is a block of CommonMark text that optionally has a title which is displayed above a schema member's description. The
|
128
|
+
look of a notice block can be controlled by specifying a custom class for it and then styled via CSS.
|
129
|
+
|
130
|
+
The `notices` option allows you to customize the notices that appear for a specific schema member using a proc.
|
131
|
+
|
132
|
+
The proc will be called for each schema member and needs to return an array of notices or an empty array if there are none.
|
133
|
+
|
134
|
+
A `notice` has the following options:
|
135
|
+
|
136
|
+
| Option | Description |
|
137
|
+
| :----- | :---------- |
|
138
|
+
| `body` | CommonMark body of the notice |
|
139
|
+
| `title` | Optional title of the notice |
|
140
|
+
| `class` | Optional CSS class for the wrapper `<div>` of the notice |
|
141
|
+
| `title_class` | Optional CSS class for the `<span>` of the notice's title |
|
142
|
+
|
143
|
+
Example of a `notices` proc that adds a notice to the `TeamDiscussion` type:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
options[:notice] = (schema_member_path) -> {
|
147
|
+
notices = []
|
148
|
+
|
149
|
+
if schema_member_path == "TeamDiscussion"
|
150
|
+
notices << {
|
151
|
+
class: "preview-notice",
|
152
|
+
body: "Available via the [Team Discussion](/previews/team-discussion) preview.",
|
153
|
+
}
|
154
|
+
end
|
155
|
+
|
156
|
+
notices
|
157
|
+
}
|
158
|
+
```
|
159
|
+
|
160
|
+
The format of `schema_member_path` is a dot delimited path to the schema member. For example:
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
"Author", # an object
|
164
|
+
"ExtraInfo" # an interface,
|
165
|
+
"Author.socialSecurityNumber" # a field
|
166
|
+
"Book.author.includeMiddleInitial" # an argument
|
167
|
+
"Likeable" # a union,
|
168
|
+
"Cover" # an enum
|
169
|
+
"Cover.DIGITAL" # an enum value
|
170
|
+
"BookOrder" # an input object
|
171
|
+
"Mutation.addLike" # a mutation
|
172
|
+
```
|
122
173
|
|
123
174
|
## Development
|
124
175
|
|
@@ -1,9 +1,7 @@
|
|
1
|
-
|
1
|
+
<h1><%= type[:name] %></h1>
|
2
2
|
|
3
|
-
<%= type[:
|
3
|
+
<%= include.('notices.html', notices: type[:notices]) %>
|
4
4
|
|
5
|
-
|
5
|
+
<%= type[:description] %>
|
6
6
|
|
7
7
|
<%= include.('values.html', values: type[:values]) %>
|
8
|
-
|
9
|
-
<% end %>
|
@@ -1,9 +1,7 @@
|
|
1
|
-
|
1
|
+
<h1><%= type[:name] %></h1>
|
2
2
|
|
3
|
-
<%= type[:
|
3
|
+
<%= include.('notices.html', notices: type[:notices]) %>
|
4
4
|
|
5
|
-
|
5
|
+
<%= type[:description] %>
|
6
6
|
|
7
7
|
<%= include.('possible_types.html', possible_types: type[:possible_types]) %>
|
8
|
-
|
9
|
-
<% end %>
|
@@ -4,6 +4,7 @@
|
|
4
4
|
<span id="<%= slugify.(connection[:name]) %>" class="field-name connection-name"><%= connection[:name] %> (<a href="<%= base_url %>/<%= connection[:type][:path] %>"><code><%= connection[:type][:info] %></code></a>)</span>
|
5
5
|
|
6
6
|
<div class="description-wrapper">
|
7
|
+
<%= include.('notices.html', notices: connection[:notices]) %>
|
7
8
|
<p><%= connection[:description] %></p>
|
8
9
|
|
9
10
|
<% unless connection[:arguments].empty? %>
|
@@ -4,6 +4,8 @@
|
|
4
4
|
<span id="<%= slugify.(field[:name]) %>" class="field-name"><%= field[:name] %> (<a href="<%= base_url %>/<%= field[:type][:path] %>"><code><%= field[:type][:info] %></code></a>)</span>
|
5
5
|
|
6
6
|
<div class="description-wrapper">
|
7
|
+
<%= include.('notices.html', notices: field[:notices]) %>
|
8
|
+
|
7
9
|
<%= field[:description] %>
|
8
10
|
|
9
11
|
<% unless field[:arguments].empty? %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<% notices.each do |notice| %>
|
2
|
+
<div class="notice <%= classes[:notice] %> <%= notice[:class] %>">
|
3
|
+
<% if notice[:title] %>
|
4
|
+
<span class="notice-title <%= classes[:notice_title] %> <%= notice[:title_class] %>"><%= notice[:title] %></span>
|
5
|
+
<% end %>
|
6
|
+
<%= markdownify.(notice[:body]) %>
|
7
|
+
</div>
|
8
|
+
<% end %>
|
@@ -5,6 +5,8 @@
|
|
5
5
|
<h4 id="<%= slugify.(value[:name]) %>" class="name"><%= value[:name] %></h4>
|
6
6
|
|
7
7
|
<div class="description-wrapper">
|
8
|
+
<%= include.('notices.html', notices: value[:notices]) %>
|
9
|
+
|
8
10
|
<% if value[:is_deprecated] %>
|
9
11
|
<div class="deprecation-notice <%= classes[:deprecation_notice] %>">
|
10
12
|
<span class="deprecation-title">Deprecation notice</span>
|
data/lib/graphql-docs/parser.rb
CHANGED
@@ -8,6 +8,9 @@ module GraphQLDocs
|
|
8
8
|
|
9
9
|
def initialize(schema, options)
|
10
10
|
@options = options
|
11
|
+
|
12
|
+
@options[:notices] ||= -> (schema_member_path) { [] }
|
13
|
+
|
11
14
|
@schema = GraphQL::Schema.from_definition(schema)
|
12
15
|
@processed_schema = {
|
13
16
|
operation_types: [],
|
@@ -25,6 +28,8 @@ module GraphQLDocs
|
|
25
28
|
@schema.types.each_value do |object|
|
26
29
|
data = {}
|
27
30
|
|
31
|
+
data[:notices] = @options[:notices].call(object.name)
|
32
|
+
|
28
33
|
case object
|
29
34
|
when ::GraphQL::ObjectType
|
30
35
|
if object.name == 'Query'
|
@@ -32,7 +37,7 @@ module GraphQLDocs
|
|
32
37
|
data[:description] = object.description
|
33
38
|
|
34
39
|
data[:interfaces] = object.interfaces.map(&:name).sort
|
35
|
-
data[:fields], data[:connections] = fetch_fields(object.fields)
|
40
|
+
data[:fields], data[:connections] = fetch_fields(object.fields, object.name)
|
36
41
|
|
37
42
|
@processed_schema[:operation_types] << data
|
38
43
|
elsif object.name == 'Mutation'
|
@@ -43,15 +48,17 @@ module GraphQLDocs
|
|
43
48
|
|
44
49
|
object.fields.each_value do |mutation|
|
45
50
|
h = {}
|
51
|
+
|
52
|
+
h[:notices] = @options[:notices].call([object.name, mutation.name].join('.'))
|
46
53
|
h[:name] = mutation.name
|
47
54
|
h[:description] = mutation.description
|
48
|
-
h[:input_fields], _ = fetch_fields(mutation.arguments)
|
55
|
+
h[:input_fields], _ = fetch_fields(mutation.arguments, [object.name, mutation.name].join('.'))
|
49
56
|
|
50
57
|
return_type = mutation.type
|
51
58
|
if return_type.unwrap.respond_to?(:fields)
|
52
|
-
h[:return_fields], _ = fetch_fields(return_type.unwrap.fields)
|
59
|
+
h[:return_fields], _ = fetch_fields(return_type.unwrap.fields, return_type.name)
|
53
60
|
else # it is a scalar return type
|
54
|
-
h[:return_fields], _ = fetch_fields({ "#{return_type.name}" => mutation })
|
61
|
+
h[:return_fields], _ = fetch_fields({ "#{return_type.name}" => mutation }, return_type.name)
|
55
62
|
end
|
56
63
|
|
57
64
|
@processed_schema[:mutation_types] << h
|
@@ -61,14 +68,14 @@ module GraphQLDocs
|
|
61
68
|
data[:description] = object.description
|
62
69
|
|
63
70
|
data[:interfaces] = object.interfaces.map(&:name).sort
|
64
|
-
data[:fields], data[:connections] = fetch_fields(object.fields)
|
71
|
+
data[:fields], data[:connections] = fetch_fields(object.fields, object.name)
|
65
72
|
|
66
73
|
@processed_schema[:object_types] << data
|
67
74
|
end
|
68
75
|
when ::GraphQL::InterfaceType
|
69
76
|
data[:name] = object.name
|
70
77
|
data[:description] = object.description
|
71
|
-
data[:fields], data[:connections] = fetch_fields(object.fields)
|
78
|
+
data[:fields], data[:connections] = fetch_fields(object.fields, object.name)
|
72
79
|
|
73
80
|
@processed_schema[:interface_types] << data
|
74
81
|
when ::GraphQL::EnumType
|
@@ -77,6 +84,7 @@ module GraphQLDocs
|
|
77
84
|
|
78
85
|
data[:values] = object.values.values.map do |val|
|
79
86
|
h = {}
|
87
|
+
h[:notices] = @options[:notices].call([object.name, val.name].join('.'))
|
80
88
|
h[:name] = val.name
|
81
89
|
h[:description] = val.description
|
82
90
|
unless val.deprecation_reason.nil?
|
@@ -97,7 +105,7 @@ module GraphQLDocs
|
|
97
105
|
data[:name] = object.name
|
98
106
|
data[:description] = object.description
|
99
107
|
|
100
|
-
data[:input_fields], _ = fetch_fields(object.input_fields)
|
108
|
+
data[:input_fields], _ = fetch_fields(object.input_fields, object.name)
|
101
109
|
|
102
110
|
@processed_schema[:input_object_types] << data
|
103
111
|
when ::GraphQL::ScalarType
|
@@ -132,13 +140,14 @@ module GraphQLDocs
|
|
132
140
|
|
133
141
|
private
|
134
142
|
|
135
|
-
def fetch_fields(object_fields)
|
143
|
+
def fetch_fields(object_fields, parent_path)
|
136
144
|
fields = []
|
137
145
|
connections = []
|
138
146
|
|
139
147
|
object_fields.each_value do |field|
|
140
148
|
hash = {}
|
141
149
|
|
150
|
+
hash[:notices] = @options[:notices].call([parent_path, field.name].join('.'))
|
142
151
|
hash[:name] = field.name
|
143
152
|
hash[:description] = field.description
|
144
153
|
if field.respond_to?(:deprecation_reason) && !field.deprecation_reason.nil?
|
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.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -280,6 +280,7 @@ files:
|
|
280
280
|
- lib/graphql-docs/layouts/includes/connections.html
|
281
281
|
- lib/graphql-docs/layouts/includes/fields.html
|
282
282
|
- lib/graphql-docs/layouts/includes/input_fields.html
|
283
|
+
- lib/graphql-docs/layouts/includes/notices.html
|
283
284
|
- lib/graphql-docs/layouts/includes/possible_types.html
|
284
285
|
- lib/graphql-docs/layouts/includes/sidebar.html
|
285
286
|
- lib/graphql-docs/layouts/includes/values.html
|