Skip to content

Commit

Permalink
fix graphql specs. #422, #424, #440
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 4, 2020
1 parent 519550e commit 384e24f
Show file tree
Hide file tree
Showing 12 changed files with 3,572 additions and 538 deletions.
3,943 changes: 3,460 additions & 483 deletions app/graphql/schema.graphql

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions app/graphql/types/dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def response(**args)
re3data_id: args[:re3data_id],
year: args[:year],
resource_type_id: "Dataset",
has_person: args[:has_person],
has_funder: args[:has_funder],
has_organization: args[:has_organization],
has_citations: args[:has_citations],
has_views: args[:has_views],
has_downloads: args[:has_downloads],
Expand Down
17 changes: 16 additions & 1 deletion app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ module DoiItem
argument :funder_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_person, Boolean, required: false
argument :has_funder, Boolean, required: false
argument :has_organization, Boolean, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
Expand All @@ -64,6 +67,9 @@ module DoiItem
argument :funder_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_person, Boolean, required: false
argument :has_funder, Boolean, required: false
argument :has_organization, Boolean, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
Expand All @@ -76,6 +82,9 @@ module DoiItem
argument :funder_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_person, Boolean, required: false
argument :has_funder, Boolean, required: false
argument :has_organization, Boolean, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
Expand All @@ -88,6 +97,9 @@ module DoiItem
argument :funder_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_person, Boolean, required: false
argument :has_funder, Boolean, required: false
argument :has_organization, Boolean, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
Expand All @@ -100,6 +112,9 @@ module DoiItem
argument :funder_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_person, Boolean, required: false
argument :has_funder, Boolean, required: false
argument :has_organization, Boolean, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
Expand Down Expand Up @@ -204,7 +219,7 @@ def version_of(**args)
def response(**args)
return [] if args[:ids].blank?

@response ||= Doi.query(args[:query], ids: args[:ids], funder_id: object[:id], user_id: args[:user_id], client_id: args[:client_id], provider_id: args[:provider_id], has_citations: args[:has_citations], has_views: args[:has_views], has_downloads: args[:has_downloads], state: "findable", page: { number: 1, size: args[:first] }).results.to_a
@response ||= Doi.query(args[:query], ids: args[:ids], funder_id: object[:id], user_id: args[:user_id], client_id: args[:client_id], provider_id: args[:provider_id], has_person: args[:has_person], has_funder: args[:has_funder], has_organization: args[:has_organization], has_citations: args[:has_citations], has_views: args[:has_views], has_downloads: args[:has_downloads], state: "findable", page: { number: 1, size: args[:first] }).results.to_a
end

def doi_link(url)
Expand Down
5 changes: 4 additions & 1 deletion app/graphql/types/publication_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def response(**args)
affiliation_id: args[:affiliation_id],
re3data_id: args[:re3data_id],
year: args[:year],
resource_type_id: "Text",
resource_type_id: "Text",
has_person: args[:has_person],
has_funder: args[:has_funder],
has_organization: args[:has_organization],
has_citations: args[:has_citations],
has_views: args[:has_views],
has_downloads: args[:has_downloads],
Expand Down
105 changes: 69 additions & 36 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,18 @@ def people(query: nil, first: nil)
argument :user_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :resource_type_id, String, required: false
argument :has_person, Boolean, required: false
argument :has_funder, Boolean, required: false
argument :has_organization, Boolean, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
end

def works(query: nil, ids: nil, user_id: nil, client_id: nil, provider_id: nil, first: nil)
if ids.present?
dois = ids.split(",").map { |i| doi_from_url(i) }
ElasticsearchLoader.for(Doi).load_many(dois)
else
Doi.query(query, user_id: user_id, client_id: client_id, provider_id: provider_id, state: "findable", page: { number: 1, size: first }).results.to_a
end
def works(**args)
response(**args)
end

field :work, WorkType, null: false do
Expand All @@ -173,14 +175,18 @@ def work(id:)
argument :user_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_person, Boolean, required: false
argument :has_funder, Boolean, required: false
argument :has_organization, Boolean, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
end

def datasets(query: nil, user_id: nil, client_id: nil, provider_id: nil, has_citations: nil, has_views: nil, has_downloads: nil, first: nil)
Doi.query(query, user_id: user_id.present? ? orcid_from_url(user_id) : nil, client_id: client_id, provider_id: provider_id, resource_type_id: "Dataset", state: "findable", has_citations: has_citations, has_views: has_views, has_downloads: has_downloads, page: { number: 1, size: first }).results.to_a
def datasets(**args)
args[:resource_type_id] = "Dataset"
response(**args)
end

field :dataset, DatasetType, null: false do
Expand All @@ -196,14 +202,18 @@ def dataset(id:)
argument :user_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_person, Boolean, required: false
argument :has_funder, Boolean, required: false
argument :has_organization, Boolean, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
end

def publications(query: nil, user_id: nil, client_id: nil, provider_id: nil, has_citations: nil, has_views: nil, has_downloads: nil, first: nil)
Doi.query(query, user_id: user_id.present? ? orcid_from_url(user_id) : nil, client_id: client_id, provider_id: provider_id, has_citations: has_citations, has_views: has_views, has_downloads: has_downloads, resource_type_id: "Text", state: "findable", page: { number: 1, size: first }).results.to_a
def publications(query: nil, user_id: nil, client_id: nil, provider_id: nil, has_person: args[:has_person], has_funder: args[:has_funder], has_organization: args[:has_organization], has_citations: nil, has_views: nil, has_downloads: nil, first: nil)
args[:resource_type_id] = "Text"
response(**args)
end

field :publication, PublicationType, null: false do
Expand All @@ -222,8 +232,9 @@ def publication(id:)
argument :first, Int, required: false, default_value: 25
end

def audiovisuals(query: nil, has_citations: nil, has_views: nil, has_downloads: nil, first: nil)
Doi.query(query, resource_type_id: "Audiovisual", state: "findable", has_citations: has_citations, has_views: has_views, has_downloads: has_downloads, page: { number: 1, size: first }).results.to_a
def audiovisuals(**args)
args[:resource_type_id] = "Audiovisual"
response(**args)
end

field :audiovisual, AudiovisualType, null: false do
Expand All @@ -239,8 +250,9 @@ def audiovisual(id:)
argument :first, Int, required: false, default_value: 25
end

def collections(query: nil, first: nil)
Doi.query(query, resource_type_id: "Collection", state: "findable", page: { number: 1, size: first }).results.to_a
def collections(**args)
args[:resource_type_id] = "Collection"
response(**args)
end

field :collection, CollectionType, null: false do
Expand All @@ -256,8 +268,9 @@ def collection(id:)
argument :first, Int, required: false, default_value: 25
end

def data_papers(query: nil, first: nil)
Doi.query(query, resource_type_id: "DataPaper", state: "findable", page: { number: 1, size: first }).results.to_a
def data_papers(**args)
args[:resource_type_id] = "DataPaper"
response(**args)
end

field :data_paper, DataPaperType, null: false do
Expand All @@ -273,8 +286,9 @@ def data_paper(id:)
argument :first, Int, required: false, default_value: 25
end

def events(query: nil, first: nil)
Doi.query(query, resource_type_id: "Event", state: "findable", page: { number: 1, size: first }).results.to_a
def events(**args)
args[:resource_type_id] = "Event"
response(**args)
end

field :event, EventType, null: false do
Expand All @@ -290,8 +304,9 @@ def event(id:)
argument :first, Int, required: false, default_value: 25
end

def images(query: nil, first: nil)
Doi.query(query, resource_type_id: "Image", state: "findable", page: { number: 1, size: first }).results.to_a
def images(**args)
args[:resource_type_id] = "Image"
response(**args)
end

field :image, ImageType, null: false do
Expand All @@ -310,8 +325,9 @@ def image(id:)
argument :first, Int, required: false, default_value: 25
end

def interactive_resources(query: nil, has_citations: nil, has_views: nil, has_downloads: nil, first: nil)
Doi.query(query, resource_type_id: "InteractiveResource", state: "findable", has_citations: has_citations, has_views: has_views, has_downloads: has_downloads, page: { number: 1, size: first }).results.to_a
def interactive_resources(**args)
args[:resource_type_id] = "InteractiveResource"
response(**args)
end

field :interactive_resource, InteractiveResourceType, null: false do
Expand All @@ -327,8 +343,9 @@ def interactive_resource(id:)
argument :first, Int, required: false, default_value: 25
end

def models(query: nil, first: nil)
Doi.query(query, resource_type_id: "Model", state: "findable", page: { number: 1, size: first }).results.to_a
def models(**args)
args[:resource_type_id] = "Model"
response(**args)
end

field :model, ModelType, null: false do
Expand All @@ -344,14 +361,18 @@ def model(id:)
argument :user_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_person, Boolean, required: false
argument :has_funder, Boolean, required: false
argument :has_organization, Boolean, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
end

def physical_objects(query: nil, user_id: nil, client_id: nil, provider_id: nil, has_citations: nil, has_views: nil, has_downloads: nil, first: nil)
Doi.query(query, user_id: user_id.present? ? orcid_from_url(user_id) : nil, client_id: client_id, provider_id: provider_id, resource_type_id: "PhysicalObject", state: "findable", has_citations: has_citations, has_views: has_views, has_downloads: has_downloads, page: { number: 1, size: first }).results.to_a
def physical_objects(query: nil, user_id: nil, client_id: nil, provider_id: nil, has_person: args[:has_person], has_funder: args[:has_funder], has_organization: args[:has_organization], has_citations: nil, has_views: nil, has_downloads: nil, first: nil)
args[:resource_type_id] = "PhysicalObject"
response(**args)
end

field :physical_object, PhysicalObjectType, null: false do
Expand All @@ -370,7 +391,8 @@ def physical_object(id:)
end

def services(**args)
Doi.query(args[:query], resource_type_id: "Service", client_id: args[:client_id], provider_id: args[:provider_id], state: "findable", page: { number: 1, size: args[:first] }).results.to_a
args[:resource_type_id] = "Service"
response(**args)
end

field :service, ServiceType, null: false do
Expand All @@ -386,14 +408,18 @@ def service(id:)
argument :user_id, String, required: false
argument :client_id, String, required: false
argument :provider_id, String, required: false
argument :has_person, Boolean, required: false
argument :has_funder, Boolean, required: false
argument :has_organization, Boolean, required: false
argument :has_citations, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
end

def softwares(query: nil, user_id: nil, client_id: nil, provider_id: nil, has_citations: nil, has_views: nil, has_downloads: nil, first: nil)
Doi.query(query, user_id: user_id.present? ? orcid_from_url(user_id) : nil, client_id: client_id, provider_id: provider_id, has_citations: has_citations, has_views: has_views, has_downloads: has_downloads, resource_type_id: "Software", state: "findable", page: { number: 1, size: first }).results.to_a
def softwares(**args)
args[:resource_type_id] = "Software"
response(**args)
end

field :software, SoftwareType, null: false do
Expand All @@ -409,8 +435,9 @@ def software(id:)
argument :first, Int, required: false, default_value: 25
end

def sounds(query: nil, first: nil)
Doi.query(query, resource_type_id: "Sound", state: "findable", page: { number: 1, size: first }).results.to_a
def sounds(**args)
args[:resource_type_id] = "Sound"
response(**args)
end

field :sound, SoundType, null: false do
Expand All @@ -426,8 +453,9 @@ def sound(id:)
argument :first, Int, required: false, default_value: 25
end

def workflows(query: nil, first: nil)
Doi.query(query, resource_type_id: "Workflow", state: "findable", page: { number: 1, size: first }).results.to_a
def workflows(**args)
args[:resource_type_id] = "Workflow"
response(**args)
end

field :workflow, WorkflowType, null: false do
Expand All @@ -443,8 +471,9 @@ def workflow(id:)
argument :first, Int, required: false, default_value: 25
end

def others(query: nil, first: nil)
Doi.query(query, resource_type_id: "Other", state: "findable", page: { number: 1, size: first }).results.to_a
def others(**args)
args[:resource_type_id] = "Other"
response(**args)
end

field :other, OtherType, null: false do
Expand Down Expand Up @@ -474,6 +503,10 @@ def usage_report(id:)
result
end

def response(**args)
@response ||= Doi.query(args[:query], ids: args[:ids], user_id: args[:user_id], client_id: args[:client_id], provider_id: args[:provider_id], resource_type_id: args[:resource_type_id], has_person: args[:has_person], has_funder: args[:has_funder], has_organization: args[:has_organization], has_citations: args[:has_citations], has_views: args[:has_views], has_downloads: args[:has_downloads], state: "findable", page: { number: 1, size: args[:first] }).results.to_a
end

def set_doi(id)
doi = doi_from_url(id)
fail ActiveRecord::RecordNotFound if doi.nil?
Expand Down
5 changes: 4 additions & 1 deletion app/graphql/types/software_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def response(**args)
affiliation_id: args[:affiliation_id],
re3data_id: args[:re3data_id],
year: args[:year],
resource_type_id: "Software",
resource_type_id: "Software",
has_person: args[:has_person],
has_funder: args[:has_funder],
has_organization: args[:has_organization],
has_citations: args[:has_citations],
has_views: args[:has_views],
has_downloads: args[:has_downloads],
Expand Down
5 changes: 4 additions & 1 deletion app/graphql/types/work_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def response(**args)
affiliation_id: args[:affiliation_id],
re3data_id: args[:re3data_id],
year: args[:year],
resource_type_id: args[:resource_type_id],
resource_type_id: args[:resource_type_id],
has_person: args[:has_person],
has_funder: args[:has_funder],
has_organization: args[:has_organization],
has_citations: args[:has_citations],
has_views: args[:has_views],
has_downloads: args[:has_downloads],
Expand Down
3 changes: 0 additions & 3 deletions spec/graphql/types/dataset_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

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
8 changes: 6 additions & 2 deletions spec/graphql/types/doi_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
it { is_expected.to have_field(:citationsOverTime).of_type("[YearTotal!]") }
it { is_expected.to have_field(:viewsOverTime).of_type("[YearMonthTotal!]") }
it { is_expected.to have_field(:downloadsOverTime).of_type("[YearMonthTotal!]") }
it { is_expected.to have_field(:citations).of_type("[Work!]") }
it { is_expected.to have_field(:references).of_type("[Work!]") }
it { is_expected.to have_field(:citations).of_type("WorkConnectionWithMeta") }
it { is_expected.to have_field(:references).of_type("WorkConnectionWithMeta") }
it { is_expected.to have_field(:parts).of_type("WorkConnectionWithMeta") }
it { is_expected.to have_field(:part_of).of_type("WorkConnectionWithMeta") }
it { is_expected.to have_field(:versions).of_type("WorkConnectionWithMeta") }
it { is_expected.to have_field(:version_of).of_type("WorkConnectionWithMeta") }
end
end
3 changes: 0 additions & 3 deletions spec/graphql/types/publication_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

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
Loading

0 comments on commit 384e24f

Please sign in to comment.