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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72ec410a12852586cbdf082b669fc6dc04a04883
4
- data.tar.gz: 604571380c7008a7b1e708a3b9063718d94123c6
3
+ metadata.gz: ff2d6fddab0c0c4dd83298aa1137a5ff50565ed4
4
+ data.tar.gz: 5b5f461978561689bd4b4593f0e453c2e59cdff7
5
5
  SHA512:
6
- metadata.gz: cafa5a5fd565c857dcb7564f32b3e669d9ead0c0f2ed9b9a294139ee01eb5d9dce34c79387e3d71b6be548f51e46c983cc3e10689e187a507284d5efc74ec5ee
7
- data.tar.gz: 679c13720eb0c6cc2aa9bdb6fed436beb9779d5d78336ac419471d9e11c6ef5b789effe8a79b8301ce2037ddb15be0de6615fde3ccb30a80befce09bbf6b5eff
6
+ metadata.gz: 7235b43da05965859f48c16be81e18225d80cd0f2b0d22a4748d22803431bd9dedb10eaae485105d27455d45ff1f47e135bc0e55600e879a0d4a9fa1c9f2aeba
7
+ data.tar.gz: 0a00134d9c51cff577e7c499a7ec6d335eb2624842da704a23f7b55bbf7cad6df6765210e4dc80d961095bd4acbf0ace2b4da561039126cc95acac857ab8207e
@@ -25,3 +25,5 @@ matrix:
25
25
  include:
26
26
  - script: bundle exec rake rubocop
27
27
  rvm: 2.5.0
28
+ - script: bundle exec rake html_proofer
29
+ rvm: 2.5.0
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
- if ENV['CI']
22
- Rake::Task[:generate_sample].invoke('https://www.gjtorikian.com/graphql-docs')
23
- require 'html-proofer'
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
- proofer_options = { disable_external: true, assume_extension: true }
27
- HTMLProofer.check_directory(output_dir, proofer_options).run
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'
@@ -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.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'
@@ -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
- @graphql_operation_template = ERB.new(File.read(@options[:templates][:operations]))
17
- @graphql_object_template = ERB.new(File.read(@options[:templates][:objects]))
18
- @graphql_mutations_template = ERB.new(File.read(@options[:templates][:mutations]))
19
- @graphql_interfaces_template = ERB.new(File.read(@options[:templates][:interfaces]))
20
- @graphql_enums_template = ERB.new(File.read(@options[:templates][:enums]))
21
- @graphql_unions_template = ERB.new(File.read(@options[:templates][:unions]))
22
- @graphql_input_objects_template = ERB.new(File.read(@options[:templates][:input_objects]))
23
- @graphql_scalars_template = ERB.new(File.read(@options[:templates][:scalars]))
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
- create_graphql_operation_pages
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 @options[:landing_pages][:index].nil?
39
- write_file('static', 'index', File.read(@options[:landing_pages][:index]), trim: false)
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
- unless @options[:landing_pages][:object].nil?
43
- write_file('static', 'object', File.read(@options[:landing_pages][:object]), trim: false)
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 @options[:landing_pages][:mutation].nil?
47
- write_file('operation', 'mutation', File.read(@options[:landing_pages][:mutation]), trim: false)
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 @options[:landing_pages][:interface].nil?
51
- write_file('static', 'interface', File.read(@options[:landing_pages][:interface]), trim: false)
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 @options[:landing_pages][:enum].nil?
55
- write_file('static', 'enum', File.read(@options[:landing_pages][:enum]), trim: false)
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 @options[:landing_pages][:union].nil?
59
- write_file('static', 'union', File.read(@options[:landing_pages][:union]), trim: false)
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 @options[:landing_pages][:input_object].nil?
63
- write_file('static', 'input_object', File.read(@options[:landing_pages][:input_object]), trim: false)
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 @options[:landing_pages][:scalar].nil?
67
- write_file('static', 'scalar', File.read(@options[:landing_pages][:scalar]), trim: false)
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 create_graphql_operation_pages
95
+ def create_graphql_query_pages
85
96
  graphql_operation_types.each do |query_type|
86
97
  metadata = ''
87
- if query_type[:name] == 'Query'
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 = @graphql_operation_template.result(OpenStruct.new(opts).instance_eval { binding })
101
- write_file('operation', query_type[:name], metadata + contents)
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 = @graphql_object_template.result(OpenStruct.new(opts).instance_eval { binding })
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
@@ -21,6 +21,10 @@ module GraphQLDocs
21
21
  ::CommonMarker.render_html(string, :DEFAULT).strip
22
22
  end
23
23
 
24
+ def graphql_root_types
25
+ @parsed_schema[:root_types] || []
26
+ end
27
+
24
28
  def graphql_operation_types
25
29
  @parsed_schema[:operation_types] || []
26
30
  end
@@ -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 == 'Query'
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 == 'Mutation'
57
+ elsif object.name == root_types['mutation']
49
58
  data[:name] = object.name
50
59
  data[:description] = object.description
51
60
 
@@ -1,3 +1,3 @@
1
1
  module GraphQLDocs
2
- VERSION = '1.4.0'
2
+ VERSION = '1.4.1'
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: 1.4.0
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-05-11 00:00:00.000000000 Z
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.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.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