graphql 0.0.4 → 0.1.0
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/lib/graph_ql/directive.rb +36 -0
- data/lib/graph_ql/directives/directive_chain.rb +33 -0
- data/lib/graph_ql/directives/include_directive.rb +15 -0
- data/lib/graph_ql/directives/skip_directive.rb +15 -0
- data/lib/graph_ql/enum.rb +34 -0
- data/lib/graph_ql/fields/abstract_field.rb +37 -0
- data/lib/graph_ql/fields/access_field.rb +24 -0
- data/lib/graph_ql/fields/field.rb +34 -0
- data/lib/graph_ql/interface.rb +14 -0
- data/lib/graph_ql/introspection/arguments_field.rb +5 -0
- data/lib/graph_ql/introspection/directive_type.rb +12 -0
- data/lib/graph_ql/introspection/enum_value_type.rb +10 -0
- data/lib/graph_ql/introspection/enum_values_field.rb +15 -0
- data/lib/graph_ql/introspection/field_type.rb +11 -0
- data/lib/graph_ql/introspection/fields_field.rb +14 -0
- data/lib/graph_ql/introspection/input_fields_field.rb +12 -0
- data/lib/graph_ql/introspection/input_value_type.rb +10 -0
- data/lib/graph_ql/introspection/of_type_field.rb +12 -0
- data/lib/graph_ql/introspection/possible_types_field.rb +12 -0
- data/lib/graph_ql/introspection/schema_type.rb +32 -0
- data/lib/graph_ql/introspection/type_kind_enum.rb +7 -0
- data/lib/graph_ql/introspection/type_type.rb +22 -0
- data/lib/graph_ql/parser/nodes.rb +72 -0
- data/lib/graph_ql/parser/parser.rb +108 -0
- data/lib/graph_ql/parser/transform.rb +86 -0
- data/lib/graph_ql/parser/visitor.rb +47 -0
- data/lib/graph_ql/query.rb +50 -0
- data/lib/graph_ql/query/arguments.rb +25 -0
- data/lib/graph_ql/query/field_resolution_strategy.rb +83 -0
- data/lib/graph_ql/query/fragment_spread_resolution_strategy.rb +16 -0
- data/lib/graph_ql/query/inline_fragment_resolution_strategy.rb +14 -0
- data/lib/graph_ql/query/operation_resolver.rb +28 -0
- data/lib/graph_ql/query/selection_resolver.rb +20 -0
- data/lib/graph_ql/query/type_resolver.rb +19 -0
- data/lib/graph_ql/repl.rb +27 -0
- data/lib/graph_ql/schema.rb +30 -0
- data/lib/graph_ql/schema/type_reducer.rb +44 -0
- data/lib/graph_ql/type_kinds.rb +15 -0
- data/lib/graph_ql/types/abstract_type.rb +14 -0
- data/lib/graph_ql/types/boolean_type.rb +6 -0
- data/lib/graph_ql/types/float_type.rb +6 -0
- data/lib/graph_ql/types/input_object_type.rb +17 -0
- data/lib/graph_ql/types/input_value.rb +10 -0
- data/lib/graph_ql/types/int_type.rb +6 -0
- data/lib/graph_ql/types/list_type.rb +10 -0
- data/lib/graph_ql/types/non_null_type.rb +18 -0
- data/lib/graph_ql/types/non_null_with_bang.rb +5 -0
- data/lib/graph_ql/types/object_type.rb +62 -0
- data/lib/graph_ql/types/scalar_type.rb +5 -0
- data/lib/graph_ql/types/string_type.rb +6 -0
- data/lib/graph_ql/types/type_definer.rb +16 -0
- data/lib/graph_ql/union.rb +35 -0
- data/lib/graph_ql/validations/fields_are_defined_on_type.rb +44 -0
- data/lib/graph_ql/validations/fields_will_merge.rb +80 -0
- data/lib/graph_ql/validations/fragments_are_used.rb +24 -0
- data/lib/graph_ql/validator.rb +29 -0
- data/lib/graph_ql/version.rb +3 -0
- data/lib/graphql.rb +92 -99
- data/readme.md +17 -177
- data/spec/graph_ql/directive_spec.rb +81 -0
- data/spec/graph_ql/enum_spec.rb +5 -0
- data/spec/graph_ql/fields/field_spec.rb +10 -0
- data/spec/graph_ql/interface_spec.rb +13 -0
- data/spec/graph_ql/introspection/directive_type_spec.rb +40 -0
- data/spec/graph_ql/introspection/schema_type_spec.rb +39 -0
- data/spec/graph_ql/introspection/type_type_spec.rb +104 -0
- data/spec/graph_ql/parser/parser_spec.rb +120 -0
- data/spec/graph_ql/parser/transform_spec.rb +109 -0
- data/spec/graph_ql/parser/visitor_spec.rb +31 -0
- data/spec/graph_ql/query/operation_resolver_spec.rb +14 -0
- data/spec/graph_ql/query_spec.rb +82 -0
- data/spec/graph_ql/schema/type_reducer_spec.rb +24 -0
- data/spec/graph_ql/types/input_object_type_spec.rb +12 -0
- data/spec/graph_ql/types/object_type_spec.rb +35 -0
- data/spec/graph_ql/union_spec.rb +27 -0
- data/spec/graph_ql/validations/fields_are_defined_on_type_spec.rb +28 -0
- data/spec/graph_ql/validations/fields_will_merge_spec.rb +40 -0
- data/spec/graph_ql/validations/fragments_are_used_spec.rb +28 -0
- data/spec/graph_ql/validator_spec.rb +24 -0
- data/spec/spec_helper.rb +2 -2
- data/spec/support/dummy_app.rb +123 -63
- data/spec/support/dummy_data.rb +11 -0
- metadata +107 -59
- data/lib/graphql/call.rb +0 -8
- data/lib/graphql/connection.rb +0 -65
- data/lib/graphql/field.rb +0 -12
- data/lib/graphql/field_definer.rb +0 -25
- data/lib/graphql/introspection/call_type.rb +0 -13
- data/lib/graphql/introspection/connection.rb +0 -9
- data/lib/graphql/introspection/field_type.rb +0 -10
- data/lib/graphql/introspection/root_call_argument_node.rb +0 -5
- data/lib/graphql/introspection/root_call_type.rb +0 -20
- data/lib/graphql/introspection/schema_call.rb +0 -8
- data/lib/graphql/introspection/schema_type.rb +0 -17
- data/lib/graphql/introspection/type_call.rb +0 -8
- data/lib/graphql/introspection/type_type.rb +0 -18
- data/lib/graphql/node.rb +0 -244
- data/lib/graphql/parser/parser.rb +0 -39
- data/lib/graphql/parser/transform.rb +0 -22
- data/lib/graphql/query.rb +0 -109
- data/lib/graphql/root_call.rb +0 -202
- data/lib/graphql/root_call_argument.rb +0 -11
- data/lib/graphql/root_call_argument_definer.rb +0 -17
- data/lib/graphql/schema/all.rb +0 -46
- data/lib/graphql/schema/schema.rb +0 -87
- data/lib/graphql/schema/schema_validation.rb +0 -32
- data/lib/graphql/syntax/call.rb +0 -8
- data/lib/graphql/syntax/field.rb +0 -9
- data/lib/graphql/syntax/fragment.rb +0 -7
- data/lib/graphql/syntax/node.rb +0 -8
- data/lib/graphql/syntax/query.rb +0 -8
- data/lib/graphql/syntax/variable.rb +0 -7
- data/lib/graphql/types/boolean_type.rb +0 -3
- data/lib/graphql/types/number_type.rb +0 -3
- data/lib/graphql/types/object_type.rb +0 -6
- data/lib/graphql/types/string_type.rb +0 -3
- data/lib/graphql/version.rb +0 -3
- data/spec/graphql/node_spec.rb +0 -69
- data/spec/graphql/parser/parser_spec.rb +0 -168
- data/spec/graphql/parser/transform_spec.rb +0 -157
- data/spec/graphql/query_spec.rb +0 -274
- data/spec/graphql/root_call_spec.rb +0 -69
- data/spec/graphql/schema/schema_spec.rb +0 -93
- data/spec/graphql/schema/schema_validation_spec.rb +0 -48
- data/spec/support/nodes.rb +0 -175
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GraphQL::Schema::Schema do
|
4
|
-
let(:schema) { GraphQL::SCHEMA }
|
5
|
-
describe 'global instance' do
|
6
|
-
it 'exists as GraphQL::SCHEMA' do
|
7
|
-
assert GraphQL::SCHEMA.is_a?(GraphQL::Schema::Schema)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#get_call' do
|
12
|
-
it 'finds calls from their class name' do
|
13
|
-
assert_equal Nodes::ContextCall, schema.get_call("context")
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'finds calls from declared names' do
|
17
|
-
assert_equal Nodes::LikePostCall, schema.get_call("upvote_post")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#get_type' do
|
22
|
-
it 'finds nodes from their class name' do
|
23
|
-
assert_equal Nodes::PostNode, schema.get_type("post")
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'finds nodes from declared names' do
|
27
|
-
assert_equal Nodes::ThumbUpNode, schema.get_type("upvote")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'querying schema' do
|
32
|
-
let(:query_string) { }
|
33
|
-
let(:query) { GraphQL::Query.new(query_string) }
|
34
|
-
let(:result) { GraphQL::SCHEMA.all }
|
35
|
-
|
36
|
-
describe 'querying calls' do
|
37
|
-
let(:upvote_post_call) { result["schema"]["calls"]["edges"].find {|e| e["node"]["name"] == "upvote_post"} }
|
38
|
-
|
39
|
-
it 'returns all calls' do
|
40
|
-
assert_equal 7, result["schema"]["calls"]["count"]
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'doesnt show abstract call classes' do
|
44
|
-
call_names = result["schema"]["calls"]["edges"].map {|e| e["node"]["name"] }
|
45
|
-
assert(!call_names.include?("find"))
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'shows return types' do
|
49
|
-
assert_equal ["post", "upvote"], upvote_post_call["node"]["returns"]
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'shows argument types' do
|
53
|
-
expected_arguments = [{"node"=>{"name"=>"post_data", "type"=>"object"}}, {"node"=>{"name"=>"person_id", "type"=>"number"}}]
|
54
|
-
assert_equal expected_arguments, upvote_post_call["node"]["arguments"]["edges"]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'querying types' do
|
59
|
-
let(:post_type) { result["schema"]["types"]["edges"].find { |e| e["node"]["name"] == "post" }["node"]}
|
60
|
-
let(:content_field) { post_type["fields"]["edges"].find { |e| e["node"]["name"] == "content" }["node"]}
|
61
|
-
let(:select_call) { content_field["calls"]["edges"].find { |e| e["node"]["name"] == "select"}["node"]}
|
62
|
-
let(:type_names) { result["schema"]["types"]["edges"].map {|t| t["node"]["name"] }}
|
63
|
-
|
64
|
-
it 'returns all types' do
|
65
|
-
types_count = 19
|
66
|
-
assert_equal types_count, result["schema"]["types"]["count"]
|
67
|
-
assert_equal types_count, type_names.length
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'doesnt return types that dont expose anything' do
|
71
|
-
type_names = result["schema"]["types"]["edges"].map {|e| e["node"]["name"] }
|
72
|
-
assert(!type_names.include?("application"))
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'show type name & fields' do
|
76
|
-
assert_equal "post", post_type["name"]
|
77
|
-
assert_equal 8, post_type["fields"]["count"]
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'has custom types' do
|
81
|
-
assert type_names.include?("letter_selection")
|
82
|
-
assert_equal "letter_selection", content_field["type"]
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'shows field type & calls' do
|
86
|
-
assert_equal "letter_selection", content_field["type"]
|
87
|
-
assert_equal 3, content_field["calls"]["count"]
|
88
|
-
assert_equal "select", select_call["name"]
|
89
|
-
assert_equal "from_chars (req), for_chars (req)", select_call["arguments"]
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GraphQL::Schema::SchemaValidation do
|
4
|
-
let(:schema) { GraphQL::SCHEMA }
|
5
|
-
|
6
|
-
it 'runs' do
|
7
|
-
schema.validate
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "when the exposes_class doesnt exist" do
|
11
|
-
before do
|
12
|
-
Nodes::PostNode.exposes("BogusPost")
|
13
|
-
end
|
14
|
-
after do
|
15
|
-
Nodes::PostNode.exposes("Post")
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'raises an error' do
|
19
|
-
assert_raises(GraphQL::ExposesClassMissingError) { schema.validate }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "when there's a bad field type" do
|
24
|
-
before do
|
25
|
-
Nodes::PostNode.field.bogus_kind(:bogus_title)
|
26
|
-
end
|
27
|
-
after do
|
28
|
-
Nodes::PostNode.remove_field(:bogus_title)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'raises an error' do
|
32
|
-
assert_raises(GraphQL::NodeNotDefinedError) { schema.validate }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "when a field cant find a corresponding method" do
|
37
|
-
before do
|
38
|
-
Nodes::PostNode.field.string(:bogus_title)
|
39
|
-
end
|
40
|
-
after do
|
41
|
-
Nodes::PostNode.remove_field(:bogus_title)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'raises an error' do
|
45
|
-
assert_raises(GraphQL::FieldNotDefinedError) { schema.validate }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/spec/support/nodes.rb
DELETED
@@ -1,175 +0,0 @@
|
|
1
|
-
require 'graphql'
|
2
|
-
require 'support/dummy_app.rb'
|
3
|
-
|
4
|
-
module Nodes
|
5
|
-
class ApplicationNode < GraphQL::Node
|
6
|
-
field.number(:id)
|
7
|
-
cursor :id
|
8
|
-
|
9
|
-
class << self
|
10
|
-
attr_accessor :model_class
|
11
|
-
def node_for(m_class)
|
12
|
-
@model_class = m_class
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
class ApplicationConnection < GraphQL::Connection
|
19
|
-
type :connection
|
20
|
-
call :first, -> (prev_items, first) { prev_items.first(first.to_i) }
|
21
|
-
call :after, -> (prev_items, after) { prev_items.select {|i| i.id > after.to_i } }
|
22
|
-
|
23
|
-
field.number(:count)
|
24
|
-
field.boolean(:any)
|
25
|
-
|
26
|
-
def count
|
27
|
-
target.count
|
28
|
-
end
|
29
|
-
|
30
|
-
def any
|
31
|
-
target.any?
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class CommentsConnection < ApplicationConnection
|
36
|
-
type :comments
|
37
|
-
field.number :viewer_name_length
|
38
|
-
field.number :average_rating
|
39
|
-
|
40
|
-
# just to test context:
|
41
|
-
def viewer_name_length
|
42
|
-
context.person_name.length
|
43
|
-
end
|
44
|
-
|
45
|
-
def average_rating
|
46
|
-
total_rating = target.map(&:rating).inject(&:+).to_f
|
47
|
-
total_rating / target.size
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class DateType < GraphQL::Node
|
52
|
-
exposes "Date"
|
53
|
-
type :date
|
54
|
-
call :minus_days, -> (prev_value, minus_days) { prev_value - minus_days.to_i }
|
55
|
-
field.number(:year)
|
56
|
-
field.number(:month)
|
57
|
-
end
|
58
|
-
|
59
|
-
class PostNode < ApplicationNode
|
60
|
-
node_for Post
|
61
|
-
exposes "Post"
|
62
|
-
desc "A blog post entry"
|
63
|
-
|
64
|
-
field.string(:title)
|
65
|
-
field.letter_selection(:content)
|
66
|
-
field.number(:length)
|
67
|
-
field.comments(:comments)
|
68
|
-
field.date(:published_at)
|
69
|
-
field.connection(:likes)
|
70
|
-
|
71
|
-
def length
|
72
|
-
target.content.length
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class CommentNode < ApplicationNode
|
77
|
-
node_for Comment
|
78
|
-
exposes "Comment"
|
79
|
-
field.string(:content)
|
80
|
-
field.letter_selection(:letters)
|
81
|
-
field.post(:post)
|
82
|
-
|
83
|
-
def letters; content; end
|
84
|
-
end
|
85
|
-
|
86
|
-
# wraps a Like, for testing explicit name
|
87
|
-
class ThumbUpNode < ApplicationNode
|
88
|
-
node_for(Like)
|
89
|
-
exposes "Like"
|
90
|
-
type "upvote"
|
91
|
-
field.number :post_id
|
92
|
-
def id
|
93
|
-
target.id.to_s + target.id.to_s
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
class ContextNode < GraphQL::Node
|
98
|
-
exposes "Context"
|
99
|
-
field.string(:person_name)
|
100
|
-
field.boolean(:present)
|
101
|
-
|
102
|
-
def cursor
|
103
|
-
"context"
|
104
|
-
end
|
105
|
-
|
106
|
-
def present
|
107
|
-
true
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
class LetterSelectionType < GraphQL::Node
|
112
|
-
type :letter_selection
|
113
|
-
call :from, -> (prev_value, chars) { prev_value[(chars.to_i)..-1] }
|
114
|
-
call :for, -> (prev_value, chars) { prev_value[0, (chars.to_i)] }
|
115
|
-
call :select, -> (prev_value, from_chars, for_chars) { prev_value[from_chars.to_i, for_chars.to_i] }
|
116
|
-
def as_result
|
117
|
-
apply_calls(target)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
class FindCall < GraphQL::RootCall
|
122
|
-
abstract!
|
123
|
-
argument.number("ids", any_number: true)
|
124
|
-
def execute!(*ids)
|
125
|
-
model_class = model_type
|
126
|
-
items = ids.map { |id| model_class.find(id.to_i) }
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
class PostCall < FindCall
|
131
|
-
returns :post
|
132
|
-
def model_type
|
133
|
-
Post
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
class CommentCall < FindCall
|
138
|
-
returns :comment
|
139
|
-
def model_type
|
140
|
-
Comment
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
class ThumbUpCall < FindCall
|
145
|
-
returns :thumb_up
|
146
|
-
def model_type
|
147
|
-
Like
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
class ContextCall < GraphQL::RootCall
|
152
|
-
returns :context
|
153
|
-
def execute!
|
154
|
-
context
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
class LikePostCall < GraphQL::RootCall
|
159
|
-
indentifier "upvote_post"
|
160
|
-
returns :post, :upvote
|
161
|
-
|
162
|
-
argument.object("post_data")
|
163
|
-
argument.number("person_id")
|
164
|
-
|
165
|
-
|
166
|
-
def execute!(post_data, person_id)
|
167
|
-
post_id = post_data["id"]
|
168
|
-
like = Like.create(post_id: post_id)
|
169
|
-
{
|
170
|
-
post: Post.find(post_id),
|
171
|
-
upvote: like
|
172
|
-
}
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|