1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
class ServerTest < Minitest::Test
include Rack::Test::Methods
def app
Server.new
end
def test_get_graphql_with_query_string
header 'Content-Type', 'application/graphql'
get '/', query: '{me}'
assert last_response.ok?
assert_equal 200, last_response.status
refute_empty last_response.body
json = JSON.parse(last_response.body)
assert_equal 'mo', json['data']['me']['name']
end
def test_get_graphql_with_post_body
header 'Content-Type', 'application/graphql'
post '/', '{me}'
assert last_response.ok?
assert_equal 200, last_response.status
refute_empty last_response.body
json = JSON.parse(last_response.body)
assert_equal 'mo', json['data']['me']
end
def test_get_schema
header 'Content-Type', 'application/graphql'
post '/', '{ __schema { types { name } } }'
assert last_response.ok?
json = JSON.parse(last_response.body)
[
'Boolean',
'Cake',
'Query',
'String',
'__Directive',
'__DirectiveLocation',
'__EnumValue',
'__InputValue',
'__Type',
'__TypeKind',
].each do |type|
assert json['data']['__schema']['types'].include?('name' => type)
end
end
def test_get_query_type
header 'Content-Type', 'application/graphql'
post '/', '{ __schema { queryType { name } } }'
assert last_response.ok?
json = JSON.parse(last_response.body)
assert 'Query', json['data']['__schema']['queryType']['name']
end
def test_get_cakes_type
header 'Content-Type', 'application/graphql'
post '/', <<~GQL
{
__type(name: "Cake") {
name
kind
}
}
GQL
assert last_response.ok?
json = JSON.parse(last_response.body)
assert_equal 'Cake', json['data']['__type']['name']
assert_equal 'OBJECT', json['data']['__type']['kind']
end
def test_get_cake_fields
header 'Content-Type', 'application/graphql'
post '/', <<~GQL
{
__type(name: "Cake") {
name
fields {
name
type {
name
kind
}
}
}
}
GQL
assert last_response.ok?
json = JSON.parse(last_response.body)
assert_equal 'Cake', json.dig('data', '__type', 'name')
assert_equal [{
'name' => 'name',
'type' => {
'name' => nil,
'kind' => 'NON_NULL'
}
}], json.dig('data', '__type', 'fields')
end
end
|