From 9ff0244c0a470eed367335d89becbf499304160d Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 26 Jan 2020 22:57:42 +0100 Subject: [PATCH] more specs for graphql. #401 --- app/graphql/schema.graphql | 43 ++++++++++++++++++- ...lient_dataset_connection_with_meta_type.rb | 2 +- app/graphql/types/client_type.rb | 6 +++ .../data_catalog_connection_with_meta_type.rb | 2 +- .../types/funder_connection_with_meta_type.rb | 5 +-- app/graphql/types/funder_type.rb | 4 +- ...ovider_client_connection_with_meta_type.rb | 14 ++++++ app/graphql/types/provider_type.rb | 8 +++- spec/graphql/types/client_type_spec.rb | 14 ++++++ spec/graphql/types/data_catalog_type_spec.rb | 16 +++++++ spec/graphql/types/dataset_type_spec.rb | 13 ++++++ spec/graphql/types/funder_type_spec.rb | 13 ++++++ spec/graphql/types/provider_type_spec.rb | 14 ++++++ spec/graphql/types/publication_type_spec.rb | 13 ++++++ spec/graphql/types/query_type_spec.rb | 2 +- spec/graphql/types/software_type_spec.rb | 13 ++++++ 16 files changed, 172 insertions(+), 10 deletions(-) create mode 100644 app/graphql/types/provider_client_connection_with_meta_type.rb create mode 100644 spec/graphql/types/client_type_spec.rb create mode 100644 spec/graphql/types/data_catalog_type_spec.rb create mode 100644 spec/graphql/types/dataset_type_spec.rb create mode 100644 spec/graphql/types/funder_type_spec.rb create mode 100644 spec/graphql/types/provider_type_spec.rb create mode 100644 spec/graphql/types/publication_type_spec.rb create mode 100644 spec/graphql/types/software_type_spec.rb diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 3363b108b..a7fbb6f06 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -154,6 +154,11 @@ type Audiovisual implements DoiItem { Information about clients """ type Client { + """ + Client alternate name + """ + alternateName: String + """ Datasets managed by the client """ @@ -273,6 +278,11 @@ type Client { """ systemEmail: String + """ + The type of the item. + """ + type: String! + """ The homepage of the client """ @@ -3334,7 +3344,7 @@ type Provider { query: String software: String year: String - ): ClientConnectionWithMeta! + ): ProviderClientConnectionWithMeta! """ Country where the provider is located @@ -3346,6 +3356,11 @@ type Provider { """ description: String + """ + Provider display name + """ + displayName: String + """ Field of science covered by provider """ @@ -3415,12 +3430,38 @@ type Provider { """ rorId: String! + """ + The type of the item. + """ + type: String! + """ Website of the provider """ website: String } +""" +The connection type for Client. +""" +type ProviderClientConnectionWithMeta { + """ + A list of edges. + """ + edges: [ClientEdge] + + """ + A list of nodes. + """ + nodes: [Client] + + """ + Information to aid in pagination. + """ + pageInfo: PageInfo! + totalCount: Int! +} + """ The connection type for Provider. """ diff --git a/app/graphql/types/client_dataset_connection_with_meta_type.rb b/app/graphql/types/client_dataset_connection_with_meta_type.rb index 0e5a6f326..91053e9e3 100644 --- a/app/graphql/types/client_dataset_connection_with_meta_type.rb +++ b/app/graphql/types/client_dataset_connection_with_meta_type.rb @@ -3,7 +3,7 @@ class ClientDatasetConnectionWithMetaType < BaseConnection edge_type(DatasetEdgeType) field_class GraphQL::Cache::Field - + field :total_count, Integer, null: false, cache: true def total_count diff --git a/app/graphql/types/client_type.rb b/app/graphql/types/client_type.rb index ce96ac689..7d125db9a 100644 --- a/app/graphql/types/client_type.rb +++ b/app/graphql/types/client_type.rb @@ -4,7 +4,9 @@ class ClientType < BaseObject description "Information about clients" field :id, ID, null: false, hash_key: "uid", description: "Unique identifier for each client" + field :type, String, null: false, description: "The type of the item." field :name, String, null: false, description: "Client name" + field :alternate_name, String, null: true, description: "Client alternate 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" @@ -31,6 +33,10 @@ class ClientType < BaseObject argument :first, Int, required: false, default_value: 25 end + def type + "Client" + end + def prefixes(**args) collection = ClientPrefix.joins(:client, :prefix).where('datacentre.symbol = ?', object.uid) collection = collection.query(args[:query]) if args[:query].present? diff --git a/app/graphql/types/data_catalog_connection_with_meta_type.rb b/app/graphql/types/data_catalog_connection_with_meta_type.rb index f780859d4..7c02dd45a 100644 --- a/app/graphql/types/data_catalog_connection_with_meta_type.rb +++ b/app/graphql/types/data_catalog_connection_with_meta_type.rb @@ -3,7 +3,7 @@ class DataCatalogConnectionWithMetaType < BaseConnection edge_type(DataCatalogEdgeType) field_class GraphQL::Cache::Field - + field :total_count, Integer, null: true, cache: true field :dataset_connection_count, Integer, null: false, cache: true diff --git a/app/graphql/types/funder_connection_with_meta_type.rb b/app/graphql/types/funder_connection_with_meta_type.rb index 45c170890..4d1ab00f7 100644 --- a/app/graphql/types/funder_connection_with_meta_type.rb +++ b/app/graphql/types/funder_connection_with_meta_type.rb @@ -1,10 +1,9 @@ # frozen_string_literal: true class FunderConnectionWithMetaType < BaseConnection - edge_type(FunderEdgeType) field_class GraphQL::Cache::Field - + field :total_count, Integer, null: false, cache: true field :publication_connection_count, Integer, null: false, cache: true field :dataset_connection_count, Integer, null: false, cache: true @@ -15,7 +14,7 @@ def total_count Funder.query(args[:query], limit: 0).dig(:meta, "total").to_i end - + def publication_connection_count Event.query(nil, citation_type: "Funder-ScholarlyArticle").results.total end diff --git a/app/graphql/types/funder_type.rb b/app/graphql/types/funder_type.rb index b1652cae1..cadf02d78 100644 --- a/app/graphql/types/funder_type.rb +++ b/app/graphql/types/funder_type.rb @@ -2,7 +2,7 @@ class FunderType < BaseObject description "Information about funders" - + field :id, ID, null: false, description: "Crossref Funder ID" field :type, String, null: false, description: "The type of the item." field :name, String, null: false, description: "The name of the funder." @@ -34,7 +34,7 @@ def datasets(**args) ids = Event.query(nil, obj_id: object[:id], citation_type: "Dataset-Funder").results.to_a.map do |e| doi_from_url(e.subj_id) end - + ElasticsearchLoader.for(Doi).load_many(ids) end diff --git a/app/graphql/types/provider_client_connection_with_meta_type.rb b/app/graphql/types/provider_client_connection_with_meta_type.rb new file mode 100644 index 000000000..fd8ebb1db --- /dev/null +++ b/app/graphql/types/provider_client_connection_with_meta_type.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class ProviderClientConnectionWithMetaType < BaseConnection + edge_type(ClientEdgeType) + field_class GraphQL::Cache::Field + + field :total_count, Integer, null: false, cache: true + + def total_count + args = object.arguments + + Client.query(args[:query], provider_id: object.parent.uid, year: args[:year], software: args[:software], page: { number: 1, size: 0 }).results.total + end +end diff --git a/app/graphql/types/provider_type.rb b/app/graphql/types/provider_type.rb index 9fdcac724..eba303fb7 100644 --- a/app/graphql/types/provider_type.rb +++ b/app/graphql/types/provider_type.rb @@ -4,7 +4,9 @@ class ProviderType < BaseObject description "Information about providers" field :id, ID, null: false, hash_key: "uid", description: "Unique identifier for each provider" + field :type, String, null: false, description: "The type of the item." field :name, String, null: false, description: "Provider name" + field :displayName, String, null: true, description: "Provider display name" field :ror_id, String, null: false, description: "Research Organization Registry (ROR) identifier" field :description, String, null: true, description: "Description of the provider" field :website, String, null: true, description: "Website of the provider" @@ -22,13 +24,17 @@ class ProviderType < BaseObject argument :first, Int, required: false, default_value: 25 end - field :clients, ClientConnectionWithMetaType, null: false, description: "Clients associated with the provider", connection: true do + field :clients, ProviderClientConnectionWithMetaType, null: false, description: "Clients associated with the provider", connection: true do 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 type + "Provider" + end + def country return {} unless object.country_code.present? { diff --git a/spec/graphql/types/client_type_spec.rb b/spec/graphql/types/client_type_spec.rb new file mode 100644 index 000000000..679b8b7bd --- /dev/null +++ b/spec/graphql/types/client_type_spec.rb @@ -0,0 +1,14 @@ +require "rails_helper" + +describe ClientType do + describe "fields" do + subject { described_class } + + it { is_expected.to have_field(:id).of_type(!types.ID) } + it { is_expected.to have_field(:type).of_type("String!") } + it { is_expected.to have_field(:name).of_type("String!") } + it { is_expected.to have_field(:alternateName).of_type("String") } + it { is_expected.to have_field(:description).of_type("String") } + it { is_expected.to have_field(:datasets).of_type("ClientDatasetConnectionWithMeta!") } + end +end diff --git a/spec/graphql/types/data_catalog_type_spec.rb b/spec/graphql/types/data_catalog_type_spec.rb new file mode 100644 index 000000000..26f57fc7d --- /dev/null +++ b/spec/graphql/types/data_catalog_type_spec.rb @@ -0,0 +1,16 @@ +# require "rails_helper" + +# describe DataCatalogType do +# describe "fields" do +# subject { described_class } + +# it { is_expected.to have_field(:id).of_type(!types.ID) } +# it { is_expected.to have_field(:type).of_type("String!") } +# # it { is_expected.to have_field(:name).of_type("[Person!]") } +# # it { is_expected.to have_field(:alternateName).of_type("[Title!]") } +# # it { is_expected.to have_field(:description).of_type("Int") } +# # it { is_expected.to have_field(:certicates).of_type("String") } +# # it { is_expected.to have_field(:subjects).of_type("String") } +# # it { is_expected.to have_field(:datasets).of_type("String") } +# end +# end diff --git a/spec/graphql/types/dataset_type_spec.rb b/spec/graphql/types/dataset_type_spec.rb new file mode 100644 index 000000000..0116cd62d --- /dev/null +++ b/spec/graphql/types/dataset_type_spec.rb @@ -0,0 +1,13 @@ +require "rails_helper" + +describe DatasetType do + describe "fields" do + subject { described_class } + + it { is_expected.to have_field(:id).of_type(!types.ID) } + it { is_expected.to have_field(:type).of_type("String!") } + it { is_expected.to have_field(:datasets).of_type("DatasetDatasetConnectionWithMeta!") } + it { is_expected.to have_field(:publications).of_type("DatasetPublicationConnectionWithMeta!") } + it { is_expected.to have_field(:softwareSourceCodes).of_type("DatasetSoftwareConnectionWithMeta!") } + end +end diff --git a/spec/graphql/types/funder_type_spec.rb b/spec/graphql/types/funder_type_spec.rb new file mode 100644 index 000000000..3d57ac5e8 --- /dev/null +++ b/spec/graphql/types/funder_type_spec.rb @@ -0,0 +1,13 @@ +require "rails_helper" + +describe FunderType do + describe "fields" do + subject { described_class } + + it { is_expected.to have_field(:id).of_type(!types.ID) } + it { is_expected.to have_field(:type).of_type("String!") } + it { is_expected.to have_field(:name).of_type("String!") } + it { is_expected.to have_field(:alternateName).of_type("[String!]") } + it { is_expected.to have_field(:datasets).of_type("FunderDatasetConnectionWithMeta!") } + end +end diff --git a/spec/graphql/types/provider_type_spec.rb b/spec/graphql/types/provider_type_spec.rb new file mode 100644 index 000000000..dcc7c5fe1 --- /dev/null +++ b/spec/graphql/types/provider_type_spec.rb @@ -0,0 +1,14 @@ +require "rails_helper" + +describe ProviderType do + describe "fields" do + subject { described_class } + + it { is_expected.to have_field(:id).of_type(!types.ID) } + it { is_expected.to have_field(:type).of_type("String!") } + it { is_expected.to have_field(:name).of_type("String!") } + it { is_expected.to have_field(:displayName).of_type("String") } + it { is_expected.to have_field(:description).of_type("String") } + it { is_expected.to have_field(:clients).of_type("ProviderClientConnectionWithMeta!") } + end +end diff --git a/spec/graphql/types/publication_type_spec.rb b/spec/graphql/types/publication_type_spec.rb new file mode 100644 index 000000000..ce1d75b13 --- /dev/null +++ b/spec/graphql/types/publication_type_spec.rb @@ -0,0 +1,13 @@ +require "rails_helper" + +describe PublicationType do + describe "fields" do + subject { described_class } + + it { is_expected.to have_field(:id).of_type(!types.ID) } + it { is_expected.to have_field(:type).of_type("String!") } + it { is_expected.to have_field(:datasets).of_type("PublicationDatasetConnectionWithMeta!") } + it { is_expected.to have_field(:publications).of_type("PublicationPublicationConnectionWithMeta!") } + it { is_expected.to have_field(:softwareSourceCodes).of_type("PublicationSoftwareConnectionWithMeta!") } + end +end diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index 8311b2ad8..9bf5ce276 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -12,7 +12,7 @@ it { is_expected.to have_field(:services).of_type("ServiceConnectionWithMeta!") } end - describe "query", elasticsearch: true do + describe "query datasets", elasticsearch: true do let!(:datasets) { create_list(:doi, 3, aasm_state: "findable") } before do diff --git a/spec/graphql/types/software_type_spec.rb b/spec/graphql/types/software_type_spec.rb new file mode 100644 index 000000000..400204f8e --- /dev/null +++ b/spec/graphql/types/software_type_spec.rb @@ -0,0 +1,13 @@ +require "rails_helper" + +describe SoftwareType do + describe "fields" do + subject { described_class } + + it { is_expected.to have_field(:id).of_type(!types.ID) } + it { is_expected.to have_field(:type).of_type("String!") } + it { is_expected.to have_field(:datasets).of_type("SoftwareDatasetConnectionWithMeta!") } + it { is_expected.to have_field(:publications).of_type("SoftwarePublicationConnectionWithMeta!") } + it { is_expected.to have_field(:softwareSourceCodes).of_type("SoftwareSoftwareConnectionWithMeta!") } + end +end