From 811f06aaa25dc253cbd6c3eb5187e0be29a2337d Mon Sep 17 00:00:00 2001 From: Joseph Rhoads Date: Fri, 12 May 2023 11:04:49 -0400 Subject: [PATCH] Issue datacite 1816 - Facets missing from some/most (Specific WorkType)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 --- app/graphql/schema.graphql | 151 +++++++++++++++--- .../audiovisual_connection_with_total_type.rb | 73 +-------- ...book_chapter_connection_with_total_type.rb | 81 +--------- .../types/book_connection_with_total_type.rb | 81 +--------- .../collection_connection_with_total_type.rb | 80 +--------- ...erence_paper_connection_with_total_type.rb | 81 +--------- ...agement_plan_connection_with_total_type.rb | 81 +--------- .../data_paper_connection_with_total_type.rb | 40 +---- .../dataset_connection_with_total_type.rb | 82 +--------- ...dissertation_connection_with_total_type.rb | 81 +--------- .../types/image_connection_with_total_type.rb | 39 +---- .../instrument_connection_with_total_type.rb | 63 +------- ...ive_resource_connection_with_total_type.rb | 64 +------- .../types/interfaces/base_interface.rb | 5 + .../types/interfaces/work_facets_interface.rb | 114 +++++++++++++ ...rnal_article_connection_with_total_type.rb | 64 +------- .../types/model_connection_with_total_type.rb | 72 +-------- .../types/other_connection_with_total_type.rb | 72 +-------- .../peer_review_connection_with_total_type.rb | 72 +-------- ...sical_object_connection_with_total_type.rb | 72 +-------- .../preprint_connection_with_total_type.rb | 72 +-------- .../publication_connection_with_total_type.rb | 71 +------- .../service_connection_with_total_type.rb | 72 +-------- .../software_connection_with_total_type.rb | 106 +++--------- .../types/sound_connection_with_total_type.rb | 72 +-------- .../types/work_connection_with_total_type.rb | 106 +----------- .../workflow_connection_with_total_type.rb | 81 +--------- config/application.rb | 1 + 28 files changed, 288 insertions(+), 1761 deletions(-) create mode 100644 app/graphql/types/interfaces/base_interface.rb create mode 100644 app/graphql/types/interfaces/work_facets_interface.rb diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 7b5a76570..cd2d420e0 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -386,7 +386,7 @@ type Audiovisual implements DoiItem { """ The connection type for Audiovisual. """ -type AudiovisualConnectionWithTotal { +type AudiovisualConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] authors: [Facet!] @@ -395,6 +395,8 @@ type AudiovisualConnectionWithTotal { """ edges: [AudiovisualEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -402,6 +404,7 @@ type AudiovisualConnectionWithTotal { A list of nodes. """ nodes: [Audiovisual] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -979,7 +982,7 @@ type BookChapter implements DoiItem { """ The connection type for BookChapter. """ -type BookChapterConnectionWithTotal { +type BookChapterConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] authors: [Facet!] @@ -988,6 +991,8 @@ type BookChapterConnectionWithTotal { """ edges: [BookChapterEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -995,6 +1000,7 @@ type BookChapterConnectionWithTotal { A list of nodes. """ nodes: [BookChapter] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -1024,7 +1030,7 @@ type BookChapterEdge { """ The connection type for Book. """ -type BookConnectionWithTotal { +type BookConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] authors: [Facet!] @@ -1033,6 +1039,8 @@ type BookConnectionWithTotal { """ edges: [BookEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -1040,6 +1048,7 @@ type BookConnectionWithTotal { A list of nodes. """ nodes: [Book] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -1391,7 +1400,7 @@ type Collection implements DoiItem { """ The connection type for Collection. """ -type CollectionConnectionWithTotal { +type CollectionConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] authors: [Facet!] @@ -1400,6 +1409,8 @@ type CollectionConnectionWithTotal { """ edges: [CollectionEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -1407,12 +1418,14 @@ type CollectionConnectionWithTotal { A list of nodes. """ nodes: [Collection] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. """ pageInfo: PageInfo! published: [Facet!] + registrationAgencies: [Facet!] repositories: [Facet!] totalCount: Int! } @@ -1709,7 +1722,7 @@ type ConferencePaper implements DoiItem { """ The connection type for ConferencePaper. """ -type ConferencePaperConnectionWithTotal { +type ConferencePaperConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] authors: [Facet!] @@ -1718,6 +1731,8 @@ type ConferencePaperConnectionWithTotal { """ edges: [ConferencePaperEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -1725,6 +1740,7 @@ type ConferencePaperConnectionWithTotal { A list of nodes. """ nodes: [ConferencePaper] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -2320,7 +2336,7 @@ type DataManagementPlan implements DoiItem { """ The connection type for DataManagementPlan. """ -type DataManagementPlanConnectionWithTotal { +type DataManagementPlanConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] authors: [Facet!] @@ -2329,6 +2345,8 @@ type DataManagementPlanConnectionWithTotal { """ edges: [DataManagementPlanEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -2336,6 +2354,7 @@ type DataManagementPlanConnectionWithTotal { A list of nodes. """ nodes: [DataManagementPlan] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -2639,14 +2658,17 @@ type DataPaper implements DoiItem { """ The connection type for DataPaper. """ -type DataPaperConnectionWithTotal { +type DataPaperConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [DataPaperEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -2654,6 +2676,7 @@ type DataPaperConnectionWithTotal { A list of nodes. """ nodes: [DataPaper] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -2978,7 +3001,7 @@ type Dataset implements DoiItem { """ The connection type for Dataset. """ -type DatasetConnectionWithTotal { +type DatasetConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] authors: [Facet!] datasetConnectionCount: Int! @@ -2988,6 +3011,8 @@ type DatasetConnectionWithTotal { """ edges: [DatasetEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] funderConnectionCount: Int! languages: [Facet!] licenses: [Facet!] @@ -2996,6 +3021,7 @@ type DatasetConnectionWithTotal { A list of nodes. """ nodes: [Dataset] + openLicenseResourceTypes: [Facet!] organizationConnectionCount: Int! """ @@ -3394,7 +3420,7 @@ type Dissertation implements DoiItem { """ The connection type for Dissertation. """ -type DissertationConnectionWithTotal { +type DissertationConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] authors: [Facet!] @@ -3403,6 +3429,8 @@ type DissertationConnectionWithTotal { """ edges: [DissertationEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -3410,6 +3438,7 @@ type DissertationConnectionWithTotal { A list of nodes. """ nodes: [Dissertation] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -4942,13 +4971,17 @@ type Image implements DoiItem { """ The connection type for Image. """ -type ImageConnectionWithTotal { +type ImageConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [ImageEdge] + fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -4956,6 +4989,7 @@ type ImageConnectionWithTotal { A list of nodes. """ nodes: [Image] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -5259,20 +5293,25 @@ type Instrument implements DoiItem { """ The connection type for Instrument. """ -type InstrumentConnectionWithTotal { +type InstrumentConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [InstrumentEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] + languages: [Facet!] licenses: [Facet!] """ A list of nodes. """ nodes: [Instrument] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -5576,14 +5615,17 @@ type InteractiveResource implements DoiItem { """ The connection type for InteractiveResource. """ -type InteractiveResourceConnectionWithTotal { +type InteractiveResourceConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [InteractiveResourceEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -5591,6 +5633,7 @@ type InteractiveResourceConnectionWithTotal { A list of nodes. """ nodes: [InteractiveResource] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -5899,14 +5942,17 @@ type JournalArticle implements DoiItem { """ The connection type for JournalArticle. """ -type JournalArticleConnectionWithTotal { +type JournalArticleConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [JournalArticleEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -5914,6 +5960,7 @@ type JournalArticleConnectionWithTotal { A list of nodes. """ nodes: [JournalArticle] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -6513,14 +6560,17 @@ type Model implements DoiItem { """ The connection type for Model. """ -type ModelConnectionWithTotal { +type ModelConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [ModelEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -6528,6 +6578,7 @@ type ModelConnectionWithTotal { A list of nodes. """ nodes: [Model] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -7003,14 +7054,17 @@ type Other implements DoiItem { """ The connection type for Other. """ -type OtherConnectionWithTotal { +type OtherConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [OtherEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -7018,15 +7072,16 @@ type OtherConnectionWithTotal { A list of nodes. """ nodes: [Other] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. """ pageInfo: PageInfo! + published: [Facet!] registrationAgencies: [Facet!] repositories: [Facet!] totalCount: Int! - years: [Facet!] } """ @@ -7346,14 +7401,17 @@ type PeerReview implements DoiItem { """ The connection type for PeerReview. """ -type PeerReviewConnectionWithTotal { +type PeerReviewConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [PeerReviewEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -7361,6 +7419,7 @@ type PeerReviewConnectionWithTotal { A list of nodes. """ nodes: [PeerReview] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -7801,14 +7860,17 @@ type PhysicalObject implements DoiItem { """ The connection type for PhysicalObject. """ -type PhysicalObjectConnectionWithTotal { +type PhysicalObjectConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [PhysicalObjectEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -7816,6 +7878,7 @@ type PhysicalObjectConnectionWithTotal { A list of nodes. """ nodes: [PhysicalObject] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -8172,14 +8235,17 @@ type Preprint implements DoiItem { """ The connection type for Preprint. """ -type PreprintConnectionWithTotal { +type PreprintConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [PreprintEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -8187,6 +8253,7 @@ type PreprintConnectionWithTotal { A list of nodes. """ nodes: [Preprint] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -8490,8 +8557,9 @@ type Publication implements DoiItem { """ The connection type for Publication. """ -type PublicationConnectionWithTotal { +type PublicationConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] datasetConnectionCount: Int! """ @@ -8499,6 +8567,8 @@ type PublicationConnectionWithTotal { """ edges: [PublicationEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] funderConnectionCount: Int! languages: [Facet!] licenses: [Facet!] @@ -8507,6 +8577,7 @@ type PublicationConnectionWithTotal { A list of nodes. """ nodes: [Publication] + openLicenseResourceTypes: [Facet!] organizationConnectionCount: Int! """ @@ -9453,14 +9524,17 @@ type Service implements DoiItem { """ The connection type for Service. """ -type ServiceConnectionWithTotal { +type ServiceConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [ServiceEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -9468,6 +9542,7 @@ type ServiceConnectionWithTotal { A list of nodes. """ nodes: [Service] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -9797,8 +9872,9 @@ type SoftwareApplication { """ The connection type for Software. """ -type SoftwareConnectionWithTotal { +type SoftwareConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] datasetConnectionCount: Int! """ @@ -9806,6 +9882,8 @@ type SoftwareConnectionWithTotal { """ edges: [SoftwareEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] funderConnectionCount: Int! languages: [Facet!] licenses: [Facet!] @@ -9814,6 +9892,7 @@ type SoftwareConnectionWithTotal { A list of nodes. """ nodes: [Software] + openLicenseResourceTypes: [Facet!] organizationConnectionCount: Int! """ @@ -10121,14 +10200,17 @@ type Sound implements DoiItem { """ The connection type for Sound. """ -type SoundConnectionWithTotal { +type SoundConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] + authors: [Facet!] """ A list of edges. """ edges: [SoundEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -10136,6 +10218,7 @@ type SoundConnectionWithTotal { A list of nodes. """ nodes: [Sound] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. @@ -10650,7 +10733,7 @@ type Work implements DoiItem { """ The connection type for Work. """ -type WorkConnectionWithTotal { +type WorkConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] authors: [Facet!] @@ -10699,6 +10782,21 @@ type WorkEdge { node: Work } +interface WorkFacetsInterface { + affiliations: [Facet!] + authors: [Facet!] + fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] + languages: [Facet!] + licenses: [Facet!] + openLicenseResourceTypes: [Facet!] + published: [Facet!] + registrationAgencies: [Facet!] + repositories: [Facet!] + totalCount: Int! +} + type Workflow implements DoiItem { """ Metadata in bibtex format @@ -10976,7 +11074,7 @@ type Workflow implements DoiItem { """ The connection type for Workflow. """ -type WorkflowConnectionWithTotal { +type WorkflowConnectionWithTotal implements WorkFacetsInterface { affiliations: [Facet!] authors: [Facet!] @@ -10985,6 +11083,8 @@ type WorkflowConnectionWithTotal { """ edges: [WorkflowEdge] fieldsOfScience: [Facet!] + fieldsOfScienceCombined: [Facet!] + fieldsOfScienceRepository: [Facet!] languages: [Facet!] licenses: [Facet!] @@ -10992,6 +11092,7 @@ type WorkflowConnectionWithTotal { A list of nodes. """ nodes: [Workflow] + openLicenseResourceTypes: [Facet!] """ Information to aid in pagination. diff --git a/app/graphql/types/audiovisual_connection_with_total_type.rb b/app/graphql/types/audiovisual_connection_with_total_type.rb index f8b3e4f04..24c681401 100644 --- a/app/graphql/types/audiovisual_connection_with_total_type.rb +++ b/app/graphql/types/audiovisual_connection_with_total_type.rb @@ -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 diff --git a/app/graphql/types/book_chapter_connection_with_total_type.rb b/app/graphql/types/book_chapter_connection_with_total_type.rb index 33f549366..46b12d57f 100644 --- a/app/graphql/types/book_chapter_connection_with_total_type.rb +++ b/app/graphql/types/book_chapter_connection_with_total_type.rb @@ -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 diff --git a/app/graphql/types/book_connection_with_total_type.rb b/app/graphql/types/book_connection_with_total_type.rb index c0ffb7c90..9c5ce4a72 100644 --- a/app/graphql/types/book_connection_with_total_type.rb +++ b/app/graphql/types/book_connection_with_total_type.rb @@ -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 diff --git a/app/graphql/types/collection_connection_with_total_type.rb b/app/graphql/types/collection_connection_with_total_type.rb index 47a528e78..67da5dc4f 100644 --- a/app/graphql/types/collection_connection_with_total_type.rb +++ b/app/graphql/types/collection_connection_with_total_type.rb @@ -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 diff --git a/app/graphql/types/conference_paper_connection_with_total_type.rb b/app/graphql/types/conference_paper_connection_with_total_type.rb index 9e1928b30..557e017de 100644 --- a/app/graphql/types/conference_paper_connection_with_total_type.rb +++ b/app/graphql/types/conference_paper_connection_with_total_type.rb @@ -3,84 +3,5 @@ class ConferencePaperConnectionWithTotalType < BaseConnection edge_type(ConferencePaperEdgeType) 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 authors - if object.aggregations.authors - facet_by_authors(object.aggregations.authors.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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/data_management_plan_connection_with_total_type.rb b/app/graphql/types/data_management_plan_connection_with_total_type.rb index 2a8c755d9..07d78a81a 100644 --- a/app/graphql/types/data_management_plan_connection_with_total_type.rb +++ b/app/graphql/types/data_management_plan_connection_with_total_type.rb @@ -3,84 +3,5 @@ class DataManagementPlanConnectionWithTotalType < BaseConnection edge_type(DataManagementPlanEdgeType) 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 diff --git a/app/graphql/types/data_paper_connection_with_total_type.rb b/app/graphql/types/data_paper_connection_with_total_type.rb index d100ca57b..a6a0d0061 100644 --- a/app/graphql/types/data_paper_connection_with_total_type.rb +++ b/app/graphql/types/data_paper_connection_with_total_type.rb @@ -3,43 +3,5 @@ class DataPaperConnectionWithTotalType < BaseConnection edge_type(DataPaperEdgeType) 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 :licenses, [FacetType], null: true, cache: true - field :languages, [FacetType], null: true, cache: true - - def total_count - object.total_count - end - - def published - facet_by_range(object.aggregations.published.buckets) - end - - def registration_agencies - facet_by_registration_agency( - object.aggregations.registration_agencies.buckets, - ) - end - - def repositories - facet_by_combined_key(object.aggregations.clients.buckets) - end - - def affiliations - facet_by_combined_key(object.aggregations.affiliations.buckets) - end - - def licenses - facet_by_license(object.aggregations.licenses.buckets) - end - - def languages - facet_by_language(object.aggregations.languages.buckets) - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/dataset_connection_with_total_type.rb b/app/graphql/types/dataset_connection_with_total_type.rb index 6fc42ac1f..25bd7b5c3 100644 --- a/app/graphql/types/dataset_connection_with_total_type.rb +++ b/app/graphql/types/dataset_connection_with_total_type.rb @@ -2,17 +2,9 @@ class DatasetConnectionWithTotalType < BaseConnection edge_type(DatasetEdgeType) - field_class GraphQL::Cache::Field + implements Interfaces::WorkFacetsInterface - 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 + field_class GraphQL::Cache::Field field :dataset_connection_count, Integer, null: false, cache: true field :publication_connection_count, Integer, null: false, cache: true @@ -21,76 +13,6 @@ class DatasetConnectionWithTotalType < BaseConnection field :funder_connection_count, Integer, null: false, cache: true field :organization_connection_count, Integer, null: false, 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 - def dataset_connection_count @dataset_connection_count ||= Event.query( diff --git a/app/graphql/types/dissertation_connection_with_total_type.rb b/app/graphql/types/dissertation_connection_with_total_type.rb index 892ffe1e3..3c256a3b7 100644 --- a/app/graphql/types/dissertation_connection_with_total_type.rb +++ b/app/graphql/types/dissertation_connection_with_total_type.rb @@ -3,84 +3,5 @@ class DissertationConnectionWithTotalType < BaseConnection edge_type(DissertationEdgeType) 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 diff --git a/app/graphql/types/image_connection_with_total_type.rb b/app/graphql/types/image_connection_with_total_type.rb index a28ca37ae..bdce45fbe 100644 --- a/app/graphql/types/image_connection_with_total_type.rb +++ b/app/graphql/types/image_connection_with_total_type.rb @@ -3,42 +3,5 @@ class ImageConnectionWithTotalType < BaseConnection edge_type(ImageEdgeType) 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 :licenses, [FacetType], null: true, cache: true - field :languages, [FacetType], null: true, cache: true - - def total_count - object.total_count - end - - def published - facet_by_range(object.aggregations.published.buckets) - end - - def registration_agencies - facet_by_registration_agency( - object.aggregations.registration_agencies.buckets, - ) - end - - def repositories - facet_by_combined_key(object.aggregations.clients.buckets) - end - - def affiliations - facet_by_combined_key(object.aggregations.affiliations.buckets) - end - - def licenses - facet_by_license(object.aggregations.licenses.buckets) - end - - def languages - facet_by_language(object.aggregations.languages.buckets) - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/instrument_connection_with_total_type.rb b/app/graphql/types/instrument_connection_with_total_type.rb index 38af30287..77ab74288 100644 --- a/app/graphql/types/instrument_connection_with_total_type.rb +++ b/app/graphql/types/instrument_connection_with_total_type.rb @@ -3,66 +3,5 @@ class InstrumentConnectionWithTotalType < BaseConnection edge_type(InstrumentEdgeType) 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 :fields_of_science, [FacetType], null: true, cache: true - field :affiliations, [FacetType], null: true, cache: true - field :licenses, [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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/interactive_resource_connection_with_total_type.rb b/app/graphql/types/interactive_resource_connection_with_total_type.rb index 592495b11..7c512ed56 100644 --- a/app/graphql/types/interactive_resource_connection_with_total_type.rb +++ b/app/graphql/types/interactive_resource_connection_with_total_type.rb @@ -3,67 +3,5 @@ class InteractiveResourceConnectionWithTotalType < BaseConnection edge_type(InteractiveResourceEdgeType) 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 :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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/interfaces/base_interface.rb b/app/graphql/types/interfaces/base_interface.rb new file mode 100644 index 000000000..45a134654 --- /dev/null +++ b/app/graphql/types/interfaces/base_interface.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module BaseInterface + include GraphQL::Schema::Interface +end diff --git a/app/graphql/types/interfaces/work_facets_interface.rb b/app/graphql/types/interfaces/work_facets_interface.rb new file mode 100644 index 000000000..5dc58c19e --- /dev/null +++ b/app/graphql/types/interfaces/work_facets_interface.rb @@ -0,0 +1,114 @@ +# frozen_string_literal: true + +module Interfaces::WorkFacetsInterface + include BaseInterface + field_class GraphQL::Cache::Field + + field :total_count, Integer, null: false, cache: true + + field :published, [FacetType], null: true, cache: true + field :open_license_resource_types, [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 :authors, [FacetType], null: true, cache: true + field :fields_of_science, [FacetType], null: true, cache: true + field :fields_of_science_combined, [FacetType], null: true, cache: true + field :fields_of_science_repository, [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 open_license_resource_types + if object.aggregations.open_licenses + facet_by_combined_key(object.aggregations.open_licenses.resource_types.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 fields_of_science_combined + if object.aggregations.fields_of_science_combined + facet_by_fos(object.aggregations.fields_of_science_combined.buckets) + else + [] + end + end + + def fields_of_science_repository + if object.aggregations.fields_of_science_repository + facet_by_fos(object.aggregations.fields_of_science_repository.buckets) + else + [] + end + end + + def languages + if object.aggregations.languages + facet_by_language(object.aggregations.languages.buckets) + else + [] + end + end +end diff --git a/app/graphql/types/journal_article_connection_with_total_type.rb b/app/graphql/types/journal_article_connection_with_total_type.rb index cef302b19..dbe2fe892 100644 --- a/app/graphql/types/journal_article_connection_with_total_type.rb +++ b/app/graphql/types/journal_article_connection_with_total_type.rb @@ -3,67 +3,5 @@ class JournalArticleConnectionWithTotalType < BaseConnection edge_type(JournalArticleEdgeType) 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 :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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/model_connection_with_total_type.rb b/app/graphql/types/model_connection_with_total_type.rb index 167d27322..c354b68ea 100644 --- a/app/graphql/types/model_connection_with_total_type.rb +++ b/app/graphql/types/model_connection_with_total_type.rb @@ -3,75 +3,5 @@ class ModelConnectionWithTotalType < BaseConnection edge_type(ModelEdgeType) 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 :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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/other_connection_with_total_type.rb b/app/graphql/types/other_connection_with_total_type.rb index f7dc416d3..ba1aefcb6 100644 --- a/app/graphql/types/other_connection_with_total_type.rb +++ b/app/graphql/types/other_connection_with_total_type.rb @@ -3,75 +3,5 @@ class OtherConnectionWithTotalType < BaseConnection edge_type(OtherEdgeType) field_class GraphQL::Cache::Field - - field :total_count, Integer, null: false, cache: true - field :years, [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 :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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/peer_review_connection_with_total_type.rb b/app/graphql/types/peer_review_connection_with_total_type.rb index 6bf2c777b..44b50a616 100644 --- a/app/graphql/types/peer_review_connection_with_total_type.rb +++ b/app/graphql/types/peer_review_connection_with_total_type.rb @@ -3,75 +3,5 @@ class PeerReviewConnectionWithTotalType < BaseConnection edge_type(PeerReviewEdgeType) 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 :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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/physical_object_connection_with_total_type.rb b/app/graphql/types/physical_object_connection_with_total_type.rb index f13ec3a36..ce6710998 100644 --- a/app/graphql/types/physical_object_connection_with_total_type.rb +++ b/app/graphql/types/physical_object_connection_with_total_type.rb @@ -3,75 +3,5 @@ class PhysicalObjectConnectionWithTotalType < BaseConnection edge_type(PhysicalObjectEdgeType) 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 :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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/preprint_connection_with_total_type.rb b/app/graphql/types/preprint_connection_with_total_type.rb index 85c7b88f1..aef35a5e4 100644 --- a/app/graphql/types/preprint_connection_with_total_type.rb +++ b/app/graphql/types/preprint_connection_with_total_type.rb @@ -3,75 +3,5 @@ class PreprintConnectionWithTotalType < BaseConnection edge_type(PreprintEdgeType) 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 :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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/publication_connection_with_total_type.rb b/app/graphql/types/publication_connection_with_total_type.rb index d1e0656f6..fccdb431b 100644 --- a/app/graphql/types/publication_connection_with_total_type.rb +++ b/app/graphql/types/publication_connection_with_total_type.rb @@ -3,15 +3,7 @@ class PublicationConnectionWithTotalType < BaseConnection edge_type(PublicationEdgeType) 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 :licenses, [FacetType], null: true, cache: true - field :languages, [FacetType], null: true, cache: true + implements Interfaces::WorkFacetsInterface field :publication_connection_count, Integer, null: false, cache: true field :dataset_connection_count, Integer, null: false, cache: true @@ -20,67 +12,6 @@ class PublicationConnectionWithTotalType < BaseConnection field :funder_connection_count, Integer, null: false, cache: true field :organization_connection_count, Integer, null: false, 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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end def publication_connection_count @publication_connection_count ||= diff --git a/app/graphql/types/service_connection_with_total_type.rb b/app/graphql/types/service_connection_with_total_type.rb index a9366626a..af0868c77 100644 --- a/app/graphql/types/service_connection_with_total_type.rb +++ b/app/graphql/types/service_connection_with_total_type.rb @@ -3,55 +3,9 @@ class ServiceConnectionWithTotalType < BaseConnection edge_type(ServiceEdgeType) field_class GraphQL::Cache::Field + implements Interfaces::WorkFacetsInterface - 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 :pid_entities, [FacetType], null: true, cache: true - field :fields_of_science, [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 pid_entities if object.aggregations.pid_entities facet_by_software(object.aggregations.pid_entities.subject.buckets) @@ -59,28 +13,4 @@ def pid_entities [] 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 end diff --git a/app/graphql/types/software_connection_with_total_type.rb b/app/graphql/types/software_connection_with_total_type.rb index 31f93b0a3..ac12bd56e 100644 --- a/app/graphql/types/software_connection_with_total_type.rb +++ b/app/graphql/types/software_connection_with_total_type.rb @@ -3,136 +3,66 @@ class SoftwareConnectionWithTotalType < BaseConnection edge_type(SoftwareEdgeType) field_class GraphQL::Cache::Field + implements Interfaces::WorkFacetsInterface - 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 :licenses, [FacetType], null: true, cache: true - field :languages, [FacetType], null: true, cache: true - - field :software_connection_count, Integer, null: false, cache: true - field :publication_connection_count, Integer, null: false, cache: true field :dataset_connection_count, Integer, null: false, cache: true - field :person_connection_count, Integer, null: false, cache: true field :funder_connection_count, Integer, null: false, cache: true field :organization_connection_count, Integer, null: false, cache: true + field :person_connection_count, Integer, null: false, cache: true + field :publication_connection_count, Integer, null: false, cache: true + field :software_connection_count, Integer, null: false, 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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end - - def software_connection_count + def dataset_connection_count Event.query( nil, - citation_type: "SoftwareSourceCode-SoftwareSourceCode", - page: { number: 1, size: 0 }, + citation_type: "Dataset-SoftwareSourceCode", page: { number: 1, size: 0 }, ). results. total end - def publication_connection_count + def funder_connection_count Event.query( nil, - citation_type: "ScholarlyArticle-SoftwareSourceCode", - page: { number: 1, size: 0 }, + citation_type: "Funder-SoftwareSourceCode", page: { number: 1, size: 0 }, ). results. total end - def dataset_connection_count + def organization_connection_count Event.query( nil, - citation_type: "Dataset-SoftwareSourceCode", page: { number: 1, size: 0 }, + citation_type: "Organization-SoftwareSourceCode", + page: { number: 1, size: 0 }, ). results. total end - def person_connection_count + def software_connection_count Event.query( nil, - citation_type: "Person-SoftwareSourceCode", page: { number: 1, size: 0 }, + citation_type: "SoftwareSourceCode-SoftwareSourceCode", + page: { number: 1, size: 0 }, ). results. total end - def funder_connection_count + def person_connection_count Event.query( nil, - citation_type: "Funder-SoftwareSourceCode", page: { number: 1, size: 0 }, + citation_type: "Person-SoftwareSourceCode", page: { number: 1, size: 0 }, ). results. total end - def organization_connection_count + def publication_connection_count Event.query( nil, - citation_type: "Organization-SoftwareSourceCode", + citation_type: "ScholarlyArticle-SoftwareSourceCode", page: { number: 1, size: 0 }, ). results. diff --git a/app/graphql/types/sound_connection_with_total_type.rb b/app/graphql/types/sound_connection_with_total_type.rb index 9fbb9441c..6760664bf 100644 --- a/app/graphql/types/sound_connection_with_total_type.rb +++ b/app/graphql/types/sound_connection_with_total_type.rb @@ -3,75 +3,5 @@ class SoundConnectionWithTotalType < BaseConnection edge_type(SoundEdgeType) 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 :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 languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end + implements Interfaces::WorkFacetsInterface end diff --git a/app/graphql/types/work_connection_with_total_type.rb b/app/graphql/types/work_connection_with_total_type.rb index 7fb8d4436..ff55d6c9e 100644 --- a/app/graphql/types/work_connection_with_total_type.rb +++ b/app/graphql/types/work_connection_with_total_type.rb @@ -3,28 +3,14 @@ class WorkConnectionWithTotalType < BaseConnection edge_type(WorkEdgeType) field_class GraphQL::Cache::Field + implements Interfaces::WorkFacetsInterface - field :total_count, Integer, null: false, cache: true field :totalCountFromCrossref, resolver: TotalCountFromCrossref, null: true, cache: true field :total_open_licenses, Integer, null: true, cache: true field :total_content_url, Integer, null: true, cache: true - field :published, [FacetType], null: true, cache: true field :resource_types, [FacetType], null: true, cache: true - field :open_license_resource_types, [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 :authors, [FacetType], null: true, cache: true - field :fields_of_science, [FacetType], null: true, cache: true - field :fields_of_science_combined, [FacetType], null: true, cache: true - field :fields_of_science_repository, [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 total_content_url object.aggregations.content_url_count.value.to_i @@ -34,14 +20,6 @@ def total_open_licenses object.aggregations.open_licenses.doc_count.to_i end - def published - if object.aggregations.published - facet_by_range(object.aggregations.published.buckets) - else - [] - end - end - def resource_types if object.aggregations.resource_types facet_by_combined_key(object.aggregations.resource_types.buckets) @@ -49,86 +27,4 @@ def resource_types [] end end - - def open_license_resource_types - if object.aggregations.open_licenses - facet_by_combined_key(object.aggregations.open_licenses.resource_types.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 fields_of_science_combined - if object.aggregations.fields_of_science_combined - facet_by_fos(object.aggregations.fields_of_science_combined.buckets) - else - [] - end - end - - def fields_of_science_repository - if object.aggregations.fields_of_science_repository - facet_by_fos(object.aggregations.fields_of_science_repository.buckets) - else - [] - end - end - - def languages - if object.aggregations.languages - facet_by_language(object.aggregations.languages.buckets) - else - [] - end - end end diff --git a/app/graphql/types/workflow_connection_with_total_type.rb b/app/graphql/types/workflow_connection_with_total_type.rb index d08db5ef9..181be0217 100644 --- a/app/graphql/types/workflow_connection_with_total_type.rb +++ b/app/graphql/types/workflow_connection_with_total_type.rb @@ -3,84 +3,5 @@ class WorkflowConnectionWithTotalType < BaseConnection edge_type(WorkflowEdgeType) 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 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 diff --git a/config/application.rb b/config/application.rb index 12fced0b1..3add43f92 100644 --- a/config/application.rb +++ b/config/application.rb @@ -81,6 +81,7 @@ class Application < Rails::Application # Allow middleware to be loaded. (compressed_requests) config.autoload_paths += %W(#{config.root}/lib #{config.root}/lib/middleware) + config.autoload_paths += %W(#{config.root}/app/graphql/types ) config.eager_load_paths += %W(#{config.root}/lib #{config.root}/lib/middleware) # Settings in config/environments/* take precedence over those specified here.