gqli 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a92aeb50f3395eeb402d70097e5a90b95f78c8ccf9971c92635f4423748a52b
4
- data.tar.gz: 49d4f4186b14b60b38383e0436940049e6c489857854652daff112ec9e5f94d8
3
+ metadata.gz: 2d34056882c2b95aeff8c3c1ff8155c0ebe1018480085e3a00ab84653124fc51
4
+ data.tar.gz: b32f2fd8fe6acd08587e71e36d11d7aedde72e3b30e106a10e9de017a3d9c908
5
5
  SHA512:
6
- metadata.gz: f1b611ab9b505ed267a4c0ecb943d357fc250f4221a07351b3b8ea5dd9968cba1d03aea84b64d9c727719cb1acc3f74aec12dda3f14b6f8ab82fd5aba786b23d
7
- data.tar.gz: f314024396af8dab242f65136da3cd42248976824454ca105d84390902f8b974c6c0c776c4e76b2f7bc60853dcb8d88e09ad0787690d0fc087cfd6113f896050
6
+ metadata.gz: 55f5936ee3d57ca83373627034f70f081cc599358f24328017f3e97f25d7e97de247cf3ce4292ce2b68ff5435110b118d24f6273ab3001fcabeb5868f2d74733
7
+ data.tar.gz: fa00c085ab0f2bc8d669425b769e0a7699fe6065024d5c6768dfa78a5f1934347bd95bcd1981689a4d9b41473739568c33f55ca6fd276fcb182547a9a3f9f226
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.4.0
3
+ - 2.5.1
4
+ - 2.4.1
4
5
  - 2.3.1
5
- - 2.2.1
6
6
  notifications:
7
7
  slack:
8
8
  secure: Zr3mKCiTb0vaTD4MPtTG8BbyYyErFuoxioM25QyrqePKVkDFeZC1MtGmg5klQQrJiWTKZPa/zB8NAHYkoUxg9I+z15JK0hYfz9KRubEpCrXCaqTC9Vzq88kJ3LN8YsTyBF66izaBH2KLsOfaJRxwplFzZqgpg4GG2DUBPtrGtes=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## Unreleased
4
+
5
+ ## v0.2.0
6
+ ### Added
7
+ * Added `__node` to be able to create nodes in case there's a name collision with a reserved keyword or a built-in method.
8
+
3
9
  ## v0.1.0
4
10
 
5
11
  Initial Release
data/README.md CHANGED
@@ -146,7 +146,7 @@ puts response.query.to_gql
146
146
  puts
147
147
  puts "Response received"
148
148
  response.data.catCollection.items.each do |c|
149
- puts "Name: #{c.nam}e"
149
+ puts "Name: #{c.name}"
150
150
  puts "Likes: #{c.likes.join(", ")}"
151
151
  puts "Lives #: #{c.lives}"
152
152
  c.bestFriend.tap do |bf|
@@ -183,7 +183,7 @@ query {
183
183
  }
184
184
 
185
185
  Response received
186
- Name: e
186
+ Name: Happy Cat
187
187
  Likes: cheezburger
188
188
  Lives #: 1
189
189
  Best Friend:
@@ -261,6 +261,36 @@ end
261
261
  response = ContentfulClient.new.cats(5)
262
262
  ```
263
263
 
264
+ ### Dealing with name collisions
265
+
266
+ By defining queries via a DSL, you may sometimes find that the fields you query for are also the names of built-in methods or reserved keywords of the language.
267
+
268
+ To avoid collisions you can use the `__node` helper, for example:
269
+
270
+ ```ruby
271
+ query = GQLi::DSL.query {
272
+ catCollection {
273
+ items {
274
+ sys {
275
+ __node('id')
276
+ }
277
+ }
278
+ }
279
+ }
280
+ ```
281
+
282
+ The helper method `__node`, can also receive arguments and have children nodes as expected from any other node declaration, for example:
283
+
284
+ ```
285
+ query = GQLi::DSL.query {
286
+ __node('catCollection', limit: 5) {
287
+ items {
288
+ name
289
+ }
290
+ }
291
+ }
292
+ ```
293
+
264
294
  ## Yet to be implemented
265
295
 
266
296
  * Mutation queries
data/lib/gqli/base.rb CHANGED
@@ -20,7 +20,13 @@ module GQLi
20
20
  # Adds type match node
21
21
  def __on(type_name, &block)
22
22
  require_relative './node'
23
- @__nodes << Node.new("... on #{type_name}", [], __depth + 1, &block)
23
+ @__nodes << Node.new("... on #{type_name}", {}, __depth + 1, &block)
24
+ end
25
+
26
+ # Adds children node into current node
27
+ def __node(name, params = {}, &block)
28
+ require_relative './node'
29
+ @__nodes << Node.new(name, params, __depth + 1, &block)
24
30
  end
25
31
 
26
32
  protected
data/lib/gqli/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # GraphQL Client and DSL library
4
4
  module GQLi
5
5
  # Gem version
6
- VERSION = '0.1.0'
6
+ VERSION = '0.2.0'
7
7
  end
@@ -201,5 +201,49 @@ describe GQLi::DSL do
201
201
  }
202
202
  GRAPHQL
203
203
  end
204
+
205
+ it 'can use __node to define nodes that would collide otherwise' do
206
+ query = subject.query {
207
+ catCollection {
208
+ items {
209
+ sys {
210
+ __node('id')
211
+ }
212
+ }
213
+ }
214
+ }
215
+
216
+ expect(query.to_gql).to eq <<~GRAPHQL
217
+ query {
218
+ catCollection {
219
+ items {
220
+ sys {
221
+ id
222
+ }
223
+ }
224
+ }
225
+ }
226
+ GRAPHQL
227
+ end
228
+
229
+ it '__node can receive arguments and children nodes' do
230
+ query = subject.query {
231
+ __node('catCollection', limit: 1) {
232
+ items {
233
+ name
234
+ }
235
+ }
236
+ }
237
+
238
+ expect(query.to_gql).to eq <<~GRAPHQL
239
+ query {
240
+ catCollection(limit: 1) {
241
+ items {
242
+ name
243
+ }
244
+ }
245
+ }
246
+ GRAPHQL
247
+ end
204
248
  end
205
249
  end
data/usage.rb CHANGED
@@ -88,7 +88,7 @@ puts response.query.to_gql
88
88
  puts
89
89
  puts "Response received"
90
90
  response.data.catCollection.items.each do |c|
91
- puts "Name: #{c.nam}e"
91
+ puts "Name: #{c.name}"
92
92
  puts "Likes: #{c.likes.join(", ")}"
93
93
  puts "Lives #: #{c.lives}"
94
94
  c.bestFriend.tap do |bf|
@@ -45,7 +45,7 @@ puts response.query.to_gql
45
45
  puts
46
46
  puts "Response received"
47
47
  response.data.catCollection.items.each do |c|
48
- puts "Name: #{c.nam}e"
48
+ puts "Name: #{c.name}"
49
49
  puts "Likes: #{c.likes.join(", ")}"
50
50
  puts "Lives #: #{c.lives}"
51
51
  c.bestFriend.tap do |bf|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gqli
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
  - Contentful GmbH (David Litvak Bruno)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-16 00:00:00.000000000 Z
11
+ date: 2018-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http