diff options
author | Bob Van Landuyt <bob@gitlab.com> | 2019-06-20 08:02:33 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-06-20 08:02:33 +0000 |
commit | 406808583c2392a0b57f68f98b2418e9d23b23ab (patch) | |
tree | 98613723a6caf6dc152f9ff431e75906ebe2c5ca /app/graphql | |
parent | adeccba13676b831335e2f12f779f77602298b31 (diff) | |
download | gitlab-ce-406808583c2392a0b57f68f98b2418e9d23b23ab.tar.gz |
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`.
Diffstat (limited to 'app/graphql')
-rw-r--r-- | app/graphql/types/base_object.rb | 1 | ||||
-rw-r--r-- | app/graphql/types/issue_type.rb | 2 | ||||
-rw-r--r-- | app/graphql/types/label_type.rb | 1 | ||||
-rw-r--r-- | app/graphql/types/merge_request_type.rb | 2 | ||||
-rw-r--r-- | app/graphql/types/namespace_type.rb | 1 | ||||
-rw-r--r-- | app/graphql/types/notes/note_type.rb | 2 | ||||
-rw-r--r-- | app/graphql/types/project_type.rb | 1 |
7 files changed, 10 insertions, 0 deletions
diff --git a/app/graphql/types/base_object.rb b/app/graphql/types/base_object.rb index e40059c46bb..dad16898ba6 100644 --- a/app/graphql/types/base_object.rb +++ b/app/graphql/types/base_object.rb @@ -4,6 +4,7 @@ module Types class BaseObject < GraphQL::Schema::Object prepend Gitlab::Graphql::Present prepend Gitlab::Graphql::ExposePermissions + prepend Gitlab::Graphql::MarkdownField field_class Types::BaseField diff --git a/app/graphql/types/issue_type.rb b/app/graphql/types/issue_type.rb index f2365499eee..8b208cab1df 100644 --- a/app/graphql/types/issue_type.rb +++ b/app/graphql/types/issue_type.rb @@ -14,7 +14,9 @@ module Types field :iid, GraphQL::ID_TYPE, null: false field :title, GraphQL::STRING_TYPE, null: false + markdown_field :title_html, null: true field :description, GraphQL::STRING_TYPE, null: true + markdown_field :description_html, null: true field :state, IssueStateEnum, null: false field :reference, GraphQL::STRING_TYPE, null: false, method: :to_reference do diff --git a/app/graphql/types/label_type.rb b/app/graphql/types/label_type.rb index ccd466edc1a..50eb1b89c61 100644 --- a/app/graphql/types/label_type.rb +++ b/app/graphql/types/label_type.rb @@ -5,6 +5,7 @@ module Types graphql_name 'Label' field :description, GraphQL::STRING_TYPE, null: true + markdown_field :description_html, null: true field :title, GraphQL::STRING_TYPE, null: false field :color, GraphQL::STRING_TYPE, null: false field :text_color, GraphQL::STRING_TYPE, null: false diff --git a/app/graphql/types/merge_request_type.rb b/app/graphql/types/merge_request_type.rb index dac4c24cf10..577ccd48ef8 100644 --- a/app/graphql/types/merge_request_type.rb +++ b/app/graphql/types/merge_request_type.rb @@ -15,7 +15,9 @@ module Types field :id, GraphQL::ID_TYPE, null: false field :iid, GraphQL::STRING_TYPE, null: false field :title, GraphQL::STRING_TYPE, null: false + markdown_field :title_html, null: true field :description, GraphQL::STRING_TYPE, null: true + markdown_field :description_html, null: true field :state, MergeRequestStateEnum, null: false field :created_at, Types::TimeType, null: false field :updated_at, Types::TimeType, null: false diff --git a/app/graphql/types/namespace_type.rb b/app/graphql/types/namespace_type.rb index f6d91320e50..62feccaa660 100644 --- a/app/graphql/types/namespace_type.rb +++ b/app/graphql/types/namespace_type.rb @@ -12,6 +12,7 @@ module Types field :full_path, GraphQL::ID_TYPE, null: false field :description, GraphQL::STRING_TYPE, null: true + markdown_field :description_html, null: true field :visibility, GraphQL::STRING_TYPE, null: true field :lfs_enabled, GraphQL::BOOLEAN_TYPE, null: true, method: :lfs_enabled? field :request_access_enabled, GraphQL::BOOLEAN_TYPE, null: true diff --git a/app/graphql/types/notes/note_type.rb b/app/graphql/types/notes/note_type.rb index 85c55d16ac2..fe54a45c7dc 100644 --- a/app/graphql/types/notes/note_type.rb +++ b/app/graphql/types/notes/note_type.rb @@ -35,6 +35,8 @@ module Types method: :note, description: "The content note itself" + markdown_field :body_html, null: true, method: :note + field :created_at, Types::TimeType, null: false field :updated_at, Types::TimeType, null: false field :discussion, Types::Notes::DiscussionType, null: true, description: "The discussion this note is a part of" diff --git a/app/graphql/types/project_type.rb b/app/graphql/types/project_type.rb index 81914b70c7f..ac957eafafc 100644 --- a/app/graphql/types/project_type.rb +++ b/app/graphql/types/project_type.rb @@ -17,6 +17,7 @@ module Types field :name, GraphQL::STRING_TYPE, null: false field :description, GraphQL::STRING_TYPE, null: true + markdown_field :description_html, null: true field :tag_list, GraphQL::STRING_TYPE, null: true |