graphql 1.7.14 → 1.8.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/generators/graphql/function_generator.rb +1 -1
- data/lib/generators/graphql/loader_generator.rb +1 -1
- data/lib/generators/graphql/mutation_generator.rb +1 -6
- data/lib/generators/graphql/templates/function.erb +2 -2
- data/lib/generators/graphql/templates/loader.erb +2 -2
- data/lib/graphql.rb +2 -0
- data/lib/graphql/argument.rb +0 -1
- data/lib/graphql/backwards_compatibility.rb +2 -3
- data/lib/graphql/base_type.rb +18 -16
- data/lib/graphql/compatibility/query_parser_specification.rb +0 -117
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -14
- data/lib/graphql/define/assign_object_field.rb +5 -12
- data/lib/graphql/deprecated_dsl.rb +28 -0
- data/lib/graphql/directive.rb +0 -1
- data/lib/graphql/enum_type.rb +1 -3
- data/lib/graphql/execution.rb +0 -1
- data/lib/graphql/execution/multiplex.rb +29 -12
- data/lib/graphql/field.rb +5 -20
- data/lib/graphql/function.rb +12 -0
- data/lib/graphql/input_object_type.rb +1 -3
- data/lib/graphql/internal_representation/node.rb +14 -26
- data/lib/graphql/internal_representation/visit.rb +6 -3
- data/lib/graphql/introspection/arguments_field.rb +0 -1
- data/lib/graphql/introspection/enum_values_field.rb +0 -1
- data/lib/graphql/introspection/fields_field.rb +0 -1
- data/lib/graphql/introspection/input_fields_field.rb +0 -1
- data/lib/graphql/introspection/interfaces_field.rb +0 -1
- data/lib/graphql/introspection/of_type_field.rb +0 -1
- data/lib/graphql/introspection/possible_types_field.rb +0 -1
- data/lib/graphql/introspection/schema_field.rb +0 -1
- data/lib/graphql/introspection/type_by_name_field.rb +0 -1
- data/lib/graphql/introspection/typename_field.rb +0 -1
- data/lib/graphql/language.rb +0 -3
- data/lib/graphql/language/generation.rb +182 -3
- data/lib/graphql/language/lexer.rb +69 -144
- data/lib/graphql/language/lexer.rl +4 -15
- data/lib/graphql/language/nodes.rb +76 -136
- data/lib/graphql/language/parser.rb +621 -668
- data/lib/graphql/language/parser.y +11 -17
- data/lib/graphql/language/token.rb +3 -10
- data/lib/graphql/object_type.rb +6 -1
- data/lib/graphql/query.rb +13 -8
- data/lib/graphql/query/arguments.rb +33 -48
- data/lib/graphql/query/context.rb +1 -0
- data/lib/graphql/query/literal_input.rb +1 -4
- data/lib/graphql/relay/connection_resolve.rb +3 -0
- data/lib/graphql/relay/global_id_resolve.rb +5 -1
- data/lib/graphql/relay/relation_connection.rb +19 -14
- data/lib/graphql/schema.rb +219 -12
- data/lib/graphql/schema/argument.rb +33 -0
- data/lib/graphql/schema/build_from_definition.rb +18 -64
- data/lib/graphql/schema/enum.rb +76 -0
- data/lib/graphql/schema/field.rb +127 -0
- data/lib/graphql/schema/field/dynamic_resolve.rb +63 -0
- data/lib/graphql/schema/field/unwrapped_resolve.rb +20 -0
- data/lib/graphql/schema/input_object.rb +61 -0
- data/lib/graphql/schema/interface.rb +32 -0
- data/lib/graphql/schema/loader.rb +2 -2
- data/lib/graphql/schema/member.rb +97 -0
- data/lib/graphql/schema/member/build_type.rb +106 -0
- data/lib/graphql/schema/member/has_fields.rb +56 -0
- data/lib/graphql/schema/member/instrumentation.rb +113 -0
- data/lib/graphql/schema/member/list_type_proxy.rb +21 -0
- data/lib/graphql/schema/member/non_null_type_proxy.rb +21 -0
- data/lib/graphql/schema/object.rb +65 -0
- data/lib/graphql/schema/printer.rb +266 -33
- data/lib/graphql/schema/scalar.rb +25 -0
- data/lib/graphql/schema/traversal.rb +26 -17
- data/lib/graphql/schema/union.rb +48 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -5
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +8 -15
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +1 -11
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +5 -7
- data/lib/graphql/tracing.rb +0 -1
- data/lib/graphql/tracing/platform_tracing.rb +7 -20
- data/lib/graphql/tracing/scout_tracing.rb +2 -2
- data/lib/graphql/unresolved_type_error.rb +2 -3
- data/lib/graphql/version.rb +1 -1
- data/readme.md +1 -1
- data/spec/dummy/app/channels/graphql_channel.rb +1 -22
- data/spec/dummy/log/development.log +0 -239
- data/spec/dummy/log/test.log +0 -204
- data/spec/dummy/test/system/action_cable_subscription_test.rb +0 -4
- data/spec/dummy/tmp/screenshots/failures_test_it_handles_subscriptions.png +0 -0
- data/spec/generators/graphql/function_generator_spec.rb +0 -26
- data/spec/generators/graphql/loader_generator_spec.rb +0 -24
- data/spec/graphql/analysis/max_query_complexity_spec.rb +3 -3
- data/spec/graphql/analysis/max_query_depth_spec.rb +3 -3
- data/spec/graphql/backtrace_spec.rb +0 -10
- data/spec/graphql/base_type_spec.rb +5 -19
- data/spec/graphql/boolean_type_spec.rb +3 -3
- data/spec/graphql/directive_spec.rb +1 -3
- data/spec/graphql/enum_type_spec.rb +5 -18
- data/spec/graphql/execution/execute_spec.rb +1 -1
- data/spec/graphql/execution/multiplex_spec.rb +2 -2
- data/spec/graphql/float_type_spec.rb +2 -2
- data/spec/graphql/id_type_spec.rb +1 -1
- data/spec/graphql/input_object_type_spec.rb +2 -15
- data/spec/graphql/int_type_spec.rb +2 -2
- data/spec/graphql/internal_representation/rewrite_spec.rb +2 -2
- data/spec/graphql/introspection/schema_type_spec.rb +0 -1
- data/spec/graphql/language/generation_spec.rb +186 -21
- data/spec/graphql/language/lexer_spec.rb +1 -21
- data/spec/graphql/language/nodes_spec.rb +12 -21
- data/spec/graphql/language/parser_spec.rb +1 -1
- data/spec/graphql/query/arguments_spec.rb +15 -37
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -2
- data/spec/graphql/query/variables_spec.rb +1 -1
- data/spec/graphql/query_spec.rb +5 -31
- data/spec/graphql/rake_task_spec.rb +1 -3
- data/spec/graphql/relay/base_connection_spec.rb +1 -1
- data/spec/graphql/relay/connection_instrumentation_spec.rb +2 -2
- data/spec/graphql/relay/connection_resolve_spec.rb +1 -1
- data/spec/graphql/relay/connection_type_spec.rb +1 -1
- data/spec/graphql/relay/mutation_spec.rb +3 -3
- data/spec/graphql/relay/relation_connection_spec.rb +1 -65
- data/spec/graphql/schema/build_from_definition_spec.rb +4 -86
- data/spec/graphql/schema/enum_spec.rb +60 -0
- data/spec/graphql/schema/field_spec.rb +14 -0
- data/spec/graphql/schema/input_object_spec.rb +43 -0
- data/spec/graphql/schema/interface_spec.rb +98 -0
- data/spec/graphql/schema/object_spec.rb +119 -0
- data/spec/graphql/schema/printer_spec.rb +15 -92
- data/spec/graphql/schema/scalar_spec.rb +40 -0
- data/spec/graphql/schema/union_spec.rb +35 -0
- data/spec/graphql/schema/validation_spec.rb +1 -1
- data/spec/graphql/schema/warden_spec.rb +11 -11
- data/spec/graphql/schema_spec.rb +25 -23
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +2 -10
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -2
- data/spec/graphql/string_type_spec.rb +3 -3
- data/spec/graphql/subscriptions_spec.rb +1 -1
- data/spec/graphql/tracing/platform_tracing_spec.rb +1 -60
- data/spec/support/dummy/schema.rb +25 -39
- data/spec/support/jazz.rb +334 -0
- data/spec/support/lazy_helpers.rb +21 -23
- data/spec/support/star_wars/data.rb +7 -6
- data/spec/support/star_wars/schema.rb +109 -142
- metadata +39 -33
- data/lib/graphql/execution/instrumentation.rb +0 -82
- data/lib/graphql/language/block_string.rb +0 -47
- data/lib/graphql/language/document_from_schema_definition.rb +0 -277
- data/lib/graphql/language/printer.rb +0 -351
- data/lib/graphql/tracing/data_dog_tracing.rb +0 -49
- data/spec/graphql/execution/instrumentation_spec.rb +0 -165
- data/spec/graphql/language/block_string_spec.rb +0 -70
- data/spec/graphql/language/document_from_schema_definition_spec.rb +0 -770
- data/spec/graphql/language/printer_spec.rb +0 -203
@@ -126,7 +126,7 @@ describe GraphQL::Execution::Multiplex do
|
|
126
126
|
"before multiplex 1",
|
127
127
|
"before multiplex 2",
|
128
128
|
"before Q1", "before Q2", "before Q3",
|
129
|
-
"after
|
129
|
+
"after Q1", "after Q2", "after Q3",
|
130
130
|
"after multiplex 2",
|
131
131
|
"after multiplex 1",
|
132
132
|
], checks
|
@@ -176,7 +176,7 @@ describe GraphQL::Execution::Multiplex do
|
|
176
176
|
assert_raises(GraphQL::Error) do
|
177
177
|
InspectSchema.execute("{ raiseError }")
|
178
178
|
end
|
179
|
-
unhandled_err_json = '
|
179
|
+
unhandled_err_json = 'null'
|
180
180
|
assert_equal unhandled_err_json, InspectQueryInstrumentation.last_json
|
181
181
|
end
|
182
182
|
end
|
@@ -9,8 +9,8 @@ describe GraphQL::FLOAT_TYPE do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "rejects other types" do
|
12
|
-
|
13
|
-
|
12
|
+
assert_equal nil, GraphQL::FLOAT_TYPE.coerce_isolated_input("55")
|
13
|
+
assert_equal nil, GraphQL::FLOAT_TYPE.coerce_isolated_input(true)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -26,7 +26,7 @@ describe GraphQL::ID_TYPE do
|
|
26
26
|
let(:query_string) { %|query getMilk { cow: milk(id: 1.0) { id } }| }
|
27
27
|
|
28
28
|
it "doesn't allow other types" do
|
29
|
-
|
29
|
+
assert_equal nil, result["data"]
|
30
30
|
assert_equal 1, result["errors"].length
|
31
31
|
end
|
32
32
|
end
|
@@ -218,19 +218,6 @@ describe GraphQL::InputObjectType do
|
|
218
218
|
assert_equal(expected, actual)
|
219
219
|
end
|
220
220
|
end
|
221
|
-
|
222
|
-
describe 'with invalid name' do
|
223
|
-
it 'raises the correct error' do
|
224
|
-
assert_raises(GraphQL::InvalidNameError) do
|
225
|
-
InvalidInputTest = GraphQL::InputObjectType.define do
|
226
|
-
name "Some::Invalid Name"
|
227
|
-
end
|
228
|
-
|
229
|
-
# Force evaluation
|
230
|
-
InvalidInputTest.name
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
221
|
end
|
235
222
|
end
|
236
223
|
|
@@ -264,7 +251,7 @@ describe GraphQL::InputObjectType do
|
|
264
251
|
assert_equal 'Test', result['a']
|
265
252
|
|
266
253
|
assert result.key?('b')
|
267
|
-
|
254
|
+
assert_equal nil, result['b']
|
268
255
|
|
269
256
|
assert_equal "Test", result['c']
|
270
257
|
end
|
@@ -277,7 +264,7 @@ describe GraphQL::InputObjectType do
|
|
277
264
|
assert_equal 1, result['b']
|
278
265
|
|
279
266
|
assert result.key?('c')
|
280
|
-
|
267
|
+
assert_equal nil, result['c']
|
281
268
|
end
|
282
269
|
|
283
270
|
it "omitted arguments are not returned" do
|
@@ -9,8 +9,8 @@ describe GraphQL::INT_TYPE do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "rejects other types" do
|
12
|
-
|
13
|
-
|
12
|
+
assert_equal nil, GraphQL::INT_TYPE.coerce_isolated_input("55")
|
13
|
+
assert_equal nil, GraphQL::INT_TYPE.coerce_isolated_input(true)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -110,7 +110,7 @@ describe GraphQL::InternalRepresentation::Rewrite do
|
|
110
110
|
|
111
111
|
it "groups selections by object types which they apply to" do
|
112
112
|
doc = rewrite_result.operation_definitions["getPlant"]
|
113
|
-
|
113
|
+
assert_equal nil, doc.definition
|
114
114
|
|
115
115
|
plant_scoped_selection = doc.scoped_children[schema.types["Query"]]["plant"]
|
116
116
|
assert_equal ["Fruit", "Nut", "Plant"], plant_scoped_selection.scoped_children.keys.map(&:name).sort
|
@@ -132,7 +132,7 @@ describe GraphQL::InternalRepresentation::Rewrite do
|
|
132
132
|
|
133
133
|
it "tracks parent nodes" do
|
134
134
|
doc = rewrite_result.operation_definitions["getPlant"]
|
135
|
-
|
135
|
+
assert_equal nil, doc.parent
|
136
136
|
|
137
137
|
plant_selection = doc.typed_children[schema.types["Query"]]["plant"]
|
138
138
|
assert_equal doc, plant_selection.parent
|
@@ -2,35 +2,200 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe GraphQL::Language::Generation do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
let(:document) { GraphQL::Language::Parser.parse(query_string) }
|
6
|
+
let(:query_string) {%|
|
7
|
+
query getStuff($someVar: Int = 1, $anotherVar: [String!], $skipNested: Boolean! = false) @skip(if: false) {
|
8
|
+
myField: someField(someArg: $someVar, ok: 1.4) @skip(if: $anotherVar) @thing(or: "Whatever")
|
9
|
+
anotherField(someArg: [1, 2, 3]) {
|
10
|
+
nestedField
|
11
|
+
...moreNestedFields @skip(if: $skipNested)
|
12
|
+
}
|
13
|
+
... on OtherType @include(unless: false) {
|
14
|
+
field(arg: [{key: "value", anotherKey: 0.9, anotherAnotherKey: WHATEVER}])
|
15
|
+
anotherField
|
16
|
+
}
|
17
|
+
... {
|
18
|
+
id
|
19
|
+
}
|
8
20
|
}
|
9
21
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
22
|
+
fragment moreNestedFields on NestedType @or(something: "ok") {
|
23
|
+
anotherNestedField
|
24
|
+
}
|
25
|
+
|}
|
26
|
+
|
27
|
+
describe ".generate" do
|
28
|
+
it "generates query string" do
|
29
|
+
assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
|
14
30
|
end
|
15
31
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
21
|
-
|
32
|
+
describe "inputs" do
|
33
|
+
let(:query_string) {%|
|
34
|
+
query {
|
35
|
+
field(null_value: null, null_in_array: [1, null, 3], int: 3, float: 4.7e-24, bool: false, string: "☀︎🏆\\n escaped \\" unicode ¶ /", enum: ENUM_NAME, array: [7, 8, 9], object: {a: [1, 2, 3], b: {c: "4"}}, unicode_bom: "\xef\xbb\xbfquery")
|
36
|
+
}
|
37
|
+
|}
|
22
38
|
|
23
|
-
|
39
|
+
it "generate" do
|
40
|
+
assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
|
41
|
+
end
|
24
42
|
end
|
25
43
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
44
|
+
describe "schema" do
|
45
|
+
describe "schema with convention names for root types" do
|
46
|
+
let(:query_string) {<<-schema
|
47
|
+
schema {
|
48
|
+
query: Query
|
49
|
+
mutation: Mutation
|
50
|
+
subscription: Subscription
|
51
|
+
}
|
52
|
+
schema
|
53
|
+
}
|
54
|
+
|
55
|
+
it 'omits schema definition' do
|
56
|
+
refute document.to_query_string =~ /schema/
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "schema with custom query root name" do
|
61
|
+
let(:query_string) {<<-schema
|
62
|
+
schema {
|
63
|
+
query: MyQuery
|
64
|
+
mutation: Mutation
|
65
|
+
subscription: Subscription
|
66
|
+
}
|
67
|
+
schema
|
68
|
+
}
|
69
|
+
|
70
|
+
it 'includes schema definition' do
|
71
|
+
assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "schema with custom mutation root name" do
|
76
|
+
let(:query_string) {<<-schema
|
77
|
+
schema {
|
78
|
+
query: Query
|
79
|
+
mutation: MyMutation
|
80
|
+
subscription: Subscription
|
81
|
+
}
|
82
|
+
schema
|
83
|
+
}
|
84
|
+
|
85
|
+
it 'includes schema definition' do
|
86
|
+
assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "schema with custom subscription root name" do
|
91
|
+
let(:query_string) {<<-schema
|
92
|
+
schema {
|
93
|
+
query: Query
|
94
|
+
mutation: Mutation
|
95
|
+
subscription: MySubscription
|
96
|
+
}
|
97
|
+
schema
|
98
|
+
}
|
99
|
+
|
100
|
+
it 'includes schema definition' do
|
101
|
+
assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "full featured schema" do
|
106
|
+
# From: https://github.com/graphql/graphql-js/blob/bc96406ab44453a120da25a0bd6e2b0237119ddf/src/language/__tests__/schema-kitchen-sink.graphql
|
107
|
+
let(:query_string) {<<-schema
|
108
|
+
schema {
|
109
|
+
query: QueryType
|
110
|
+
mutation: MutationType
|
111
|
+
}
|
112
|
+
|
113
|
+
# Union description
|
114
|
+
union AnnotatedUnion @onUnion = A | B
|
115
|
+
|
116
|
+
type Foo implements Bar {
|
117
|
+
one: Type
|
118
|
+
two(argument: InputType!): Type
|
119
|
+
three(argument: InputType, other: String): Int
|
120
|
+
four(argument: String = "string"): String
|
121
|
+
five(argument: [String] = ["string", "string"]): String
|
122
|
+
six(argument: InputType = {key: "value"}): Type
|
123
|
+
seven(argument: String = null): Type
|
124
|
+
}
|
125
|
+
|
126
|
+
# Scalar description
|
127
|
+
scalar CustomScalar
|
32
128
|
|
33
|
-
|
129
|
+
type AnnotatedObject @onObject(arg: "value") {
|
130
|
+
annotatedField(arg: Type = "default" @onArg): Type @onField
|
131
|
+
}
|
132
|
+
|
133
|
+
interface Bar {
|
134
|
+
one: Type
|
135
|
+
four(argument: String = "string"): String
|
136
|
+
}
|
137
|
+
|
138
|
+
# Enum description
|
139
|
+
enum Site {
|
140
|
+
# Enum value description
|
141
|
+
DESKTOP
|
142
|
+
MOBILE
|
143
|
+
}
|
144
|
+
|
145
|
+
interface AnnotatedInterface @onInterface {
|
146
|
+
annotatedField(arg: Type @onArg): Type @onField
|
147
|
+
}
|
148
|
+
|
149
|
+
union Feed = Story | Article | Advert
|
150
|
+
|
151
|
+
# Input description
|
152
|
+
input InputType {
|
153
|
+
key: String!
|
154
|
+
answer: Int = 42
|
155
|
+
}
|
156
|
+
|
157
|
+
union AnnotatedUnion @onUnion = A | B
|
158
|
+
|
159
|
+
scalar CustomScalar
|
160
|
+
|
161
|
+
# Directive description
|
162
|
+
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
|
163
|
+
|
164
|
+
scalar AnnotatedScalar @onScalar
|
165
|
+
|
166
|
+
enum Site {
|
167
|
+
DESKTOP
|
168
|
+
MOBILE
|
169
|
+
}
|
170
|
+
|
171
|
+
enum AnnotatedEnum @onEnum {
|
172
|
+
ANNOTATED_VALUE @onEnumValue
|
173
|
+
OTHER_VALUE
|
174
|
+
}
|
175
|
+
|
176
|
+
input InputType {
|
177
|
+
key: String!
|
178
|
+
answer: Int = 42
|
179
|
+
}
|
180
|
+
|
181
|
+
input AnnotatedInput @onInputObjectType {
|
182
|
+
annotatedField: Type @onField
|
183
|
+
}
|
184
|
+
|
185
|
+
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
|
186
|
+
|
187
|
+
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
|
188
|
+
schema
|
189
|
+
}
|
190
|
+
|
191
|
+
it "generate" do
|
192
|
+
assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
|
193
|
+
end
|
194
|
+
|
195
|
+
it "doesn't mutate the document" do
|
196
|
+
assert_equal document.to_query_string, document.to_query_string
|
197
|
+
end
|
198
|
+
end
|
34
199
|
end
|
35
200
|
end
|
36
201
|
end
|
@@ -26,15 +26,6 @@ describe GraphQL::Language::Lexer do
|
|
26
26
|
assert_equal tokens[0], tokens[1].prev_token
|
27
27
|
end
|
28
28
|
|
29
|
-
describe "block strings" do
|
30
|
-
let(:query_string) { %|{ a(b: """\nc\n d\n""")}|}
|
31
|
-
|
32
|
-
it "tokenizes them" do
|
33
|
-
str_token = tokens[5]
|
34
|
-
assert_equal "c\n d", str_token.value
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
29
|
it "unescapes escaped characters" do
|
39
30
|
assert_equal "\" \\ / \b \f \n \r \t", subject.tokenize('"\\" \\\\ \\/ \\b \\f \\n \\r \\t"').first.to_s
|
40
31
|
end
|
@@ -49,18 +40,7 @@ describe GraphQL::Language::Lexer do
|
|
49
40
|
|
50
41
|
it "clears the previous_token between runs" do
|
51
42
|
tok_2 = subject.tokenize(query_string)
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
it "counts string position properly" do
|
56
|
-
tokens = subject.tokenize('{ a(b: "c")}')
|
57
|
-
str_token = tokens[5]
|
58
|
-
assert_equal :STRING, str_token.name
|
59
|
-
assert_equal "c", str_token.value
|
60
|
-
assert_equal 8, str_token.col
|
61
|
-
assert_equal '(STRING "c" [1:8])', str_token.inspect
|
62
|
-
rparen_token = tokens[6]
|
63
|
-
assert_equal '(RPAREN ")" [1:10])', rparen_token.inspect
|
43
|
+
assert_equal nil, tok_2[0].prev_token
|
64
44
|
end
|
65
45
|
end
|
66
46
|
end
|
@@ -2,6 +2,18 @@
|
|
2
2
|
require "spec_helper"
|
3
3
|
|
4
4
|
describe GraphQL::Language::Nodes::AbstractNode do
|
5
|
+
describe "child and scalar attributes" do
|
6
|
+
it "are inherited by node subclasses" do
|
7
|
+
subclassed_directive = Class.new(GraphQL::Language::Nodes::Directive)
|
8
|
+
|
9
|
+
assert_equal GraphQL::Language::Nodes::Directive.scalar_attributes,
|
10
|
+
subclassed_directive.scalar_attributes
|
11
|
+
|
12
|
+
assert_equal GraphQL::Language::Nodes::Directive.child_attributes,
|
13
|
+
subclassed_directive.child_attributes
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
5
17
|
describe "#filename" do
|
6
18
|
it "is set after .parse_file" do
|
7
19
|
filename = "spec/support/parser/filename_example.graphql"
|
@@ -21,25 +33,4 @@ describe GraphQL::Language::Nodes::AbstractNode do
|
|
21
33
|
assert_nil doc.filename
|
22
34
|
end
|
23
35
|
end
|
24
|
-
|
25
|
-
describe "#to_query_tring" do
|
26
|
-
let(:document) {
|
27
|
-
GraphQL.parse('type Query { a: String! }')
|
28
|
-
}
|
29
|
-
|
30
|
-
class CustomPrinter < GraphQL::Language::Printer
|
31
|
-
def print_field_definition(print_field_definition)
|
32
|
-
"<Field Hidden>"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "accepts a custom printer" do
|
37
|
-
expected = <<-SCHEMA
|
38
|
-
type Query {
|
39
|
-
<Field Hidden>
|
40
|
-
}
|
41
|
-
SCHEMA
|
42
|
-
assert_equal expected.chomp, document.to_query_string(printer: CustomPrinter.new)
|
43
|
-
end
|
44
|
-
end
|
45
36
|
end
|
@@ -16,7 +16,7 @@ describe GraphQL::Language::Parser do
|
|
16
16
|
|
17
17
|
it "creates an anonymous fragment definition" do
|
18
18
|
assert fragment.is_a?(GraphQL::Language::Nodes::FragmentDefinition)
|
19
|
-
|
19
|
+
assert_equal nil, fragment.name
|
20
20
|
assert_equal 1, fragment.selections.length
|
21
21
|
assert_equal "NestedType", fragment.type.name
|
22
22
|
assert_equal 1, fragment.directives.length
|
@@ -16,22 +16,10 @@ describe GraphQL::Query::Arguments do
|
|
16
16
|
argument :c, !test_input_1, as: :inputObject
|
17
17
|
end
|
18
18
|
|
19
|
-
GraphQL::Query::Arguments.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
c: GraphQL::Query::Arguments.new(
|
24
|
-
{
|
25
|
-
d: 3,
|
26
|
-
e: 4,
|
27
|
-
},
|
28
|
-
argument_definitions: test_input_1.arguments,
|
29
|
-
defaults_used: Set.new
|
30
|
-
),
|
31
|
-
},
|
32
|
-
argument_definitions: test_input_2.arguments,
|
33
|
-
defaults_used: Set.new
|
34
|
-
)
|
19
|
+
GraphQL::Query::Arguments.construct_arguments_class(test_input_1)
|
20
|
+
GraphQL::Query::Arguments.construct_arguments_class(test_input_2)
|
21
|
+
arg_values = {a: 1, b: 2, c: { d: 3, e: 4 }}
|
22
|
+
test_input_2.arguments_class.new(arg_values, context: nil)
|
35
23
|
}
|
36
24
|
|
37
25
|
it "returns keys as strings, with aliases" do
|
@@ -81,11 +69,11 @@ describe GraphQL::Query::Arguments do
|
|
81
69
|
)
|
82
70
|
end
|
83
71
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
)
|
72
|
+
args_class = Class.new(GraphQL::Query::Arguments) do
|
73
|
+
self.argument_definitions = types
|
74
|
+
end
|
75
|
+
|
76
|
+
new_arguments = args_class.new(transformed_args, context: nil)
|
89
77
|
expected_hash = {
|
90
78
|
"A" => 1,
|
91
79
|
"B" => 2,
|
@@ -106,10 +94,9 @@ describe GraphQL::Query::Arguments do
|
|
106
94
|
test_input_type
|
107
95
|
}
|
108
96
|
it "wraps input objects, but not other hashes" do
|
109
|
-
args =
|
97
|
+
args = input_type.arguments_class.new(
|
110
98
|
{a: 1, b: {a: 2}, c: {a: 3}},
|
111
|
-
|
112
|
-
defaults_used: Set.new
|
99
|
+
context: nil
|
113
100
|
)
|
114
101
|
assert_kind_of GraphQL::Query::Arguments, args["b"]
|
115
102
|
assert_instance_of Hash, args["c"]
|
@@ -128,8 +115,8 @@ describe GraphQL::Query::Arguments do
|
|
128
115
|
end
|
129
116
|
|
130
117
|
it "returns nil for missing keys" do
|
131
|
-
|
132
|
-
|
118
|
+
assert_equal nil, arguments["z"]
|
119
|
+
assert_equal nil, arguments[7]
|
133
120
|
end
|
134
121
|
end
|
135
122
|
|
@@ -211,15 +198,6 @@ describe GraphQL::Query::Arguments do
|
|
211
198
|
assert_equal({"a" => 1, "b" => 2}, last_args.to_h)
|
212
199
|
end
|
213
200
|
|
214
|
-
it "indicates when default argument values were applied" do
|
215
|
-
schema.execute("{ argTest(a: 1) }")
|
216
|
-
|
217
|
-
last_args = arg_values.last
|
218
|
-
|
219
|
-
assert_equal false, last_args.default_used?('a')
|
220
|
-
assert_equal true, last_args.default_used?('b')
|
221
|
-
end
|
222
|
-
|
223
201
|
it "works from variables" do
|
224
202
|
variables = { "arg" => { "a" => 1, "d" => nil } }
|
225
203
|
schema.execute("query ArgTest($arg: TestInput){ argTest(d: $arg) }", variables: variables)
|
@@ -325,10 +303,10 @@ describe GraphQL::Query::Arguments do
|
|
325
303
|
end
|
326
304
|
|
327
305
|
it "generates argument classes that responds to keys as functions" do
|
328
|
-
|
306
|
+
assert_equal nil, input_object.arguments_class
|
329
307
|
|
330
308
|
GraphQL::Query::Arguments.construct_arguments_class(input_object)
|
331
|
-
args = input_object.arguments_class.new({foo: 3, bar: -90},
|
309
|
+
args = input_object.arguments_class.new({foo: 3, bar: -90}, context: nil)
|
332
310
|
|
333
311
|
assert_equal 3, args.foo
|
334
312
|
assert_equal -90, args.bar
|