Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions app/graphql/concerns/optional_embed_description.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module OptionalEmbedDescription
extend ActiveSupport::Concern

AUDIO_DESCRIPTION = 'A URL to an audio file to accompany this object.'
DESCRIPTION = 'A one to two sentence description of your object.'
DETERMINER_DESCRIPTION = %q[
The word that appears before this object's title in a sentence.
An enum of (a, an, the, "", auto). If auto is chosen,
the consumer of your data should chose between "a" or "an". Default is "" (blank).
]
LOCALE_DESCRIPTION = %[
The locale these tags are marked up in.
Of the format language_TERRITORY. Default is en_US.
]
LOCALE_ALTERNATIVE_DESCRIPTION = 'An array of other locales this page is available in.'
SITE_NAME_DESCRIPTION = %[
If your object is part of a larger web site,
the name which should be displayed for the overall site.
]
VIDEO_DESCRIPTION = 'A URL to a video file that complements this object.'
end
Comment thread
toyhammered marked this conversation as resolved.
Outdated
10 changes: 10 additions & 0 deletions app/graphql/types/embed/website_embed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class Types::Embed::WebsiteEmbed < Types::BaseObject
include OptionalEmbedDescription
implements Types::Interface::RequiredEmbed

field :site_name, String,
description: SITE_NAME_DESCRIPTION,
null: false
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final newline missing. (https://rubystyle.guide#newline-eof)

28 changes: 28 additions & 0 deletions app/graphql/types/interface/required_embed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Types::Interface::RequiredEmbed
Comment thread
toyhammered marked this conversation as resolved.
Outdated
include Types::Interface::Base
description 'Required fields for an Embed based off the Open Graph protocol'

field :title, String,
null: true,
description: ''

field :kind, String,
null: false,
description: ''

field :description, String,
null: true,
description: ''

field :site, String,
null: true,
description: ''

field :url, String,
null: true,
description: ''

# field :image, Types::EmbedImage,
# null: true,
# description: ''
end
4 changes: 4 additions & 0 deletions app/graphql/types/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class Types::Post < Types::BaseObject
null: true,
description: 'The reason why this post was locked.'

field :embed, Types::Union::EmbedItem,
null: true,
description: ''

field :comments, Types::Comment.connection_type,
null: false,
description: 'All comments related to this post.'
Expand Down
5 changes: 5 additions & 0 deletions app/graphql/types/union/embed_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Types::Union::EmbedItem < Types::Union::Base

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good argument to using a union vs just referencing the base embed interface that all embeds inherit from?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not actually sure. I've always preferred using a union vs referencing the base embed, I think it reads nicer. But both function the same way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading this: https://artsy.github.io/blog/2019/01/14/graphql-union-vs-interface/ I think I prefer Unions.

description 'All the different Embed types'

possible_types Types::Embed::WebsiteEmbed
end