From a5f660aecb97dc48c0cf4b0788e0269b327e1067 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Wed, 4 Dec 2019 14:55:30 +0000 Subject: [PATCH] support doi queries for client_id and provider_id in graphql --- app/graphql/types/query_type.rb | 24 ++++++++++++++++-------- spec/models/provider_spec.rb | 4 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 29e07d530..5e5c0e50f 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -146,15 +146,17 @@ def people(query: nil, first: nil) field :creative_works, CreativeWorkConnectionWithMetaType, null: false, connection: true, max_page_size: 100 do argument :query, String, required: false argument :ids, String, required: false + argument :client_id, String, required: false + argument :provider_id, String, required: false argument :first, Int, required: false, default_value: 25 end - def creative_works(query: nil, ids: nil, first: nil) + def creative_works(query: nil, ids: nil, client_id: nil, provider_id: nil, first: nil) if ids.present? dois = ids.split(",").map { |i| doi_from_url(i) } Doi.find_by_id(dois, page: { number: 1, size: first }).results.to_a else - Doi.query(query, state: "findable", page: { number: 1, size: first }).results.to_a + Doi.query(query, client_id: client_id, provider_id: provider_id, state: "findable", page: { number: 1, size: first }).results.to_a end end @@ -168,11 +170,13 @@ def creative_work(id:) field :datasets, DatasetConnectionWithMetaType, null: false, connection: true, max_page_size: 100 do argument :query, String, required: false + argument :client_id, String, required: false + argument :provider_id, String, required: false argument :first, Int, required: false, default_value: 25 end - def datasets(query: nil, first: nil) - Doi.query(query, resource_type_id: "Dataset", state: "findable", page: { number: 1, size: first }).results.to_a + def datasets(query: nil, client_id: nil, provider_id: nil, first: nil) + Doi.query(query, client_id: client_id, provider_id: provider_id, resource_type_id: "Dataset", state: "findable", page: { number: 1, size: first }).results.to_a end field :dataset, DatasetType, null: false do @@ -185,11 +189,13 @@ def dataset(id:) field :publications, PublicationConnectionWithMetaType, null: false, connection: true, max_page_size: 100 do argument :query, String, required: false + argument :client_id, String, required: false + argument :provider_id, String, required: false argument :first, Int, required: false, default_value: 25 end - def publications(query: nil, first: nil) - Doi.query(query, resource_type_id: "Text", state: "findable", page: { number: 1, size: first }).results.to_a + def publications(query: nil, client_id: nil, provider_id: nil, first: nil) + Doi.query(query, client_id: client_id, provider_id: provider_id, resource_type_id: "Text", state: "findable", page: { number: 1, size: first }).results.to_a end field :publication, PublicationType, null: false do @@ -355,11 +361,13 @@ def service(id:) field :software_source_codes, SoftwareConnectionWithMetaType, null: false, connection: true, max_page_size: 100 do argument :query, String, required: false + argument :client_id, String, required: false + argument :provider_id, String, required: false argument :first, Int, required: false, default_value: 25 end - def software_source_codes(query: nil, first: nil) - Doi.query(query, resource_type_id: "Software", state: "findable", page: { number: 1, size: first }).results.to_a + def software_source_codes(query: nil, client_id: nil, provider_id: nil, first: nil) + Doi.query(query, client_id: client_id, provider_id: provider_id, resource_type_id: "Software", state: "findable", page: { number: 1, size: first }).results.to_a end field :software_source_code, SoftwareType, null: false do diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb index 2a6566c06..7de240796 100644 --- a/spec/models/provider_spec.rb +++ b/spec/models/provider_spec.rb @@ -101,8 +101,8 @@ it "works" do expect(subject.role_name).to eq("ROLE_CONSORTIUM") - expect(subject.member_type).to eq("consortium") - expect(subject.member_type_label).to eq("Consortium") + expect(subject.member_type).to eq("consortium_member") + expect(subject.member_type_label).to eq("Consortium Member") expect(subject.consortium_organizations.length).to eq(3) consortium_organization = subject.consortium_organizations.last expect(consortium_organization.consortium_id).to eq("VIVA")