Skip to content

Commit

Permalink
support doi queries for client_id and provider_id in graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 4, 2019
1 parent abfcb5a commit a5f660a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 16 additions & 8 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/models/provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a5f660a

Please sign in to comment.