diff --git a/app/graphql/types/organization_dataset_connection_with_meta_type.rb b/app/graphql/types/organization_dataset_connection_with_meta_type.rb new file mode 100644 index 000000000..ab6394a62 --- /dev/null +++ b/app/graphql/types/organization_dataset_connection_with_meta_type.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class OrganizationDatasetConnectionWithMetaType < BaseConnection + edge_type(EventDataEdgeType, edge_class: EventDataEdge) + field_class GraphQL::Cache::Field + + field :total_count, Integer, null: false, cache: true + + def total_count + Event.query(nil, obj_id: object.parent[:id], citation_type: "Dataset-Organization").results.total + end +end \ No newline at end of file diff --git a/app/graphql/types/organization_publication_connection_with_meta_type.rb b/app/graphql/types/organization_publication_connection_with_meta_type.rb new file mode 100644 index 000000000..2f2db5eb9 --- /dev/null +++ b/app/graphql/types/organization_publication_connection_with_meta_type.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class OrganizationPublicationConnectionWithMetaType < BaseConnection + edge_type(EventDataEdgeType, edge_class: EventDataEdge) + field_class GraphQL::Cache::Field + + field :total_count, Integer, null: false, cache: true + + def total_count + Event.query(nil, obj_id: object.parent[:id], citation_type: "Organization-ScholarlyArticle").results.total + end +end diff --git a/app/graphql/types/organization_software_connection_with_meta_type.rb b/app/graphql/types/organization_software_connection_with_meta_type.rb new file mode 100644 index 000000000..436868257 --- /dev/null +++ b/app/graphql/types/organization_software_connection_with_meta_type.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class OrganizationSoftwareConnectionWithMetaType < BaseConnection + edge_type(EventDataEdgeType, edge_class: EventDataEdge) + field_class GraphQL::Cache::Field + + field :total_count, Integer, null: false, cache: true + + def total_count + Event.query(nil, obj_id: object.parent[:id], citation_type: "Organization-SoftwareSourceCode").results.total + end +end diff --git a/app/graphql/types/organization_type.rb b/app/graphql/types/organization_type.rb index 11d1c9709..fdc953fa3 100644 --- a/app/graphql/types/organization_type.rb +++ b/app/graphql/types/organization_type.rb @@ -15,4 +15,39 @@ class OrganizationType < BaseObject field :fund_ref, [String], null: true, description: "Crossref Funder ID identifiers for organization" field :wikidata, [String], null: true, description: "Wikidata identifiers for organization" field :grid, [String], null: true, description: "GRID identifiers for organization" + + field :datasets, OrganizationDatasetConnectionWithMetaType, null: false, description: "Funded datasets", connection: true, max_page_size: 100 do + argument :first, Int, required: false, default_value: 25 + end + + field :publications, OrganizationPublicationConnectionWithMetaType, null: false, description: "Funded publications", connection: true do + argument :query, String, required: false + argument :first, Int, required: false, default_value: 25 + end + + field :softwares, OrganizationSoftwareConnectionWithMetaType, 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-Organization").results.to_a.map do |e| + doi_from_url(e.subj_id) + end + + ElasticsearchLoader.for(Doi).load_many(ids) + end + + def publications(**args) + ids = Event.query(nil, obj_id: object[:id], citation_type: "Organization-ScholarlyArticle").results.to_a.map do |e| + doi_from_url(e.subj_id) + end + ElasticsearchLoader.for(Doi).load_many(ids) + end + + def softwares(**args) + ids = Event.query(nil, obj_id: object[:id], citation_type: "Organization-SoftwareSourceCode").results.to_a.map do |e| + doi_from_url(e.subj_id) + end + ElasticsearchLoader.for(Doi).load_many(ids) + end end