Skip to content

Commit

Permalink
Spike: can we simplify the GraphQL types?
Browse files Browse the repository at this point in the history
  • Loading branch information
brucebolt committed Dec 19, 2024
1 parent 67b2efb commit d2c455d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 366 deletions.
108 changes: 35 additions & 73 deletions app/graphql/types/edition_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,45 @@ class WithdrawnNotice < Types::BaseObject
field :withdrawn_at, GraphQL::Types::ISO8601DateTime
end

class EditionLinks < Types::BaseObject
links_field :available_translations, [EditionType]
links_field :government, [EditionType]
links_field :ordered_also_attends_cabinet, [EditionType]
links_field :ordered_assistant_whips, [EditionType]
links_field :ordered_baronesses_and_lords_in_waiting_whips, [EditionType]
links_field :ordered_cabinet_ministers, [EditionType]
links_field :ordered_house_lords_whips, [EditionType]
links_field :ordered_house_of_commons_whips, [EditionType]
links_field :ordered_junior_lords_of_the_treasury_whips, [EditionType]
links_field :ordered_ministerial_departments, [EditionType]
links_field :ordered_ministers, [EditionType]
links_field :ordered_parent_organisations, [EditionType]
links_field :ordered_roles, [EditionType]
links_field :organisations, [EditionType]
links_field :parent_taxons, [EditionType]
links_field :people, [EditionType]
links_field :person, [EditionType]
links_field :role_appointments, [EditionType]
links_field :role, [EditionType]
links_field :taxons, [EditionType]
links_field :topical_events, [EditionType]
links_field :world_locations, [EditionType]
end

field :active, Boolean, null: false
field :analytics_identifier, String
field :base_path, String
field :content_id, ID
field :current, Boolean
field :description, String
field :details, GraphQL::Types::JSON, null: false
field :document_type, String
field :ended_on, GraphQL::Types::ISO8601DateTime
field :first_published_at, GraphQL::Types::ISO8601DateTime, null: false
field :iso2, String
field :links, EditionLinks, method: :itself
field :locale, String, null: false
field :name, String, null: false
field :phase, String, null: false
field :public_updated_at, GraphQL::Types::ISO8601DateTime, null: false
field :publishing_app, String
Expand All @@ -23,9 +54,13 @@ class WithdrawnNotice < Types::BaseObject
field :rendering_app, String
field :scheduled_publishing_delay_seconds, Int
field :schema_name, String
field :slug, String, null: false
field :started_on, GraphQL::Types::ISO8601DateTime
field :state, String
field :supports_historical_accounts, Boolean
field :title, String, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime
field :web_url, String
field :withdrawn_notice, WithdrawnNotice

def withdrawn_notice
Expand All @@ -43,79 +78,6 @@ def not_stored_in_publishing_api
alias_method :publishing_scheduled_at, :not_stored_in_publishing_api
alias_method :scheduled_publishing_delay_seconds, :not_stored_in_publishing_api

class Translation < Types::BaseObject
field :locale, String
field :base_path, String
end

class GovernmentDetails < Types::BaseObject
field :current, Boolean
end

class GovernmentLink < Types::BaseObject
field :base_path, String
field :content_id, String
field :details, GovernmentDetails
field :title, String
end

class OrganisationLink < Types::BaseObject
field :base_path, String
field :content_id, String
field :title, String
end

class PersonLink < Types::BaseObject
field :base_path, String
field :content_id, String
field :title, String
end

class Taxon < Types::BaseObject
field :base_path, String
field :content_id, String
field :document_type, String
field :phase, String
field :title, String
end

class TaxonLink < Taxon
class TaxonLinks < Types::BaseObject
links_field :parent_taxons, [Taxon]
end

field :links, TaxonLinks, method: :itself
end

class TopicalEventLink < Types::BaseObject
field :base_path, String
field :content_id, String
field :title, String
end

class WorldLocationLink < Types::BaseObject
field :base_path, String
field :content_id, String
field :title, String
end

class EditionLinks < Types::BaseObject
field :available_translations, [Translation]
links_field :government, [GovernmentLink]
links_field :organisations, [OrganisationLink]
links_field :people, [PersonLink]
links_field :taxons, [TaxonLink]
links_field :topical_events, [TopicalEventLink]
links_field :world_locations, [WorldLocationLink]

def available_translations
Presenters::Queries::AvailableTranslations.by_edition(object)
.translations.fetch(:available_translations, [])
end
end

field :links, EditionLinks, method: :itself

private

def presented_edition
Expand Down
135 changes: 0 additions & 135 deletions app/graphql/types/ministers_index_type.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/graphql/types/news_article_type.rb

This file was deleted.

8 changes: 1 addition & 7 deletions app/graphql/types/query_type/edition_type_or_subtype.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
module Types
class QueryType
class EditionTypeOrSubtype < Types::BaseUnion
EDITION_TYPES = [
Types::EditionType,
Types::MinistersIndexType,
Types::NewsArticleType,
Types::RoleType,
Types::WorldIndexType,
].freeze
EDITION_TYPES = [Types::EditionType].freeze

possible_types(*EDITION_TYPES)

Expand Down
Loading

0 comments on commit d2c455d

Please sign in to comment.