graphql-searchkick 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 235a0119fe2602c6aeb34499722732867652dbb2b87dda7a47b50057aa448c7e
4
- data.tar.gz: cabaf6e7cfdd93d7975bcad1cc17bbc9f432f050a02a552ca049170cbe52bb63
3
+ metadata.gz: 4fee00e8a9d4edbe1018df1d8982027893e187fb27badc7e09e7f73e47d132db
4
+ data.tar.gz: 901185c3a8834928539f8f2fcb310e9b5653b3e8cc896115dab20bad88f04784
5
5
  SHA512:
6
- metadata.gz: 9bb1e7558b2c6fb51043dfee2feac38fa38e1713dc5b262aadba75b036cee0ad0a69c23b655d5d0966214c91e0b43d62e6d75362b80c843d9c6d05b608bfe9a8
7
- data.tar.gz: 6f26cead074d9fb63578a02f01fa00d2159b8c2118c64e477dd68505ce9c2e358eb7ded075d1272d1575928e4a799592eeb2d1a1ab6a82763955a5de6054dfbb
6
+ metadata.gz: dd780c7d95f84876a8d4d50b6852e34f14d947ce305895fbbd6c953861ec931abbe29d4da721b2760a571d7f4ee4606c7fd5c217fa7f36ad55c49fd940b7e564
7
+ data.tar.gz: a03fa9e8472e1da6e89af95a12d95d7e3d901d7438cc5cf0fb8f17270216154f582dbc14380acad0023ebff0e9892627a824a5f5c5641d13654bc26d1d79a380
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  Gemfile.lock
10
+ .vscode/**
10
11
 
11
12
  # rspec failure tracking
12
13
  .rspec_status
@@ -1,6 +1,33 @@
1
1
  ---
2
+ dist: bionic
2
3
  language: ruby
4
+ gemfile:
5
+ - Gemfile
3
6
  cache: bundler
4
7
  rvm:
5
8
  - 2.5.7
6
- before_install: gem install bundler -v 2.1.4
9
+ script: bundle exec rake spec
10
+ before_install:
11
+ - gem install bundler -v 2.1.4
12
+ - sudo apt-get install libsqlite3-dev
13
+ - bundle install
14
+ - ./spec/ci/install_elasticsearch.sh
15
+ cache:
16
+ directories:
17
+ - $HOME/elasticsearch
18
+ jdk: openjdk10
19
+ env:
20
+ - ELASTICSEARCH_VERSION=7.6.1
21
+ jobs:
22
+ include:
23
+ - rvm: 2.5
24
+ gemfile: gemfiles/graphql_1.8.gemfile
25
+ - rvm: 2.5
26
+ gemfile: gemfiles/graphql_1.9.gemfile
27
+ - rvm: 2.5
28
+ gemfile: gemfiles/graphql_1.10.gemfile
29
+ - rvm: 2.5
30
+ gemfile: gemfiles/searchkick_3.0.gemfile
31
+ env: ELASTICSEARCH_VERSION=6.8.7
32
+ - rvm: 2.5
33
+ gemfile: gemfiles/searchkick_4.0.gemfile
@@ -0,0 +1,42 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+ end
data/README.md CHANGED
@@ -1,10 +1,21 @@
1
1
  # Graphql::Searchkick
2
2
 
3
+ Integrate Searchkick with GraphQL Connections easily.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/graphql-searchkick.svg)](https://badge.fury.io/rb/graphql-searchkick)
6
+ [![Build Status](https://travis-ci.org/CompanyCam/graphql-searchkick.svg?branch=master)](https://travis-ci.org/CompanyCam/graphql-searchkick)
3
7
  [![Maintainability](https://api.codeclimate.com/v1/badges/1102df197f6f271b9885/maintainability)](https://codeclimate.com/github/CompanyCam/graphql-searchkick/maintainability)
4
8
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/graphql/searchkick`. To experiment with that code, run `bin/console` for an interactive prompt.
9
+ ## Note
10
+
11
+ The current version of the gem only works with `GraphQL::Relay::BaseConnection` and descendants. If you need support for `GraphQL::Pagination::Connection` feel free to open an issue or create a PR.
12
+
13
+ ## Considerations & Limits
6
14
 
7
- TODO: Delete this and the text above, and describe your gem
15
+ - This will run _every_ usage of this field through Searchkick.
16
+ - The current implementation doesn't support suggestions or aggregations.
17
+
18
+ If you find any of these undesirable, open an issue or PR.
8
19
 
9
20
  ## Installation
10
21
 
@@ -22,19 +33,61 @@ Or install it yourself as:
22
33
 
23
34
  $ gem install graphql-searchkick
24
35
 
36
+ ## Setup
37
+
38
+ Include the field integration into your field class.
39
+
40
+ ```ruby
41
+ class BaseField < GraphQL::Schema::Field
42
+ include GraphQL::Searchkick::FieldIntegration
43
+ end
44
+ ```
45
+
25
46
  ## Usage
26
47
 
27
- TODO: Write usage instructions here
48
+ Add `search: ModelClass` to any connection field that you want to allow querying.
49
+
50
+ ```ruby
51
+ field :projects, Types::ProjectType.connection_type, null: false, search: Project
52
+ ```
53
+
54
+ Your field will now have an optional `query` argument of type `String` as part of it's definition.
55
+
56
+ If `query` is `nil?` or `empty?` the default value `'*'` is used.
57
+
58
+ ### Search Arguments
59
+
60
+ If you would like to pass options to the `search` method, override the resolver for the field that returns a `Hash`.
61
+
62
+ ```ruby
63
+ def projects(arguments)
64
+ {
65
+ where: {
66
+ active: arguments[:active],
67
+ coordinates: {
68
+ near: arguments[:coords],
69
+ within: '1km'
70
+ }
71
+ }
72
+ }
73
+ end
74
+ ```
75
+
76
+ This will translate into:
77
+
78
+ ```ruby
79
+ Project.search('*', where: { active: true, coordinates: { near: { lat: 40.815110, lon: -96.709523 }, within: '1km' } })
80
+ ```
28
81
 
29
82
  ## Development
30
83
 
31
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
84
+ After checking out the repo, run `bin/setup` to install dependencies. Then run `docker-compose up` to start Elasticsearch. Finally, run `bundle exec appraisal rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
85
 
33
86
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
87
 
35
88
  ## Contributing
36
89
 
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/graphql-searchkick.
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/CompanyCam/graphql-searchkick.
38
91
 
39
92
  ## License
40
93
 
data/bin/setup CHANGED
@@ -4,5 +4,4 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
-
8
- # Do any other automated setup that you need to do here
7
+ bundle exec appraisal install
@@ -25,6 +25,7 @@ GEM
25
25
  thor (>= 0.14.0)
26
26
  codeclimate-test-reporter (1.0.9)
27
27
  simplecov (<= 0.13)
28
+ coderay (1.1.2)
28
29
  concurrent-ruby (1.1.6)
29
30
  diff-lcs (1.3)
30
31
  docile (1.1.5)
@@ -38,15 +39,47 @@ GEM
38
39
  multi_json
39
40
  faraday (0.17.3)
40
41
  multipart-post (>= 1.2, < 3)
42
+ ffi (1.12.2)
43
+ formatador (0.2.5)
41
44
  graphql (1.10.5)
45
+ guard (2.16.2)
46
+ formatador (>= 0.2.4)
47
+ listen (>= 2.7, < 4.0)
48
+ lumberjack (>= 1.0.12, < 2.0)
49
+ nenv (~> 0.1)
50
+ notiffany (~> 0.0)
51
+ pry (>= 0.9.12)
52
+ shellany (~> 0.0)
53
+ thor (>= 0.18.1)
54
+ guard-compat (1.2.1)
55
+ guard-rspec (4.7.3)
56
+ guard (~> 2.1)
57
+ guard-compat (~> 1.1)
58
+ rspec (>= 2.99.0, < 4.0)
42
59
  hashie (3.6.0)
43
60
  i18n (1.8.2)
44
61
  concurrent-ruby (~> 1.0)
45
62
  json (2.3.0)
63
+ listen (3.1.5)
64
+ rb-fsevent (~> 0.9, >= 0.9.4)
65
+ rb-inotify (~> 0.9, >= 0.9.7)
66
+ ruby_dep (~> 1.2)
67
+ lumberjack (1.2.4)
68
+ method_source (1.0.0)
46
69
  minitest (5.14.0)
47
70
  multi_json (1.14.1)
48
71
  multipart-post (2.1.1)
72
+ nenv (0.3.0)
73
+ notiffany (0.1.3)
74
+ nenv (~> 0.1)
75
+ shellany (~> 0.0)
76
+ pry (0.13.1)
77
+ coderay (~> 1.1)
78
+ method_source (~> 1.0)
49
79
  rake (12.3.3)
80
+ rb-fsevent (0.10.4)
81
+ rb-inotify (0.10.1)
82
+ ffi (~> 1.0)
50
83
  rspec (3.8.0)
51
84
  rspec-core (~> 3.8.0)
52
85
  rspec-expectations (~> 3.8.0)
@@ -60,10 +93,12 @@ GEM
60
93
  diff-lcs (>= 1.2.0, < 2.0)
61
94
  rspec-support (~> 3.8.0)
62
95
  rspec-support (3.8.0)
96
+ ruby_dep (1.5.0)
63
97
  searchkick (4.3.0)
64
98
  activemodel (>= 5)
65
99
  elasticsearch (>= 6)
66
100
  hashie
101
+ shellany (0.0.1)
67
102
  simplecov (0.13.0)
68
103
  docile (~> 1.1.0)
69
104
  json (>= 1.8, < 3)
@@ -85,6 +120,8 @@ DEPENDENCIES
85
120
  codeclimate-test-reporter
86
121
  graphql (~> 1.10)
87
122
  graphql-searchkick!
123
+ guard
124
+ guard-rspec
88
125
  rake (~> 12.0)
89
126
  rspec (~> 3.0)
90
127
  sqlite3
@@ -25,6 +25,7 @@ GEM
25
25
  thor (>= 0.14.0)
26
26
  codeclimate-test-reporter (1.0.9)
27
27
  simplecov (<= 0.13)
28
+ coderay (1.1.2)
28
29
  concurrent-ruby (1.1.6)
29
30
  diff-lcs (1.3)
30
31
  docile (1.1.5)
@@ -38,15 +39,47 @@ GEM
38
39
  multi_json
39
40
  faraday (0.17.3)
40
41
  multipart-post (>= 1.2, < 3)
42
+ ffi (1.12.2)
43
+ formatador (0.2.5)
41
44
  graphql (1.10.5)
45
+ guard (2.16.2)
46
+ formatador (>= 0.2.4)
47
+ listen (>= 2.7, < 4.0)
48
+ lumberjack (>= 1.0.12, < 2.0)
49
+ nenv (~> 0.1)
50
+ notiffany (~> 0.0)
51
+ pry (>= 0.9.12)
52
+ shellany (~> 0.0)
53
+ thor (>= 0.18.1)
54
+ guard-compat (1.2.1)
55
+ guard-rspec (4.7.3)
56
+ guard (~> 2.1)
57
+ guard-compat (~> 1.1)
58
+ rspec (>= 2.99.0, < 4.0)
42
59
  hashie (3.6.0)
43
60
  i18n (1.8.2)
44
61
  concurrent-ruby (~> 1.0)
45
62
  json (2.3.0)
63
+ listen (3.1.5)
64
+ rb-fsevent (~> 0.9, >= 0.9.4)
65
+ rb-inotify (~> 0.9, >= 0.9.7)
66
+ ruby_dep (~> 1.2)
67
+ lumberjack (1.2.4)
68
+ method_source (1.0.0)
46
69
  minitest (5.14.0)
47
70
  multi_json (1.14.1)
48
71
  multipart-post (2.1.1)
72
+ nenv (0.3.0)
73
+ notiffany (0.1.3)
74
+ nenv (~> 0.1)
75
+ shellany (~> 0.0)
76
+ pry (0.13.1)
77
+ coderay (~> 1.1)
78
+ method_source (~> 1.0)
49
79
  rake (12.3.3)
80
+ rb-fsevent (0.10.4)
81
+ rb-inotify (0.10.1)
82
+ ffi (~> 1.0)
50
83
  rspec (3.8.0)
51
84
  rspec-core (~> 3.8.0)
52
85
  rspec-expectations (~> 3.8.0)
@@ -60,10 +93,12 @@ GEM
60
93
  diff-lcs (>= 1.2.0, < 2.0)
61
94
  rspec-support (~> 3.8.0)
62
95
  rspec-support (3.8.0)
96
+ ruby_dep (1.5.0)
63
97
  searchkick (4.3.0)
64
98
  activemodel (>= 5)
65
99
  elasticsearch (>= 6)
66
100
  hashie
101
+ shellany (0.0.1)
67
102
  simplecov (0.13.0)
68
103
  docile (~> 1.1.0)
69
104
  json (>= 1.8, < 3)
@@ -85,6 +120,8 @@ DEPENDENCIES
85
120
  codeclimate-test-reporter
86
121
  graphql (~> 1.8)
87
122
  graphql-searchkick!
123
+ guard
124
+ guard-rspec
88
125
  rake (~> 12.0)
89
126
  rspec (~> 3.0)
90
127
  sqlite3
@@ -25,6 +25,7 @@ GEM
25
25
  thor (>= 0.14.0)
26
26
  codeclimate-test-reporter (1.0.9)
27
27
  simplecov (<= 0.13)
28
+ coderay (1.1.2)
28
29
  concurrent-ruby (1.1.6)
29
30
  diff-lcs (1.3)
30
31
  docile (1.1.5)
@@ -38,15 +39,47 @@ GEM
38
39
  multi_json
39
40
  faraday (0.17.3)
40
41
  multipart-post (>= 1.2, < 3)
42
+ ffi (1.12.2)
43
+ formatador (0.2.5)
41
44
  graphql (1.10.5)
45
+ guard (2.16.2)
46
+ formatador (>= 0.2.4)
47
+ listen (>= 2.7, < 4.0)
48
+ lumberjack (>= 1.0.12, < 2.0)
49
+ nenv (~> 0.1)
50
+ notiffany (~> 0.0)
51
+ pry (>= 0.9.12)
52
+ shellany (~> 0.0)
53
+ thor (>= 0.18.1)
54
+ guard-compat (1.2.1)
55
+ guard-rspec (4.7.3)
56
+ guard (~> 2.1)
57
+ guard-compat (~> 1.1)
58
+ rspec (>= 2.99.0, < 4.0)
42
59
  hashie (3.6.0)
43
60
  i18n (1.8.2)
44
61
  concurrent-ruby (~> 1.0)
45
62
  json (2.3.0)
63
+ listen (3.1.5)
64
+ rb-fsevent (~> 0.9, >= 0.9.4)
65
+ rb-inotify (~> 0.9, >= 0.9.7)
66
+ ruby_dep (~> 1.2)
67
+ lumberjack (1.2.4)
68
+ method_source (1.0.0)
46
69
  minitest (5.14.0)
47
70
  multi_json (1.14.1)
48
71
  multipart-post (2.1.1)
72
+ nenv (0.3.0)
73
+ notiffany (0.1.3)
74
+ nenv (~> 0.1)
75
+ shellany (~> 0.0)
76
+ pry (0.13.1)
77
+ coderay (~> 1.1)
78
+ method_source (~> 1.0)
49
79
  rake (12.3.3)
80
+ rb-fsevent (0.10.4)
81
+ rb-inotify (0.10.1)
82
+ ffi (~> 1.0)
50
83
  rspec (3.8.0)
51
84
  rspec-core (~> 3.8.0)
52
85
  rspec-expectations (~> 3.8.0)
@@ -60,10 +93,12 @@ GEM
60
93
  diff-lcs (>= 1.2.0, < 2.0)
61
94
  rspec-support (~> 3.8.0)
62
95
  rspec-support (3.8.0)
96
+ ruby_dep (1.5.0)
63
97
  searchkick (4.3.0)
64
98
  activemodel (>= 5)
65
99
  elasticsearch (>= 6)
66
100
  hashie
101
+ shellany (0.0.1)
67
102
  simplecov (0.13.0)
68
103
  docile (~> 1.1.0)
69
104
  json (>= 1.8, < 3)
@@ -85,6 +120,8 @@ DEPENDENCIES
85
120
  codeclimate-test-reporter
86
121
  graphql (~> 1.9)
87
122
  graphql-searchkick!
123
+ guard
124
+ guard-rspec
88
125
  rake (~> 12.0)
89
126
  rspec (~> 3.0)
90
127
  sqlite3
@@ -25,6 +25,7 @@ GEM
25
25
  thor (>= 0.14.0)
26
26
  codeclimate-test-reporter (1.0.9)
27
27
  simplecov (<= 0.13)
28
+ coderay (1.1.2)
28
29
  concurrent-ruby (1.1.6)
29
30
  diff-lcs (1.3)
30
31
  docile (1.1.5)
@@ -38,15 +39,47 @@ GEM
38
39
  multi_json
39
40
  faraday (1.0.0)
40
41
  multipart-post (>= 1.2, < 3)
42
+ ffi (1.12.2)
43
+ formatador (0.2.5)
41
44
  graphql (1.10.5)
45
+ guard (2.16.2)
46
+ formatador (>= 0.2.4)
47
+ listen (>= 2.7, < 4.0)
48
+ lumberjack (>= 1.0.12, < 2.0)
49
+ nenv (~> 0.1)
50
+ notiffany (~> 0.0)
51
+ pry (>= 0.9.12)
52
+ shellany (~> 0.0)
53
+ thor (>= 0.18.1)
54
+ guard-compat (1.2.1)
55
+ guard-rspec (4.7.3)
56
+ guard (~> 2.1)
57
+ guard-compat (~> 1.1)
58
+ rspec (>= 2.99.0, < 4.0)
42
59
  hashie (3.6.0)
43
60
  i18n (1.8.2)
44
61
  concurrent-ruby (~> 1.0)
45
62
  json (2.3.0)
63
+ listen (3.1.5)
64
+ rb-fsevent (~> 0.9, >= 0.9.4)
65
+ rb-inotify (~> 0.9, >= 0.9.7)
66
+ ruby_dep (~> 1.2)
67
+ lumberjack (1.2.4)
68
+ method_source (1.0.0)
46
69
  minitest (5.14.0)
47
70
  multi_json (1.14.1)
48
71
  multipart-post (2.1.1)
72
+ nenv (0.3.0)
73
+ notiffany (0.1.3)
74
+ nenv (~> 0.1)
75
+ shellany (~> 0.0)
76
+ pry (0.13.1)
77
+ coderay (~> 1.1)
78
+ method_source (~> 1.0)
49
79
  rake (12.3.3)
80
+ rb-fsevent (0.10.4)
81
+ rb-inotify (0.10.1)
82
+ ffi (~> 1.0)
50
83
  rspec (3.8.0)
51
84
  rspec-core (~> 3.8.0)
52
85
  rspec-expectations (~> 3.8.0)
@@ -60,10 +93,12 @@ GEM
60
93
  diff-lcs (>= 1.2.0, < 2.0)
61
94
  rspec-support (~> 3.8.0)
62
95
  rspec-support (3.8.0)
96
+ ruby_dep (1.5.0)
63
97
  searchkick (3.0.3)
64
98
  activemodel (>= 4.2)
65
99
  elasticsearch (>= 5)
66
100
  hashie
101
+ shellany (0.0.1)
67
102
  simplecov (0.13.0)
68
103
  docile (~> 1.1.0)
69
104
  json (>= 1.8, < 3)
@@ -85,6 +120,8 @@ DEPENDENCIES
85
120
  codeclimate-test-reporter
86
121
  elasticsearch (< 6.0)
87
122
  graphql-searchkick!
123
+ guard
124
+ guard-rspec
88
125
  rake (~> 12.0)
89
126
  rspec (~> 3.0)
90
127
  searchkick (~> 3.0)
@@ -25,6 +25,7 @@ GEM
25
25
  thor (>= 0.14.0)
26
26
  codeclimate-test-reporter (1.0.9)
27
27
  simplecov (<= 0.13)
28
+ coderay (1.1.2)
28
29
  concurrent-ruby (1.1.6)
29
30
  diff-lcs (1.3)
30
31
  docile (1.1.5)
@@ -38,15 +39,47 @@ GEM
38
39
  multi_json
39
40
  faraday (0.17.3)
40
41
  multipart-post (>= 1.2, < 3)
42
+ ffi (1.12.2)
43
+ formatador (0.2.5)
41
44
  graphql (1.10.5)
45
+ guard (2.16.2)
46
+ formatador (>= 0.2.4)
47
+ listen (>= 2.7, < 4.0)
48
+ lumberjack (>= 1.0.12, < 2.0)
49
+ nenv (~> 0.1)
50
+ notiffany (~> 0.0)
51
+ pry (>= 0.9.12)
52
+ shellany (~> 0.0)
53
+ thor (>= 0.18.1)
54
+ guard-compat (1.2.1)
55
+ guard-rspec (4.7.3)
56
+ guard (~> 2.1)
57
+ guard-compat (~> 1.1)
58
+ rspec (>= 2.99.0, < 4.0)
42
59
  hashie (3.6.0)
43
60
  i18n (1.8.2)
44
61
  concurrent-ruby (~> 1.0)
45
62
  json (2.3.0)
63
+ listen (3.1.5)
64
+ rb-fsevent (~> 0.9, >= 0.9.4)
65
+ rb-inotify (~> 0.9, >= 0.9.7)
66
+ ruby_dep (~> 1.2)
67
+ lumberjack (1.2.4)
68
+ method_source (1.0.0)
46
69
  minitest (5.14.0)
47
70
  multi_json (1.14.1)
48
71
  multipart-post (2.1.1)
72
+ nenv (0.3.0)
73
+ notiffany (0.1.3)
74
+ nenv (~> 0.1)
75
+ shellany (~> 0.0)
76
+ pry (0.13.1)
77
+ coderay (~> 1.1)
78
+ method_source (~> 1.0)
49
79
  rake (12.3.3)
80
+ rb-fsevent (0.10.4)
81
+ rb-inotify (0.10.1)
82
+ ffi (~> 1.0)
50
83
  rspec (3.8.0)
51
84
  rspec-core (~> 3.8.0)
52
85
  rspec-expectations (~> 3.8.0)
@@ -60,10 +93,12 @@ GEM
60
93
  diff-lcs (>= 1.2.0, < 2.0)
61
94
  rspec-support (~> 3.8.0)
62
95
  rspec-support (3.8.0)
96
+ ruby_dep (1.5.0)
63
97
  searchkick (4.3.0)
64
98
  activemodel (>= 5)
65
99
  elasticsearch (>= 6)
66
100
  hashie
101
+ shellany (0.0.1)
67
102
  simplecov (0.13.0)
68
103
  docile (~> 1.1.0)
69
104
  json (>= 1.8, < 3)
@@ -84,6 +119,8 @@ DEPENDENCIES
84
119
  appraisal
85
120
  codeclimate-test-reporter
86
121
  graphql-searchkick!
122
+ guard
123
+ guard-rspec
87
124
  rake (~> 12.0)
88
125
  rspec (~> 3.0)
89
126
  searchkick (~> 4.0)
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency 'appraisal'
26
26
  spec.add_development_dependency 'codeclimate-test-reporter'
27
+ spec.add_development_dependency 'guard'
28
+ spec.add_development_dependency 'guard-rspec'
27
29
  spec.add_development_dependency 'rake', '~> 12.0'
28
30
  spec.add_development_dependency 'rspec', '~> 3.0'
29
31
  spec.add_development_dependency 'activerecord', '~> 6.0'
@@ -10,7 +10,7 @@ module GraphQL
10
10
 
11
11
  SEARCH_ALL = '*'.freeze
12
12
 
13
- attr_reader :query, :model_class, :options, :limit_value, :offset_value
13
+ attr_accessor :query, :model_class, :options, :limit_value, :offset_value
14
14
 
15
15
  def_delegators :load, :results, :hits, :took, :error
16
16
  def_delegators :load, :total_count, :current_page, :total_pages
@@ -28,7 +28,7 @@ module GraphQL
28
28
  @options = options || {}
29
29
 
30
30
  if @options.key?(:limit)
31
- @limit_value = @options[:limit]
31
+ self.limit_value = @options[:limit]
32
32
  end
33
33
  end
34
34
 
@@ -40,12 +40,22 @@ module GraphQL
40
40
  @result
41
41
  end
42
42
 
43
- def limit=(val)
44
- @limit_value = val
43
+ def limit(value)
44
+ clone.limit!(value)
45
45
  end
46
46
 
47
- def offset=(val)
48
- @offset_value = val
47
+ def offset(value)
48
+ clone.offset!(value)
49
+ end
50
+
51
+ def limit!(value)
52
+ self.limit_value = value
53
+ self
54
+ end
55
+
56
+ def offset!(value)
57
+ self.offset_value = value
58
+ self
49
59
  end
50
60
  end
51
61
  end
@@ -4,151 +4,42 @@ require 'graphql'
4
4
 
5
5
  module GraphQL
6
6
  module Searchkick
7
- class ResultConnection < GraphQL::Relay::BaseConnection
7
+ class ResultConnection < GraphQL::Pagination::RelationConnection
8
8
 
9
- def search_results
10
- return @results if defined? @results
11
-
12
- apply_pagination
13
- execute_search
14
-
15
- @results = nodes
16
- end
17
-
18
- def execute_search
19
- nodes.load
20
- end
21
-
22
- # must return a cursor for this object/connection pair
23
- def cursor_from_node(item)
24
- item_index = paged_nodes.index(item)
25
-
26
- if item_index.nil?
27
- raise("Can't generate cursor, item not found in connection: #{item}")
28
- else
29
- offset = item_index + 1
30
-
31
- if after
32
- offset += offset_from_cursor(after)
33
- elsif before
34
- offset += offset_from_cursor(before) - 1 - search_results.size
35
- end
36
-
37
- if first && last && first >= last
38
- offset += first - last
9
+ def has_next_page
10
+ if @has_next_page.nil?
11
+ @has_next_page = if @before_offset && @before_offset > 0
12
+ true
13
+ elsif first
14
+ initial_offset = after && offset_from_cursor(after) || 0
15
+ nodes.total_count > initial_offset + first
16
+ else
17
+ false
39
18
  end
40
-
41
- encode(offset.to_s)
42
19
  end
20
+ @has_next_page
43
21
  end
44
22
 
45
- def page_info
46
- self
23
+ def relation_count(relation)
24
+ relation.total_count
47
25
  end
48
26
 
49
- def has_next_page
50
- if first
51
- initial_offset = after ? offset_from_cursor(after) : 0
52
- return search_results.total_count > initial_offset + first
53
- end
54
-
55
- if GraphQL::Relay::ConnectionType.bidirectional_pagination && last
56
- return search_results.length >= last
57
- end
58
- false
27
+ def relation_limit(relation)
28
+ relation.limit_value
59
29
  end
60
30
 
61
- def has_previous_page
62
- if last
63
- search_results.total_count >= last && search_results.size > last
64
- elsif GraphQL::Relay::ConnectionType.bidirectional_pagination && after
65
- offset_from_cursor(after) > 0
66
- else
67
- false
68
- end
31
+ def relation_offset(relation)
32
+ relation.offset_value
69
33
  end
70
34
 
71
- private
72
-
73
- def apply_pagination
74
- if after
75
- offset = (search_offset(nodes) || 0) + offset_from_cursor(after)
76
- set_offset(nodes, offset)
77
- end
78
-
79
- if before && after
80
- if offset_from_cursor(after) < offset_from_cursor(before)
81
- limit = offset_from_cursor(before) - offset_from_cursor(after) - 1
82
- set_limit(nodes, limit)
83
- else
84
- set_limit(nodes, 0)
85
- end
86
- elsif before
87
- set_limit(nodes, offset_from_cursor(before) - 1)
88
- end
89
-
90
- if first
91
- if search_limit(nodes).nil? || search_limit(nodes) > first
92
- set_limit(nodes, first)
93
- end
94
- end
95
-
96
- if last
97
- if search_limit(nodes)
98
- if last <= search_limit(nodes)
99
- offset = (search_offset(nodes) || 0) + (search_limit(nodes) - last)
100
- set_offset(nodes, offset)
101
- set_limit(nodes, last)
102
- end
103
- end
104
- end
105
-
106
- if max_page_size && !first && !last
107
- if search_limit(nodes).nil? || search_limit(nodes) > max_page_size
108
- set_limit(nodes, max_page_size)
109
- end
110
- end
111
- end
112
-
113
- # must return nodes for this connection after paging
114
- def paged_nodes
115
- sliced_nodes
116
- end
117
-
118
- # must return all nodes for this connection after chopping off first and last
119
- def sliced_nodes
120
- search_results
121
- end
122
-
123
- def search_limit(lazy_search)
124
- lazy_search.limit_value
125
- end
126
-
127
- def search_offset(lazy_search)
128
- lazy_search.offset_value
129
- end
130
-
131
- def set_offset(relation, offset)
132
- if offset >= 0
133
- relation.offset = offset
134
- else
135
- relation.offset = 0
136
- end
137
- end
35
+ def null_relation(relation)
36
+ relation.limit(0)
37
+ end
138
38
 
139
- def set_limit(relation, limit)
140
- if limit >= 0
141
- relation.limit = limit
142
- else
143
- relation.limit = 0
144
- end
145
- end
39
+ def load_nodes
40
+ @nodes ||= limited_nodes
41
+ end
146
42
 
147
- def offset_from_cursor(cursor)
148
- decode(cursor).to_i
149
- end
150
43
  end
151
-
152
- GraphQL::Relay::BaseConnection.register_connection_implementation(LazySearch, ResultConnection)
153
44
  end
154
45
  end
@@ -1,5 +1,5 @@
1
1
  module Graphql
2
2
  module Searchkick
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-searchkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Wilken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-19 00:00:00.000000000 Z
11
+ date: 2020-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -135,6 +163,7 @@ files:
135
163
  - ".travis.yml"
136
164
  - Appraisals
137
165
  - Gemfile
166
+ - Guardfile
138
167
  - LICENSE.txt
139
168
  - README.md
140
169
  - Rakefile