Skip to content

Commit

Permalink
support graphql doi queries by list of IDs. #366
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Nov 28, 2019
1 parent 36f7559 commit 811f214
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 61 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ gem 'graphql-cache', '~> 0.6.0', git: "https://github.com/stackshareio/graphql-c
gem 'apollo-federation', '~> 0.5.1'
gem 'google-protobuf', '3.10.0.rc.1'
gem 'sprockets', '~> 3.7', '>= 3.7.2'
gem 'elastic-apm', '~> 3.2'

group :development, :test do
gem 'rspec-rails', '~> 3.8', '>= 3.8.2'
Expand Down
101 changes: 43 additions & 58 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ GEM
specs:
aasm (5.0.6)
concurrent-ruby (~> 1.0)
actioncable (5.2.3)
actionpack (= 5.2.3)
actioncable (5.2.4)
actionpack (= 5.2.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.3)
actionpack (= 5.2.3)
actionview (= 5.2.3)
activejob (= 5.2.3)
actionmailer (5.2.4)
actionpack (= 5.2.4)
actionview (= 5.2.4)
activejob (= 5.2.4)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.3)
actionview (= 5.2.3)
activesupport (= 5.2.3)
actionpack (5.2.4)
actionview (= 5.2.4)
activesupport (= 5.2.4)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.3)
activesupport (= 5.2.3)
actionview (5.2.4)
activesupport (= 5.2.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
Expand All @@ -38,20 +38,20 @@ GEM
activemodel (>= 4.1, < 6.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (5.2.3)
activesupport (= 5.2.3)
activejob (5.2.4)
activesupport (= 5.2.4)
globalid (>= 0.3.6)
activemodel (5.2.3)
activesupport (= 5.2.3)
activerecord (5.2.3)
activemodel (= 5.2.3)
activesupport (= 5.2.3)
activemodel (5.2.4)
activesupport (= 5.2.4)
activerecord (5.2.4)
activemodel (= 5.2.4)
activesupport (= 5.2.4)
arel (>= 9.0)
activestorage (5.2.3)
actionpack (= 5.2.3)
activerecord (= 5.2.3)
activestorage (5.2.4)
actionpack (= 5.2.4)
activerecord (= 5.2.4)
marcel (~> 0.3.1)
activesupport (5.2.3)
activesupport (5.2.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
Expand All @@ -67,13 +67,13 @@ GEM
audited (4.9.0)
activerecord (>= 4.2, < 6.1)
aws-eventstream (1.0.3)
aws-partitions (1.244.0)
aws-sdk-core (3.81.0)
aws-partitions (1.246.0)
aws-sdk-core (3.82.0)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.25.0)
aws-sdk-kms (1.26.0)
aws-sdk-core (~> 3, >= 3.71.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.57.0)
Expand Down Expand Up @@ -191,9 +191,6 @@ GEM
sxp (~> 1.0)
edtf (3.0.5)
activesupport (>= 3.0, < 7.0)
elastic-apm (3.2.0)
concurrent-ruby (~> 1.0)
http (>= 3.0)
elasticsearch (7.1.0)
elasticsearch-api (= 7.1.0)
elasticsearch-transport (= 7.1.0)
Expand Down Expand Up @@ -222,7 +219,7 @@ GEM
railties (>= 3.0.0)
faker (1.9.6)
i18n (>= 0.7)
faraday (0.17.0)
faraday (0.17.1)
multipart-post (>= 1.2, < 3)
faraday-encoding (0.0.5)
faraday
Expand All @@ -233,10 +230,7 @@ GEM
faraday (>= 0.9)
fast_jsonapi (1.5)
activesupport (>= 4.2)
ffi (1.11.2)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
ffi (1.11.3)
flipper (0.16.2)
flipper-active_support_cache_store (0.16.2)
activesupport (>= 3.2, < 6)
Expand All @@ -261,16 +255,8 @@ GEM
hashdiff (1.0.0)
hashie (4.0.0)
htmlentities (4.3.4)
http (4.2.0)
addressable (~> 2.3)
http-cookie (~> 1.0)
http-form_data (~> 2.0)
http-parser (~> 1.2.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
http-form_data (2.1.1)
http-parser (1.2.1)
ffi-compiler (>= 1.0, < 2.0)
i18n (1.7.0)
concurrent-ruby (~> 1.0)
i18n_data (0.8.0)
Expand Down Expand Up @@ -316,7 +302,7 @@ GEM
logstash-event (1.2.02)
logstash-logger (0.26.1)
logstash-event (~> 1.2)
loofah (2.3.1)
loofah (2.4.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
Expand Down Expand Up @@ -384,27 +370,27 @@ GEM
rack (>= 1.0, < 3)
rack-utf8_sanitizer (1.6.0)
rack (>= 1.0, < 3.0)
rails (5.2.3)
actioncable (= 5.2.3)
actionmailer (= 5.2.3)
actionpack (= 5.2.3)
actionview (= 5.2.3)
activejob (= 5.2.3)
activemodel (= 5.2.3)
activerecord (= 5.2.3)
activestorage (= 5.2.3)
activesupport (= 5.2.3)
rails (5.2.4)
actioncable (= 5.2.4)
actionmailer (= 5.2.4)
actionpack (= 5.2.4)
actionview (= 5.2.4)
activejob (= 5.2.4)
activemodel (= 5.2.4)
activerecord (= 5.2.4)
activestorage (= 5.2.4)
activesupport (= 5.2.4)
bundler (>= 1.3.0)
railties (= 5.2.3)
railties (= 5.2.4)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (5.2.3)
actionpack (= 5.2.3)
activesupport (= 5.2.3)
railties (5.2.4)
actionpack (= 5.2.4)
activesupport (= 5.2.4)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
Expand Down Expand Up @@ -522,7 +508,7 @@ GEM
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.10)
trollop (2.9.9)
trollop (2.9.10)
turnout (2.5.0)
i18n (>= 0.7, < 2)
rack (>= 1.3, < 3)
Expand Down Expand Up @@ -575,7 +561,6 @@ DEPENDENCIES
database_cleaner
diffy (~> 3.2, >= 3.2.1)
dotenv
elastic-apm (~> 3.2)
elasticsearch (~> 7.1.0)
elasticsearch-extensions (~> 0.0.29)
elasticsearch-model (~> 7.0)
Expand Down
10 changes: 8 additions & 2 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,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 :first, Int, required: false, default_value: 25
end

def creative_works(query: nil, first: nil)
Doi.query(query, state: "findable", page: { number: 1, size: first }).results.to_a
def creative_works(query: nil, ids: 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
end
end

field :creative_work, CreativeWorkType, null: false do
Expand Down

0 comments on commit 811f214

Please sign in to comment.