graphql 1.7.14 → 1.8.0.pre1
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 +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
@@ -88,7 +88,7 @@ describe GraphQL::Query::SerialExecution::ValueResolution do
|
|
88
88
|
err = assert_raises(GraphQL::UnresolvedTypeError) { result }
|
89
89
|
expected_message = "The value from \"resolvesToNilInterface\" on \"Query\" could not be resolved to \"SomeInterface\". " \
|
90
90
|
"(Received: `nil`, Expected: [SomeObject]) " \
|
91
|
-
"Make sure you have defined a `
|
91
|
+
"Make sure you have defined a `type_from_object` proc on your schema and that value `1337` " \
|
92
92
|
"gets resolved to a valid type."
|
93
93
|
assert_equal expected_message, err.message
|
94
94
|
end
|
@@ -105,7 +105,7 @@ describe GraphQL::Query::SerialExecution::ValueResolution do
|
|
105
105
|
err = assert_raises(GraphQL::UnresolvedTypeError) { result }
|
106
106
|
expected_message = "The value from \"resolvesToWrongTypeInterface\" on \"Query\" could not be resolved to \"SomeInterface\". " \
|
107
107
|
"(Received: `OtherObject`, Expected: [SomeObject]) " \
|
108
|
-
"Make sure you have defined a `
|
108
|
+
"Make sure you have defined a `type_from_object` proc on your schema and that value `:something` " \
|
109
109
|
"gets resolved to a valid type."
|
110
110
|
assert_equal expected_message, err.message
|
111
111
|
end
|
@@ -111,7 +111,7 @@ describe GraphQL::Query::Variables do
|
|
111
111
|
let(:provided_variables) { { "ids" => [nil] } }
|
112
112
|
it "returns an error" do
|
113
113
|
assert_equal 1, result["errors"].length
|
114
|
-
|
114
|
+
assert_equal nil, result["data"]
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
data/spec/graphql/query_spec.rb
CHANGED
@@ -85,7 +85,7 @@ describe GraphQL::Query do
|
|
85
85
|
operation_name: operation_name,
|
86
86
|
max_depth: max_depth,
|
87
87
|
)
|
88
|
-
query.query_string = '{ __type(name: "
|
88
|
+
query.query_string = '{ __type(name: "Cheese") { name } }'
|
89
89
|
assert_equal "Cheese", query.result["data"] ["__type"]["name"]
|
90
90
|
end
|
91
91
|
end
|
@@ -111,7 +111,7 @@ describe GraphQL::Query do
|
|
111
111
|
}
|
112
112
|
|
113
113
|
it "returns nil" do
|
114
|
-
|
114
|
+
assert_equal nil, query.operation_name
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -148,7 +148,7 @@ describe GraphQL::Query do
|
|
148
148
|
}
|
149
149
|
|
150
150
|
it "returns the inferred operation name" do
|
151
|
-
|
151
|
+
assert_equal nil, query.selected_operation_name
|
152
152
|
end
|
153
153
|
end
|
154
154
|
end
|
@@ -253,32 +253,6 @@ describe GraphQL::Query do
|
|
253
253
|
assert_equal [nil], Instrumenter::ERROR_LOG
|
254
254
|
end
|
255
255
|
end
|
256
|
-
|
257
|
-
describe "when an error propagated through execution" do
|
258
|
-
module ExtensionsInstrumenter
|
259
|
-
LOG = []
|
260
|
-
def self.before_query(q); end;
|
261
|
-
|
262
|
-
def self.after_query(q)
|
263
|
-
q.result["extensions"] = { "a" => 1 }
|
264
|
-
LOG << :ok
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
let(:schema) {
|
269
|
-
Dummy::Schema.redefine {
|
270
|
-
instrument(:query, ExtensionsInstrumenter)
|
271
|
-
}
|
272
|
-
}
|
273
|
-
|
274
|
-
it "can add to extensions" do
|
275
|
-
ExtensionsInstrumenter::LOG.clear
|
276
|
-
assert_raises(RuntimeError) do
|
277
|
-
schema.execute "{ error }"
|
278
|
-
end
|
279
|
-
assert_equal [:ok], ExtensionsInstrumenter::LOG
|
280
|
-
end
|
281
|
-
end
|
282
256
|
end
|
283
257
|
|
284
258
|
it "uses root_value as the object for the root type" do
|
@@ -558,7 +532,7 @@ describe GraphQL::Query do
|
|
558
532
|
|
559
533
|
it "overrides the schema's max_depth" do
|
560
534
|
assert result["data"].key?("cheese")
|
561
|
-
|
535
|
+
assert_equal nil, result["errors"]
|
562
536
|
end
|
563
537
|
end
|
564
538
|
end
|
@@ -725,7 +699,7 @@ describe GraphQL::Query do
|
|
725
699
|
|
726
700
|
it "returns nil when there is no selected operation" do
|
727
701
|
query = GraphQL::Query.new(schema, '# Only a comment')
|
728
|
-
|
702
|
+
assert_equal nil, query.irep_selection
|
729
703
|
end
|
730
704
|
end
|
731
705
|
|
@@ -34,9 +34,7 @@ describe GraphQL::RakeTask do
|
|
34
34
|
end
|
35
35
|
dumped_json = File.read("./schema.json")
|
36
36
|
expected_json = JSON.pretty_generate(RakeTaskSchema.execute(GraphQL::Introspection::INTROSPECTION_QUERY))
|
37
|
-
|
38
|
-
# Test that that JSON is logically equivalent, not serialized the same
|
39
|
-
assert_equal(JSON.parse(expected_json), JSON.parse(dumped_json))
|
37
|
+
assert_equal(expected_json, dumped_json)
|
40
38
|
|
41
39
|
dumped_idl = File.read("./schema.graphql")
|
42
40
|
expected_idl = rake_task_schema_defn.chomp
|
@@ -12,7 +12,7 @@ describe GraphQL::Relay::ConnectionInstrumentation do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "keeps a reference to the function" do
|
15
|
-
conn_field = StarWars::Faction.fields["shipsWithMaxPageSize"]
|
15
|
+
conn_field = StarWars::Faction.graphql_definition.fields["shipsWithMaxPageSize"]
|
16
16
|
assert_instance_of StarWars::ShipsWithMaxPageSize, conn_field.function
|
17
17
|
end
|
18
18
|
|
@@ -77,7 +77,7 @@ describe GraphQL::Relay::ConnectionInstrumentation do
|
|
77
77
|
# Before the object is wrapped in a connection, the instrumentation sees `Array`
|
78
78
|
assert_equal ["StarWars::FactionRecord", "Array", "GraphQL::Relay::ArrayConnection"], ctx[:before_built_ins]
|
79
79
|
# After the object is wrapped in a connection, it sees the connection object
|
80
|
-
assert_equal ["StarWars::
|
80
|
+
assert_equal ["StarWars::Faction", "GraphQL::Relay::ArrayConnection", "GraphQL::Relay::ArrayConnection"], ctx[:after_built_ins]
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -73,7 +73,7 @@ describe GraphQL::Relay::ConnectionType do
|
|
73
73
|
|
74
74
|
it "nullifies the parent and adds an error" do
|
75
75
|
result = star_wars_query(query_string)
|
76
|
-
|
76
|
+
assert_equal nil, result["data"]["basesWithNullName"]["edges"][0]["node"]
|
77
77
|
assert_equal "Boom!", result["errors"][0]["message"]
|
78
78
|
end
|
79
79
|
end
|
@@ -193,17 +193,17 @@ describe GraphQL::Relay::Mutation do
|
|
193
193
|
end
|
194
194
|
|
195
195
|
it "doesn't get a mutation in the metadata" do
|
196
|
-
|
196
|
+
assert_equal nil, custom_return_type.mutation
|
197
197
|
end
|
198
198
|
|
199
199
|
it "supports input fields with nil default value" do
|
200
200
|
assert input.arguments['nullDefault'].default_value?
|
201
|
-
|
201
|
+
assert_equal nil, input.arguments['nullDefault'].default_value
|
202
202
|
end
|
203
203
|
|
204
204
|
it "supports input fields with no default value" do
|
205
205
|
assert !input.arguments['noDefault'].default_value?
|
206
|
-
|
206
|
+
assert_equal nil, input.arguments['noDefault'].default_value
|
207
207
|
end
|
208
208
|
|
209
209
|
it "supports input fields with non-nil default value" do
|
@@ -74,35 +74,6 @@ describe GraphQL::Relay::RelationConnection do
|
|
74
74
|
)
|
75
75
|
end
|
76
76
|
|
77
|
-
it "makes one sql query for items and another for count" do
|
78
|
-
query_str = <<-GRAPHQL
|
79
|
-
{
|
80
|
-
empire {
|
81
|
-
bases(first: 2) {
|
82
|
-
totalCount
|
83
|
-
edges {
|
84
|
-
cursor
|
85
|
-
node {
|
86
|
-
name
|
87
|
-
}
|
88
|
-
}
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|
92
|
-
GRAPHQL
|
93
|
-
io = StringIO.new
|
94
|
-
begin
|
95
|
-
prev_logger = ActiveRecord::Base.logger
|
96
|
-
ActiveRecord::Base.logger = Logger.new(io)
|
97
|
-
result = star_wars_query(query_str, "first" => 2)
|
98
|
-
ensure
|
99
|
-
ActiveRecord::Base.logger = prev_logger
|
100
|
-
end
|
101
|
-
assert_equal 2, io.string.scan("\n").count, "Two log entries"
|
102
|
-
assert_equal 3, result["data"]["empire"]["bases"]["totalCount"]
|
103
|
-
assert_equal 2, result["data"]["empire"]["bases"]["edges"].size
|
104
|
-
end
|
105
|
-
|
106
77
|
it "provides bidirectional_pagination" do
|
107
78
|
result = star_wars_query(query_string, "first" => 1)
|
108
79
|
last_cursor = get_last_cursor(result)
|
@@ -117,13 +88,6 @@ describe GraphQL::Relay::RelationConnection do
|
|
117
88
|
assert_equal true, get_page_info(result)["hasNextPage"]
|
118
89
|
assert_equal true, get_page_info(result)["hasPreviousPage"]
|
119
90
|
|
120
|
-
last_cursor = get_last_cursor(result)
|
121
|
-
result = with_bidirectional_pagination {
|
122
|
-
star_wars_query(query_string, "last" => 1, "before" => last_cursor)
|
123
|
-
}
|
124
|
-
assert_equal true, get_page_info(result)["hasNextPage"]
|
125
|
-
assert_equal false, get_page_info(result)["hasPreviousPage"]
|
126
|
-
|
127
91
|
result = star_wars_query(query_string, "first" => 100)
|
128
92
|
last_cursor = get_last_cursor(result)
|
129
93
|
|
@@ -136,6 +100,7 @@ describe GraphQL::Relay::RelationConnection do
|
|
136
100
|
}
|
137
101
|
assert_equal true, get_page_info(result)["hasNextPage"]
|
138
102
|
assert_equal true, get_page_info(result)["hasPreviousPage"]
|
103
|
+
|
139
104
|
end
|
140
105
|
|
141
106
|
it 'slices the result' do
|
@@ -599,35 +564,6 @@ describe GraphQL::Relay::RelationConnection do
|
|
599
564
|
result = star_wars_query(query_string, "last" => 1, "nameIncludes" => "ea", "before" => before)
|
600
565
|
assert_equal(["Death Star"], get_names(result))
|
601
566
|
end
|
602
|
-
|
603
|
-
it "makes one sql query for items and another for count" do
|
604
|
-
query_str = <<-GRAPHQL
|
605
|
-
{
|
606
|
-
empire {
|
607
|
-
basesAsSequelDataset(first: 2) {
|
608
|
-
totalCount
|
609
|
-
edges {
|
610
|
-
cursor
|
611
|
-
node {
|
612
|
-
name
|
613
|
-
}
|
614
|
-
}
|
615
|
-
}
|
616
|
-
}
|
617
|
-
}
|
618
|
-
GRAPHQL
|
619
|
-
result = nil
|
620
|
-
io = StringIO.new
|
621
|
-
begin
|
622
|
-
StarWars::DB.loggers << Logger.new(io)
|
623
|
-
result = star_wars_query(query_str, "first" => 2)
|
624
|
-
ensure
|
625
|
-
StarWars::DB.loggers.pop
|
626
|
-
end
|
627
|
-
assert_equal 2, io.string.scan("SELECT").count
|
628
|
-
assert_equal 3, result["data"]["empire"]["basesAsSequelDataset"]["totalCount"]
|
629
|
-
assert_equal 2, result["data"]["empire"]["basesAsSequelDataset"]["edges"].size
|
630
|
-
end
|
631
567
|
end
|
632
568
|
end
|
633
569
|
|
@@ -30,20 +30,6 @@ type HelloScalars {
|
|
30
30
|
build_schema_and_compare_output(schema.chop)
|
31
31
|
end
|
32
32
|
|
33
|
-
it 'can build a schema with default input object values' do
|
34
|
-
schema = <<-SCHEMA
|
35
|
-
input InputObject {
|
36
|
-
a: Int
|
37
|
-
}
|
38
|
-
|
39
|
-
type Query {
|
40
|
-
a(input: InputObject = {a: 1}): String
|
41
|
-
}
|
42
|
-
SCHEMA
|
43
|
-
|
44
|
-
build_schema_and_compare_output(schema.chop)
|
45
|
-
end
|
46
|
-
|
47
33
|
it 'can build a schema with directives' do
|
48
34
|
schema = <<-SCHEMA
|
49
35
|
schema {
|
@@ -308,7 +294,7 @@ schema {
|
|
308
294
|
}
|
309
295
|
|
310
296
|
type Hello {
|
311
|
-
str(
|
297
|
+
str(int: Int, bool: Boolean): String
|
312
298
|
}
|
313
299
|
SCHEMA
|
314
300
|
|
@@ -505,7 +491,7 @@ type HelloScalars {
|
|
505
491
|
}
|
506
492
|
|
507
493
|
type Mutation {
|
508
|
-
addHelloScalars(
|
494
|
+
addHelloScalars(str: String, int: Int, bool: Boolean): HelloScalars
|
509
495
|
}
|
510
496
|
SCHEMA
|
511
497
|
|
@@ -520,7 +506,7 @@ enum Color {
|
|
520
506
|
}
|
521
507
|
|
522
508
|
type Mutation {
|
523
|
-
hello(
|
509
|
+
hello(str: String, int: Int, color: Color = RED, nullDefault: Int = null): String
|
524
510
|
}
|
525
511
|
|
526
512
|
type Query {
|
@@ -545,7 +531,7 @@ type HelloScalars {
|
|
545
531
|
}
|
546
532
|
|
547
533
|
type Subscription {
|
548
|
-
subscribeHelloScalars(
|
534
|
+
subscribeHelloScalars(str: String, int: Int, bool: Boolean): HelloScalars
|
549
535
|
}
|
550
536
|
SCHEMA
|
551
537
|
|
@@ -603,74 +589,6 @@ type Query {
|
|
603
589
|
|
604
590
|
build_schema_and_compare_output(schema.chop)
|
605
591
|
end
|
606
|
-
|
607
|
-
it 'supports empty types' do
|
608
|
-
schema = <<-SCHEMA
|
609
|
-
type Query {
|
610
|
-
}
|
611
|
-
SCHEMA
|
612
|
-
|
613
|
-
build_schema_and_compare_output(schema.chop)
|
614
|
-
end
|
615
|
-
|
616
|
-
it "tracks original AST node" do
|
617
|
-
schema_definition = <<-GRAPHQL
|
618
|
-
schema {
|
619
|
-
query: Query
|
620
|
-
}
|
621
|
-
|
622
|
-
enum Enum {
|
623
|
-
VALUE
|
624
|
-
}
|
625
|
-
|
626
|
-
type Query {
|
627
|
-
field(argument: String): String
|
628
|
-
deprecatedField(argument: String): String @deprecated(reason: "Test")
|
629
|
-
}
|
630
|
-
|
631
|
-
interface Interface {
|
632
|
-
field(argument: String): String
|
633
|
-
}
|
634
|
-
|
635
|
-
union Union = Query
|
636
|
-
|
637
|
-
scalar Scalar
|
638
|
-
|
639
|
-
input Input {
|
640
|
-
argument: String
|
641
|
-
}
|
642
|
-
|
643
|
-
directive @Directive (
|
644
|
-
# Argument
|
645
|
-
argument: String
|
646
|
-
) on SCHEMA
|
647
|
-
|
648
|
-
type Type implements Interface {
|
649
|
-
field(argument: String): String
|
650
|
-
}
|
651
|
-
GRAPHQL
|
652
|
-
|
653
|
-
schema = GraphQL::Schema.from_definition(schema_definition)
|
654
|
-
|
655
|
-
assert_equal [1, 1], schema.ast_node.position
|
656
|
-
assert_equal [5, 1], schema.types["Enum"].ast_node.position
|
657
|
-
assert_equal [6, 3], schema.types["Enum"].values["VALUE"].ast_node.position
|
658
|
-
assert_equal [9, 1], schema.types["Query"].ast_node.position
|
659
|
-
assert_equal [10, 3], schema.types["Query"].fields["field"].ast_node.position
|
660
|
-
assert_equal [10, 9], schema.types["Query"].fields["field"].arguments["argument"].ast_node.position
|
661
|
-
assert_equal [11, 45], schema.types["Query"].fields["deprecatedField"].ast_node.directives[0].position
|
662
|
-
assert_equal [11, 57], schema.types["Query"].fields["deprecatedField"].ast_node.directives[0].arguments[0].position
|
663
|
-
assert_equal [14, 1], schema.types["Interface"].ast_node.position
|
664
|
-
assert_equal [15, 3], schema.types["Interface"].fields["field"].ast_node.position
|
665
|
-
assert_equal [15, 9], schema.types["Interface"].fields["field"].arguments["argument"].ast_node.position
|
666
|
-
assert_equal [18, 1], schema.types["Union"].ast_node.position
|
667
|
-
assert_equal [20, 1], schema.types["Scalar"].ast_node.position
|
668
|
-
assert_equal [22, 1], schema.types["Input"].ast_node.position
|
669
|
-
assert_equal [22, 1], schema.types["Input"].arguments["argument"].ast_node.position
|
670
|
-
assert_equal [26, 1], schema.directives["Directive"].ast_node.position
|
671
|
-
assert_equal [28, 3], schema.directives["Directive"].arguments["argument"].ast_node.position
|
672
|
-
assert_equal [31, 22], schema.types["Type"].ast_node.interfaces[0].position
|
673
|
-
end
|
674
592
|
end
|
675
593
|
|
676
594
|
describe 'Failures' do
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe GraphQL::Schema::Enum do
|
5
|
+
let(:enum) { Jazz::Family }
|
6
|
+
describe "type info" do
|
7
|
+
it "tells about the definition" do
|
8
|
+
assert_equal "Family", enum.graphql_name
|
9
|
+
assert_equal 29, enum.description.length
|
10
|
+
assert_equal 6, enum.values.size
|
11
|
+
end
|
12
|
+
|
13
|
+
it "inherits values and description" do
|
14
|
+
new_enum = Class.new(enum) do
|
15
|
+
value :Nonsense
|
16
|
+
value :PERCUSSION, "new description"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Description was inherited
|
20
|
+
assert_equal 29, new_enum.description.length
|
21
|
+
# values were inherited without modifying the parent
|
22
|
+
assert_equal 6, enum.values.size
|
23
|
+
assert_equal 7, new_enum.values.size
|
24
|
+
perc_value = new_enum.values.find { |v| v.name == "PERCUSSION" }
|
25
|
+
assert_equal "new description", perc_value.description
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
describe ".to_graphql" do
|
31
|
+
it "creates an EnumType" do
|
32
|
+
enum_type = enum.to_graphql
|
33
|
+
assert_equal "Family", enum_type.name
|
34
|
+
assert_equal "Groups of musical instruments", enum_type.description
|
35
|
+
|
36
|
+
string_val = enum_type.values["STRING"]
|
37
|
+
didg_val = enum_type.values["DIDGERIDOO"]
|
38
|
+
assert_equal "STRING", string_val.name
|
39
|
+
assert_equal :str, string_val.value
|
40
|
+
assert_equal "DIDGERIDOO", didg_val.name
|
41
|
+
assert_equal "Merged into BRASS", didg_val.deprecation_reason
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "in queries" do
|
46
|
+
it "works as return values" do
|
47
|
+
query_str = "{ instruments { family } }"
|
48
|
+
expected_families = ["STRING", "WOODWIND", "BRASS", "KEYS", "KEYS", "PERCUSSION"]
|
49
|
+
result = Jazz::Schema.execute(query_str)
|
50
|
+
assert_equal expected_families, result["data"]["instruments"].map { |i| i["family"] }
|
51
|
+
end
|
52
|
+
|
53
|
+
it "works as input" do
|
54
|
+
query_str = "query($family: Family!) { instruments(family: $family) { name } }"
|
55
|
+
expected_names = ["Piano", "Organ"]
|
56
|
+
result = Jazz::Schema.execute(query_str, variables: { "family" => "KEYS" })
|
57
|
+
assert_equal expected_names, result["data"]["instruments"].map { |i| i["name"] }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|