Skip to content

Commit

Permalink
more specs for graphql. #401
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 26, 2020
1 parent 8a72165 commit 9ff0244
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 10 deletions.
43 changes: 42 additions & 1 deletion app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ type Audiovisual implements DoiItem {
Information about clients
"""
type Client {
"""
Client alternate name
"""
alternateName: String

"""
Datasets managed by the client
"""
Expand Down Expand Up @@ -273,6 +278,11 @@ type Client {
"""
systemEmail: String

"""
The type of the item.
"""
type: String!

"""
The homepage of the client
"""
Expand Down Expand Up @@ -3334,7 +3344,7 @@ type Provider {
query: String
software: String
year: String
): ClientConnectionWithMeta!
): ProviderClientConnectionWithMeta!

"""
Country where the provider is located
Expand All @@ -3346,6 +3356,11 @@ type Provider {
"""
description: String

"""
Provider display name
"""
displayName: String

"""
Field of science covered by provider
"""
Expand Down Expand Up @@ -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.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/graphql/types/client_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions app/graphql/types/funder_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions app/graphql/types/provider_client_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion app/graphql/types/provider_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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?
{
Expand Down
14 changes: 14 additions & 0 deletions spec/graphql/types/client_type_spec.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions spec/graphql/types/data_catalog_type_spec.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions spec/graphql/types/dataset_type_spec.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions spec/graphql/types/funder_type_spec.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions spec/graphql/types/provider_type_spec.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions spec/graphql/types/publication_type_spec.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/graphql/types/query_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/graphql/types/software_type_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9ff0244

Please sign in to comment.