Skip to content

Commit

Permalink
Issue datacite 1816 - Facets missing from some/most (Specific WorkTyp…
Browse files Browse the repository at this point in the history
…e)ConnectionWithTotalType (#961)

* Refactor GQL work facets into an interface

* Apply WorksFacetInterface to dataset_connection

* Update schema.graphql

* Move total_count to the WorkFacetInterface

* Continue refactor of *_with_total_type.rb files to use WorkFacetInterface

* Refactor more *_with_total_type.rb files to use WorkFacetInterface

* Refactor last *_with_total_type.rb files to use WorkFacetInterface

* Appease Rubocop

* resource_type aggregation only useful in the General WorkConnecitonWithTotal

* Update schema.graphql
  • Loading branch information
jrhoads authored May 12, 2023
1 parent 3b36bdd commit 811f06a
Show file tree
Hide file tree
Showing 28 changed files with 288 additions and 1,761 deletions.
151 changes: 126 additions & 25 deletions app/graphql/schema.graphql

Large diffs are not rendered by default.

73 changes: 1 addition & 72 deletions app/graphql/types/audiovisual_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,5 @@
class AudiovisualConnectionWithTotalType < BaseConnection
edge_type(AudiovisualEdgeType)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
field :fields_of_science, [FacetType], null: true, cache: true
field :authors, [FacetType], null: true, cache: true
field :licenses, [FacetType], null: true, cache: true
field :languages, [FacetType], null: true, cache: true

def total_count
object.total_count
end

def published
if object.aggregations.published
facet_by_range(object.aggregations.published.buckets)
else
[]
end
end

def registration_agencies
if object.aggregations.registration_agencies
facet_by_registration_agency(
object.aggregations.registration_agencies.buckets,
)
else
[]
end
end

def repositories
if object.aggregations.clients
facet_by_combined_key(object.aggregations.clients.buckets)
else
[]
end
end

def affiliations
if object.aggregations.affiliations
facet_by_combined_key(object.aggregations.affiliations.buckets)
else
[]
end
end

def authors
if object.aggregations.authors
facet_by_authors(object.aggregations.authors.buckets)
else
[]
end
end

def licenses
if object.aggregations.licenses
facet_by_license(object.aggregations.licenses.buckets)
else
[]
end
end

def languages
if object.aggregations.languages
facet_by_language(object.aggregations.languages.buckets)
else
[]
end
end
implements Interfaces::WorkFacetsInterface
end
81 changes: 1 addition & 80 deletions app/graphql/types/book_chapter_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,84 +3,5 @@
class BookChapterConnectionWithTotalType < BaseConnection
edge_type(BookChapterEdgeType)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
field :fields_of_science, [FacetType], null: true, cache: true
field :authors, [FacetType], null: true, cache: true
field :licenses, [FacetType], null: true, cache: true
field :languages, [FacetType], null: true, cache: true

def total_count
object.total_count
end

def published
if object.aggregations.published
facet_by_range(object.aggregations.published.buckets)
else
[]
end
end

def registration_agencies
if object.aggregations.registration_agencies
facet_by_registration_agency(
object.aggregations.registration_agencies.buckets
)
else
[]
end
end

def repositories
if object.aggregations.clients
facet_by_combined_key(object.aggregations.clients.buckets)
else
[]
end
end

def authors
if object.aggregations.authors
facet_by_authors(object.aggregations.authors.buckets)
else
[]
end
end

def affiliations
if object.aggregations.affiliations
facet_by_combined_key(object.aggregations.affiliations.buckets)
else
[]
end
end

def licenses
if object.aggregations.licenses
facet_by_license(object.aggregations.licenses.buckets)
else
[]
end
end

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
else
[]
end
end

def languages
if object.aggregations.languages
facet_by_language(object.aggregations.languages.buckets)
else
[]
end
end
implements Interfaces::WorkFacetsInterface
end
81 changes: 1 addition & 80 deletions app/graphql/types/book_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,6 @@

class BookConnectionWithTotalType < BaseConnection
edge_type(BookEdgeType)
implements Interfaces::WorkFacetsInterface
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :published, [FacetType], null: true, cache: true
field :registration_agencies, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
field :fields_of_science, [FacetType], null: true, cache: true
field :authors, [FacetType], null: true, cache: true
field :licenses, [FacetType], null: true, cache: true
field :languages, [FacetType], null: true, cache: true

def total_count
object.total_count
end

def published
if object.aggregations.published
facet_by_range(object.aggregations.published.buckets)
else
[]
end
end

def registration_agencies
if object.aggregations.registration_agencies
facet_by_registration_agency(
object.aggregations.registration_agencies.buckets
)
else
[]
end
end

def repositories
if object.aggregations.clients
facet_by_combined_key(object.aggregations.clients.buckets)
else
[]
end
end

def affiliations
if object.aggregations.affiliations
facet_by_combined_key(object.aggregations.affiliations.buckets)
else
[]
end
end

def licenses
if object.aggregations.licenses
facet_by_license(object.aggregations.licenses.buckets)
else
[]
end
end

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
else
[]
end
end

def authors
if object.aggregations.authors
facet_by_authors(object.aggregations.authors.buckets)
else
[]
end
end

def languages
if object.aggregations.languages
facet_by_language(object.aggregations.languages.buckets)
else
[]
end
end
end
80 changes: 1 addition & 79 deletions app/graphql/types/collection_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,5 @@
class CollectionConnectionWithTotalType < BaseConnection
edge_type(CollectionEdgeType)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :published, [FacetType], null: true, cache: true
field :repositories, [FacetType], null: true, cache: true
field :affiliations, [FacetType], null: true, cache: true
field :fields_of_science, [FacetType], null: true, cache: true
field :authors, [FacetType], null: true, cache: true
field :licenses, [FacetType], null: true, cache: true
field :languages, [FacetType], null: true, cache: true

def total_count
object.total_count
end

def published
if object.aggregations.published
facet_by_range(object.aggregations.published.buckets)
else
[]
end
end

def registration_agencies
if object.aggregations.registration_agencies
facet_by_registration_agency(
object.aggregations.registration_agencies.buckets
)
else
[]
end
end

def repositories
if object.aggregations.clients
facet_by_combined_key(object.aggregations.clients.buckets)
else
[]
end
end

def affiliations
if object.aggregations.affiliations
facet_by_combined_key(object.aggregations.affiliations.buckets)
else
[]
end
end

def authors
if object.aggregations.authors
facet_by_authors(object.aggregations.authors.buckets)
else
[]
end
end

def licenses
if object.aggregations.licenses
facet_by_license(object.aggregations.licenses.buckets)
else
[]
end
end

def fields_of_science
if object.aggregations.fields_of_science
facet_by_fos(object.aggregations.fields_of_science.subject.buckets)
else
[]
end
end

def languages
if object.aggregations.languages
facet_by_language(object.aggregations.languages.buckets)
else
[]
end
end
implements Interfaces::WorkFacetsInterface
end
Loading

0 comments on commit 811f06a

Please sign in to comment.