2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
return if Rails.env.production?
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Graphql
|
|
|
|
module Docs
|
|
|
|
# Helper with functions to be used by HAML templates
|
|
|
|
# This includes graphql-docs gem helpers class.
|
|
|
|
# You can check the included module on: https://github.com/gjtorikian/graphql-docs/blob/v1.6.0/lib/graphql-docs/helpers.rb
|
|
|
|
module Helper
|
|
|
|
include GraphQLDocs::Helpers
|
|
|
|
|
|
|
|
def auto_generated_comment
|
|
|
|
<<-MD.strip_heredoc
|
|
|
|
<!---
|
|
|
|
This documentation is auto generated by a script.
|
|
|
|
|
|
|
|
Please do not edit this file directly, check compile_docs task on lib/tasks/gitlab/graphql.rake.
|
|
|
|
--->
|
|
|
|
MD
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def render_name_and_description(object)
|
|
|
|
content = "### #{object[:name]}\n"
|
|
|
|
|
|
|
|
if object[:description].present?
|
|
|
|
content += "\n#{object[:description]}.\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
content
|
|
|
|
end
|
|
|
|
|
|
|
|
def sorted_by_name(objects)
|
|
|
|
objects.sort_by { |o| o[:name] }
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def render_field(field)
|
|
|
|
'| %s | %s | %s |' % [
|
2020-11-24 15:15:51 +05:30
|
|
|
render_name(field),
|
2020-04-08 14:13:33 +05:30
|
|
|
render_field_type(field[:type][:info]),
|
2020-11-24 15:15:51 +05:30
|
|
|
render_description(field)
|
2020-04-08 14:13:33 +05:30
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def render_enum_value(value)
|
|
|
|
'| %s | %s |' % [
|
|
|
|
render_name(value),
|
|
|
|
render_description(value)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_name(object)
|
|
|
|
rendered_name = "`#{object[:name]}`"
|
|
|
|
rendered_name += ' **{warning-solid}**' if object[:is_deprecated]
|
2020-04-08 14:13:33 +05:30
|
|
|
rendered_name
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
# Returns the object description. If the object has been deprecated,
|
2020-04-08 14:13:33 +05:30
|
|
|
# the deprecation reason will be returned in place of the description.
|
2020-11-24 15:15:51 +05:30
|
|
|
def render_description(object)
|
|
|
|
return object[:description] unless object[:is_deprecated]
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
"**Deprecated:** #{object[:deprecation_reason]}"
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
# 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.
|
|
|
|
def render_field_type(type)
|
|
|
|
array_type = type[/\[(.+)\]/, 1]
|
|
|
|
|
|
|
|
if array_type
|
|
|
|
"#{array_type} => Array"
|
|
|
|
else
|
|
|
|
type
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# We are ignoring connections and built in types for now,
|
|
|
|
# they should be added when queries are generated.
|
|
|
|
def objects
|
|
|
|
graphql_object_types.select do |object_type|
|
|
|
|
!object_type[:name]["Connection"] &&
|
|
|
|
!object_type[:name]["Edge"] &&
|
|
|
|
!object_type[:name]["__"]
|
|
|
|
end
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
# We ignore the built-in enum types.
|
|
|
|
def enums
|
|
|
|
graphql_enum_types.select do |enum_type|
|
|
|
|
!enum_type[:name].in?(%w(__DirectiveLocation __TypeKind))
|
|
|
|
end
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|