graphql-connections 1.0.0 → 1.1.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: 4f48d965da430fdbc88992199c0fef0e92e0bfe6f75f900735abd80d96edc098
4
- data.tar.gz: 3513296ea1afb7d5300c1c9737462bd5baf407f797cb45737e1fa97ccdc52bfb
3
+ metadata.gz: ef27f5fb3f9d555769a1328f85b342b65b472e2d282a0e46296ba91441572641
4
+ data.tar.gz: dc5a4b2884b5266acad35c37b400fade1ea3850beaa2a03eb2d2974276bcd02a
5
5
  SHA512:
6
- metadata.gz: 5f728d6e4fc47a7e0d7bb87cef013542e31370d33da2eb9289244dddb8a9dbd7ff80588726c437b1edc43fe569029c087a2016c76e62f80b30218f4b99a44060
7
- data.tar.gz: 1f294f11f5f1e24bc525d1893ecd1de64ba39aae1bcbc9fd72487bfbd3d55b31983627de6c36c97d109b1f989b215fa312615750a31bea307de9d781aa5f2812
6
+ metadata.gz: 2b7ba37f332c49b5238969a683c1cdfbdcec8c76074d1e3d3903e1d2f8668bed48ea069a55cd65ed49f8ee6dceb7b5022dbfee2d95b1ca8452bb15d1b5d04053
7
+ data.tar.gz: 5375969fb009a1e7e7691f19fab5c0c60befc071d4cebf5e73a7854831508ee240e9209daeb4c33cf1f972cda56524fc97862105d2b0e8c0161a14e142fc3f3c
data/README.md CHANGED
@@ -21,6 +21,8 @@ gem "graphql-connections"
21
21
 
22
22
  ## Usage
23
23
 
24
+ ### ActiveRecord
25
+
24
26
  You can use a stable connection wrapper on a specific field:
25
27
 
26
28
  ```ruby
@@ -69,14 +71,33 @@ Or you can apply a stable connection to all Active Record relations returning by
69
71
 
70
72
  ```ruby
71
73
  class ApplicationSchema < GraphQL::Schema
72
- use GraphQL::Pagination::Connections
73
-
74
74
  connections.add(ActiveRecord::Relation, GraphQL::Connections::Stable)
75
75
  end
76
76
  ```
77
77
 
78
78
  **NOTE:** Don't use stable connections for relations whose ordering is too complicated for cursor generation.
79
79
 
80
+ ### Elasticsearch via Chewy
81
+
82
+ Register connection for all Chewy requests:
83
+
84
+ ```ruby
85
+ class ApplicationSchema < GraphQL::Schema
86
+ connections.add(Chewy::Search::Request, GraphQL::Connections::ChewyConnection)
87
+ end
88
+ ```
89
+
90
+ And define field like below:
91
+
92
+ ```ruby
93
+ field :messages, Types::Message.connection_type, null: false
94
+
95
+ def messages
96
+ CitiesIndex.query(match: {name: "Moscow"})
97
+ end
98
+
99
+ **NOTE:** Using `first` and `last`arguments simultaneously is not supported yet.
100
+
80
101
  ## Development
81
102
 
82
103
  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.
@@ -16,3 +16,5 @@ require "graphql/connections/key_asc"
16
16
  require "graphql/connections/keyset/base"
17
17
  require "graphql/connections/keyset/asc"
18
18
  require "graphql/connections/keyset/desc"
19
+
20
+ require "graphql/connections/chewy"
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphQL
4
+ module Connections
5
+ class Chewy < ::GraphQL::Pagination::RelationConnection
6
+ private
7
+
8
+ def load_nodes
9
+ @nodes ||= limited_nodes.objects
10
+ end
11
+
12
+ def relation_count(relation)
13
+ offset = relation_offset(relation) || 0
14
+ limit = relation_limit(relation)
15
+ count = relation.count - offset
16
+
17
+ if limit.nil?
18
+ count
19
+ else
20
+ [count, limit].min
21
+ end
22
+ end
23
+
24
+ def relation_limit(relation)
25
+ relation.send(:raw_limit_value)&.to_i
26
+ end
27
+
28
+ def relation_offset(relation)
29
+ relation.send(:raw_offset_value)&.to_i
30
+ end
31
+
32
+ def null_relation(relation)
33
+ relation.none
34
+ end
35
+ end
36
+ end
37
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module Paging
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-connections
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Misha Merkushin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-12 00:00:00.000000000 Z
11
+ date: 2021-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_bot_rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '6.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '6.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faker
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: chewy
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '7.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '7.2'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: combustion
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -161,6 +203,7 @@ files:
161
203
  - README.md
162
204
  - lib/graphql/connections.rb
163
205
  - lib/graphql/connections/base.rb
206
+ - lib/graphql/connections/chewy.rb
164
207
  - lib/graphql/connections/key_asc.rb
165
208
  - lib/graphql/connections/keyset/asc.rb
166
209
  - lib/graphql/connections/keyset/base.rb