diff --git a/app/graphql/types/person_dataset_connection_with_meta_type.rb b/app/graphql/types/person_dataset_connection_with_meta_type.rb new file mode 100644 index 000000000..2351c43d1 --- /dev/null +++ b/app/graphql/types/person_dataset_connection_with_meta_type.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class PersonDatasetConnectionWithMetaType < 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: https_to_http(object.parent.uid ? "https://orcid.org/#{object.parent.uid}" : nil || object.parent[:id]), citation_type: "Dataset-Person").results.total + end + + def https_to_http(url) + uri = Addressable::URI.parse(url) + uri.scheme = "http" if uri.present? + uri.to_s + end +end \ No newline at end of file diff --git a/app/graphql/types/person_publication_connection_with_meta_type.rb b/app/graphql/types/person_publication_connection_with_meta_type.rb new file mode 100644 index 000000000..45544c029 --- /dev/null +++ b/app/graphql/types/person_publication_connection_with_meta_type.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class PersonPublicationConnectionWithMetaType < 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: https_to_http(object.parent.uid ? "https://orcid.org/#{object.parent.uid}" : nil || object.parent[:id]), citation_type: "Person-ScholarlyArticle").results.total + end + + def https_to_http(url) + uri = Addressable::URI.parse(url) + uri.scheme = "http" if uri.present? + uri.to_s + end +end diff --git a/app/graphql/types/person_software_connection_with_meta_type.rb b/app/graphql/types/person_software_connection_with_meta_type.rb new file mode 100644 index 000000000..c922332da --- /dev/null +++ b/app/graphql/types/person_software_connection_with_meta_type.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class PersonSoftwareConnectionWithMetaType < 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: https_to_http(object.parent.uid ? "https://orcid.org/#{object.parent.uid}" : nil || object.parent[:id]), citation_type: "Person-SoftwareSourceCode").results.total + end + + def https_to_http(url) + uri = Addressable::URI.parse(url) + uri.scheme = "http" if uri.present? + uri.to_s + end +end