Skip to content

Commit 3b02215

Browse files
authored
graphlient: Add signatures (#987)
* ./bin/init_new_gem graphlient * Add rbs * Add test * Remove empty files * Fix rubocop offenses ``` Offenses: graphlient.rbs:3:70: C: [Correctable] RBS/Style/InstanceWithInstance: Use self instead of instance. def initialize: (String url, ?Hash[Symbol, untyped] options) ?{ (instance) -> void } -> void ^^^^^^^^ graphlient.rbs:7:7: C: [Correctable] RBS/Layout/OverloadIndentation: Indent the | to the first : | (?Hash[Symbol | String, untyped]? variables) { () -> untyped } -> untyped ^ 1 file inspected, 2 offenses detected, 2 offenses autocorrectable ```
1 parent 4562d89 commit 3b02215

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

gems/graphlient/.rubocop.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This configuration inherits from /.rubocop.yml.
2+
# You can configure RBS style of this gem.
3+
# This file is used on CI. It is configured to automatically
4+
# make rubocop suggestions on pull requests for this gem.
5+
# If you do not like the style enforcement, you should remove this file.
6+
inherit_from: ../../.rubocop.yml
7+
8+
##
9+
# If you want to customize the style, please consult with the gem reviewers.
10+
# You can see the list of cops at https://github.com/ksss/rubocop-on-rbs/blob/main/docs/modules/ROOT/pages/cops.adoc
11+
12+
RBS/Layout:
13+
Enabled: true
14+
15+
RBS/Lint:
16+
Enabled: true
17+
18+
RBS/Style:
19+
Enabled: true

gems/graphlient/0.8/_test/test.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
require "graphlient"
2+
3+
client = Graphlient::Client.new('https://test-graphql.biz/graphql',
4+
headers: {
5+
'Authorization' => 'Bearer 123'
6+
},
7+
http_options: {
8+
read_timeout: 20,
9+
write_timeout: 30
10+
}
11+
)
12+
13+
# simple query
14+
response = client.query <<~GRAPHQL
15+
query {
16+
invoice(id: 10) {
17+
id
18+
total
19+
line_items {
20+
price
21+
item_type
22+
}
23+
}
24+
}
25+
GRAPHQL
26+
27+
response = client.query do
28+
# steep:ignore:start
29+
query do
30+
invoice(id: 10) do
31+
id
32+
total
33+
line_items do
34+
price
35+
item_type
36+
end
37+
end
38+
end
39+
# steep:ignore:end
40+
end
41+
42+
# Executing Parameterized Queries and Mutations
43+
query = <<-GRAPHQL
44+
query($ids: [Int]) {
45+
invoices(ids: $ids) {
46+
id
47+
fee_in_cents
48+
}
49+
}
50+
GRAPHQL
51+
variables = { ids: [42] }
52+
53+
client.query(query, variables)
54+
55+
client.query(ids: [42]) do
56+
# steep:ignore:start
57+
query(ids: [:int]) do
58+
invoices(ids: :ids) do
59+
id
60+
fee_in_cents
61+
end
62+
end
63+
# steep:ignore:end
64+
end

gems/graphlient/0.8/graphlient.rbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Graphlient
2+
class Client
3+
def initialize: (String url, ?Hash[Symbol, untyped] options) ?{ (self) -> void } -> void
4+
5+
# FIXME: return GraphQL::Client::Response instead of untyped
6+
def query: (String query, ?Hash[Symbol | String, untyped]? variables) -> untyped
7+
| (?Hash[Symbol | String, untyped]? variables) { () -> untyped } -> untyped
8+
end
9+
end

0 commit comments

Comments
 (0)