graphql-docs 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73edf72a2d765a3e79d721c603acc05832fae79f
4
- data.tar.gz: a5f747385749b0babc5a2c42a60c7cbb98633a25
3
+ metadata.gz: 4935d2987679ab16e3a82d24f4839b484dbc289e
4
+ data.tar.gz: f4ddc20c6c2702e28b17c7c64648811d59a017ff
5
5
  SHA512:
6
- metadata.gz: 8846e1d564b782a17205374cbc151da843fdee19b4b967a54bb5cc889a7034a6fbe0e8b61e0141a0bfd78584c4c08a80437e0bad27755613859c41c867e7ca83
7
- data.tar.gz: 060991173dbeedbb7b173f9c4c4f4c0b666f7b1f51d8214113c27fcf93c59550402eed3746efa508301cf274425817f9af59da29f810e8d31e83f149504629e2
6
+ metadata.gz: d5bdeee0342d29830457a27c24924c14db9b4850fa75bc751abf449ae0c95c0dce091c5a7f4bea41423e864935c7ca82cda939bf81b7071154d3291db67844ca
7
+ data.tar.gz: '018e1e9d4f837d7a326a430cbb75fe76cba0d5ff3731ef25b3dff54074ca6ab3bfb9ce596fd9ad9e95b030d9f0ab7bec9d550adbda28776ec1ffb13c970df09c'
data/README.md CHANGED
@@ -112,6 +112,7 @@ In your ERB layouts, there are several helper methods you can use. The helper me
112
112
  * `slugify(str)` - This slugifies the given string.
113
113
  * `include(filename, opts)` - This embeds a template from your `includes` folder, passing along the local options provided.
114
114
  * `markdown(string)` - This converts a string from Markdown to HTML.
115
+ * `format_type(field)` - This formats a type into an IDL-like representation. For example: `!Blah` or `[!Foo]`.
115
116
  * `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.
116
117
 
117
118
  To call these methods within templates, you must use the dot notation, such as `<%= slugify.(text) %>`.
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency 'minitest', '~> 5.0'
37
37
  spec.add_development_dependency 'minitest-focus', '~> 1.1'
38
38
  spec.add_development_dependency 'pry', '~> 0.10.0'
39
- spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rake'
40
40
  spec.add_development_dependency 'rubocop-github'
41
41
  spec.add_development_dependency 'webmock', '~> 2.3'
42
42
  end
@@ -20,6 +20,63 @@ module GraphQLDocs
20
20
  GitHub::Markdown.render(string || 'n/a')
21
21
  end
22
22
 
23
+ # Do you think I am proud of this? I am not.
24
+ def format_type(field)
25
+ type_path = name_slug = nil
26
+ type_name = ''
27
+
28
+ if field['type']['kind'] == 'NON_NULL'
29
+ type_name << '!'
30
+
31
+ if !field['type']['ofType']['ofType'].nil?
32
+ # we're going to be a list...but what kind?!
33
+ type_name << '['
34
+ if !field['type']['ofType']['ofType']['ofType'].nil?
35
+ # A required list of required items: ![!Blah]
36
+ if field['type']['ofType']['ofType']['kind'] == 'NON_NULL'
37
+ type_name << '!'
38
+ end
39
+ type_path = field['type']['ofType']['ofType']['ofType']['kind']
40
+ type_name << field['type']['ofType']['ofType']['ofType']['name']
41
+ name_slug = field['type']['ofType']['ofType']['ofType']['name']
42
+ else
43
+ # A required list of non-required items: ![Blah]
44
+ type_path = field['type']['ofType']['ofType']['kind']
45
+ type_name << field['type']['ofType']['ofType']['name']
46
+ name_slug = field['type']['ofType']['ofType']['name']
47
+ end
48
+ type_name << ']'
49
+ else
50
+ # Simple non-null item: !Blah
51
+ type_path = field['type']['ofType']['kind']
52
+ type_name << field['type']['ofType']['name']
53
+ name_slug = field['type']['ofType']['name']
54
+ end
55
+ elsif field['type']['kind'] == 'LIST'
56
+ type_name << '['
57
+ if field['type']['ofType']['kind'] == 'NON_NULL'
58
+ # Nullable list of non-null items: [!Blah]
59
+ type_name << '!'
60
+ type_path = field['type']['ofType']['ofType']['kind']
61
+ type_name << field['type']['ofType']['ofType']['name']
62
+ name_slug = field['type']['ofType']['ofType']['name']
63
+ else
64
+ # Nullable list of nullable items: [Blah]
65
+ type_path = field['type']['ofType']['kind']
66
+ type_name << field['type']['ofType']['name']
67
+ name_slug = field['type']['ofType']['name']
68
+ end
69
+ type_name << ']'
70
+ else
71
+ # Simple nullable item: Blah
72
+ type_path = field['type']['kind']
73
+ type_name << field['type']['name']
74
+ name_slug = field['type']['name']
75
+ end
76
+
77
+ [type_path.downcase, type_name, name_slug.downcase]
78
+ end
79
+
23
80
  def graphql_mutation_types
24
81
  @parsed_schema['mutation_types']
25
82
  end
@@ -9,18 +9,12 @@
9
9
  <tbody>
10
10
  <% args.each do |argument| %>
11
11
  <tr>
12
- <td><code><%= argument['name'] %><code></td>
12
+ <td><code><%= argument['name'] %></code></td>
13
13
  <td>
14
14
 
15
- <% if argument['type']['name'] == "Non-Null" %>
16
- <% @arg_path = argument['type']['ofType']['kind'] %>
17
- <% @arg_name = argument['type']['ofType']['name'] %>
18
- <% else %>
19
- <% @arg_path = argument['type']['kind'] %>
20
- <% @arg_name = argument['type']['name'] %>
21
- <% end %>
15
+ <% @type_path, @type_name, @name_slug = format_type.(argument) %>
22
16
 
23
- <code><%= @arg_name %></code>
17
+ <code><a href="<%= base_url %>/<%= @type_path %>/<%= @name_slug %>"><%= @type_name %></a></code>
24
18
  </td>
25
19
  <td>
26
20
  <p><%= markdown.(argument['description']) %></p>
@@ -5,26 +5,9 @@
5
5
  <div class="field-entry <%= classes[:field_entry] %>">
6
6
  <% next if field['name'] == "id" || field['name'].blank? %>
7
7
 
8
- <% if field['type']['ofType'] && !field['type']['ofType']['ofType'].nil? %>
9
- <% if !field['type']['ofType']['ofType']['ofType'].nil? %>
10
- <% @type_path = field['type']['ofType']['ofType']['ofType']['kind'] %>
11
- <% @type_name = field['type']['ofType']['ofType']['ofType']['name'] %>
12
- <% else %>
13
- <% @type_path = field['type']['ofType']['ofType']['kind'] %>
14
- <% @type_name = field['type']['ofType']['ofType']['name'] %>
15
- <% end %>
16
- <% elsif field['type']['ofType'].blank? %>
17
- <% @type_path = field['type']['kind'] %>
18
- <% @type_name = field['type']['name'] %>
19
- <% elsif field['type']['name'] == "Non-Null" || field['type']['ofType']['name'] == "Non-Null" %>
20
- <% @type_path = field['type']['ofType']['kind'] %>
21
- <% @type_name = field['type']['ofType']['name'] %>
22
- <% else %>
23
- <% @type_path = field['type']['ofType']['kind'] %>
24
- <% @type_name = field['type']['ofType']['name'] %>
25
- <% end %>
26
-
27
- <span class="field-name"><%= field['name'] %> (<code><a href="<%= base_url %>/<%= @type_path.downcase %>/<%= slugify.(@type_name) %>"><%= @type_name %></a></code>)</span>
8
+ <% @type_path, @type_name, @name_slug = format_type.(field) %>
9
+
10
+ <span class="field-name"><%= field['name'] %> (<code><a href="<%= base_url %>/<%= @type_path %>/<%= @name_slug %>"><%= @type_name %></a></code>)</span>
28
11
 
29
12
  <div class="description-wrapper">
30
13
  <% if field['isDeprecated'] %>
@@ -7,26 +7,9 @@
7
7
  <div class="field-entry <%= classes[:field_entry] %>">
8
8
  <% next if field['name'] == "id" || field['name'].blank? %>
9
9
 
10
- <% if field['type']['ofType'] && !field['type']['ofType']['ofType'].nil? %>
11
- <% if !field['type']['ofType']['ofType']['ofType'].nil? %>
12
- <% @type_path = field['type']['ofType']['ofType']['ofType']['kind'] %>
13
- <% @type_name = field['type']['ofType']['ofType']['ofType']['name'] %>
14
- <% else %>
15
- <% @type_path = field['type']['ofType']['ofType']['kind'] %>
16
- <% @type_name = field['type']['ofType']['ofType']['name'] %>
17
- <% end %>
18
- <% elsif field['type']['ofType'].blank? %>
19
- <% @type_path = field['type']['kind'] %>
20
- <% @type_name = field['type']['name'] %>
21
- <% elsif field['type']['name'] == "Non-Null" || field['type']['ofType']['name'] == "Non-Null" %>
22
- <% @type_path = field['type']['ofType']['kind'] %>
23
- <% @type_name = field['type']['ofType']['name'] %>
24
- <% else %>
25
- <% @type_path = field['type']['ofType']['kind'] %>
26
- <% @type_name = field['type']['ofType']['name'] %>
27
- <% end %>
28
-
29
- <span class="field-name"><%= field['name'] %> (<a href="<%= base_url %>/<%= @type_path.downcase %>/<%= slugify.(@type_name) %>"><code><%= @type_name %></code></a>)</span>
10
+ <% @type_path, @type_name, @name_slug = format_type.(field) %>
11
+
12
+ <span class="field-name"><%= field['name'] %> (<a href="<%= base_url %>/<%= @type_path %>/<%= @name_slug %>"><code><%= @type_name %></code></a>)</span>
30
13
 
31
14
  <div class="description-wrapper">
32
15
  <%= field['description'] %>
@@ -1,3 +1,3 @@
1
1
  module GraphQLDocs
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
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: 0.3.0
4
+ version: 0.4.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: 2017-03-04 00:00:00.000000000 Z
11
+ date: 2017-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -196,16 +196,16 @@ dependencies:
196
196
  name: rake
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - "~>"
199
+ - - ">="
200
200
  - !ruby/object:Gem::Version
201
- version: '10.0'
201
+ version: '0'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - "~>"
206
+ - - ">="
207
207
  - !ruby/object:Gem::Version
208
- version: '10.0'
208
+ version: '0'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: rubocop-github
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -328,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
328
328
  version: '0'
329
329
  requirements: []
330
330
  rubyforge_project:
331
- rubygems_version: 2.4.5.1
331
+ rubygems_version: 2.6.12
332
332
  signing_key:
333
333
  specification_version: 4
334
334
  summary: Easily generate beautiful documentation from your GraphQL schema.