graphqlmd 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6065d284022c32bbad1063031cc29c1b2b572d48b55160cf74a7af632786e90
4
- data.tar.gz: 0ac3353137d0d1009138b31502ce65c4fdbd9a792ab5bf51bc53e525869cdc27
3
+ metadata.gz: 491acad5247c7115bc66ce15c3ec49ecb2a5eede531a335743e1b2e3f732f4ad
4
+ data.tar.gz: 5185b2d3746e5af4df9beb70582ce94547fbf3c690b108c7449525cb66203da9
5
5
  SHA512:
6
- metadata.gz: 8641781630e65ce96103d14ac799bc89d43cad59efd179e03db3fde1d38ab7613164e058356474d6c3ffef02cc0eb6dac06732deb66d40ae7c3fc2bfc3fc3984
7
- data.tar.gz: 0caca010c75dbc7f4e454039fca3311dd50d41092e6cd6ac97f4b3fe7f2890fb03288268af4beade91284be5bc0a8c90962d7e8739e0f460485e325e9d28e72e
6
+ metadata.gz: a6abaef651cd3dbd565b0ba9e33cbd3faa87b9b78c0a2ab2f69db47671e2f1d560bcca25bc6ea6f074ceeef78008ff8c61fa945acfc15233bde4eb01b181087b
7
+ data.tar.gz: ad9b3d985f3721f9558acbdee3cbb1265e84b80db0312c5b3757939b8204462febe13a800dcfc62cf2ee7149010a76011b4559cc1b7ad56ee7a9844dbd94ce98
@@ -5,9 +5,12 @@ require 'optparse'
5
5
 
6
6
  options = {
7
7
  url: 'http://localhost:3000/graphql',
8
+ title: 'GraphQL API',
9
+ note: nil,
8
10
  is_hide_client_mutation_id: true,
9
11
  is_hide_scalar: true,
10
12
  is_hide_deprecated: false,
13
+ is_hide_table_of_contents: false,
11
14
  is_allow_links: true,
12
15
  is_vuepress: false,
13
16
  ignored_queries: [],
@@ -30,6 +33,16 @@ OptionParser.new do |opts|
30
33
  options[:url] = url
31
34
  end
32
35
 
36
+ opts.on(
37
+ '-t', '--title [TITLE]', "Title (default: #{options[:title]})"
38
+ ) do |title|
39
+ options[:title] = title
40
+ end
41
+
42
+ opts.on '--note [NOTE]', 'Text after title (default: nil)' do |note|
43
+ options[:note] = note
44
+ end
45
+
33
46
  opts.on '--no-deprecated', 'Do not add deprecated objects, fields, args and etc.' do
34
47
  options[:is_hide_deprecated] = true
35
48
  end
@@ -38,6 +51,10 @@ OptionParser.new do |opts|
38
51
  options[:is_allow_links] = false
39
52
  end
40
53
 
54
+ opts.on '--no-table-of-contents', 'Do not add table of contents' do
55
+ options[:is_hide_table_of_contents] = true
56
+ end
57
+
41
58
  opts.on '--client-mutation-id', 'Add clientMutationId to docs' do
42
59
  options[:is_hide_client_mutation_id] = false
43
60
  end
@@ -9,7 +9,10 @@ class Graphqlmd::Graphqlmd
9
9
 
10
10
  def initialize options
11
11
  @url = options[:url]
12
+ @title = options[:title]
13
+ @note = options[:note]
12
14
  @is_hide_client_mutation_id = options[:is_hide_client_mutation_id]
15
+ @is_hide_table_of_contents = options[:is_hide_table_of_contents]
13
16
  @is_hide_deprecated = options[:is_hide_deprecated]
14
17
  @is_hide_scalar = options[:is_hide_scalar]
15
18
  @is_allow_links = options[:is_allow_links]
@@ -22,6 +25,10 @@ class Graphqlmd::Graphqlmd
22
25
  def call
23
26
  response = fetch_schema
24
27
  data = JSON.parse(response.body).dig 'data', 'schema'
28
+
29
+ puts_title
30
+ puts_note
31
+ puts_top_table_of_contents
25
32
  puts_queries data['queries']
26
33
  puts_mutations data['mutations']
27
34
  puts_objects data['types']
@@ -29,12 +36,37 @@ class Graphqlmd::Graphqlmd
29
36
 
30
37
  private
31
38
 
39
+ def puts_title
40
+ return if @title.nil?
41
+ return if @title.empty?
42
+
43
+ puts "# #{@title}\n\n"
44
+ end
45
+
46
+ def puts_note
47
+ return if @note.nil?
48
+ return if @note.empty?
49
+
50
+ puts "#{@note}\n\n"
51
+ end
52
+
53
+ def puts_top_table_of_contents
54
+ return if @is_hide_table_of_contents
55
+
56
+ puts '- [Queries](#queries)'
57
+ puts '- [Mutations](#mutations)'
58
+ puts '- [Objects](#objects)'
59
+ puts "\n"
60
+ end
61
+
32
62
  def puts_queries data
33
63
  print_header 'Queries'
34
64
  queries = data['fields']
35
65
  .reject { |v| @ignored_queries.include? v['name'] }
36
66
  .sort_by { |v| v['name'] }
37
67
 
68
+ puts_table_of_contents queries
69
+
38
70
  queries.each do |v|
39
71
  puts "\n### #{v['name']}\n"
40
72
  print_deprecation v
@@ -50,9 +82,10 @@ private
50
82
  mutations = data['fields']
51
83
  .reject { |v| @ignored_mutations.include? v['name'] }
52
84
  .sort_by { |v| v['name'] }
53
-
54
85
  mutations = mutations.reject { |v| v['isDeprecated'] } if @is_hide_deprecated
55
86
 
87
+ puts_table_of_contents mutations
88
+
56
89
  mutations.each do |v|
57
90
  puts "\n### #{v['name']}\n"
58
91
  print_deprecation v
@@ -71,6 +104,8 @@ private
71
104
  .sort_by { |v| v['name'] }
72
105
  objects = objects.reject { |v| v['kind'] == SCALAR } if @is_hide_scalar
73
106
 
107
+ puts_table_of_contents objects
108
+
74
109
  objects.each do |v|
75
110
  puts "\n### #{v['name']}\n"
76
111
  puts "#{print_description v['description']}\n" unless v['description'].nil?
@@ -85,6 +120,14 @@ private
85
120
  puts "## #{value}\n"
86
121
  end
87
122
 
123
+ def puts_table_of_contents items
124
+ return if @is_hide_table_of_contents
125
+
126
+ items.each do |v|
127
+ puts "- [#{v['name']}](##{v['name'].downcase})"
128
+ end
129
+ end
130
+
88
131
  def print_fields fields
89
132
  return if fields.nil?
90
133
  return if fields.empty?
@@ -120,7 +163,8 @@ private
120
163
  puts "Name | Type | Description\n"
121
164
  puts "-|-|-|-\n"
122
165
  args.each do |v|
123
- puts "#{v['name']} | #{type_as_string(v['type'])} | #{print_description(v['description'])}\n"
166
+ description = v['description'] || (v['type'] && v['type']['ofType'] && v['type']['ofType']['description'])
167
+ puts "#{v['name']} | #{type_as_string(v['type'])} | #{print_description(description)}\n"
124
168
  end
125
169
  end
126
170
 
@@ -39,32 +39,41 @@ module Graphqlmd
39
39
  type {
40
40
  ...TypeRef
41
41
  }
42
+ description
42
43
  defaultValue
43
44
  }
44
45
  fragment TypeRef on __Type {
45
46
  kind
46
47
  name
48
+ description
47
49
  ofType {
48
50
  kind
49
51
  name
52
+ description
50
53
  ofType {
51
54
  kind
52
55
  name
56
+ description
53
57
  ofType {
54
58
  kind
55
59
  name
60
+ description
56
61
  ofType {
57
62
  kind
58
63
  name
64
+ description
59
65
  ofType {
60
66
  kind
61
67
  name
68
+ description
62
69
  ofType {
63
70
  kind
64
71
  name
72
+ description
65
73
  ofType {
66
74
  kind
67
75
  name
76
+ description
68
77
  }
69
78
  }
70
79
  }
@@ -1,3 +1,3 @@
1
1
  module Graphqlmd
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphqlmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kalinichev