Skip to content

Commit

Permalink
creativework for person
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Jan 16, 2020
1 parent 0d188df commit 9395f52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

class PersonCreativeWorkConnectionWithMetaType < 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.id)).results.total
end

def https_to_http(url)
uri = Addressable::URI.parse(url)
uri.scheme = "http" if uri.present?
uri.to_s
end
end
11 changes: 11 additions & 0 deletions app/graphql/types/person_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class PersonType < BaseObject
argument :first, Int, required: false, default_value: 25
end

field :creative_works, PersonCreativeWorkConnectionWithMetaType, null: true, description: "Authored creative works", connection: true do
argument :first, Int, required: false, default_value: 25
end

def type
"Person"
end
Expand All @@ -49,6 +53,13 @@ def software_source_codes(**_args)
ElasticsearchLoader.for(Doi).load_many(ids)
end

def creative_works(**_args)
ids = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.map do |e|
doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end

def citation_count(**_args)
dois = Event.query(nil, page: { size: 500 }, obj_id: https_to_http(object[:id])).results.to_a.map do |e|
doi_from_url(e.subj_id)
Expand Down

0 comments on commit 9395f52

Please sign in to comment.