graphql-docs 1.9.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +12 -0
- data/.travis.yml +4 -4
- data/Gemfile +1 -0
- data/Rakefile +4 -1
- data/graphql-docs.gemspec +5 -5
- data/lib/graphql-docs/configuration.rb +6 -5
- data/lib/graphql-docs/generator.rb +32 -52
- data/lib/graphql-docs/helpers.rb +11 -13
- data/lib/graphql-docs/layouts/default.html +1 -1
- data/lib/graphql-docs/parser.rb +69 -76
- data/lib/graphql-docs/renderer.rb +8 -8
- data/lib/graphql-docs/version.rb +2 -1
- data/lib/graphql-docs.rb +16 -24
- metadata +22 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f020e4e5b4934ba5304c8b806fe7467580a69d6cf1c46bcfdb9da87616e5d7a2
|
4
|
+
data.tar.gz: 46221390779db63e655ee6056cb73e82d428d3e1447e49668023bf0adc0f3a50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ea882325c99359946bc746a83e4b83c91bebd904b9021fb0ec28122a3f8a2d5ffeec287b15aefa5c83616442b6c5aa1b0d2ba7a426422270871d92cfcae5933
|
7
|
+
data.tar.gz: 57ad8d227e62610adb18e519e19dcdfef9254270244fe422afc0ff66357e5c3a03e1d5195d56a5d53e3f495da913a7b1bd63afeaada3b3c2a843229b2b0395bf
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# These are supported funding model platforms
|
2
|
+
|
3
|
+
github: gjtorikian
|
4
|
+
patreon: gjtorikian
|
5
|
+
open_collective: garen-torikian
|
6
|
+
#ko_fi: # Replace with a single Ko-fi username
|
7
|
+
#tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
8
|
+
#community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
9
|
+
#liberapay: # Replace with a single Liberapay username
|
10
|
+
issuehunt: gjtorikian
|
11
|
+
#otechie: # Replace with a single Otechie username
|
12
|
+
#custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'bundler/gem_tasks'
|
3
4
|
require 'rake/testtask'
|
4
5
|
|
@@ -31,7 +32,7 @@ task :console do
|
|
31
32
|
require 'graphql-docs'
|
32
33
|
|
33
34
|
def reload!
|
34
|
-
files = $LOADED_FEATURES.select { |feat| feat =~
|
35
|
+
files = $LOADED_FEATURES.select { |feat| feat =~ %r{/graphql-docs/} }
|
35
36
|
files.each { |file| load file }
|
36
37
|
end
|
37
38
|
|
@@ -46,6 +47,7 @@ task :generate_sample do
|
|
46
47
|
|
47
48
|
options = {}
|
48
49
|
options[:delete_output] = true
|
50
|
+
options[:base_url] = ENV.fetch('GQL_DOCS_BASE_URL', '')
|
49
51
|
options[:filename] = File.join(File.dirname(__FILE__), 'test', 'graphql-docs', 'fixtures', 'gh-schema.graphql')
|
50
52
|
|
51
53
|
GraphQLDocs.build(options)
|
@@ -65,6 +67,7 @@ end
|
|
65
67
|
|
66
68
|
desc 'Generate and publish docs to gh-pages'
|
67
69
|
task :publish do
|
70
|
+
ENV['GQL_DOCS_BASE_URL'] = '/graphql-docs'
|
68
71
|
Rake::Task[:generate_sample].invoke('https://www.gjtorikian.com/graphql-docs')
|
69
72
|
Dir.mktmpdir do |tmp|
|
70
73
|
system "mv output/* #{tmp}"
|
data/graphql-docs.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
|
-
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require 'graphql-docs/version'
|
6
6
|
|
@@ -21,14 +21,14 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_dependency 'graphql', '~> 1.
|
24
|
+
spec.add_dependency 'graphql', '~> 1.12'
|
25
25
|
|
26
26
|
# rendering
|
27
27
|
spec.add_dependency 'commonmarker', '~> 0.16'
|
28
|
-
spec.add_dependency '
|
29
|
-
spec.add_dependency 'escape_utils', '~> 1.2'
|
28
|
+
spec.add_dependency 'escape_utils', '~> 1.2'
|
30
29
|
spec.add_dependency 'extended-markdown-filter', '~> 0.4'
|
31
30
|
spec.add_dependency 'gemoji', '~> 3.0'
|
31
|
+
spec.add_dependency 'html-pipeline', '~> 2.9'
|
32
32
|
spec.add_dependency 'sass', '~> 3.4'
|
33
33
|
|
34
34
|
spec.add_development_dependency 'awesome_print'
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module GraphQLDocs
|
3
4
|
module Configuration
|
4
5
|
GRAPHQLDOCS_DEFAULTS = {
|
@@ -11,9 +12,9 @@ module GraphQLDocs
|
|
11
12
|
output_dir: './output/',
|
12
13
|
pipeline_config: {
|
13
14
|
pipeline:
|
14
|
-
%i
|
15
|
-
|
16
|
-
|
15
|
+
%i[ExtendedMarkdownFilter
|
16
|
+
EmojiFilter
|
17
|
+
TableOfContentsFilter],
|
17
18
|
context: {
|
18
19
|
gfm: false,
|
19
20
|
unsafe: true, # necessary for layout needs, given that it's all HTML templates
|
@@ -37,7 +38,7 @@ module GraphQLDocs
|
|
37
38
|
unions: "#{File.dirname(__FILE__)}/layouts/graphql_unions.html",
|
38
39
|
input_objects: "#{File.dirname(__FILE__)}/layouts/graphql_input_objects.html",
|
39
40
|
scalars: "#{File.dirname(__FILE__)}/layouts/graphql_scalars.html",
|
40
|
-
directives: "#{File.dirname(__FILE__)}/layouts/graphql_directives.html"
|
41
|
+
directives: "#{File.dirname(__FILE__)}/layouts/graphql_directives.html"
|
41
42
|
},
|
42
43
|
|
43
44
|
landing_pages: {
|
@@ -59,7 +60,7 @@ module GraphQLDocs
|
|
59
60
|
field_entry: '',
|
60
61
|
deprecation_notice: '',
|
61
62
|
notice: '',
|
62
|
-
notice_title: ''
|
63
|
+
notice_title: ''
|
63
64
|
}
|
64
65
|
}.freeze
|
65
66
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'erb'
|
3
4
|
require 'sass'
|
4
5
|
|
@@ -14,14 +15,13 @@ module GraphQLDocs
|
|
14
15
|
|
15
16
|
@renderer = @options[:renderer].new(@parsed_schema, @options)
|
16
17
|
|
17
|
-
%i
|
18
|
-
|
19
|
-
|
20
|
-
end
|
18
|
+
%i[operations objects mutations interfaces enums unions input_objects scalars directives].each do |sym|
|
19
|
+
raise IOError, "`#{sym}` template #{@options[:templates][sym]} was not found" unless File.exist?(@options[:templates][sym])
|
20
|
+
|
21
21
|
instance_variable_set("@graphql_#{sym}_template", ERB.new(File.read(@options[:templates][sym])))
|
22
22
|
end
|
23
23
|
|
24
|
-
%i
|
24
|
+
%i[index object query mutation interface enum union input_object scalar directive].each do |sym|
|
25
25
|
if @options[:landing_pages][sym].nil?
|
26
26
|
instance_variable_set("@#{sym}_landing_page", nil)
|
27
27
|
elsif !File.exist?(@options[:landing_pages][sym])
|
@@ -33,7 +33,7 @@ module GraphQLDocs
|
|
33
33
|
|
34
34
|
if File.extname((@options[:landing_pages][sym])) == '.erb'
|
35
35
|
opts = @options.merge(@options[:landing_pages][:variables]).merge(helper_methods)
|
36
|
-
if
|
36
|
+
if yaml?(landing_page_contents)
|
37
37
|
metadata, landing_page = split_into_metadata_and_contents(landing_page_contents, parse: false)
|
38
38
|
erb_template = ERB.new(landing_page)
|
39
39
|
else
|
@@ -60,45 +60,25 @@ module GraphQLDocs
|
|
60
60
|
create_graphql_scalar_pages
|
61
61
|
create_graphql_directive_pages
|
62
62
|
|
63
|
-
unless @graphql_index_landing_page.nil?
|
64
|
-
write_file('static', 'index', @graphql_index_landing_page, trim: false)
|
65
|
-
end
|
63
|
+
write_file('static', 'index', @graphql_index_landing_page, trim: false) unless @graphql_index_landing_page.nil?
|
66
64
|
|
67
|
-
unless @graphql_object_landing_page.nil?
|
68
|
-
write_file('static', 'object', @graphql_object_landing_page, trim: false)
|
69
|
-
end
|
65
|
+
write_file('static', 'object', @graphql_object_landing_page, trim: false) unless @graphql_object_landing_page.nil?
|
70
66
|
|
71
|
-
if !@graphql_query_landing_page.nil? && !has_query
|
72
|
-
write_file('operation', 'query', @graphql_query_landing_page, trim: false)
|
73
|
-
end
|
67
|
+
write_file('operation', 'query', @graphql_query_landing_page, trim: false) if !@graphql_query_landing_page.nil? && !has_query
|
74
68
|
|
75
|
-
unless @graphql_mutation_landing_page.nil?
|
76
|
-
write_file('operation', 'mutation', @graphql_mutation_landing_page, trim: false)
|
77
|
-
end
|
69
|
+
write_file('operation', 'mutation', @graphql_mutation_landing_page, trim: false) unless @graphql_mutation_landing_page.nil?
|
78
70
|
|
79
|
-
unless @graphql_interface_landing_page.nil?
|
80
|
-
write_file('static', 'interface', @graphql_interface_landing_page, trim: false)
|
81
|
-
end
|
71
|
+
write_file('static', 'interface', @graphql_interface_landing_page, trim: false) unless @graphql_interface_landing_page.nil?
|
82
72
|
|
83
|
-
unless @graphql_enum_landing_page.nil?
|
84
|
-
write_file('static', 'enum', @graphql_enum_landing_page, trim: false)
|
85
|
-
end
|
73
|
+
write_file('static', 'enum', @graphql_enum_landing_page, trim: false) unless @graphql_enum_landing_page.nil?
|
86
74
|
|
87
|
-
unless @graphql_union_landing_page.nil?
|
88
|
-
write_file('static', 'union', @graphql_union_landing_page, trim: false)
|
89
|
-
end
|
75
|
+
write_file('static', 'union', @graphql_union_landing_page, trim: false) unless @graphql_union_landing_page.nil?
|
90
76
|
|
91
|
-
unless @graphql_input_object_landing_page.nil?
|
92
|
-
write_file('static', 'input_object', @graphql_input_object_landing_page, trim: false)
|
93
|
-
end
|
77
|
+
write_file('static', 'input_object', @graphql_input_object_landing_page, trim: false) unless @graphql_input_object_landing_page.nil?
|
94
78
|
|
95
|
-
unless @graphql_scalar_landing_page.nil?
|
96
|
-
write_file('static', 'scalar', @graphql_scalar_landing_page, trim: false)
|
97
|
-
end
|
79
|
+
write_file('static', 'scalar', @graphql_scalar_landing_page, trim: false) unless @graphql_scalar_landing_page.nil?
|
98
80
|
|
99
|
-
unless @graphql_directive_landing_page.nil?
|
100
|
-
write_file('static', 'directive', @graphql_directive_landing_page, trim: false)
|
101
|
-
end
|
81
|
+
write_file('static', 'directive', @graphql_directive_landing_page, trim: false) unless @graphql_directive_landing_page.nil?
|
102
82
|
|
103
83
|
if @options[:use_default_styles]
|
104
84
|
assets_dir = File.join(File.dirname(__FILE__), 'layouts', 'assets')
|
@@ -117,23 +97,23 @@ module GraphQLDocs
|
|
117
97
|
def create_graphql_query_pages
|
118
98
|
graphql_operation_types.each do |query_type|
|
119
99
|
metadata = ''
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
query_type[:description] = query_landing_page
|
100
|
+
next unless query_type[:name] == graphql_root_types['query']
|
101
|
+
|
102
|
+
unless @options[:landing_pages][:query].nil?
|
103
|
+
query_landing_page = @options[:landing_pages][:query]
|
104
|
+
query_landing_page = File.read(query_landing_page)
|
105
|
+
if yaml?(query_landing_page)
|
106
|
+
pieces = yaml_split(query_landing_page)
|
107
|
+
pieces[2] = pieces[2].chomp
|
108
|
+
metadata = pieces[1, 3].join("\n")
|
109
|
+
query_landing_page = pieces[4]
|
131
110
|
end
|
132
|
-
|
133
|
-
contents = @graphql_operations_template.result(OpenStruct.new(opts).instance_eval { binding })
|
134
|
-
write_file('operation', 'query', metadata + contents)
|
135
|
-
return true
|
111
|
+
query_type[:description] = query_landing_page
|
136
112
|
end
|
113
|
+
opts = default_generator_options(type: query_type)
|
114
|
+
contents = @graphql_operations_template.result(OpenStruct.new(opts).instance_eval { binding })
|
115
|
+
write_file('operation', 'query', metadata + contents)
|
116
|
+
return true
|
137
117
|
end
|
138
118
|
false
|
139
119
|
end
|
@@ -229,7 +209,7 @@ module GraphQLDocs
|
|
229
209
|
FileUtils.mkdir_p(path)
|
230
210
|
end
|
231
211
|
|
232
|
-
if
|
212
|
+
if yaml?(contents)
|
233
213
|
# Split data
|
234
214
|
meta, contents = split_into_metadata_and_contents(contents)
|
235
215
|
@options = @options.merge(meta)
|
data/lib/graphql-docs/helpers.rb
CHANGED
@@ -10,7 +10,7 @@ module GraphQLDocs
|
|
10
10
|
|
11
11
|
def slugify(str)
|
12
12
|
slug = str.gsub(SLUGIFY_PRETTY_REGEXP, '-')
|
13
|
-
slug.gsub!(
|
13
|
+
slug.gsub!(/^\-|\-$/i, '')
|
14
14
|
slug.downcase
|
15
15
|
end
|
16
16
|
|
@@ -22,6 +22,7 @@ module GraphQLDocs
|
|
22
22
|
|
23
23
|
def markdownify(string)
|
24
24
|
return '' if string.nil?
|
25
|
+
|
25
26
|
type = @options[:pipeline_config][:context][:unsafe] ? :UNSAFE : :DEFAULT
|
26
27
|
::CommonMarker.render_html(string, type).strip
|
27
28
|
end
|
@@ -67,27 +68,23 @@ module GraphQLDocs
|
|
67
68
|
end
|
68
69
|
|
69
70
|
def split_into_metadata_and_contents(contents, parse: true)
|
70
|
-
opts = {}
|
71
71
|
pieces = yaml_split(contents)
|
72
|
-
if pieces.size < 4
|
73
|
-
|
74
|
-
"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.",
|
75
|
-
)
|
76
|
-
end
|
72
|
+
raise "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." if pieces.size < 4
|
73
|
+
|
77
74
|
# Parse
|
78
75
|
begin
|
79
|
-
if parse
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
76
|
+
meta = if parse
|
77
|
+
YAML.safe_load(pieces[2]) || {}
|
78
|
+
else
|
79
|
+
pieces[2]
|
80
|
+
end
|
84
81
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
85
82
|
raise "Could not parse YAML for #{name}: #{e.message}"
|
86
83
|
end
|
87
84
|
[meta, pieces[4]]
|
88
85
|
end
|
89
86
|
|
90
|
-
def
|
87
|
+
def yaml?(contents)
|
91
88
|
contents =~ /\A-{3,5}\s*$/
|
92
89
|
end
|
93
90
|
|
@@ -114,6 +111,7 @@ module GraphQLDocs
|
|
114
111
|
|
115
112
|
Helpers.instance_methods.each do |name|
|
116
113
|
next if name == :helper_methods
|
114
|
+
|
117
115
|
@helper_methods[name] = method(name)
|
118
116
|
end
|
119
117
|
|
data/lib/graphql-docs/parser.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'graphql'
|
3
4
|
|
4
5
|
module GraphQLDocs
|
@@ -10,13 +11,13 @@ module GraphQLDocs
|
|
10
11
|
def initialize(schema, options)
|
11
12
|
@options = options
|
12
13
|
|
13
|
-
@options[:notices] ||= ->
|
14
|
+
@options[:notices] ||= ->(_schema_member_path) { [] }
|
14
15
|
|
15
|
-
if schema.is_a?(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
@schema = if schema.is_a?(String)
|
17
|
+
GraphQL::Schema.from_definition(schema)
|
18
|
+
elsif schema < GraphQL::Schema
|
19
|
+
schema
|
20
|
+
end
|
20
21
|
|
21
22
|
@processed_schema = {
|
22
23
|
operation_types: [],
|
@@ -27,81 +28,71 @@ module GraphQLDocs
|
|
27
28
|
union_types: [],
|
28
29
|
input_object_types: [],
|
29
30
|
scalar_types: [],
|
30
|
-
directive_types: []
|
31
|
+
directive_types: []
|
31
32
|
}
|
32
33
|
end
|
33
34
|
|
34
35
|
def parse
|
35
|
-
|
36
36
|
root_types = {}
|
37
|
-
[
|
38
|
-
unless @schema.root_type_for_operation(operation).nil?
|
39
|
-
root_types[operation] = @schema.root_type_for_operation(operation).name
|
40
|
-
end
|
37
|
+
%w[query mutation].each do |operation|
|
38
|
+
root_types[operation] = @schema.root_type_for_operation(operation).graphql_name unless @schema.root_type_for_operation(operation).nil?
|
41
39
|
end
|
42
40
|
@processed_schema[:root_types] = root_types
|
43
41
|
|
44
42
|
@schema.types.each_value do |object|
|
45
43
|
data = {}
|
46
44
|
|
47
|
-
data[:notices] = @options[:notices].call(object.
|
45
|
+
data[:notices] = @options[:notices].call(object.graphql_name)
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
data[:name] = object.name
|
53
|
-
data[:description] = object.description
|
47
|
+
if object < ::GraphQL::Schema::Object
|
48
|
+
data[:name] = object.graphql_name
|
49
|
+
data[:description] = object.description
|
54
50
|
|
55
|
-
|
56
|
-
data[:
|
51
|
+
if data[:name] == root_types['query']
|
52
|
+
data[:interfaces] = object.interfaces.map(&:graphql_name).sort
|
53
|
+
data[:fields], data[:connections] = fetch_fields(object.fields, object.graphql_name)
|
57
54
|
|
58
55
|
@processed_schema[:operation_types] << data
|
59
|
-
elsif
|
60
|
-
data[:name] = object.name
|
61
|
-
data[:description] = object.description
|
62
|
-
|
56
|
+
elsif data[:name] == root_types['mutation']
|
63
57
|
@processed_schema[:operation_types] << data
|
64
58
|
|
65
59
|
object.fields.each_value do |mutation|
|
66
60
|
h = {}
|
67
61
|
|
68
|
-
h[:notices] = @options[:notices].call([object.
|
69
|
-
h[:name] = mutation.
|
62
|
+
h[:notices] = @options[:notices].call([object.graphql_name, mutation.graphql_name].join('.'))
|
63
|
+
h[:name] = mutation.graphql_name
|
70
64
|
h[:description] = mutation.description
|
71
|
-
h[:input_fields],
|
65
|
+
h[:input_fields], = fetch_fields(mutation.arguments, [object.graphql_name, mutation.graphql_name].join('.'))
|
72
66
|
|
73
67
|
return_type = mutation.type
|
74
68
|
if return_type.unwrap.respond_to?(:fields)
|
75
|
-
h[:return_fields],
|
69
|
+
h[:return_fields], = fetch_fields(return_type.unwrap.fields, return_type.graphql_name)
|
76
70
|
else # it is a scalar return type
|
77
|
-
h[:return_fields],
|
71
|
+
h[:return_fields], = fetch_fields({ return_type.graphql_name => mutation }, return_type.graphql_name)
|
78
72
|
end
|
79
73
|
|
80
74
|
@processed_schema[:mutation_types] << h
|
81
75
|
end
|
82
76
|
else
|
83
|
-
data[:
|
84
|
-
data[:
|
85
|
-
|
86
|
-
data[:interfaces] = object.interfaces.map(&:name).sort
|
87
|
-
data[:fields], data[:connections] = fetch_fields(object.fields, object.name)
|
77
|
+
data[:interfaces] = object.interfaces.map(&:graphql_name).sort
|
78
|
+
data[:fields], data[:connections] = fetch_fields(object.fields, object.graphql_name)
|
88
79
|
|
89
80
|
@processed_schema[:object_types] << data
|
90
81
|
end
|
91
|
-
|
92
|
-
data[:name] = object.
|
82
|
+
elsif object < ::GraphQL::Schema::Interface
|
83
|
+
data[:name] = object.graphql_name
|
93
84
|
data[:description] = object.description
|
94
|
-
data[:fields], data[:connections] = fetch_fields(object.fields, object.
|
85
|
+
data[:fields], data[:connections] = fetch_fields(object.fields, object.graphql_name)
|
95
86
|
|
96
87
|
@processed_schema[:interface_types] << data
|
97
|
-
|
98
|
-
data[:name] = object.
|
88
|
+
elsif object < ::GraphQL::Schema::Enum
|
89
|
+
data[:name] = object.graphql_name
|
99
90
|
data[:description] = object.description
|
100
91
|
|
101
92
|
data[:values] = object.values.values.map do |val|
|
102
93
|
h = {}
|
103
|
-
h[:notices] = @options[:notices].call([object.
|
104
|
-
h[:name] = val.
|
94
|
+
h[:notices] = @options[:notices].call([object.graphql_name, val.graphql_name].join('.'))
|
95
|
+
h[:name] = val.graphql_name
|
105
96
|
h[:description] = val.description
|
106
97
|
unless val.deprecation_reason.nil?
|
107
98
|
h[:is_deprecated] = true
|
@@ -111,38 +102,38 @@ module GraphQLDocs
|
|
111
102
|
end
|
112
103
|
|
113
104
|
@processed_schema[:enum_types] << data
|
114
|
-
|
115
|
-
data[:name] = object.
|
105
|
+
elsif object < ::GraphQL::Schema::Union
|
106
|
+
data[:name] = object.graphql_name
|
116
107
|
data[:description] = object.description
|
117
|
-
data[:possible_types] = object.possible_types.map(&:
|
108
|
+
data[:possible_types] = object.possible_types.map(&:graphql_name).sort
|
118
109
|
|
119
110
|
@processed_schema[:union_types] << data
|
120
|
-
|
121
|
-
data[:name] = object.
|
111
|
+
elsif object < GraphQL::Schema::InputObject
|
112
|
+
data[:name] = object.graphql_name
|
122
113
|
data[:description] = object.description
|
123
114
|
|
124
|
-
data[:input_fields],
|
115
|
+
data[:input_fields], = fetch_fields(object.arguments, object.graphql_name)
|
125
116
|
|
126
117
|
@processed_schema[:input_object_types] << data
|
127
|
-
|
128
|
-
data[:name] = object.
|
118
|
+
elsif object < GraphQL::Schema::Scalar
|
119
|
+
data[:name] = object.graphql_name
|
129
120
|
data[:description] = object.description
|
130
121
|
|
131
122
|
@processed_schema[:scalar_types] << data
|
132
123
|
else
|
133
|
-
raise TypeError, "I'm not sure what #{object.class} is!"
|
124
|
+
raise TypeError, "I'm not sure what #{object.class} < #{object.superclass.name} is!"
|
134
125
|
end
|
135
126
|
end
|
136
127
|
|
137
128
|
@schema.directives.each_value do |directive|
|
138
129
|
data = {}
|
139
|
-
data[:notices] = @options[:notices].call(directive.
|
130
|
+
data[:notices] = @options[:notices].call(directive.graphql_name)
|
140
131
|
|
141
|
-
data[:name] = directive.
|
132
|
+
data[:name] = directive.graphql_name
|
142
133
|
data[:description] = directive.description
|
143
134
|
data[:locations] = directive.locations
|
144
135
|
|
145
|
-
data[:arguments],
|
136
|
+
data[:arguments], = fetch_fields(directive.arguments, directive.graphql_name)
|
146
137
|
|
147
138
|
@processed_schema[:directive_types] << data
|
148
139
|
end
|
@@ -152,9 +143,7 @@ module GraphQLDocs
|
|
152
143
|
@processed_schema[:interface_types].each do |interface|
|
153
144
|
interface[:implemented_by] = []
|
154
145
|
@processed_schema[:object_types].each do |obj|
|
155
|
-
if obj[:interfaces].include?(interface[:name])
|
156
|
-
interface[:implemented_by] << obj[:name]
|
157
|
-
end
|
146
|
+
interface[:implemented_by] << obj[:name] if obj[:interfaces].include?(interface[:name])
|
158
147
|
end
|
159
148
|
end
|
160
149
|
|
@@ -170,8 +159,8 @@ module GraphQLDocs
|
|
170
159
|
object_fields.each_value do |field|
|
171
160
|
hash = {}
|
172
161
|
|
173
|
-
hash[:notices] = @options[:notices].call([parent_path, field.
|
174
|
-
hash[:name] = field.
|
162
|
+
hash[:notices] = @options[:notices].call([parent_path, field.graphql_name].join('.'))
|
163
|
+
hash[:name] = field.graphql_name
|
175
164
|
hash[:description] = field.description
|
176
165
|
if field.respond_to?(:deprecation_reason) && !field.deprecation_reason.nil?
|
177
166
|
hash[:is_deprecated] = true
|
@@ -184,17 +173,15 @@ module GraphQLDocs
|
|
184
173
|
if field.respond_to?(:arguments)
|
185
174
|
field.arguments.each_value do |arg|
|
186
175
|
h = {}
|
187
|
-
h[:name] = arg.
|
176
|
+
h[:name] = arg.graphql_name
|
188
177
|
h[:description] = arg.description
|
189
178
|
h[:type] = generate_type(arg.type)
|
190
|
-
if arg.default_value?
|
191
|
-
h[:default_value] = arg.default_value
|
192
|
-
end
|
179
|
+
h[:default_value] = arg.default_value if arg.default_value?
|
193
180
|
hash[:arguments] << h
|
194
181
|
end
|
195
182
|
end
|
196
183
|
|
197
|
-
if !argument?(field) &&
|
184
|
+
if !argument?(field) && connection?(field)
|
198
185
|
connections << hash
|
199
186
|
else
|
200
187
|
fields << hash
|
@@ -205,42 +192,48 @@ module GraphQLDocs
|
|
205
192
|
end
|
206
193
|
|
207
194
|
def generate_type(type)
|
208
|
-
name = type.unwrap.
|
209
|
-
|
210
|
-
|
195
|
+
name = type.unwrap.graphql_name
|
196
|
+
|
197
|
+
path = if type.unwrap < GraphQL::Schema::Object
|
211
198
|
if name == 'Query'
|
212
199
|
'operation'
|
213
200
|
else
|
214
201
|
'object'
|
215
202
|
end
|
216
|
-
|
203
|
+
elsif type.unwrap < GraphQL::Schema::Scalar
|
217
204
|
'scalar'
|
218
|
-
|
205
|
+
elsif type.unwrap < GraphQL::Schema::Interface
|
219
206
|
'interface'
|
220
|
-
|
207
|
+
elsif type.unwrap < GraphQL::Schema::Enum
|
221
208
|
'enum'
|
222
|
-
|
209
|
+
elsif type.unwrap < GraphQL::Schema::InputObject
|
223
210
|
'input_object'
|
224
|
-
|
211
|
+
elsif type.unwrap < GraphQL::Schema::Union
|
225
212
|
'union'
|
226
213
|
else
|
227
|
-
raise TypeError, "Unknown type
|
214
|
+
raise TypeError, "Unknown type for `#{name}`: `#{type.unwrap.class}`"
|
228
215
|
end
|
229
216
|
|
230
217
|
{
|
231
218
|
name: name,
|
232
|
-
path: path
|
233
|
-
info: type.
|
219
|
+
path: "#{path}/#{slugify(name)}",
|
220
|
+
info: type.to_type_signature
|
234
221
|
}
|
235
222
|
end
|
236
223
|
|
237
224
|
def argument?(field)
|
238
|
-
field.is_a?(::GraphQL::Argument)
|
225
|
+
field.is_a?(::GraphQL::Schema::Argument)
|
226
|
+
end
|
227
|
+
|
228
|
+
def connection?(field)
|
229
|
+
field.respond_to?(:connection?) && field.connection?
|
239
230
|
end
|
240
231
|
|
241
232
|
def sort_by_name!
|
242
233
|
@processed_schema.each_pair do |key, value|
|
243
|
-
next if
|
234
|
+
next if value.empty?
|
235
|
+
next if %i[operation_types root_types].include?(key)
|
236
|
+
|
244
237
|
value.sort_by! { |o| o[:name] }
|
245
238
|
end
|
246
239
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'html/pipeline'
|
3
4
|
require 'yaml'
|
4
5
|
require 'extended-markdown-filter'
|
@@ -13,9 +14,7 @@ module GraphQLDocs
|
|
13
14
|
@parsed_schema = parsed_schema
|
14
15
|
@options = options
|
15
16
|
|
16
|
-
unless @options[:templates][:default].nil?
|
17
|
-
@graphql_default_layout = ERB.new(File.read(@options[:templates][:default]))
|
18
|
-
end
|
17
|
+
@graphql_default_layout = ERB.new(File.read(@options[:templates][:default])) unless @options[:templates][:default].nil?
|
19
18
|
|
20
19
|
@pipeline_config = @options[:pipeline_config] || {}
|
21
20
|
pipeline = @pipeline_config[:pipeline] || {}
|
@@ -40,10 +39,11 @@ module GraphQLDocs
|
|
40
39
|
end
|
41
40
|
|
42
41
|
def render(contents, type: nil, name: nil, filename: nil)
|
43
|
-
opts = { base_url: @options[:base_url], output_dir: @options[:output_dir] }.merge({ type: type, name: name, filename: filename}).merge(helper_methods)
|
42
|
+
opts = { base_url: @options[:base_url], output_dir: @options[:output_dir] }.merge({ type: type, name: name, filename: filename }).merge(helper_methods)
|
44
43
|
|
45
44
|
contents = to_html(contents, context: { filename: filename })
|
46
45
|
return contents if @graphql_default_layout.nil?
|
46
|
+
|
47
47
|
opts[:content] = contents
|
48
48
|
@graphql_default_layout.result(OpenStruct.new(opts).instance_eval { binding })
|
49
49
|
end
|
@@ -54,12 +54,12 @@ module GraphQLDocs
|
|
54
54
|
|
55
55
|
private
|
56
56
|
|
57
|
-
def filter_key(
|
58
|
-
|
57
|
+
def filter_key(str)
|
58
|
+
str.downcase
|
59
59
|
end
|
60
60
|
|
61
|
-
def filter?(
|
62
|
-
|
61
|
+
def filter?(filter)
|
62
|
+
filter < HTML::Pipeline::Filter
|
63
63
|
rescue LoadError, ArgumentError
|
64
64
|
false
|
65
65
|
end
|
data/lib/graphql-docs/version.rb
CHANGED
data/lib/graphql-docs.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'graphql-docs/helpers'
|
3
4
|
require 'graphql-docs/renderer'
|
4
5
|
require 'graphql-docs/configuration'
|
@@ -9,19 +10,16 @@ require 'graphql-docs/version'
|
|
9
10
|
begin
|
10
11
|
require 'awesome_print'
|
11
12
|
require 'pry'
|
12
|
-
rescue LoadError; end
|
13
|
-
|
13
|
+
rescue LoadError; end # rubocop:disable Lint/SuppressedException
|
14
14
|
module GraphQLDocs
|
15
15
|
class << self
|
16
16
|
def build(options)
|
17
17
|
# do not let user provided values overwrite every single value
|
18
|
-
%i
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
18
|
+
%i[templates landing_pages].each do |opt|
|
19
|
+
next unless options.key?(opt)
|
20
|
+
|
21
|
+
GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS[opt].each_pair do |key, value|
|
22
|
+
options[opt][key] = value unless options[opt].key?(key)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
@@ -30,28 +28,18 @@ module GraphQLDocs
|
|
30
28
|
filename = options[:filename]
|
31
29
|
schema = options[:schema]
|
32
30
|
|
33
|
-
if !filename.nil? && !schema.nil?
|
34
|
-
raise ArgumentError, 'Pass in `filename` or `schema`, but not both!'
|
35
|
-
end
|
31
|
+
raise ArgumentError, 'Pass in `filename` or `schema`, but not both!' if !filename.nil? && !schema.nil?
|
36
32
|
|
37
|
-
if filename.nil? && schema.nil?
|
38
|
-
raise ArgumentError, 'Pass in either `filename` or `schema`'
|
39
|
-
end
|
33
|
+
raise ArgumentError, 'Pass in either `filename` or `schema`' if filename.nil? && schema.nil?
|
40
34
|
|
41
35
|
if filename
|
42
|
-
unless filename.is_a?(String)
|
43
|
-
raise TypeError, "Expected `String`, got `#{filename.class}`"
|
44
|
-
end
|
36
|
+
raise TypeError, "Expected `String`, got `#{filename.class}`" unless filename.is_a?(String)
|
45
37
|
|
46
|
-
unless File.exist?(filename)
|
47
|
-
raise ArgumentError, "#{filename} does not exist!"
|
48
|
-
end
|
38
|
+
raise ArgumentError, "#{filename} does not exist!" unless File.exist?(filename)
|
49
39
|
|
50
40
|
schema = File.read(filename)
|
51
41
|
else
|
52
|
-
if !schema.is_a?(String) && !
|
53
|
-
raise TypeError, "Expected `String` or `GraphQL::Schema`, got `#{schema.class}`"
|
54
|
-
end
|
42
|
+
raise TypeError, "Expected `String` or `GraphQL::Schema`, got `#{schema.class}`" if !schema.is_a?(String) && !schema_type?(schema)
|
55
43
|
|
56
44
|
schema = schema
|
57
45
|
end
|
@@ -63,5 +51,9 @@ module GraphQLDocs
|
|
63
51
|
|
64
52
|
generator.generate
|
65
53
|
end
|
54
|
+
|
55
|
+
private def schema_type?(object)
|
56
|
+
object.respond_to?(:ancestors) && object.ancestors.include?(GraphQL::Schema)
|
57
|
+
end
|
66
58
|
end
|
67
59
|
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: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.12'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.12'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: commonmarker
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,61 +39,61 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.16'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: escape_utils
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2
|
47
|
+
version: '1.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2
|
54
|
+
version: '1.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: extended-markdown-filter
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0.4'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: gemoji
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0
|
75
|
+
version: '3.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
82
|
+
version: '3.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: html-pipeline
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '2.9'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '2.9'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: sass
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -248,13 +248,14 @@ dependencies:
|
|
248
248
|
- - "~>"
|
249
249
|
- !ruby/object:Gem::Version
|
250
250
|
version: '2.3'
|
251
|
-
description:
|
251
|
+
description:
|
252
252
|
email:
|
253
253
|
- gjtorikian@gmail.com
|
254
254
|
executables: []
|
255
255
|
extensions: []
|
256
256
|
extra_rdoc_files: []
|
257
257
|
files:
|
258
|
+
- ".github/FUNDING.yml"
|
258
259
|
- ".gitignore"
|
259
260
|
- ".rubocop.yml"
|
260
261
|
- ".travis.yml"
|
@@ -339,7 +340,7 @@ homepage: https://github.com/gjtorikian/graphql-docs
|
|
339
340
|
licenses:
|
340
341
|
- MIT
|
341
342
|
metadata: {}
|
342
|
-
post_install_message:
|
343
|
+
post_install_message:
|
343
344
|
rdoc_options: []
|
344
345
|
require_paths:
|
345
346
|
- lib
|
@@ -354,9 +355,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
354
355
|
- !ruby/object:Gem::Version
|
355
356
|
version: '0'
|
356
357
|
requirements: []
|
357
|
-
|
358
|
-
|
359
|
-
signing_key:
|
358
|
+
rubygems_version: 3.2.33
|
359
|
+
signing_key:
|
360
360
|
specification_version: 4
|
361
361
|
summary: Easily generate beautiful documentation from your GraphQL schema.
|
362
362
|
test_files: []
|