graphlient 0.0.5 → 0.0.6
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 +4 -4
- data/.gitignore +2 -1
- data/.rubocop_todo.yml +32 -17
- data/.travis.yml +8 -2
- data/CHANGELOG.md +11 -0
- data/Dangerfile +1 -0
- data/Gemfile +5 -0
- data/README.md +200 -26
- data/RELEASING.md +1 -1
- data/Rakefile +1 -1
- data/graphlient.gemspec +3 -0
- data/lib/graphlient.rb +0 -5
- data/lib/graphlient/adapters/faraday_adapter.rb +43 -0
- data/lib/graphlient/client.rb +35 -20
- data/lib/graphlient/errors.rb +2 -1
- data/lib/graphlient/errors/client.rb +6 -0
- data/lib/graphlient/errors/error.rb +7 -0
- data/lib/graphlient/errors/server.rb +6 -0
- data/lib/graphlient/query.rb +13 -5
- data/lib/graphlient/version.rb +1 -1
- data/spec/graphlient/adapters/faraday_adapter_spec.rb +44 -0
- data/spec/graphlient/client_query_spec.rb +158 -0
- data/spec/graphlient/client_schema_spec.rb +19 -0
- data/spec/graphlient/extensions/query_spec.rb +6 -4
- data/spec/graphlient/query_spec.rb +72 -25
- data/spec/graphlient/static_client_query_spec.rb +39 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/context/dummy_client.rb +26 -0
- data/spec/support/dummy_app.rb +25 -0
- data/spec/support/dummy_schema.rb +9 -0
- data/spec/support/mutations/create_invoice_mutation.rb +16 -0
- data/spec/support/mutations/mutation.rb +7 -0
- data/spec/support/queries/query.rb +16 -0
- data/spec/support/types/invoice_type.rb +6 -0
- metadata +61 -8
- data/.byebug_history +0 -23
- data/lib/graphlient/config.rb +0 -21
- data/lib/graphlient/errors/http.rb +0 -12
- data/spec/graphlient/client_spec.rb +0 -42
@@ -4,11 +4,13 @@ describe Graphlient::Extensions::Query do
|
|
4
4
|
describe 'Query' do
|
5
5
|
include Graphlient::Extensions::Query
|
6
6
|
|
7
|
-
it 'returns
|
8
|
-
query =
|
9
|
-
|
7
|
+
it 'returns correct query' do
|
8
|
+
query = query do
|
9
|
+
invoice(id: 10) do
|
10
|
+
line_items
|
11
|
+
end
|
10
12
|
end
|
11
|
-
expect(query.to_s).to eq("{
|
13
|
+
expect(query.to_s).to eq("query{\n invoice(id: 10){\n line_items\n }\n }")
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -2,44 +2,91 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Graphlient::Query do
|
4
4
|
describe '#initialize' do
|
5
|
-
|
6
|
-
query
|
7
|
-
|
8
|
-
|
5
|
+
context 'query' do
|
6
|
+
it 'returns expected query with block' do
|
7
|
+
query = Graphlient::Query.new do
|
8
|
+
query do
|
9
|
+
invoice do
|
10
|
+
line_items
|
11
|
+
end
|
12
|
+
end
|
9
13
|
end
|
14
|
+
expect(query.to_s).to eq "query{\n invoice{\n line_items\n }\n }"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns expected query with block and attributes' do
|
18
|
+
query = Graphlient::Query.new do
|
19
|
+
query do
|
20
|
+
invoice(id: 10) do
|
21
|
+
line_items
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
expect(query.to_s).to eq "query{\n invoice(id: 10){\n line_items\n }\n }"
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns expected query with block and attributes' do
|
29
|
+
query = Graphlient::Query.new do
|
30
|
+
query do
|
31
|
+
invoice(id: 10) do
|
32
|
+
line_items(name: 'test')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
expect(query.to_s).to eq "query{\n invoice(id: 10){\n line_items(name: \"test\")\n }\n }"
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns expected query with block and local variables with proper type' do
|
40
|
+
int_arg = 10
|
41
|
+
float_arg = 10.3
|
42
|
+
str_arg = 'new name'
|
43
|
+
array_arg = ['str_item', 2]
|
44
|
+
query = Graphlient::Query.new do
|
45
|
+
query do
|
46
|
+
invoice(id: int_arg, threshold: float_arg, item_list: array_arg) do
|
47
|
+
line_items(name: str_arg)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
expect(query.to_s).to eq "query{\n invoice(id: 10, threshold: 10.3, item_list: [\"str_item\", 2]){\n line_items(name: \"new name\")\n }\n }"
|
10
52
|
end
|
11
|
-
expect(query.to_s).to eq "{ \ninvoice{\n line_items\n }\n }"
|
12
|
-
end
|
13
53
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
54
|
+
it 'returns proper query with query name' do
|
55
|
+
query = Graphlient::Query.new do
|
56
|
+
query do
|
57
|
+
invoice(id: 10) do
|
58
|
+
line_items do
|
59
|
+
line_item_type
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
18
63
|
end
|
64
|
+
expect(query.to_s).to eq "query{\n invoice(id: 10){\n line_items{\n line_item_type\n }\n }\n }"
|
19
65
|
end
|
20
|
-
expect(query.to_s).to eq "{ \ninvoice(id: 10){\n line_items\n }\n }"
|
21
66
|
end
|
22
67
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
68
|
+
context 'mutation' do
|
69
|
+
it 'returns proper mutation with arguments' do
|
70
|
+
mutation = Graphlient::Query.new do
|
71
|
+
mutation do
|
72
|
+
invoice(type: 'test', fee_in_cents: 20_000, total_cents: 50_000, line_items: %w(li1 li2)) do
|
73
|
+
id
|
74
|
+
end
|
75
|
+
end
|
27
76
|
end
|
77
|
+
expect(mutation.to_s).to eq "mutation{\n invoice(type: \"test\", fee_in_cents: 20000, total_cents: 50000, line_items: [\"li1\", \"li2\"]){\n id\n }\n }"
|
28
78
|
end
|
29
|
-
expect(query.to_s).to eq "{ \ninvoice(id: 10){\n line_items(name: \"test\")\n }\n }"
|
30
79
|
end
|
31
80
|
|
32
|
-
it 'returns
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
invoice(id: int_arg, threshold: float_arg, item_list: array_arg) do
|
39
|
-
line_items(name: str_arg)
|
81
|
+
it 'returns proper mutation for relay style mutation' do
|
82
|
+
mutation = Graphlient::Query.new do
|
83
|
+
mutation do
|
84
|
+
invoice(input: { type: 'test', fee_in_cents: 20_000, total_cents: 50_000, line_items: %w(li1 li2) }) do
|
85
|
+
id
|
86
|
+
end
|
40
87
|
end
|
41
88
|
end
|
42
|
-
expect(
|
89
|
+
expect(mutation.to_s).to eq "mutation{\n invoice(input: { type: \"test\", fee_in_cents: 20000, total_cents: 50000, line_items: [\"li1\", \"li2\"] }){\n id\n }\n }"
|
43
90
|
end
|
44
91
|
end
|
45
92
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Graphlient::Client do
|
4
|
+
describe 'parse and execute' do
|
5
|
+
module Graphlient::Client::Spec
|
6
|
+
Client = Graphlient::Client.new(
|
7
|
+
'http://graph.biz/graphql',
|
8
|
+
headers: { 'Authorization' => 'Bearer 1231' },
|
9
|
+
allow_dynamic_queries: false
|
10
|
+
) do |client|
|
11
|
+
client.http do |h|
|
12
|
+
h.connection do |c|
|
13
|
+
c.use Faraday::Adapter::Rack, Sinatra::Application
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Query = Client.parse do
|
19
|
+
query(:$ids => :'[Int]') do
|
20
|
+
invoices(ids: :$ids) do
|
21
|
+
id
|
22
|
+
fee_in_cents
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'defaults allow_dynamic_queries to false' do
|
29
|
+
expect(Graphlient::Client::Spec::Client.send(:client).allow_dynamic_queries).to be false
|
30
|
+
end
|
31
|
+
|
32
|
+
it '#execute' do
|
33
|
+
response = Graphlient::Client::Spec::Client.execute(Graphlient::Client::Spec::Query, ids: [42])
|
34
|
+
invoices = response.data.invoices
|
35
|
+
expect(invoices.first.id).to eq 42
|
36
|
+
expect(invoices.first.fee_in_cents).to eq 20_000
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
RSpec.shared_context 'Dummy Client', shared_context: :metadata do
|
2
|
+
include Rack::Test::Methods
|
3
|
+
|
4
|
+
def app
|
5
|
+
Sinatra::Application
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:endpoint) { 'http://graph.biz/graphql' }
|
9
|
+
|
10
|
+
let(:headers) do
|
11
|
+
{
|
12
|
+
'Authorization' => 'Bearer 1231',
|
13
|
+
'Content-Type' => 'application/json'
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:client) do
|
18
|
+
Graphlient::Client.new(endpoint, headers: headers) do |client|
|
19
|
+
client.http do |h|
|
20
|
+
h.connection do |c|
|
21
|
+
c.use Faraday::Adapter::Rack, app
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'rack/parser'
|
3
|
+
require_relative './dummy_schema'
|
4
|
+
|
5
|
+
use Rack::Parser
|
6
|
+
|
7
|
+
before do
|
8
|
+
halt! 403 unless request.env['HTTP_AUTHORIZATION'] == 'Bearer 1231'
|
9
|
+
end
|
10
|
+
|
11
|
+
post '/graphql' do
|
12
|
+
begin
|
13
|
+
headers['Content-Type'] = 'application/json'
|
14
|
+
DummySchema.execute(
|
15
|
+
params[:query],
|
16
|
+
variables: params[:variables] ? JSON.parse(params[:variables]) : {},
|
17
|
+
context: {},
|
18
|
+
operation_name: params[:operationName]
|
19
|
+
).to_json
|
20
|
+
rescue StandardError => e
|
21
|
+
warn e
|
22
|
+
warn e.backtrace.join("\n")
|
23
|
+
raise e
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
CreateInvoiceMutation = GraphQL::Relay::Mutation.define do
|
2
|
+
name 'createInvoice'
|
3
|
+
|
4
|
+
input_field :fee_in_cents, !types.Int
|
5
|
+
|
6
|
+
return_type types[InvoiceType]
|
7
|
+
|
8
|
+
resolve ->(_object, inputs, _ctx) {
|
9
|
+
[
|
10
|
+
OpenStruct.new(
|
11
|
+
id: 1231,
|
12
|
+
fee_in_cents: inputs[:fee_in_cents]
|
13
|
+
)
|
14
|
+
]
|
15
|
+
}
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Query = GraphQL::ObjectType.define do
|
2
|
+
name 'Query'
|
3
|
+
|
4
|
+
field :invoices, types[InvoiceType] do
|
5
|
+
argument :ids, types[types.Int]
|
6
|
+
description 'Find Invoices'
|
7
|
+
resolve ->(_obj, args, _ctx) {
|
8
|
+
(args[:ids] || []).map do |id|
|
9
|
+
OpenStruct.new(
|
10
|
+
id: id,
|
11
|
+
fee_in_cents: 20_000
|
12
|
+
)
|
13
|
+
end
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,22 +1,63 @@
|
|
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.6
|
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-
|
12
|
-
dependencies:
|
11
|
+
date: 2017-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: graphql-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
13
55
|
description:
|
14
56
|
email: ashkan.nasseri@gmail.com
|
15
57
|
executables: []
|
16
58
|
extensions: []
|
17
59
|
extra_rdoc_files: []
|
18
60
|
files:
|
19
|
-
- ".byebug_history"
|
20
61
|
- ".gitignore"
|
21
62
|
- ".rspec"
|
22
63
|
- ".rubocop.yml"
|
@@ -25,6 +66,7 @@ files:
|
|
25
66
|
- ".travis.yml"
|
26
67
|
- CHANGELOG.md
|
27
68
|
- CONTRIBUTING.md
|
69
|
+
- Dangerfile
|
28
70
|
- Gemfile
|
29
71
|
- LICENSE
|
30
72
|
- README.md
|
@@ -32,19 +74,30 @@ files:
|
|
32
74
|
- Rakefile
|
33
75
|
- graphlient.gemspec
|
34
76
|
- lib/graphlient.rb
|
77
|
+
- lib/graphlient/adapters/faraday_adapter.rb
|
35
78
|
- lib/graphlient/client.rb
|
36
|
-
- lib/graphlient/config.rb
|
37
79
|
- lib/graphlient/errors.rb
|
80
|
+
- lib/graphlient/errors/client.rb
|
38
81
|
- lib/graphlient/errors/error.rb
|
39
|
-
- lib/graphlient/errors/
|
82
|
+
- lib/graphlient/errors/server.rb
|
40
83
|
- lib/graphlient/extensions.rb
|
41
84
|
- lib/graphlient/extensions/query.rb
|
42
85
|
- lib/graphlient/query.rb
|
43
86
|
- lib/graphlient/version.rb
|
44
|
-
- spec/graphlient/
|
87
|
+
- spec/graphlient/adapters/faraday_adapter_spec.rb
|
88
|
+
- spec/graphlient/client_query_spec.rb
|
89
|
+
- spec/graphlient/client_schema_spec.rb
|
45
90
|
- spec/graphlient/extensions/query_spec.rb
|
46
91
|
- spec/graphlient/query_spec.rb
|
92
|
+
- spec/graphlient/static_client_query_spec.rb
|
47
93
|
- spec/spec_helper.rb
|
94
|
+
- spec/support/context/dummy_client.rb
|
95
|
+
- spec/support/dummy_app.rb
|
96
|
+
- spec/support/dummy_schema.rb
|
97
|
+
- spec/support/mutations/create_invoice_mutation.rb
|
98
|
+
- spec/support/mutations/mutation.rb
|
99
|
+
- spec/support/queries/query.rb
|
100
|
+
- spec/support/types/invoice_type.rb
|
48
101
|
homepage: http://github.com/ashkan18/graphlient
|
49
102
|
licenses:
|
50
103
|
- MIT
|
@@ -65,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
118
|
version: 1.3.6
|
66
119
|
requirements: []
|
67
120
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.5.1
|
69
122
|
signing_key:
|
70
123
|
specification_version: 4
|
71
124
|
summary: Ruby Gem for consuming GraphQL endpoints
|
data/.byebug_history
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
c
|
2
|
-
next
|
3
|
-
nex
|
4
|
-
Graphlient.config.graphql_endpoint
|
5
|
-
c
|
6
|
-
Graphlient.config.graphql_endpoint
|
7
|
-
query.to_s
|
8
|
-
c
|
9
|
-
&block
|
10
|
-
args
|
11
|
-
m
|
12
|
-
c
|
13
|
-
n
|
14
|
-
&block
|
15
|
-
args
|
16
|
-
m
|
17
|
-
c
|
18
|
-
send(m, *args, &block)
|
19
|
-
send(m, args, &block)
|
20
|
-
&block
|
21
|
-
block
|
22
|
-
args
|
23
|
-
m
|
data/lib/graphlient/config.rb
DELETED