graphql-docs 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Rakefile +5 -9
- data/graphql-docs.gemspec +2 -1
- data/lib/graphql-docs.rb +11 -1
- data/lib/graphql-docs/generator.rb +43 -30
- data/lib/graphql-docs/helpers.rb +4 -0
- data/lib/graphql-docs/parser.rb +11 -2
- data/lib/graphql-docs/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff2d6fddab0c0c4dd83298aa1137a5ff50565ed4
|
4
|
+
data.tar.gz: 5b5f461978561689bd4b4593f0e453c2e59cdff7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7235b43da05965859f48c16be81e18225d80cd0f2b0d22a4748d22803431bd9dedb10eaae485105d27455d45ff1f47e135bc0e55600e879a0d4a9fa1c9f2aeba
|
7
|
+
data.tar.gz: 0a00134d9c51cff577e7c499a7ec6d335eb2624842da704a23f7b55bbf7cad6df6765210e4dc80d961095bd4acbf0ace2b4da561039126cc95acac857ab8207e
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -14,18 +14,14 @@ end
|
|
14
14
|
|
15
15
|
task default: :test
|
16
16
|
|
17
|
-
Rake::Task[:test].enhance { Rake::Task[:html_proofer].invoke }
|
18
|
-
|
19
17
|
desc 'Invoke HTML-Proofer'
|
20
18
|
task :html_proofer do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
output_dir = File.join(File.dirname(__FILE__), 'output')
|
19
|
+
Rake::Task[:generate_sample].invoke('https://www.gjtorikian.com/graphql-docs')
|
20
|
+
require 'html-proofer'
|
21
|
+
output_dir = File.join(File.dirname(__FILE__), 'output')
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
23
|
+
proofer_options = { disable_external: true, assume_extension: true }
|
24
|
+
HTMLProofer.check_directory(output_dir, proofer_options).run
|
29
25
|
end
|
30
26
|
|
31
27
|
desc 'Set up a console'
|
data/graphql-docs.gemspec
CHANGED
@@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'graphql', '~> 1.6'
|
24
24
|
|
25
25
|
# rendering
|
26
|
-
spec.add_dependency 'html-pipeline', '~> 2.
|
26
|
+
spec.add_dependency 'html-pipeline', '~> 2.8'
|
27
|
+
spec.add_dependency 'escape_utils', '~> 1.2'
|
27
28
|
spec.add_dependency 'extended-markdown-filter', '~> 0.4'
|
28
29
|
spec.add_dependency 'gemoji', '~> 3.0'
|
29
30
|
spec.add_dependency 'sass', '~> 3.4'
|
data/lib/graphql-docs.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# rubocop:disable Naming/FileName
|
2
1
|
require 'graphql-docs/helpers'
|
3
2
|
require 'graphql-docs/renderer'
|
4
3
|
require 'graphql-docs/configuration'
|
@@ -14,6 +13,17 @@ rescue LoadError; end
|
|
14
13
|
module GraphQLDocs
|
15
14
|
class << self
|
16
15
|
def build(options)
|
16
|
+
# do not let user provided values overwrite every single value
|
17
|
+
%i(templates landing_pages).each do |opt|
|
18
|
+
if options.key?(opt)
|
19
|
+
GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS[opt].each_pair do |key, value|
|
20
|
+
unless options[opt].key?(key)
|
21
|
+
options[opt][key] = value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
17
27
|
options = GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS.merge(options)
|
18
28
|
|
19
29
|
filename = options[:filename]
|
@@ -13,20 +13,27 @@ module GraphQLDocs
|
|
13
13
|
|
14
14
|
@renderer = @options[:renderer].new(@parsed_schema, @options)
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
%i(operations objects mutations interfaces enums unions input_objects scalars).each do |sym|
|
17
|
+
if !File.exist?(@options[:templates][sym])
|
18
|
+
raise IOError, "`#{sym}` template #{@options[:templates][sym]} was not found"
|
19
|
+
end
|
20
|
+
instance_variable_set("@graphql_#{sym}_template", ERB.new(File.read(@options[:templates][sym])))
|
21
|
+
end
|
22
|
+
|
23
|
+
%i(index object query mutation interface enum union input_object scalar).each do |sym|
|
24
|
+
if @options[:landing_pages][sym].nil?
|
25
|
+
instance_variable_set("@#{sym}_landing_page", nil)
|
26
|
+
elsif !File.exist?(@options[:landing_pages][sym])
|
27
|
+
raise IOError, "`#{sym}` landing page #{@options[:landing_pages][sym]} was not found"
|
28
|
+
end
|
29
|
+
instance_variable_set("@graphql_#{sym}_landing_page", File.read(@options[:landing_pages][sym]))
|
30
|
+
end
|
24
31
|
end
|
25
32
|
|
26
33
|
def generate
|
27
34
|
FileUtils.rm_rf(@options[:output_dir]) if @options[:delete_output]
|
28
35
|
|
29
|
-
|
36
|
+
has_query = create_graphql_query_pages
|
30
37
|
create_graphql_object_pages
|
31
38
|
create_graphql_mutation_pages
|
32
39
|
create_graphql_interface_pages
|
@@ -35,36 +42,40 @@ module GraphQLDocs
|
|
35
42
|
create_graphql_input_object_pages
|
36
43
|
create_graphql_scalar_pages
|
37
44
|
|
38
|
-
unless @
|
39
|
-
write_file('static', 'index',
|
45
|
+
unless @graphql_index_landing_page.nil?
|
46
|
+
write_file('static', 'index', @graphql_index_landing_page, trim: false)
|
47
|
+
end
|
48
|
+
|
49
|
+
unless @graphql_object_landing_page.nil?
|
50
|
+
write_file('static', 'object', @graphql_object_landing_page, trim: false)
|
40
51
|
end
|
41
52
|
|
42
|
-
|
43
|
-
write_file('
|
53
|
+
if !@graphql_query_landing_page.nil? && !has_query
|
54
|
+
write_file('operation', 'query', @graphql_query_landing_page, trim: false)
|
44
55
|
end
|
45
56
|
|
46
|
-
unless @
|
47
|
-
write_file('operation', 'mutation',
|
57
|
+
unless @graphql_mutation_landing_page.nil?
|
58
|
+
write_file('operation', 'mutation', @graphql_mutation_landing_page, trim: false)
|
48
59
|
end
|
49
60
|
|
50
|
-
unless @
|
51
|
-
write_file('static', 'interface',
|
61
|
+
unless @graphql_interface_landing_page.nil?
|
62
|
+
write_file('static', 'interface', @graphql_interface_landing_page, trim: false)
|
52
63
|
end
|
53
64
|
|
54
|
-
unless @
|
55
|
-
write_file('static', 'enum',
|
65
|
+
unless @graphql_enum_landing_page.nil?
|
66
|
+
write_file('static', 'enum', @graphql_enum_landing_page, trim: false)
|
56
67
|
end
|
57
68
|
|
58
|
-
unless @
|
59
|
-
write_file('static', 'union',
|
69
|
+
unless @graphql_union_landing_page.nil?
|
70
|
+
write_file('static', 'union', @graphql_union_landing_page, trim: false)
|
60
71
|
end
|
61
72
|
|
62
|
-
unless @
|
63
|
-
write_file('static', 'input_object',
|
73
|
+
unless @graphql_input_object_landing_page.nil?
|
74
|
+
write_file('static', 'input_object', @graphql_input_object_landing_page, trim: false)
|
64
75
|
end
|
65
76
|
|
66
|
-
unless @
|
67
|
-
write_file('static', 'scalar',
|
77
|
+
unless @graphql_scalar_landing_page.nil?
|
78
|
+
write_file('static', 'scalar', @graphql_scalar_landing_page, trim: false)
|
68
79
|
end
|
69
80
|
|
70
81
|
if @options[:use_default_styles]
|
@@ -81,10 +92,10 @@ module GraphQLDocs
|
|
81
92
|
true
|
82
93
|
end
|
83
94
|
|
84
|
-
def
|
95
|
+
def create_graphql_query_pages
|
85
96
|
graphql_operation_types.each do |query_type|
|
86
97
|
metadata = ''
|
87
|
-
if query_type[:name] == '
|
98
|
+
if query_type[:name] == graphql_root_types['query']
|
88
99
|
unless @options[:landing_pages][:query].nil?
|
89
100
|
query_landing_page = @options[:landing_pages][:query]
|
90
101
|
query_landing_page = File.read(query_landing_page)
|
@@ -97,17 +108,19 @@ module GraphQLDocs
|
|
97
108
|
query_type[:description] = query_landing_page
|
98
109
|
end
|
99
110
|
opts = default_generator_options(type: query_type)
|
100
|
-
contents = @
|
101
|
-
write_file('operation',
|
111
|
+
contents = @graphql_operations_template.result(OpenStruct.new(opts).instance_eval { binding })
|
112
|
+
write_file('operation', 'query', metadata + contents)
|
113
|
+
return true
|
102
114
|
end
|
103
115
|
end
|
116
|
+
false
|
104
117
|
end
|
105
118
|
|
106
119
|
def create_graphql_object_pages
|
107
120
|
graphql_object_types.each do |object_type|
|
108
121
|
opts = default_generator_options(type: object_type)
|
109
122
|
|
110
|
-
contents = @
|
123
|
+
contents = @graphql_objects_template.result(OpenStruct.new(opts).instance_eval { binding })
|
111
124
|
write_file('object', object_type[:name], contents)
|
112
125
|
end
|
113
126
|
end
|
data/lib/graphql-docs/helpers.rb
CHANGED
data/lib/graphql-docs/parser.rb
CHANGED
@@ -30,6 +30,15 @@ module GraphQLDocs
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def parse
|
33
|
+
|
34
|
+
root_types = {}
|
35
|
+
['query', 'mutation'].each do |operation|
|
36
|
+
unless @schema.root_type_for_operation(operation).nil?
|
37
|
+
root_types[operation] = @schema.root_type_for_operation(operation).name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
@processed_schema[:root_types] = root_types
|
41
|
+
|
33
42
|
@schema.types.each_value do |object|
|
34
43
|
data = {}
|
35
44
|
|
@@ -37,7 +46,7 @@ module GraphQLDocs
|
|
37
46
|
|
38
47
|
case object
|
39
48
|
when ::GraphQL::ObjectType
|
40
|
-
if object.name == '
|
49
|
+
if object.name == root_types['query']
|
41
50
|
data[:name] = object.name
|
42
51
|
data[:description] = object.description
|
43
52
|
|
@@ -45,7 +54,7 @@ module GraphQLDocs
|
|
45
54
|
data[:fields], data[:connections] = fetch_fields(object.fields, object.name)
|
46
55
|
|
47
56
|
@processed_schema[:operation_types] << data
|
48
|
-
elsif object.name == '
|
57
|
+
elsif object.name == root_types['mutation']
|
49
58
|
data[:name] = object.name
|
50
59
|
data[:description] = object.description
|
51
60
|
|
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.
|
4
|
+
version: 1.4.1
|
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-
|
11
|
+
date: 2018-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -30,14 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '2.
|
33
|
+
version: '2.8'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '2.
|
40
|
+
version: '2.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: escape_utils
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: extended-markdown-filter
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|