Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL - Embeds #898

Open
wants to merge 10 commits into
base: the-future
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
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
5 changes: 5 additions & 0 deletions app/graphql/types/embed/audio_tag_embed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Types::Embed::AudioTagEmbed < Types::BaseObject
Copy link
Member

Choose a reason for hiding this comment

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

Why the Tag?

Copy link
Member Author

Choose a reason for hiding this comment

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

seemed kind of strange just being AudioEmbed and on the docs it used tag in the description. i.e: The og:video tag has the identical tags which I kinda liked. I can rename though.

implements Types::Interface::BaseEmbed

description 'Audio Properties'
end
Copy link

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)

17 changes: 17 additions & 0 deletions app/graphql/types/embed/image_tag_embed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Types::Embed::ImageTagEmbed < Types::BaseObject
implements Types::Interface::BaseEmbed

description 'Image Properties'

field :width, String,
null: false,
description: 'The number of pixels wide.'

field :height, String,
null: false,
description: 'The number of pixels high.'

field :alt, String,
null: false,
description: 'A description of what is in the image (not a caption).'
end
22 changes: 22 additions & 0 deletions app/graphql/types/embed/profile_embed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Types::Embed::WebsiteEmbed < Types::BaseObject
implements Types::Interface::BaseEmbed

field :first_name, String,
null: true,
description: 'A name normally given to an individual by a parent or self-chosen.'

field :last_name, String,
null: true,
description: <<~DESCRIPTION.squish
A name inherited from a family or marriage
and by which the individual is commonly known.
DESCRIPTION

field :username, String,
null: true,
description: 'A short unique string to identify them.'

field :gender, Types::Enum::Gender,
null: true,
description: 'Their gender.'
end
Copy link

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)

17 changes: 17 additions & 0 deletions app/graphql/types/embed/video_tag_embed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Types::Embed::VideoTagEmbed < Types::BaseObject
implements Types::Interface::BaseEmbed

description 'Video Properties'

field :width, String,
null: false,
description: 'The number of pixels wide.'

field :height, String,
null: false,
description: 'The number of pixels high.'

field :alt, String,
null: false,
description: 'A description of what is in the video (not a caption).'
end
3 changes: 3 additions & 0 deletions app/graphql/types/embed/website_embed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Types::Embed::WebsiteEmbed < Types::BaseObject
implements Types::Interface::BaseEmbed
end
Copy link

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)

5 changes: 5 additions & 0 deletions app/graphql/types/enum/gender.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Types::Enum::Gender < Types::Enum::Base
value 'MALE', value: 'male'
value 'FEMALE', value: 'female'
value 'OTHER', value: 'other'
end
Copy link

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)

69 changes: 69 additions & 0 deletions app/graphql/types/interface/base_embed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module Types::Interface::BaseEmbed
include Types::Interface::Base
description 'Required and Optional fields for an Embed based off the Open Graph protocol'

orphan_types Types::Embed::WebsiteEmbed

field :title, String,
null: false,
description: 'The title of your object as it should appear within the graph.'

field :kind, String,
null: false,
description: <<~DESCRIPTION.squish
The type of your object,
e.g., "video.movie".
Depending on the type you specify, other properties may also be required.
DESCRIPTION

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

field :url, String,
null: false,
description: 'The canonical URL of your object that will be used as its permanent ID in the graph'
Copy link

Choose a reason for hiding this comment

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

Line is too long. [102/100] (https://rubystyle.guide#80-character-limits)


field :image, Types::ImageTagEmbed,
null: false,
description: 'An image URL which should represent your object within the graph.'

field :audio, Types::AudioTagEmbed,
null: true,
description: 'A URL to an audio file to accompany this object.'

field :description, String,
null: true,
description: 'A one to two sentence description of your object.'

field :determiner, String,
null: true,
description: <<~DESCRIPTION.squish
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).
DESCRIPTION

field :locale, String,
null: true,
default_value: 'en_us',
description: <<~DESCRIPTION.squish
The locale these tags are marked up in.
Of the format language_territory.
DESCRIPTION

field :locale_alternative, [String],
null: true,
description: 'An array of other locales this page is available in.'

field :site_name, String,
null: true,
description: <<~DESCRIPTION.squish
If your object is part of a larger web site,
the name which should be displayed for the overall site.
DESCRIPTION

field :video, Types::VideoTagEmbed,
null: true,
description: 'A URL to a video file that complements this object.'
end
17 changes: 17 additions & 0 deletions app/graphql/types/interface/base_tag_embed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Types::Interface::BaseTagEmbed
include Types::Interface::Base

description 'Similar fields between Image, Audio, Video Tags.'

field :url, String,
null: false,
description: 'A url.'

field :secure_url, String,
null: true,
description: 'An alternate url to use if the webpage requires HTTPS.'

field :kind, String,
null: true,
description: 'A MIME type'
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::Interface::BaseEmbed,
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
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
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
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