Module: Gitlab::Graphql::Docs::Helper

Includes:
GraphQLDocs::Helpers
Included in:
Renderer
Defined in:
lib/gitlab/graphql/docs/helper.rb

Overview

Helper with functions to be used by HAML templates This includes graphql-docs gem helpers class. You can check the included module on: github.com/gjtorikian/graphql-docs/blob/v1.6.0/lib/graphql-docs/helpers.rb

Instance Method Summary collapse

Instance Method Details

#auto_generated_commentObject


14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/graphql/docs/helper.rb', line 14

def auto_generated_comment
  "<!---\nThis documentation is auto generated by a script.\n\nPlease do not edit this file directly, check compile_docs task on lib/tasks/gitlab/graphql.rake.\n--->\n".strip_heredoc
end

#enumsObject

We ignore the built-in enum types.


92
93
94
95
96
# File 'lib/gitlab/graphql/docs/helper.rb', line 92

def enums
  graphql_enum_types.select do |enum_type|
    !enum_type[:name].in?(%w(__DirectiveLocation __TypeKind))
  end
end

#objectsObject

We are ignoring connections and built in types for now, they should be added when queries are generated.


83
84
85
86
87
88
89
# File 'lib/gitlab/graphql/docs/helper.rb', line 83

def objects
  graphql_object_types.select do |object_type|
    !object_type[:name]["Connection"] &&
      !object_type[:name]["Edge"] &&
      !object_type[:name]["__"]
  end
end

#render_description(object) ⇒ Object

Returns the object description. If the object has been deprecated, the deprecation reason will be returned in place of the description.


61
62
63
64
65
# File 'lib/gitlab/graphql/docs/helper.rb', line 61

def render_description(object)
  return object[:description] unless object[:is_deprecated]

  "**Deprecated:** #{object[:deprecation_reason]}"
end

#render_enum_value(value) ⇒ Object


46
47
48
49
50
51
# File 'lib/gitlab/graphql/docs/helper.rb', line 46

def render_enum_value(value)
  '| %s | %s |' % [
    render_name(value),
    render_description(value)
    ]
end

#render_field(field) ⇒ Object


38
39
40
41
42
43
44
# File 'lib/gitlab/graphql/docs/helper.rb', line 38

def render_field(field)
  '| %s | %s | %s |' % [
    render_name(field),
    render_field_type(field[:type][:info]),
    render_description(field)
    ]
end

#render_field_type(type) ⇒ Object

Some fields types are arrays of other types and are displayed on docs wrapped in square brackets, for example: [String!]. This makes GitLab docs renderer thinks they are links so here we change them to be rendered as: String! => Array.


71
72
73
74
75
76
77
78
79
# File 'lib/gitlab/graphql/docs/helper.rb', line 71

def render_field_type(type)
  array_type = type[/\[(.+)\]/, 1]

  if array_type
    "#{array_type} => Array"
  else
    type
  end
end

#render_name(object) ⇒ Object


53
54
55
56
57
# File 'lib/gitlab/graphql/docs/helper.rb', line 53

def render_name(object)
  rendered_name = "`#{object[:name]}`"
  rendered_name += ' **{warning-solid}**' if object[:is_deprecated]
  rendered_name
end

#render_name_and_description(object) ⇒ Object


24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/graphql/docs/helper.rb', line 24

def render_name_and_description(object)
  content = "### #{object[:name]}\n"

  if object[:description].present?
    content += "\n#{object[:description]}\n"
  end

  content
end

#sorted_by_name(objects) ⇒ Object


34
35
36
# File 'lib/gitlab/graphql/docs/helper.rb', line 34

def sorted_by_name(objects)
  objects.sort_by { |o| o[:name] }
end