graphql 0.19.3 → 0.19.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/analysis/max_query_complexity.rb +1 -1
- data/lib/graphql/analysis/max_query_depth.rb +1 -1
- data/lib/graphql/boolean_type.rb +2 -2
- data/lib/graphql/define/instance_definable.rb +2 -2
- data/lib/graphql/enum_type.rb +3 -3
- data/lib/graphql/field.rb +6 -6
- data/lib/graphql/float_type.rb +2 -2
- data/lib/graphql/id_type.rb +2 -2
- data/lib/graphql/input_object_type.rb +1 -1
- data/lib/graphql/int_type.rb +2 -2
- data/lib/graphql/internal_representation/rewrite.rb +12 -12
- data/lib/graphql/introspection/arguments_field.rb +1 -1
- data/lib/graphql/introspection/enum_value_type.rb +1 -1
- data/lib/graphql/introspection/enum_values_field.rb +1 -1
- data/lib/graphql/introspection/field_type.rb +1 -1
- data/lib/graphql/introspection/fields_field.rb +1 -1
- data/lib/graphql/introspection/input_fields_field.rb +1 -1
- data/lib/graphql/introspection/input_value_type.rb +2 -2
- data/lib/graphql/introspection/interfaces_field.rb +1 -1
- data/lib/graphql/introspection/of_type_field.rb +1 -1
- data/lib/graphql/introspection/possible_types_field.rb +1 -1
- data/lib/graphql/introspection/schema_field.rb +1 -1
- data/lib/graphql/introspection/schema_type.rb +5 -5
- data/lib/graphql/introspection/type_by_name_field.rb +1 -1
- data/lib/graphql/introspection/type_type.rb +6 -6
- data/lib/graphql/introspection/typename_field.rb +1 -1
- data/lib/graphql/language.rb +1 -0
- data/lib/graphql/language/comments.rb +44 -0
- data/lib/graphql/language/definition_slice.rb +1 -1
- data/lib/graphql/language/generation.rb +35 -12
- data/lib/graphql/language/lexer.rb +29 -10
- data/lib/graphql/language/lexer.rl +25 -6
- data/lib/graphql/language/nodes.rb +30 -23
- data/lib/graphql/language/parser.rb +33 -14
- data/lib/graphql/language/parser.y +33 -14
- data/lib/graphql/language/parser_tests.rb +86 -2
- data/lib/graphql/language/token.rb +3 -2
- data/lib/graphql/language/visitor.rb +3 -3
- data/lib/graphql/object_type.rb +1 -1
- data/lib/graphql/query/arguments.rb +23 -2
- data/lib/graphql/query/serial_execution/field_resolution.rb +31 -14
- data/lib/graphql/relay/base_connection.rb +1 -3
- data/lib/graphql/relay/connection_type.rb +1 -1
- data/lib/graphql/relay/mutation.rb +1 -1
- data/lib/graphql/relay/relation_connection.rb +7 -3
- data/lib/graphql/scalar_type.rb +1 -1
- data/lib/graphql/schema.rb +19 -8
- data/lib/graphql/schema/loader.rb +2 -2
- data/lib/graphql/schema/printer.rb +63 -8
- data/lib/graphql/schema/timeout_middleware.rb +11 -11
- data/lib/graphql/schema/validation.rb +12 -12
- data/lib/graphql/static_validation/arguments_validator.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +3 -2
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -1
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +9 -4
- data/lib/graphql/static_validation/rules/fragments_are_named.rb +1 -1
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
- data/lib/graphql/static_validation/rules/fragments_are_used.rb +3 -3
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +2 -2
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +2 -2
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +6 -6
- data/lib/graphql/static_validation/type_stack.rb +2 -2
- data/lib/graphql/string_type.rb +2 -2
- data/lib/graphql/version.rb +1 -1
- data/readme.md +1 -1
- data/spec/graphql/analysis/analyze_query_spec.rb +3 -3
- data/spec/graphql/analysis/query_complexity_spec.rb +7 -7
- data/spec/graphql/introspection/directive_type_spec.rb +2 -2
- data/spec/graphql/introspection/introspection_query_spec.rb +26 -26
- data/spec/graphql/language/generation_spec.rb +137 -53
- data/spec/graphql/language/lexer_spec.rb +22 -0
- data/spec/graphql/language/visitor_spec.rb +6 -6
- data/spec/graphql/query/arguments_spec.rb +45 -1
- data/spec/graphql/query/context_spec.rb +4 -4
- data/spec/graphql/query/executor_spec.rb +1 -1
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +1 -1
- data/spec/graphql/relay/mutation_spec.rb +2 -2
- data/spec/graphql/relay/node_spec.rb +2 -2
- data/spec/graphql/relay/relation_connection_spec.rb +16 -0
- data/spec/graphql/schema/loader_spec.rb +2 -2
- data/spec/graphql/schema/middleware_chain_spec.rb +6 -6
- data/spec/graphql/schema/printer_spec.rb +268 -18
- data/spec/graphql/schema/rescue_middleware_spec.rb +1 -1
- data/spec/graphql/schema/timeout_middleware_spec.rb +2 -2
- data/spec/graphql/schema_spec.rb +2 -2
- data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +13 -0
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +1 -1
- data/spec/graphql/static_validation/type_stack_spec.rb +1 -1
- data/spec/support/dairy_app.rb +25 -25
- data/spec/support/dairy_data.rb +2 -0
- data/spec/support/star_wars_data.rb +2 -1
- data/spec/support/star_wars_schema.rb +18 -18
- metadata +19 -2
@@ -41,74 +41,158 @@ describe GraphQL::Language::Generation do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
describe "schema" do
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
describe "schema with convention names for root types" do
|
45
|
+
let(:query_string) {<<-schema
|
46
|
+
schema {
|
47
|
+
query: Query
|
48
|
+
mutation: Mutation
|
49
|
+
subscription: Subscription
|
50
|
+
}
|
51
|
+
schema
|
49
52
|
}
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
four(argument: String = "string"): String
|
56
|
-
five(argument: [String] = ["string", "string"]): String
|
57
|
-
six(argument: InputType = {key: "value"}): Type
|
58
|
-
}
|
54
|
+
it 'omits schema definition' do
|
55
|
+
refute document.to_query_string =~ /schema/
|
56
|
+
end
|
57
|
+
end
|
59
58
|
|
60
|
-
|
61
|
-
|
59
|
+
describe "schema with custom query root name" do
|
60
|
+
let(:query_string) {<<-schema
|
61
|
+
schema {
|
62
|
+
query: MyQuery
|
63
|
+
mutation: Mutation
|
64
|
+
subscription: Subscription
|
65
|
+
}
|
66
|
+
schema
|
62
67
|
}
|
63
68
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
69
|
+
it 'includes schema definition' do
|
70
|
+
assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
|
71
|
+
end
|
72
|
+
end
|
68
73
|
|
69
|
-
|
70
|
-
|
74
|
+
describe "schema with custom mutation root name" do
|
75
|
+
let(:query_string) {<<-schema
|
76
|
+
schema {
|
77
|
+
query: Query
|
78
|
+
mutation: MyMutation
|
79
|
+
subscription: Subscription
|
80
|
+
}
|
81
|
+
schema
|
71
82
|
}
|
72
83
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
scalar CustomScalar
|
78
|
-
|
79
|
-
scalar AnnotatedScalar @onScalar
|
80
|
-
|
81
|
-
enum Site {
|
82
|
-
DESKTOP
|
83
|
-
MOBILE
|
84
|
-
}
|
84
|
+
it 'includes schema definition' do
|
85
|
+
assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
|
86
|
+
end
|
87
|
+
end
|
85
88
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
+
describe "schema with custom subscription root name" do
|
90
|
+
let(:query_string) {<<-schema
|
91
|
+
schema {
|
92
|
+
query: Query
|
93
|
+
mutation: Mutation
|
94
|
+
subscription: MySubscription
|
95
|
+
}
|
96
|
+
schema
|
89
97
|
}
|
90
98
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
99
|
+
it 'includes schema definition' do
|
100
|
+
assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
|
101
|
+
end
|
102
|
+
end
|
95
103
|
|
96
|
-
|
97
|
-
|
104
|
+
describe "full featured schema" do
|
105
|
+
# From: https://github.com/graphql/graphql-js/blob/a725499b155285c2e33647a93393c82689b20b0f/src/language/__tests__/schema-kitchen-sink.graphql
|
106
|
+
let(:query_string) {<<-schema
|
107
|
+
schema {
|
108
|
+
query: QueryType
|
109
|
+
mutation: MutationType
|
110
|
+
}
|
111
|
+
|
112
|
+
# Union description
|
113
|
+
union AnnotatedUnion @onUnion = A | B
|
114
|
+
|
115
|
+
type Foo implements Bar {
|
116
|
+
one: Type
|
117
|
+
two(argument: InputType!): Type
|
118
|
+
three(argument: InputType, other: String): Int
|
119
|
+
four(argument: String = "string"): String
|
120
|
+
five(argument: [String] = ["string", "string"]): String
|
121
|
+
six(argument: InputType = {key: "value"}): Type
|
122
|
+
}
|
123
|
+
|
124
|
+
# Scalar description
|
125
|
+
scalar CustomScalar
|
126
|
+
|
127
|
+
type AnnotatedObject @onObject(arg: "value") {
|
128
|
+
annotatedField(arg: Type = "default" @onArg): Type @onField
|
129
|
+
}
|
130
|
+
|
131
|
+
interface Bar {
|
132
|
+
one: Type
|
133
|
+
four(argument: String = "string"): String
|
134
|
+
}
|
135
|
+
|
136
|
+
# Enum description
|
137
|
+
enum Site {
|
138
|
+
# Enum value description
|
139
|
+
DESKTOP
|
140
|
+
MOBILE
|
141
|
+
}
|
142
|
+
|
143
|
+
interface AnnotatedInterface @onInterface {
|
144
|
+
annotatedField(arg: Type @onArg): Type @onField
|
145
|
+
}
|
146
|
+
|
147
|
+
union Feed = Story | Article | Advert
|
148
|
+
|
149
|
+
# Input description
|
150
|
+
input InputType {
|
151
|
+
key: String!
|
152
|
+
answer: Int = 42
|
153
|
+
}
|
154
|
+
|
155
|
+
union AnnotatedUnion @onUnion = A | B
|
156
|
+
|
157
|
+
scalar CustomScalar
|
158
|
+
|
159
|
+
# Directive description
|
160
|
+
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
|
161
|
+
|
162
|
+
scalar AnnotatedScalar @onScalar
|
163
|
+
|
164
|
+
enum Site {
|
165
|
+
DESKTOP
|
166
|
+
MOBILE
|
167
|
+
}
|
168
|
+
|
169
|
+
enum AnnotatedEnum @onEnum {
|
170
|
+
ANNOTATED_VALUE @onEnumValue
|
171
|
+
OTHER_VALUE
|
172
|
+
}
|
173
|
+
|
174
|
+
input InputType {
|
175
|
+
key: String!
|
176
|
+
answer: Int = 42
|
177
|
+
}
|
178
|
+
|
179
|
+
input AnnotatedInput @onInputObjectType {
|
180
|
+
annotatedField: Type @onField
|
181
|
+
}
|
182
|
+
|
183
|
+
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
|
184
|
+
|
185
|
+
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
|
186
|
+
schema
|
98
187
|
}
|
99
188
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
schema
|
104
|
-
}
|
105
|
-
|
106
|
-
it "generate" do
|
107
|
-
assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
|
108
|
-
end
|
189
|
+
it "generate" do
|
190
|
+
assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
|
191
|
+
end
|
109
192
|
|
110
|
-
|
111
|
-
|
193
|
+
it "doesn't mutate the document" do
|
194
|
+
assert_equal document.to_query_string, document.to_query_string
|
195
|
+
end
|
112
196
|
end
|
113
197
|
end
|
114
198
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GraphQL::Language::Lexer do
|
4
|
+
subject { GraphQL::Language::Lexer }
|
5
|
+
|
6
|
+
describe ".tokenize" do
|
7
|
+
let(:query_string) {%|
|
8
|
+
{
|
9
|
+
query getCheese {
|
10
|
+
cheese(id: 1) {
|
11
|
+
... cheeseFields
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|}
|
16
|
+
let(:tokens) { subject.tokenize(query_string) }
|
17
|
+
|
18
|
+
it "keeps track of previous_token" do
|
19
|
+
assert_equal tokens[0], tokens[1].prev_token
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -19,13 +19,13 @@ describe GraphQL::Language::Visitor do
|
|
19
19
|
|
20
20
|
let(:visitor) do
|
21
21
|
v = GraphQL::Language::Visitor.new(document)
|
22
|
-
v[GraphQL::Language::Nodes::Field] << ->
|
22
|
+
v[GraphQL::Language::Nodes::Field] << ->(node, parent) { counts[:fields_entered] += 1 }
|
23
23
|
# two ways to set up enter hooks:
|
24
|
-
v[GraphQL::Language::Nodes::Argument] << ->
|
25
|
-
v[GraphQL::Language::Nodes::Argument].enter << ->
|
26
|
-
v[GraphQL::Language::Nodes::Argument].leave << ->
|
24
|
+
v[GraphQL::Language::Nodes::Argument] << ->(node, parent) { counts[:argument_names] << node.name }
|
25
|
+
v[GraphQL::Language::Nodes::Argument].enter << ->(node, parent) { counts[:arguments_entered] += 1}
|
26
|
+
v[GraphQL::Language::Nodes::Argument].leave << ->(node, parent) { counts[:arguments_left] += 1 }
|
27
27
|
|
28
|
-
v[GraphQL::Language::Nodes::Document].leave << ->
|
28
|
+
v[GraphQL::Language::Nodes::Document].leave << ->(node, parent) { counts[:finished] = true }
|
29
29
|
v
|
30
30
|
end
|
31
31
|
|
@@ -41,7 +41,7 @@ describe GraphQL::Language::Visitor do
|
|
41
41
|
|
42
42
|
describe "Visitor::SKIP" do
|
43
43
|
it "skips the rest of the node" do
|
44
|
-
visitor[GraphQL::Language::Nodes::Document] << ->
|
44
|
+
visitor[GraphQL::Language::Nodes::Document] << ->(node, parent) { GraphQL::Language::Visitor::SKIP }
|
45
45
|
visitor.visit
|
46
46
|
assert_equal(0, counts[:fields_entered])
|
47
47
|
end
|
@@ -45,6 +45,37 @@ describe GraphQL::Query::Arguments do
|
|
45
45
|
assert_equal({ a: 1, b: 2, c: { d: 3, e: 4 } }, arguments.to_h)
|
46
46
|
end
|
47
47
|
|
48
|
+
it "yields key, value, and arg_defnition" do
|
49
|
+
type_info = []
|
50
|
+
arguments.each_value do |arg_value|
|
51
|
+
value = arg_value.value.is_a?(GraphQL::Query::Arguments) ? arg_value.value.to_h : arg_value.value
|
52
|
+
type_info << [arg_value.key, value, arg_value.definition.type.unwrap.name]
|
53
|
+
end
|
54
|
+
expected_type_info =[
|
55
|
+
["a", 1, "Int"],
|
56
|
+
["b", 2, "Int"],
|
57
|
+
["c", { d: 3, e: 4 }, "TestInput1"],
|
58
|
+
]
|
59
|
+
assert_equal expected_type_info, type_info
|
60
|
+
end
|
61
|
+
|
62
|
+
it "can be copied to a new Arguments instance" do
|
63
|
+
transformed_args = {}
|
64
|
+
types = {}
|
65
|
+
arguments.each_value do |arg_value|
|
66
|
+
transformed_args[arg_value.key.upcase] = arg_value.value
|
67
|
+
types[arg_value.key.upcase] = arg_value.definition
|
68
|
+
end
|
69
|
+
|
70
|
+
new_arguments = GraphQL::Query::Arguments.new(transformed_args, argument_definitions: types)
|
71
|
+
expected_hash = {
|
72
|
+
"A" => 1,
|
73
|
+
"B" => 2,
|
74
|
+
"C" => { d: 3 , e: 4 },
|
75
|
+
}
|
76
|
+
assert_equal expected_hash, new_arguments.to_h
|
77
|
+
end
|
78
|
+
|
48
79
|
describe "nested hashes" do
|
49
80
|
let(:input_type) {
|
50
81
|
test_input_type = GraphQL::InputObjectType.define do
|
@@ -64,6 +95,19 @@ describe GraphQL::Query::Arguments do
|
|
64
95
|
end
|
65
96
|
end
|
66
97
|
|
98
|
+
describe "#[]" do
|
99
|
+
it "returns the value at that key" do
|
100
|
+
assert_equal 1, arguments["a"]
|
101
|
+
assert_equal 1, arguments[:a]
|
102
|
+
assert arguments["c"].is_a?(GraphQL::Query::Arguments)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "returns nil for missing keys" do
|
106
|
+
assert_equal nil, arguments["z"]
|
107
|
+
assert_equal nil, arguments[7]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
67
111
|
describe "#key?" do
|
68
112
|
let(:arg_values) { [] }
|
69
113
|
let(:schema) {
|
@@ -84,7 +128,7 @@ describe GraphQL::Query::Arguments do
|
|
84
128
|
argument :b, types.Int, default_value: 2
|
85
129
|
argument :c, types.Int
|
86
130
|
argument :d, test_input_type
|
87
|
-
resolve ->
|
131
|
+
resolve ->(obj, args, ctx) {
|
88
132
|
arg_values_array << args
|
89
133
|
1
|
90
134
|
}
|
@@ -5,16 +5,16 @@ describe GraphQL::Query::Context do
|
|
5
5
|
name "Query"
|
6
6
|
field :context, types.String do
|
7
7
|
argument :key, !types.String
|
8
|
-
resolve ->
|
8
|
+
resolve ->(target, args, ctx) { ctx[args[:key]] }
|
9
9
|
end
|
10
10
|
field :contextAstNodeName, types.String do
|
11
|
-
resolve ->
|
11
|
+
resolve ->(target, args, ctx) { ctx.ast_node.class.name }
|
12
12
|
end
|
13
13
|
field :contextIrepNodeName, types.String do
|
14
|
-
resolve ->
|
14
|
+
resolve ->(target, args, ctx) { ctx.irep_node.class.name }
|
15
15
|
end
|
16
16
|
field :queryName, types.String do
|
17
|
-
resolve ->
|
17
|
+
resolve ->(target, args, ctx) { ctx.query.class.name }
|
18
18
|
end
|
19
19
|
}}
|
20
20
|
let(:schema) { GraphQL::Schema.define(query: query_type, mutation: nil)}
|
@@ -22,7 +22,7 @@ describe GraphQL::Relay::Mutation do
|
|
22
22
|
|
23
23
|
after do
|
24
24
|
STAR_WARS_DATA["Ship"].delete("9")
|
25
|
-
STAR_WARS_DATA["Faction"]["1"]
|
25
|
+
STAR_WARS_DATA["Faction"]["1"].ships.delete("9")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "returns the result & clientMutationId" do
|
@@ -72,7 +72,7 @@ describe GraphQL::Relay::Mutation do
|
|
72
72
|
GraphQL::Relay::Mutation.define do
|
73
73
|
name "CustomReturnTypeTest"
|
74
74
|
return_type custom_type
|
75
|
-
resolve ->
|
75
|
+
resolve ->(input, ctx) {
|
76
76
|
OpenStruct.new(name: "Custom Return Type Test")
|
77
77
|
}
|
78
78
|
end
|
@@ -11,11 +11,11 @@ describe GraphQL::Relay::Node do
|
|
11
11
|
@previous_id_from_object_proc = StarWarsSchema.id_from_object_proc
|
12
12
|
@previous_object_from_id_proc = StarWarsSchema.object_from_id_proc
|
13
13
|
|
14
|
-
StarWarsSchema.id_from_object = ->
|
14
|
+
StarWarsSchema.id_from_object = ->(obj, type_name, ctx) {
|
15
15
|
"#{type_name}/#{obj.id}"
|
16
16
|
}
|
17
17
|
|
18
|
-
StarWarsSchema.object_from_id = ->
|
18
|
+
StarWarsSchema.object_from_id = ->(global_id, ctx) {
|
19
19
|
type_name, id = global_id.split("/")
|
20
20
|
STAR_WARS_DATA[type_name][id]
|
21
21
|
}
|
@@ -345,4 +345,20 @@ describe GraphQL::Relay::RelationConnection do
|
|
345
345
|
end
|
346
346
|
end
|
347
347
|
end
|
348
|
+
|
349
|
+
describe "#cursor_from_node" do
|
350
|
+
let(:connection) { GraphQL::Relay::RelationConnection.new(Base.where(faction_id: 1), {}) }
|
351
|
+
|
352
|
+
it "returns the cursor for a node in the connection" do
|
353
|
+
assert_equal "MQ==", connection.cursor_from_node(Base.all[0])
|
354
|
+
assert_equal "Mg==", connection.cursor_from_node(Base.all[1])
|
355
|
+
end
|
356
|
+
|
357
|
+
it "raises when the node isn't found" do
|
358
|
+
err = assert_raises(RuntimeError) {
|
359
|
+
connection.cursor_from_node(:not_found)
|
360
|
+
}
|
361
|
+
assert_includes err.message, "item not found"
|
362
|
+
end
|
363
|
+
end
|
348
364
|
end
|
@@ -22,8 +22,8 @@ describe GraphQL::Schema::Loader do
|
|
22
22
|
|
23
23
|
big_int_type = GraphQL::ScalarType.define do
|
24
24
|
name "BigInt"
|
25
|
-
coerce_input ->
|
26
|
-
coerce_result ->
|
25
|
+
coerce_input ->(value) { value =~ /\d+/ ? Integer(value) : nil }
|
26
|
+
coerce_result ->(value) { value.to_s }
|
27
27
|
end
|
28
28
|
|
29
29
|
variant_input_type = GraphQL::InputObjectType.define do
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe GraphQL::Schema::MiddlewareChain do
|
4
|
-
let(:step_1) { ->
|
5
|
-
let(:step_2) { ->
|
6
|
-
let(:step_3) { ->
|
4
|
+
let(:step_1) { ->(step_values, next_step) { step_values << 1; next_step.call } }
|
5
|
+
let(:step_2) { ->(step_values, next_step) { step_values << 2; next_step.call } }
|
6
|
+
let(:step_3) { ->(step_values, next_step) { step_values << 3; :return_value } }
|
7
7
|
let(:steps) { [step_1, step_2, step_3] }
|
8
8
|
let(:step_values) { [] }
|
9
9
|
let(:arguments) { [step_values] }
|
@@ -20,7 +20,7 @@ describe GraphQL::Schema::MiddlewareChain do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "when a step returns early" do
|
23
|
-
let(:early_return_step) { ->
|
23
|
+
let(:early_return_step) { ->(step_values, next_step) { :early_return } }
|
24
24
|
it "doesn't continue the chain" do
|
25
25
|
steps.insert(2, early_return_step)
|
26
26
|
assert_equal(:early_return, middleware_chain.call)
|
@@ -30,8 +30,8 @@ describe GraphQL::Schema::MiddlewareChain do
|
|
30
30
|
|
31
31
|
describe "when a step provides alternate arguments" do
|
32
32
|
it "passes the new arguments to the next step" do
|
33
|
-
step_1 = ->
|
34
|
-
step_2 = ->
|
33
|
+
step_1 = ->(test_arg, next_step) { assert_equal(test_arg, 'HELLO'); next_step.call(['WORLD']) }
|
34
|
+
step_2 = ->(test_arg, next_step) { assert_equal(test_arg, 'WORLD'); test_arg }
|
35
35
|
|
36
36
|
chain = GraphQL::Schema::MiddlewareChain.new(steps: [step_1, step_2], arguments: ['HELLO'])
|
37
37
|
result = chain.call
|