diff --git a/app/graphql/types/client_connection_with_meta_type.rb b/app/graphql/types/client_connection_with_meta_type.rb new file mode 100644 index 000000000..ad2864972 --- /dev/null +++ b/app/graphql/types/client_connection_with_meta_type.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class ClientConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection + edge_type(ClientEdgeType) + + field :total_count, Integer, null: false + + def total_count + object.nodes.size + end +end diff --git a/app/graphql/types/client_edge_type.rb b/app/graphql/types/client_edge_type.rb new file mode 100644 index 000000000..e523a7810 --- /dev/null +++ b/app/graphql/types/client_edge_type.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ClientEdgeType < GraphQL::Types::Relay::BaseEdge + node_type(ClientType) +end diff --git a/app/graphql/types/client_type.rb b/app/graphql/types/client_type.rb index a79c442c4..dff81b3e9 100644 --- a/app/graphql/types/client_type.rb +++ b/app/graphql/types/client_type.rb @@ -5,9 +5,12 @@ class ClientType < GraphQL::Schema::Object field :id, ID, null: false, hash_key: "uid", description: "Unique identifier for each client" field :name, String, null: false, description: "Client name" + field :re3data, String, null: true, description: "The re3data identifier for the client" field :description, String, null: true, description: "Description of the client" + field :url, String, null: true, description: "The homepage of the client" field :contact_name, String, null: true, description: "Client contact name" field :contact_email, String, null: true, description: "Client contact email" + field :software, String, null: true, description: "The name of the software that is used to run the repository" field :prefixes, PrefixConnectionWithMetaType, null: false, description: "Prefixes managed by the client", connection: true, max_page_size: 100 do argument :query, String, required: false argument :year, String, required: false diff --git a/app/graphql/types/organization_connection_with_meta_type.rb b/app/graphql/types/organization_connection_with_meta_type.rb new file mode 100644 index 000000000..bfd6d4849 --- /dev/null +++ b/app/graphql/types/organization_connection_with_meta_type.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class OrganizationConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection + edge_type(OrganizationEdgeType) + + field :total_count, Integer, null: false + + def total_count + object.nodes.size + end +end diff --git a/app/graphql/types/organization_edge_type.rb b/app/graphql/types/organization_edge_type.rb new file mode 100644 index 000000000..df81c25cc --- /dev/null +++ b/app/graphql/types/organization_edge_type.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class OrganizationEdgeType < GraphQL::Types::Relay::BaseEdge + node_type(OrganizationType) +end diff --git a/app/graphql/types/provider_connection_with_meta_type.rb b/app/graphql/types/provider_connection_with_meta_type.rb new file mode 100644 index 000000000..c2dd9e36f --- /dev/null +++ b/app/graphql/types/provider_connection_with_meta_type.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class ProviderConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection + edge_type(ProviderEdgeType) + + field :total_count, Integer, null: false + + def total_count + object.nodes.size + end +end diff --git a/app/graphql/types/provider_edge_type.rb b/app/graphql/types/provider_edge_type.rb new file mode 100644 index 000000000..3b536dc9c --- /dev/null +++ b/app/graphql/types/provider_edge_type.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ProviderEdgeType < GraphQL::Types::Relay::BaseEdge + node_type(ProviderType) +end diff --git a/app/graphql/types/provider_type.rb b/app/graphql/types/provider_type.rb index 30a2adce6..d349a78af 100644 --- a/app/graphql/types/provider_type.rb +++ b/app/graphql/types/provider_type.rb @@ -23,9 +23,12 @@ class ProviderType < BaseObject argument :first, Int, required: false, default_value: 25 end - field :clients, [ClientType], null: false, description: "Clients associated with the provider", max_page_size: 100 do + field :clients, ClientConnectionWithMetaType, null: false, description: "Clients associated with the provider", connection: true, max_page_size: 100 do argument :query, String, required: false + 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 prefixes(**args) @@ -37,6 +40,6 @@ def prefixes(**args) end def clients(**args) - Client.query(args[:query], provider_id: object.uid, page: { cursor: 1, size: args[:first] }).records + Client.query(args[:query], provider_id: object.uid, year: args[:year], software: args[:software], page: { number: 1, size: 500 }).results.to_a end end diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 168271005..a32f37cc8 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -1,13 +1,12 @@ # frozen_string_literal: true class QueryType < BaseObject - field :providers, [ProviderType], null: false do + 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, first: nil) - Provider.query(query, page: { number: 1, size: first }).records + def providers(query: nil) + Provider.query(query, page: { number: 1, size: 250 }).records.to_a end field :provider, ProviderType, null: false do @@ -18,13 +17,14 @@ def provider(id:) Provider.unscoped.where("allocator.role_name IN ('ROLE_ALLOCATOR', 'ROLE_ADMIN')").where(deleted_at: nil).where(symbol: id).first end - field :clients, [ClientType], null: false do + field :clients, ClientConnectionWithMetaType, null: false, connection: true, max_page_size: 100 do argument :query, String, required: false - argument :first, Int, required: false, default_value: 25 + argument :year, String, required: false + argument :software, String, required: false end - def clients(query: nil, first: nil) - Client.query(query, page: { number: 1, size: first }).records + def clients(query: nil, year: nil, software: nil) + Client.query(query, year: year, software: software, page: { number: 1, size: 2000 }).records.to_a end field :client, ClientType, null: false do @@ -58,13 +58,13 @@ def prefix(id:) Prefix.where(prefix: id).first end - field :funders, [FunderType], null: false do + field :funders, FunderConnectionWithMetaType, null: false, connection: true, max_page_size: 100 do argument :query, String, required: false argument :first, Int, required: false, default_value: 25 end def funders(query: nil, first: nil) - Funder.query(query, limit: first) + Funder.query(query, limit: first).fetch(:data, []) end field :funder, FunderType, null: false do @@ -72,7 +72,7 @@ def funders(query: nil, first: nil) end def funder(id:) - result = Funder.find_by_id(id).first + result = Funder.find_by_id(id)[:data].first fail ActiveRecord::RecordNotFound if result.nil? result @@ -89,7 +89,7 @@ def researcher(id:) result end - field :organizations, [OrganizationType], null: false do + field :organizations, OrganizationConnectionWithMetaType, null: false, connection: true, max_page_size: 100 do argument :query, String, required: false argument :first, Int, required: false, default_value: 25 end diff --git a/app/models/doi.rb b/app/models/doi.rb index 3d63a5e36..30ab8ce75 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -712,7 +712,7 @@ def media_ids def self.find_by_ids(ids, options={}) dois = ids.split(",").map(&:upcase) - + __elasticsearch__.search({ from: 0, size: 1000,