graphql-docs 1.9.1 → 2.0.0

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: 5bba6b854ed7edf06f8d5f383a15f2d24e56f784ee54cfe48c0e9aa7470a8dc3
4
- data.tar.gz: 5e0462b0a186033b34df3dbaa0523154644eef123f790991cdd24cd0425f8b35
3
+ metadata.gz: d9b9b70c05ecb232880397c181cd1593365494c70726c0d83da63c1159bc35ef
4
+ data.tar.gz: 171b3e869c8820f2f60f2505b98219ac2e58d5381307af54f83834102f308dde
5
5
  SHA512:
6
- metadata.gz: '093882cba91b28c5334ff75d3f9feb8db412573282204c9986edab011c85c6abd62038470d6d3a6f95570e39e86d25e6554283912920f806c0cb82c8bc0db0e0'
7
- data.tar.gz: 746f84b3a9b4614cad61490b68ac6b5299a849b9e841705a8ff6fdc7918f1d50394697cbb76fe609ee9dd7388220b35d14a77e3e16187b376b8361945193d45f
6
+ metadata.gz: ac21056c981c54b771c34eefcc842947ce0d77f0e2150d5b060bd05248b02827d065a6b35bf2f5b8bab6b82b20ecb993dbbd255f8c17a0fb3f4ef0077f0dae43
7
+ data.tar.gz: 9dbd0479cebdaf5d9e1f3dd57729cc55cb6cc43d0bd26861fd8683a5f4b8be2355a810a04dd060597832fcf1d95d27eacf5f0aa9c825027bf0f7f1a8dc1935eb
@@ -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
@@ -3,10 +3,10 @@ language: ruby
3
3
  cache: bundler
4
4
 
5
5
  rvm:
6
- - 2.3.6
7
- - 2.4.3
8
- - 2.5.0
9
- - 2.6.0
6
+ - 2.4.9
7
+ - 2.5.7
8
+ - 2.6.5
9
+ - 2.7.0
10
10
 
11
11
  git:
12
12
  depth: 10
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  source 'https://rubygems.org'
3
4
 
4
5
  # Specify your gem's dependencies in graphql-docs.gemspec
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 =~ /\/graphql-docs\// }
35
+ files = $LOADED_FEATURES.select { |feat| feat =~ %r{/graphql-docs/} }
35
36
  files.each { |file| load file }
36
37
  end
37
38
 
@@ -46,7 +47,7 @@ task :generate_sample do
46
47
 
47
48
  options = {}
48
49
  options[:delete_output] = true
49
- options[:base_url] = '/graphql-docs'
50
+ options[:base_url] = ENV.fetch('GQL_DOCS_BASE_URL', '')
50
51
  options[:filename] = File.join(File.dirname(__FILE__), 'test', 'graphql-docs', 'fixtures', 'gh-schema.graphql')
51
52
 
52
53
  GraphQLDocs.build(options)
@@ -66,6 +67,7 @@ end
66
67
 
67
68
  desc 'Generate and publish docs to gh-pages'
68
69
  task :publish do
70
+ ENV['GQL_DOCS_BASE_URL'] = '/graphql-docs'
69
71
  Rake::Task[:generate_sample].invoke('https://www.gjtorikian.com/graphql-docs')
70
72
  Dir.mktmpdir do |tmp|
71
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
- lib = File.expand_path('../lib', __FILE__)
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.8'
24
+ spec.add_dependency 'graphql', '~> 1.10'
25
25
 
26
26
  # rendering
27
27
  spec.add_dependency 'commonmarker', '~> 0.16'
28
- spec.add_dependency 'html-pipeline', '~> 2.9'
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'
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(templates landing_pages).each do |opt|
19
- if options.key?(opt)
20
- GraphQLDocs::Configuration::GRAPHQLDOCS_DEFAULTS[opt].each_pair do |key, value|
21
- unless options[opt].key?(key)
22
- options[opt][key] = value
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) && !schema.is_a?(GraphQL::Schema)
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
@@ -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(ExtendedMarkdownFilter
15
- EmojiFilter
16
- TableOfContentsFilter),
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(operations objects mutations interfaces enums unions input_objects scalars directives).each do |sym|
18
- if !File.exist?(@options[:templates][sym])
19
- raise IOError, "`#{sym}` template #{@options[:templates][sym]} was not found"
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(index object query mutation interface enum union input_object scalar directive).each do |sym|
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 has_yaml?(landing_page_contents)
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
- if query_type[:name] == graphql_root_types['query']
121
- unless @options[:landing_pages][:query].nil?
122
- query_landing_page = @options[:landing_pages][:query]
123
- query_landing_page = File.read(query_landing_page)
124
- if has_yaml?(query_landing_page)
125
- pieces = yaml_split(query_landing_page)
126
- pieces[2] = pieces[2].chomp
127
- metadata = pieces[1, 3].join("\n")
128
- query_landing_page = pieces[4]
129
- end
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
- opts = default_generator_options(type: query_type)
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 has_yaml?(contents)
212
+ if yaml?(contents)
233
213
  # Split data
234
214
  meta, contents = split_into_metadata_and_contents(contents)
235
215
  @options = @options.merge(meta)
@@ -10,7 +10,7 @@ module GraphQLDocs
10
10
 
11
11
  def slugify(str)
12
12
  slug = str.gsub(SLUGIFY_PRETTY_REGEXP, '-')
13
- slug.gsub!(%r!^\-|\-$!i, '')
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
- raise RuntimeError.new(
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
- meta = YAML.load(pieces[2]) || {}
81
- else
82
- meta = pieces[2]
83
- end
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 has_yaml?(contents)
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
 
@@ -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] ||= -> (schema_member_path) { [] }
14
+ @options[:notices] ||= ->(_schema_member_path) { [] }
14
15
 
15
- if schema.is_a?(GraphQL::Schema)
16
- @schema = schema
17
- else
18
- @schema = GraphQL::Schema.from_definition(schema)
19
- end
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,80 +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
  root_types = {}
36
- ['query', 'mutation'].each do |operation|
37
- unless @schema.root_type_for_operation(operation).nil?
38
- root_types[operation] = @schema.root_type_for_operation(operation).name
39
- 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?
40
39
  end
41
40
  @processed_schema[:root_types] = root_types
42
41
 
43
42
  @schema.types.each_value do |object|
44
43
  data = {}
45
44
 
46
- data[:notices] = @options[:notices].call(object.name)
45
+ data[:notices] = @options[:notices].call(object.graphql_name)
47
46
 
48
- case object
49
- when ::GraphQL::ObjectType
50
- if object.name == root_types['query']
51
- data[:name] = object.name
52
- data[:description] = object.description
47
+ if object < ::GraphQL::Schema::Object
48
+ data[:name] = object.graphql_name
49
+ data[:description] = object.description
53
50
 
54
- data[:interfaces] = object.interfaces.map(&:name).sort
55
- data[:fields], data[:connections] = fetch_fields(object.fields, object.name)
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)
56
54
 
57
55
  @processed_schema[:operation_types] << data
58
- elsif object.name == root_types['mutation']
59
- data[:name] = object.name
60
- data[:description] = object.description
61
-
56
+ elsif data[:name] == root_types['mutation']
62
57
  @processed_schema[:operation_types] << data
63
58
 
64
59
  object.fields.each_value do |mutation|
65
60
  h = {}
66
61
 
67
- h[:notices] = @options[:notices].call([object.name, mutation.name].join('.'))
68
- h[:name] = mutation.name
62
+ h[:notices] = @options[:notices].call([object.graphql_name, mutation.graphql_name].join('.'))
63
+ h[:name] = mutation.graphql_name
69
64
  h[:description] = mutation.description
70
- h[:input_fields], _ = fetch_fields(mutation.arguments, [object.name, mutation.name].join('.'))
65
+ h[:input_fields], = fetch_fields(mutation.arguments, [object.graphql_name, mutation.graphql_name].join('.'))
71
66
 
72
67
  return_type = mutation.type
73
68
  if return_type.unwrap.respond_to?(:fields)
74
- h[:return_fields], _ = fetch_fields(return_type.unwrap.fields, return_type.name)
69
+ h[:return_fields], = fetch_fields(return_type.unwrap.fields, return_type.graphql_name)
75
70
  else # it is a scalar return type
76
- h[:return_fields], _ = fetch_fields({ "#{return_type.name}" => mutation }, return_type.name)
71
+ h[:return_fields], = fetch_fields({ return_type.graphql_name => mutation }, return_type.graphql_name)
77
72
  end
78
73
 
79
74
  @processed_schema[:mutation_types] << h
80
75
  end
81
76
  else
82
- data[:name] = object.name
83
- data[:description] = object.description
84
-
85
- data[:interfaces] = object.interfaces.map(&:name).sort
86
- 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)
87
79
 
88
80
  @processed_schema[:object_types] << data
89
81
  end
90
- when ::GraphQL::InterfaceType
91
- data[:name] = object.name
82
+ elsif object < ::GraphQL::Schema::Interface
83
+ data[:name] = object.graphql_name
92
84
  data[:description] = object.description
93
- data[:fields], data[:connections] = fetch_fields(object.fields, object.name)
85
+ data[:fields], data[:connections] = fetch_fields(object.fields, object.graphql_name)
94
86
 
95
87
  @processed_schema[:interface_types] << data
96
- when ::GraphQL::EnumType
97
- data[:name] = object.name
88
+ elsif object < ::GraphQL::Schema::Enum
89
+ data[:name] = object.graphql_name
98
90
  data[:description] = object.description
99
91
 
100
92
  data[:values] = object.values.values.map do |val|
101
93
  h = {}
102
- h[:notices] = @options[:notices].call([object.name, val.name].join('.'))
103
- h[:name] = val.name
94
+ h[:notices] = @options[:notices].call([object.graphql_name, val.graphql_name].join('.'))
95
+ h[:name] = val.graphql_name
104
96
  h[:description] = val.description
105
97
  unless val.deprecation_reason.nil?
106
98
  h[:is_deprecated] = true
@@ -110,38 +102,38 @@ module GraphQLDocs
110
102
  end
111
103
 
112
104
  @processed_schema[:enum_types] << data
113
- when ::GraphQL::UnionType
114
- data[:name] = object.name
105
+ elsif object < ::GraphQL::Schema::Union
106
+ data[:name] = object.graphql_name
115
107
  data[:description] = object.description
116
- data[:possible_types] = object.possible_types.map(&:name).sort
108
+ data[:possible_types] = object.possible_types.map(&:graphql_name).sort
117
109
 
118
110
  @processed_schema[:union_types] << data
119
- when ::GraphQL::InputObjectType
120
- data[:name] = object.name
111
+ elsif object < GraphQL::Schema::InputObject
112
+ data[:name] = object.graphql_name
121
113
  data[:description] = object.description
122
114
 
123
- data[:input_fields], _ = fetch_fields(object.input_fields, object.name)
115
+ data[:input_fields], = fetch_fields(object.arguments, object.graphql_name)
124
116
 
125
117
  @processed_schema[:input_object_types] << data
126
- when ::GraphQL::ScalarType
127
- data[:name] = object.name
118
+ elsif object < GraphQL::Schema::Scalar
119
+ data[:name] = object.graphql_name
128
120
  data[:description] = object.description
129
121
 
130
122
  @processed_schema[:scalar_types] << data
131
123
  else
132
- raise TypeError, "I'm not sure what #{object.class} is!"
124
+ raise TypeError, "I'm not sure what #{object.class} < #{object.superclass.name} is!"
133
125
  end
134
126
  end
135
127
 
136
128
  @schema.directives.each_value do |directive|
137
129
  data = {}
138
- data[:notices] = @options[:notices].call(directive.name)
130
+ data[:notices] = @options[:notices].call(directive.graphql_name)
139
131
 
140
- data[:name] = directive.name
132
+ data[:name] = directive.graphql_name
141
133
  data[:description] = directive.description
142
134
  data[:locations] = directive.locations
143
135
 
144
- data[:arguments], _ = fetch_fields(directive.arguments, directive.name)
136
+ data[:arguments], = fetch_fields(directive.arguments, directive.graphql_name)
145
137
 
146
138
  @processed_schema[:directive_types] << data
147
139
  end
@@ -151,9 +143,7 @@ module GraphQLDocs
151
143
  @processed_schema[:interface_types].each do |interface|
152
144
  interface[:implemented_by] = []
153
145
  @processed_schema[:object_types].each do |obj|
154
- if obj[:interfaces].include?(interface[:name])
155
- interface[:implemented_by] << obj[:name]
156
- end
146
+ interface[:implemented_by] << obj[:name] if obj[:interfaces].include?(interface[:name])
157
147
  end
158
148
  end
159
149
 
@@ -169,8 +159,8 @@ module GraphQLDocs
169
159
  object_fields.each_value do |field|
170
160
  hash = {}
171
161
 
172
- hash[:notices] = @options[:notices].call([parent_path, field.name].join('.'))
173
- hash[:name] = field.name
162
+ hash[:notices] = @options[:notices].call([parent_path, field.graphql_name].join('.'))
163
+ hash[:name] = field.graphql_name
174
164
  hash[:description] = field.description
175
165
  if field.respond_to?(:deprecation_reason) && !field.deprecation_reason.nil?
176
166
  hash[:is_deprecated] = true
@@ -183,17 +173,15 @@ module GraphQLDocs
183
173
  if field.respond_to?(:arguments)
184
174
  field.arguments.each_value do |arg|
185
175
  h = {}
186
- h[:name] = arg.name
176
+ h[:name] = arg.graphql_name
187
177
  h[:description] = arg.description
188
178
  h[:type] = generate_type(arg.type)
189
- if arg.default_value?
190
- h[:default_value] = arg.default_value
191
- end
179
+ h[:default_value] = arg.default_value if arg.default_value?
192
180
  hash[:arguments] << h
193
181
  end
194
182
  end
195
183
 
196
- if !argument?(field) && field.connection?
184
+ if !argument?(field) && connection?(field)
197
185
  connections << hash
198
186
  else
199
187
  fields << hash
@@ -204,42 +192,48 @@ module GraphQLDocs
204
192
  end
205
193
 
206
194
  def generate_type(type)
207
- name = type.unwrap.to_s
208
- path = case type.unwrap
209
- when ::GraphQL::ObjectType
195
+ name = type.unwrap.graphql_name
196
+
197
+ path = if type.unwrap < GraphQL::Schema::Object
210
198
  if name == 'Query'
211
199
  'operation'
212
200
  else
213
201
  'object'
214
202
  end
215
- when ::GraphQL::ScalarType
203
+ elsif type.unwrap < GraphQL::Schema::Scalar
216
204
  'scalar'
217
- when ::GraphQL::InterfaceType
205
+ elsif type.unwrap < GraphQL::Schema::Interface
218
206
  'interface'
219
- when ::GraphQL::EnumType
207
+ elsif type.unwrap < GraphQL::Schema::Enum
220
208
  'enum'
221
- when ::GraphQL::InputObjectType
209
+ elsif type.unwrap < GraphQL::Schema::InputObject
222
210
  'input_object'
223
- when ::GraphQL::UnionType
211
+ elsif type.unwrap < GraphQL::Schema::Union
224
212
  'union'
225
213
  else
226
- raise TypeError, "Unknown type: `#{type.unwrap.class}`"
214
+ raise TypeError, "Unknown type for `#{name}`: `#{type.unwrap.class}`"
227
215
  end
228
216
 
229
217
  {
230
218
  name: name,
231
- path: path + '/' + slugify(name),
232
- info: type.to_s
219
+ path: "#{path}/#{slugify(name)}",
220
+ info: type.graphql_definition
233
221
  }
234
222
  end
235
223
 
236
224
  def argument?(field)
237
- 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?
238
230
  end
239
231
 
240
232
  def sort_by_name!
241
233
  @processed_schema.each_pair do |key, value|
242
- next if key == :operation_types || key == :root_types
234
+ next if value.empty?
235
+ next if %i[operation_types root_types].include?(key)
236
+
243
237
  value.sort_by! { |o| o[:name] }
244
238
  end
245
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(s)
58
- s.downcase
57
+ def filter_key(str)
58
+ str.downcase
59
59
  end
60
60
 
61
- def filter?(f)
62
- f < HTML::Pipeline::Filter
61
+ def filter?(filter)
62
+ filter < HTML::Pipeline::Filter
63
63
  rescue LoadError, ArgumentError
64
64
  false
65
65
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module GraphQLDocs
3
- VERSION = '1.9.1'.freeze
4
+ VERSION = '2.0.0'
4
5
  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.9.1
4
+ version: 2.0.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: 2019-09-02 00:00:00.000000000 Z
11
+ date: 2020-02-24 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.8'
19
+ version: '1.10'
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.8'
26
+ version: '1.10'
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: html-pipeline
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.9'
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.9'
54
+ version: '1.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: escape_utils
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: '1.2'
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: '1.2'
68
+ version: '0.4'
69
69
  - !ruby/object:Gem::Dependency
70
- name: extended-markdown-filter
70
+ name: gemoji
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.4'
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.4'
82
+ version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: gemoji
84
+ name: html-pipeline
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3.0'
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: '3.0'
96
+ version: '2.9'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sass
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -255,6 +255,7 @@ 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"
@@ -354,8 +355,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
354
355
  - !ruby/object:Gem::Version
355
356
  version: '0'
356
357
  requirements: []
357
- rubyforge_project:
358
- rubygems_version: 2.7.6
358
+ rubygems_version: 3.1.2
359
359
  signing_key:
360
360
  specification_version: 4
361
361
  summary: Easily generate beautiful documentation from your GraphQL schema.