graphql.rake 1.18 KB
Newer Older
Felipe Artur's avatar
Felipe Artur committed
1 2 3 4 5
# frozen_string_literal: true

return if Rails.env.production?

namespace :gitlab do
6 7
  OUTPUT_DIR = Rails.root.join("doc/api/graphql/reference")
  TEMPLATES_DIR = 'lib/gitlab/graphql/docs/templates/'
Felipe Artur's avatar
Felipe Artur committed
8 9 10 11 12 13

  namespace :graphql do
    desc 'GitLab | Generate GraphQL docs'
    task compile_docs: :environment do
      renderer = Gitlab::Graphql::Docs::Renderer.new(GitlabSchema.graphql_definition, render_options)

14
      renderer.write
Felipe Artur's avatar
Felipe Artur committed
15 16 17

      puts "Documentation compiled."
    end
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

    desc 'GitLab | Check if GraphQL docs are up to date'
    task check_docs: :environment do
      renderer = Gitlab::Graphql::Docs::Renderer.new(GitlabSchema.graphql_definition, render_options)

      doc = File.read(Rails.root.join(OUTPUT_DIR, 'index.md'))

      if doc == renderer.contents
        puts "GraphQL documentation is up to date"
      else
        puts '#' * 10
        puts '#'
        puts '# GraphQL documentation is outdated! Please update it by running `bundle exec rake gitlab:graphql:compile_docs`.'
        puts '#'
        puts '#' * 10
        abort
      end
    end
Felipe Artur's avatar
Felipe Artur committed
36 37 38 39 40 41 42 43 44
  end
end

def render_options
  {
    output_dir: OUTPUT_DIR,
    template: Rails.root.join(TEMPLATES_DIR, 'default.md.haml')
  }
end