Skip to content

Commit

Permalink
Merge branch 'master' into add_new_provenance_contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhallett committed May 20, 2019
2 parents 042cd0e + c10a4d3 commit db08cf0
Show file tree
Hide file tree
Showing 28 changed files with 114 additions and 58 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ gem 'graphql', '~> 1.9', '>= 1.9.4'
gem 'graphql-errors', '~> 0.3.0'
gem 'graphql-batch', '~> 0.4.0'
gem 'graphql-cache', '~> 0.6.0', git: "https://github.com/stackshareio/graphql-cache"
# gem 'ddtrace', '~> 0.23.3'

group :development, :test do
gem 'rspec-rails', '~> 3.8', '>= 3.8.2'
Expand Down
18 changes: 7 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
GIT
remote: https://github.com/stackshareio/graphql-cache
revision: 3c3f378ab8061326537ff6be203f6fd46fdf0acd
revision: 290c3297feeb9a4c72c627a3f0992b596628b5d1
specs:
graphql-cache (0.6.0)
graphql (~> 1, > 1.8)

GEM
remote: https://rubygems.org/
specs:
aasm (5.0.4)
aasm (5.0.5)
concurrent-ruby (~> 1.0)
actioncable (5.2.3)
actionpack (= 5.2.3)
Expand Down Expand Up @@ -65,7 +65,7 @@ GEM
audited (4.8.0)
activerecord (>= 4.0, < 5.3)
aws-eventstream (1.0.3)
aws-partitions (1.162.0)
aws-partitions (1.163.0)
aws-sdk-core (3.52.1)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1.0)
Expand All @@ -74,7 +74,7 @@ GEM
aws-sdk-kms (1.20.0)
aws-sdk-core (~> 3, >= 3.52.1)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.38.0)
aws-sdk-s3 (1.39.0)
aws-sdk-core (~> 3, >= 3.52.1)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.0)
Expand Down Expand Up @@ -134,14 +134,13 @@ GEM
builder (3.2.3)
byebug (11.0.1)
cancancan (2.3.0)
capybara (3.20.0)
capybara (3.20.2)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.2)
uglifier
xpath (~> 3.2)
case_transform (0.2)
activesupport
Expand Down Expand Up @@ -209,7 +208,6 @@ GEM
nokogiri (>= 1.4.3)
erubi (1.8.0)
excon (0.64.0)
execjs (2.7.0)
facets (3.1.0)
factory_bot (4.11.1)
activesupport (>= 3.0.0)
Expand All @@ -229,7 +227,7 @@ GEM
faraday (>= 0.9)
fast_jsonapi (1.5)
activesupport (>= 4.2)
ffi (1.10.0)
ffi (1.11.0)
flipper (0.16.2)
flipper-active_support_cache_store (0.16.2)
activesupport (>= 3.2, < 6)
Expand All @@ -245,7 +243,7 @@ GEM
promise.rb (~> 0.7.2)
graphql-errors (0.3.0)
graphql (>= 1.6.0, < 2)
haml (5.0.4)
haml (5.1.0)
temple (>= 0.8.0)
tilt
hamster (3.0.0)
Expand Down Expand Up @@ -512,8 +510,6 @@ GEM
tilt (>= 1.4, < 3)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.1.20)
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.6)
Expand Down
6 changes: 1 addition & 5 deletions app/graphql/elasticsearch_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ def initialize(model)
end

def perform(ids)
if @model.name == "Doi"
@model.find_by_id(ids).results.each { |record| fulfill(record.uid, record) }
else
@model.find_by_id(ids).records.each { |record| fulfill(record.uid, record) }
end
@model.find_by_id(ids).results.each { |record| fulfill(record.uid, record) }
ids.each { |id| fulfill(id, nil) unless fulfilled?(id) }
end
end
2 changes: 2 additions & 0 deletions app/graphql/lupo_schema.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class LupoSchema < GraphQL::Schema
use(GraphQL::Tracing::DataDogTracing, analytics_enabled: Rails.env.production?)

default_max_page_size 250
max_depth 10

Expand Down
4 changes: 3 additions & 1 deletion app/graphql/types/client_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class ClientConnectionWithMetaType < BaseConnection
field :total_count, Integer, null: false, cache: true

def total_count
object.nodes.size
args = object.arguments

Client.query(args[:query], year: args[:year], software: args[:software], page: { number: 1, size: 0 }).results.total
end
end
5 changes: 3 additions & 2 deletions app/graphql/types/client_dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class ClientDatasetConnectionWithMetaType < BaseConnection
edge_type(DatasetEdgeType)

field :total_count, Integer, null: false
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
args = object.arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class ClientPublicationConnectionWithMetaType < BaseConnection
edge_type(DatasetEdgeType)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false
field :total_count, Integer, null: false, cache: true

def total_count
args = object.arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class ClientSoftwareConnectionWithMetaType < BaseConnection
edge_type(DatasetEdgeType)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false
field :total_count, Integer, null: false, cache: true

def total_count
args = object.arguments
Expand Down
10 changes: 5 additions & 5 deletions app/graphql/types/client_type.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class ClientType < GraphQL::Schema::Object
class ClientType < BaseObject
description "Information about clients"

field :id, ID, null: false, hash_key: "uid", description: "Unique identifier for each client"
Expand Down Expand Up @@ -33,21 +33,21 @@ class ClientType < GraphQL::Schema::Object
end

def prefixes(**args)
collection = object.client_prefixes.joins(:prefix)
collection = ClientPrefix.joins(:client, :prefix).where('datacentre.symbol = ?', object.uid)
collection = collection.query(args[:query]) if args[:query].present?
collection = collection.where('YEAR(datacentre_prefixes.created_at) = ?', args[:year]) if args[:year].present?
collection
end

def datasets(**args)
Doi.query(args[:query], client_id: object.uid, resource_type_id: "Dataset", page: { number: 1, size: args[:first] }).records.to_a
Doi.query(args[:query], client_id: object.uid, resource_type_id: "Dataset", page: { number: 1, size: args[:first] }).results.to_a
end

def publications(**args)
Doi.query(args[:query], client_id: object.uid, resource_type_id: "Text", page: { number: 1, size: args[:first] }).records.to_a
Doi.query(args[:query], client_id: object.uid, resource_type_id: "Text", page: { number: 1, size: args[:first] }).results.to_a
end

def softwares(**args)
Doi.query(args[:query], client_id: object.uid, resource_type_id: "Software", page: { number: 1, size: args[:first] }).records.to_a
Doi.query(args[:query], client_id: object.uid, resource_type_id: "Software", page: { number: 1, size: args[:first] }).results.to_a
end
end
3 changes: 2 additions & 1 deletion app/graphql/types/dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class DatasetConnectionWithMetaType < BaseConnection
edge_type(DatasetEdgeType)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false
field :total_count, Integer, null: false, cache: true

def total_count
args = object.arguments
Expand Down
11 changes: 11 additions & 0 deletions app/graphql/types/dataset_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@

class DatasetType < BaseObject
implements DoiItem

field :usage_reports, DatasetUsageReportConnectionWithMetaType, null: false, description: "Usage reports for this dataset", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end

def usage_reports(**args)
ids = Event.query(nil, obj_id: object.id).fetch(:data, []).map do |e|
e[:subj_id]
end
UsageReport.find_by_id(ids, page: { number: 1, size: args[:first] }).fetch(:data, [])
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class DatasetUsageReportConnectionWithMetaType < 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).dig(:meta, "total").to_i
end
end
3 changes: 2 additions & 1 deletion app/graphql/types/organization_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class OrganizationConnectionWithMetaType < BaseConnection
edge_type(OrganizationEdgeType)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false
field :total_count, Integer, null: false, cache: true

def total_count
args = object.arguments
Expand Down
32 changes: 19 additions & 13 deletions app/graphql/types/prefix_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

class PrefixConnectionWithMetaType < BaseConnection
edge_type(PrefixEdgeType)

field :total_count, Integer, null: false
field :states, [FacetType], null: false
field :years, [FacetType], null: false
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :states, [FacetType], null: false, cache: true
field :years, [FacetType], null: false, cache: true

def total_count
object.nodes.size
Expand All @@ -14,10 +15,13 @@ def total_count
def states
args = self.object.arguments

if object.parent.class.name == "Provider"
collection = object.parent.provider_prefixes.joins(:prefix)
if object.parent._index == "providers"
collection = ProviderPrefix.joins(:provider, :prefix).where('allocator.symbol = ?', object.parent.symbol)
collection = collection.where('YEAR(allocator_prefixes.created_at) = ?', args[:year]) if args[:year].present?

collection = collection.state(args[:state].underscore.dasherize) if args[:state].present?
collection = collection.query(args[:query]) if args[:query].present?

puts collection.inspect
if args[:state].present?
[{ id: args[:state],
title: args[:state].underscore.humanize,
Expand All @@ -38,10 +42,11 @@ def states
def years
args = self.object.arguments

if object.parent.class.name == "Provider"
collection = object.parent.provider_prefixes.joins(:prefix)
if object.parent._index == "providers"
collection = ProviderPrefix.joins(:provider, :prefix).where('allocator.symbol = ?', object.parent.symbol)
collection = collection.state(args[:state].underscore.dasherize) if args[:state].present?

collection = collection.query(args[:query]) if args[:query].present?

if args[:year].present?
[{ id: args[:year],
title: args[:year],
Expand All @@ -50,9 +55,10 @@ def years
years = collection.where.not(prefixes: nil).order("YEAR(allocator_prefixes.created_at) DESC").group("YEAR(allocator_prefixes.created_at)").count
years.map { |k,v| { id: k.to_s, title: k.to_s, count: v } }
end
elsif object.parent.class.name == "Client"
collection = object.parent.client_prefixes.joins(:prefix)

elsif object.parent._index == "clients"
collection = ClientPrefix.joins(:client, :prefix).where('datacentre.symbol = ?', object.parent.symbol)
collection = collection.query(args[:query]) if args[:query].present?

if args[:year].present?
[{ id: args[:year],
title: args[:year],
Expand Down
9 changes: 6 additions & 3 deletions app/graphql/types/provider_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

class ProviderConnectionWithMetaType < BaseConnection
edge_type(ProviderEdgeType)

field :total_count, Integer, null: false
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
object.nodes.size
args = object.arguments

Provider.query(args[:query], year: args[:year], page: { number: 1, size: 0 }).results.total
end
end
5 changes: 2 additions & 3 deletions app/graphql/types/provider_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class ProviderType < BaseObject
argument :year, String, required: false
argument :software, String, required: false
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

def country
Expand All @@ -40,14 +39,14 @@ def country
end

def prefixes(**args)
collection = object.provider_prefixes.joins(:prefix)
collection = ProviderPrefix.joins(:provider, :prefix).where('allocator.symbol = ?', object.uid)
collection = collection.state(args[:state].underscore.dasherize) if args[:state].present?
collection = collection.query(args[:query]) if args[:query].present?
collection = collection.where('YEAR(allocator_prefixes.created_at) = ?', args[:year]) if args[:year].present?
collection
end

def clients(**args)
Client.query(args[:query], provider_id: object.uid, year: args[:year], software: args[:software], page: { number: 1, size: 500 }).records.to_a
Client.query(args[:query], provider_id: object.uid, year: args[:year], software: args[:software], page: { number: 1, size: args[:first] }).results.to_a
end
end
3 changes: 2 additions & 1 deletion app/graphql/types/publication_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class PublicationConnectionWithMetaType < BaseConnection
edge_type(DatasetEdgeType)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false
field :total_count, Integer, null: false, cache: true

def total_count
args = object.arguments
Expand Down
10 changes: 6 additions & 4 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
class QueryType < BaseObject
field :providers, ProviderConnectionWithMetaType, null: false, connection: true, max_page_size: 100 do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end

def providers(query: nil)
Provider.query(query, page: { number: 1, size: 250 }).records.to_a
def providers(query: nil, year: nil, first: nil)
Provider.query(query, year: year, page: { number: 1, size: first }).results.to_a
end

field :provider, ProviderType, null: false do
Expand All @@ -21,10 +22,11 @@ def provider(id:)
argument :query, String, required: false
argument :year, String, required: false
argument :software, String, required: false
argument :first, Int, required: false, default_value: 25
end

def clients(query: nil, year: nil, software: nil)
Client.query(query, year: year, software: software, page: { number: 1, size: 2000 }).records.to_a
def clients(query: nil, year: nil, software: nil, first: nil)
Client.query(query, year: year, software: software, page: { number: 1, size: first }).results.to_a
end

field :client, ClientType, null: false do
Expand Down
3 changes: 2 additions & 1 deletion app/graphql/types/software_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class SoftwareConnectionWithMetaType < BaseConnection
edge_type(DatasetEdgeType)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false
field :total_count, Integer, null: false, cache: true

def total_count
args = object.arguments
Expand Down
Loading

0 comments on commit db08cf0

Please sign in to comment.