diff --git a/app/graphql/types/client_dataset_connection_with_meta_type.rb b/app/graphql/types/client_dataset_connection_with_meta_type.rb new file mode 100644 index 000000000..0e788f9c4 --- /dev/null +++ b/app/graphql/types/client_dataset_connection_with_meta_type.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class ClientDatasetConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection + edge_type(DatasetEdgeType) + + field :total_count, Integer, null: false + + def total_count + args = object.arguments + + Doi.query(args[:query], client_id: object.parent.uid, resource_type_id: "Dataset", state: "findable", page: { number: 1, size: args[:first] }).results.total + end +end diff --git a/app/graphql/types/client_publication_connection_with_meta_type.rb b/app/graphql/types/client_publication_connection_with_meta_type.rb new file mode 100644 index 000000000..c229fa3aa --- /dev/null +++ b/app/graphql/types/client_publication_connection_with_meta_type.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class ClientPublicationConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection + edge_type(DatasetEdgeType) + + field :total_count, Integer, null: false + + def total_count + args = object.arguments + + Doi.query(args[:query], client_id: object.parent.uid, resource_type_id: "Text", state: "findable", page: { number: 1, size: args[:first] }).results.total + end +end diff --git a/app/graphql/types/client_software_connection_with_meta_type.rb b/app/graphql/types/client_software_connection_with_meta_type.rb new file mode 100644 index 000000000..ffdde48e6 --- /dev/null +++ b/app/graphql/types/client_software_connection_with_meta_type.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class ClientSoftwareConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection + edge_type(DatasetEdgeType) + + field :total_count, Integer, null: false + + def total_count + args = object.arguments + + Doi.query(args[:query], client_id: object.parent.uid, resource_type_id: "Software", state: "findable", page: { number: 1, size: args[:first] }).results.total + end +end diff --git a/app/graphql/types/client_type.rb b/app/graphql/types/client_type.rb index 3004a9409..3baa6588f 100644 --- a/app/graphql/types/client_type.rb +++ b/app/graphql/types/client_type.rb @@ -17,12 +17,17 @@ class ClientType < GraphQL::Schema::Object argument :first, Int, required: false, default_value: 25 end - field :datasets, [DatasetType], null: false, description: "Datasets managed by the client" do + field :datasets, ClientDatasetConnectionWithMetaType, null: false, connection: true, max_page_size: 100, description: "Datasets managed by the client" do argument :query, String, required: false argument :first, Int, required: false, default_value: 25 end - field :publications, [PublicationType], null: false, description: "Publications managed by the client" do + field :publications, ClientPublicationConnectionWithMetaType, null: false, connection: true, max_page_size: 100, null: false, description: "Publications managed by the client" do + argument :query, String, required: false + argument :first, Int, required: false, default_value: 25 + end + + field :publications, ClientSoftwareConnectionWithMetaType, null: false, connection: true, max_page_size: 100, null: false, description: "Software managed by the client" do argument :query, String, required: false argument :first, Int, required: false, default_value: 25 end @@ -41,4 +46,8 @@ def datasets(**args) def publications(**args) Doi.query(args[:query], client_id: object.uid, resource_type_id: "Text", page: { number: 1, size: args[:first] }).records.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 + end end