graphlient 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +2 -2
- data/CHANGELOG.md +4 -0
- data/README.md +39 -2
- data/lib/graphlient/client.rb +7 -2
- data/lib/graphlient/version.rb +1 -1
- data/spec/graphlient/client_query_spec.rb +35 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1328f248da112cdd69028ad82f37ec75ef69d707
|
4
|
+
data.tar.gz: e33c4cc31d7566a38cf8e0b2cb8dcf2abc001abb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df9ab753adb46c62d6ad8b69efad0c2a73dc41c5ce703eb47c60bbf129ae1b2eac204184bc1966d36660690261cc9467da44147652624780edf39a9b5675027c
|
7
|
+
data.tar.gz: c5e38abf851c13e336d84aa85d4c6726869bf37692bf7cd632ffc6bc78666197af0b95abb58d52ce452fee25ef9edadfb67a308382827c943cde6bdc88d5b04b
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2017-10-
|
3
|
+
# on 2017-10-23 15:14:47 -0400 using RuboCop version 0.47.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -9,7 +9,7 @@
|
|
9
9
|
# Offense count: 11
|
10
10
|
# Configuration parameters: CountComments, ExcludedMethods.
|
11
11
|
Metrics/BlockLength:
|
12
|
-
Max:
|
12
|
+
Max: 167
|
13
13
|
|
14
14
|
# Offense count: 17
|
15
15
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### 0.0.7 (10/24/2017)
|
2
|
+
|
3
|
+
* [#26](https://github.com/ashkan18/graphlient/pull/26): Support String queries - [@dblock](https://github.com/dblock).
|
4
|
+
|
1
5
|
### 0.0.6 (10/20/2017)
|
2
6
|
|
3
7
|
* [#14](https://github.com/ashkan18/graphlient/pull/14): Switch to `graphql-client` for network calls and schema validation - [@ashkan18](https://github.com/ashkan18).
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/graphlient.svg)](https://badge.fury.io/rb/graphlient)
|
4
4
|
[![Build Status](https://travis-ci.org/ashkan18/graphlient.svg?branch=master)](https://travis-ci.org/ashkan18/graphlient)
|
5
5
|
|
6
|
-
A
|
6
|
+
A friendlier Ruby client for consuming GraphQL-based APIs. Built on top of your usual [graphql-client](https://github.com/github/graphql-client), but with better defaults, and using the [faraday](https://github.com/lostisland/faraday) HTTP client.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -31,7 +31,26 @@ The schema is available automatically via `.schema`.
|
|
31
31
|
client.schema # GraphQL::Schema
|
32
32
|
```
|
33
33
|
|
34
|
-
Make queries with `query`, which takes a block for the query definition.
|
34
|
+
Make queries with `query`, which takes a String or a block for the query definition.
|
35
|
+
|
36
|
+
With a String.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
response = client.query <<~GRAPHQL
|
40
|
+
query {
|
41
|
+
invoice(id: 10) {
|
42
|
+
id
|
43
|
+
total
|
44
|
+
line_items {
|
45
|
+
price
|
46
|
+
item_type
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
GRAPHQL
|
51
|
+
```
|
52
|
+
|
53
|
+
With a block.
|
35
54
|
|
36
55
|
```ruby
|
37
56
|
response = client.query do
|
@@ -96,6 +115,24 @@ Graphlient can execute parameterized queries and mutations by providing variable
|
|
96
115
|
|
97
116
|
The following query accepts an array of IDs.
|
98
117
|
|
118
|
+
With a String.
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
query = <<-GRAPHQL
|
122
|
+
query($ids: [Int]) {
|
123
|
+
invoices(ids: $ids) {
|
124
|
+
id
|
125
|
+
fee_in_cents
|
126
|
+
}
|
127
|
+
}
|
128
|
+
GRAPHQL
|
129
|
+
variables = { ids: [42] }
|
130
|
+
|
131
|
+
client.query(query, variables)
|
132
|
+
```
|
133
|
+
|
134
|
+
With a block.
|
135
|
+
|
99
136
|
```ruby
|
100
137
|
client.query(ids: [42]) do
|
101
138
|
query(:$ids => :'[Int]') do
|
data/lib/graphlient/client.rb
CHANGED
@@ -22,13 +22,18 @@ module Graphlient
|
|
22
22
|
query_params = {}
|
23
23
|
query_params[:context] = @options if @options
|
24
24
|
query_params[:variables] = variables if variables
|
25
|
+
query = client.parse(query) if query.is_a?(String)
|
25
26
|
client.query(query, query_params)
|
26
27
|
rescue GraphQL::Client::Error => e
|
27
28
|
raise Graphlient::Errors::Client.new(e.message, e)
|
28
29
|
end
|
29
30
|
|
30
|
-
def query(variables = nil, &block)
|
31
|
-
|
31
|
+
def query(query_or_variables = nil, variables = nil, &block)
|
32
|
+
if block_given?
|
33
|
+
execute(parse(&block), query_or_variables)
|
34
|
+
else
|
35
|
+
execute(query_or_variables, variables)
|
36
|
+
end
|
32
37
|
rescue GraphQL::Client::Error => e
|
33
38
|
raise Graphlient::Errors::Client.new(e.message, e)
|
34
39
|
end
|
data/lib/graphlient/version.rb
CHANGED
@@ -56,6 +56,26 @@ describe Graphlient::Client do
|
|
56
56
|
expect(invoices).to eq([])
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
context 'parameterized GRAPHQL query' do
|
61
|
+
let(:query) do
|
62
|
+
<<-GRAPHQL
|
63
|
+
query($ids: [Int]) {
|
64
|
+
invoices(ids: $ids) {
|
65
|
+
id
|
66
|
+
fee_in_cents
|
67
|
+
}
|
68
|
+
}
|
69
|
+
GRAPHQL
|
70
|
+
end
|
71
|
+
|
72
|
+
it '#execute' do
|
73
|
+
response = client.execute(query, ids: [42])
|
74
|
+
invoices = response.data.invoices
|
75
|
+
expect(invoices.first.id).to eq 42
|
76
|
+
expect(invoices.first.fee_in_cents).to eq 20_000
|
77
|
+
end
|
78
|
+
end
|
59
79
|
end
|
60
80
|
|
61
81
|
describe '#query' do
|
@@ -90,6 +110,21 @@ describe Graphlient::Client do
|
|
90
110
|
expect(invoices.first.fee_in_cents).to eq 20_000
|
91
111
|
end
|
92
112
|
|
113
|
+
it 'returns a response from a GRAPHQL query' do
|
114
|
+
response = client.query <<~GRAPHQL
|
115
|
+
query {
|
116
|
+
invoices(ids: [10]) {
|
117
|
+
id
|
118
|
+
fee_in_cents
|
119
|
+
}
|
120
|
+
}
|
121
|
+
GRAPHQL
|
122
|
+
|
123
|
+
invoices = response.data.invoices
|
124
|
+
expect(invoices.first.id).to eq 10
|
125
|
+
expect(invoices.first.fee_in_cents).to eq 20_000
|
126
|
+
end
|
127
|
+
|
93
128
|
it 'returns a response from a mutation' do
|
94
129
|
response = client.query do
|
95
130
|
mutation do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphlient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashkan Nasseri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql-client
|