From 406808583c2392a0b57f68f98b2418e9d23b23ab Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 20 Jun 2019 08:02:33 +0000 Subject: Render GFM html in GraphQL This adds a `markdown_field` to our types. Using this helper will render a model's markdown field using the existing `MarkupHelper` with the context of the GraphQL query available to the helper. Having the context available to the helper is needed for redacting links to resources that the current user is not allowed to see. Because rendering the HTML can cause queries, the complexity of a these fields is raised by 5 above the default. The markdown field helper can be used as follows: ``` markdown_field :note_html, null: false ``` This would generate a field that will render the markdown field `note` of the model. This could be overridden by adding the `method:` argument. Passing a symbol for the method name: ``` markdown_field :body_html, null: false, method: :note ``` It will have this description by default: > The GitLab Flavored Markdown rendering of `note` This could be overridden by passing a `description:` argument. The type of a `markdown_field` is always `GraphQL::STRING_TYPE`. --- app/helpers/markup_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/helpers/markup_helper.rb') diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb index bf894360a2e..8ccb39f8444 100644 --- a/app/helpers/markup_helper.rb +++ b/app/helpers/markup_helper.rb @@ -278,7 +278,7 @@ module MarkupHelper def prepare_for_rendering(html, context = {}) return '' unless html.present? - context.merge!( + context.reverse_merge!( current_user: (current_user if defined?(current_user)), # RelativeLinkFilter -- cgit v1.2.1