diff --git a/app/graphql/types/dataset_connection_with_meta_type.rb b/app/graphql/types/dataset_connection_with_meta_type.rb deleted file mode 100644 index 983581ce6..000000000 --- a/app/graphql/types/dataset_connection_with_meta_type.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class DatasetConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection - edge_type(EventEdgeType, edge_class: EventEdge) - # edge_type(EventEdgeType) - # field :total_count, Integer, null: false - - # def total_count - # args = object.arguments - - # 1 - # end -end diff --git a/app/graphql/types/funder_dataset_connection_with_meta_type.rb b/app/graphql/types/funder_dataset_connection_with_meta_type.rb new file mode 100644 index 000000000..923bc134b --- /dev/null +++ b/app/graphql/types/funder_dataset_connection_with_meta_type.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class FunderDatasetConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection + edge_type(EventEdgeType, edge_class: EventEdge) + + field :total_count, Integer, null: false + + def total_count + Event.query(nil, obj_id: object[:id], citation_type: "Dataset-Funder").fetch(:meta, "total") + end +end diff --git a/app/graphql/types/funder_publication_connection_with_meta_type.rb b/app/graphql/types/funder_publication_connection_with_meta_type.rb new file mode 100644 index 000000000..563e5bbb0 --- /dev/null +++ b/app/graphql/types/funder_publication_connection_with_meta_type.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class FunderPublicationConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection + edge_type(EventEdgeType, edge_class: EventEdge) + + field :total_count, Integer, null: false + + def total_count + Event.query(nil, obj_id: object[:id], citation_type: "Funder-JournalArticle").fetch(:meta, "total") + end +end diff --git a/app/graphql/types/funder_software_connection_with_meta_type.rb b/app/graphql/types/funder_software_connection_with_meta_type.rb new file mode 100644 index 000000000..ea5d6399a --- /dev/null +++ b/app/graphql/types/funder_software_connection_with_meta_type.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class FunderSoftwareConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection + edge_type(EventEdgeType, edge_class: EventEdge) + + field :total_count, Integer, null: false + + def total_count + Event.query(nil, obj_id: object[:id], citation_type: "Funder-SoftwareSourceCode").fetch(:meta, "total") + end +end diff --git a/app/graphql/types/funder_type.rb b/app/graphql/types/funder_type.rb index c8fa8ee4f..7f451b8ca 100644 --- a/app/graphql/types/funder_type.rb +++ b/app/graphql/types/funder_type.rb @@ -8,15 +8,19 @@ class FunderType < BaseObject field :alternate_name, [String], null: true, description: "Alternate funder names" field :country, String, null: true, description: "Country where funder is located" field :date_modified, String, null: false, description: "Date information was last updated" - field :datasets, DatasetConnectionWithMetaType, null: false, description: "Funded datasets", connection: true, max_page_size: 100 do + field :datasets, FunderDatasetConnectionWithMetaType, null: false, description: "Funded datasets", connection: true, max_page_size: 100 do argument :first, Int, required: false, default_value: 25 end - field :publications, [PublicationType], null: false, description: "Funded publications" do + field :publications, FunderPublicationConnectionWithMetaType, null: false, description: "Funded publications", connection: true do argument :query, String, required: false argument :first, Int, required: false, default_value: 25 end + field :softwares, FunderSoftwareConnectionWithMetaType, null: false, description: "Funded software", connection: true, max_page_size: 100 do + argument :first, Int, required: false, default_value: 25 + end + def datasets(**args) ids = Event.query(nil, obj_id: object[:id], citation_type: "Dataset-Funder").fetch(:data, []).map do |e| doi_from_url(e[:subj_id]) @@ -31,6 +35,13 @@ def publications(**args) Doi.find_by_ids(ids, page: { number: 1, size: args[:first] }).to_a end + def softwares(**args) + ids = Event.query(nil, obj_id: object[:id], citation_type: "Funder-SoftwareSourceCode").fetch(:data, []).map do |e| + doi_from_url(e[:subj_id]) + end.join(",") + Doi.find_by_ids(ids, page: { number: 1, size: args[:first] }).to_a + end + def doi_from_url(url) if /\A(?:(http|https):\/\/(dx\.)?(doi.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match?(url) uri = Addressable::URI.parse(url)