Skip to content

Commit

Permalink
clean up associated works in graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 11, 2020
1 parent 217e64a commit fa39b92
Show file tree
Hide file tree
Showing 31 changed files with 469 additions and 301 deletions.
270 changes: 135 additions & 135 deletions app/graphql/schema.graphql

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions app/graphql/types/audiovisual_connection_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class AudiovisualConnectionType < BaseConnection
def total_count
args = prepare_args(object.arguments)

response(**args).results.total
response(args).results.total
end

def years
args = prepare_args(object.arguments)

res = response(**args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : nil
res = response(args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : []
end

def response(**args)
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/collection_connection_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class CollectionConnectionType < BaseConnection
def total_count
args = prepare_args(object.arguments)

response(**args).results.total
response(args).results.total
end

def years
args = prepare_args(object.arguments)

res = response(**args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : nil
res = response(args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : []
end

def response(**args)
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/data_paper_connection_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class DataPaperConnectionType < BaseConnection
def total_count
args = prepare_args(object.arguments)

response(**args).results.total
response(args).results.total
end

def years
args = prepare_args(object.arguments)

res = response(**args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : nil
res = response(args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : []
end

def response(**args)
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/dataset_connection_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class DatasetConnectionType < BaseConnection
def total_count
args = prepare_args(object.arguments)

response(**args).results.total
response(args).results.total
end

def years
args = prepare_args(object.arguments)

res = response(**args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : nil
res = response(args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : []
end

def response(**args)
Expand Down
28 changes: 14 additions & 14 deletions app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module DoiItem

field :references, WorkConnectionType, null: true, connection: true, max_page_size: 100, description: "References for this DOI" do
argument :query, String, required: false
argument :ids, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :repository_id, String, required: false
Expand All @@ -71,7 +71,7 @@ module DoiItem
end
field :citations, WorkConnectionType, null: true, connection: true, max_page_size: 100, description: "Citations for this DOI." do
argument :query, String, required: false
argument :ids, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :repository_id, String, required: false
Expand All @@ -89,7 +89,7 @@ module DoiItem
end
field :parts, WorkConnectionType, null: true, connection: true, max_page_size: 100, description: "Parts of this DOI." do
argument :query, String, required: false
argument :ids, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :repository_id, String, required: false
Expand All @@ -107,7 +107,7 @@ module DoiItem
end
field :part_of, WorkConnectionType, null: true, connection: true, max_page_size: 100, description: "The DOI is a part of this DOI." do
argument :query, String, required: false
argument :ids, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :repository_id, String, required: false
Expand All @@ -125,7 +125,7 @@ module DoiItem
end
field :versions, WorkConnectionType, null: true, connection: true, max_page_size: 100, description: "Versions of this DOI." do
argument :query, String, required: false
argument :ids, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :repository_id, String, required: false
Expand All @@ -143,7 +143,7 @@ module DoiItem
end
field :version_of, WorkConnectionType, null: true, connection: true, max_page_size: 100, description: "The DOI is a version of this DOI." do
argument :query, String, required: false
argument :ids, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
argument :funder_id, String, required: false
argument :repository_id, String, required: false
Expand Down Expand Up @@ -222,45 +222,45 @@ def formatted_citation(style: nil, locale: nil)
end

def references(**args)
ids = object.reference_ids
return [] if ids.blank?
args[:ids] = object.reference_ids
return [] if args[:ids].blank?

response(**args)
response(args)
end

def citations(**args)
args[:ids] = object.citation_ids
return [] if args[:ids].blank?

response(**args)
response(args)
end

def parts(**args)
args[:ids] = object.part_ids
return [] if args[:ids].blank?

response(**args)
response(args)
end

def part_of(**args)
args[:ids] = object.part_of_ids
return [] if args[:ids].blank?

response(**args)
response(args)
end

def versions(**args)
args[:ids] = object.version_ids
return [] if args[:ids].blank?

response(**args)
response(args)
end

def version_of(**args)
args[:ids] = object.version_of_ids
return [] if args[:ids].blank?

response(**args)
response(args)
end

def response(**args)
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/event_connection_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class EventConnectionType < BaseConnection
def total_count
args = prepare_args(object.arguments)

response(**args).results.total
response(args).results.total
end

def years
args = prepare_args(object.arguments)

res = response(**args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : nil
res = response(args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : []
end

def response(**args)
Expand Down
18 changes: 9 additions & 9 deletions app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FunderType < BaseObject

field :datasets, DatasetConnectionType, null: true, description: "Funded datasets", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
argument :repository_id, String, required: false
argument :member_id, String, required: false
Expand All @@ -30,7 +30,7 @@ class FunderType < BaseObject

field :publications, PublicationConnectionType, null: true, description: "Funded publications", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
argument :repository_id, String, required: false
argument :member_id, String, required: false
Expand All @@ -46,7 +46,7 @@ class FunderType < BaseObject

field :softwares, SoftwareConnectionType, null: true, description: "Funded software", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
argument :repository_id, String, required: false
argument :member_id, String, required: false
Expand All @@ -62,7 +62,7 @@ class FunderType < BaseObject

field :works, WorkConnectionType, null: true, description: "Funded works", connection: true do
argument :query, String, required: false
argument :ids, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
argument :repository_id, String, required: false
argument :member_id, String, required: false
Expand All @@ -85,27 +85,27 @@ def address

def publications(**args)
args[:resource_type_id] = "Text"
r = response(**args)
r = response(args)

r.results.to_a
end

def datasets(**args)
args[:resource_type_id] = "Dataset"
r = response(**args)
r = response(args)

r.results.to_a
end

def softwares(**args)
args[:resource_type_id] = "Software"
r = response(**args)
r = response(args)

r.results.to_a
end

def works(**args)
r = response(**args)
r = response(args)

r.results.to_a
end
Expand All @@ -129,6 +129,6 @@ def citation_count
end

def response(**args)
Doi.query(args[:query], funder_id: object[:id], user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], affiliation_id: args[:affiliation_id], resource_type_id: args[:resource_type_id], has_person: args[:has_person], has_organization: args[:has_organization], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], state: "findable", page: { number: 1, size: args[:first] })
Doi.query(args[:query], ids: args[:ids], funder_id: object[:id], user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], affiliation_id: args[:affiliation_id], resource_type_id: args[:resource_type_id], has_person: args[:has_person], has_organization: args[:has_organization], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], state: "findable", page: { number: 1, size: args[:first] })
end
end
6 changes: 3 additions & 3 deletions app/graphql/types/image_connection_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class ImageConnectionType < BaseConnection
def total_count
args = prepare_args(object.arguments)

response(**args).results.total
response(args).results.total
end

def years
args = prepare_args(object.arguments)

res = response(**args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : nil
res = response(args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : []
end

def response(**args)
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/instrument_connection_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class InstrumentConnectionType < BaseConnection
def total_count
args = prepare_args(object.arguments)

response(**args).results.total
response(args).results.total
end

def years
args = prepare_args(object.arguments)

res = response(**args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : nil
res = response(args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : []
end

def response(**args)
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/interactive_resource_connection_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class InteractiveResourceConnectionType < BaseConnection
def total_count
args = prepare_args(object.arguments)

response(**args).results.total
response(args).results.total
end

def years
args = prepare_args(object.arguments)

res = response(**args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : nil
res = response(args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : []
end

def response(**args)
Expand Down
21 changes: 9 additions & 12 deletions app/graphql/types/member_prefix_connection_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,26 @@ class MemberPrefixConnectionType < BaseConnection
field :years, [FacetType], null: false, cache: true

def total_count
args = object.arguments
args[:member_id] ||= object.parent.try(:role_name).present? ? object.parent.symbol.downcase : nil
args = prepare_args(object.arguments)

response(**args).results.total
response(args).results.total
end

def states
args = object.arguments
args[:member_id] ||= object.parent.try(:role_name).present? ? object.parent.symbol.downcase : nil
args = prepare_args(object.arguments)

res = response(**args)
res.results.total.positive? ? facet_by_key(res.response.aggregations.states.buckets) : nil
res = response(args)
res.results.total.positive? ? facet_by_key(res.response.aggregations.states.buckets) : []
end

def years
args = object.arguments
args[:member_id] ||= object.parent.try(:role_name).present? ? object.parent.symbol.downcase : nil
args = prepare_args(object.arguments)

res = response(**args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : nil
res = response(args)
res.results.total.positive? ? facet_by_year(res.response.aggregations.years.buckets) : []
end

def response(**args)
@response ||= ProviderPrefix.query(args[:query], provider_id: args[:member_id], state: args[:state], year: args[:year], page: { number: 1, size: 0 })
ProviderPrefix.query(args[:query], provider_id: args[:member_id], state: args[:state], year: args[:year], page: { number: 1, size: 0 })
end
end
Loading

0 comments on commit fa39b92

Please sign in to comment.