graphql 1.9.11 → 1.9.12
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/ast/query_complexity.rb +0 -8
- data/lib/graphql/analysis/ast/query_depth.rb +0 -8
- data/lib/graphql/analysis/ast/visitor.rb +26 -24
- data/lib/graphql/execution.rb +1 -0
- data/lib/graphql/execution/errors.rb +60 -0
- data/lib/graphql/execution/interpreter/runtime.rb +21 -17
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +15 -8
- data/lib/graphql/version.rb +1 -1
- metadata +5 -556
- data/spec/dummy/Gemfile +0 -12
- data/spec/dummy/README.md +0 -24
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/config/manifest.js +0 -1
- data/spec/dummy/app/assets/javascripts/application.js +0 -66
- data/spec/dummy/app/channels/application_cable/channel.rb +0 -5
- data/spec/dummy/app/channels/application_cable/connection.rb +0 -5
- data/spec/dummy/app/channels/graphql_channel.rb +0 -116
- data/spec/dummy/app/controllers/application_controller.rb +0 -4
- data/spec/dummy/app/controllers/pages_controller.rb +0 -5
- data/spec/dummy/app/helpers/application_helper.rb +0 -3
- data/spec/dummy/app/jobs/application_job.rb +0 -3
- data/spec/dummy/app/views/layouts/application.html.erb +0 -12
- data/spec/dummy/app/views/pages/show.html +0 -16
- data/spec/dummy/bin/bundle +0 -4
- data/spec/dummy/bin/rails +0 -5
- data/spec/dummy/bin/rake +0 -5
- data/spec/dummy/bin/setup +0 -31
- data/spec/dummy/bin/update +0 -27
- data/spec/dummy/bin/yarn +0 -12
- data/spec/dummy/config.ru +0 -6
- data/spec/dummy/config/application.rb +0 -30
- data/spec/dummy/config/boot.rb +0 -4
- data/spec/dummy/config/cable.yml +0 -10
- data/spec/dummy/config/environment.rb +0 -6
- data/spec/dummy/config/environments/development.rb +0 -40
- data/spec/dummy/config/environments/production.rb +0 -76
- data/spec/dummy/config/environments/test.rb +0 -37
- data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -9
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -8
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -6
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -5
- data/spec/dummy/config/initializers/inflections.rb +0 -17
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -10
- data/spec/dummy/config/locales/en.yml +0 -33
- data/spec/dummy/config/puma.rb +0 -57
- data/spec/dummy/config/routes.rb +0 -4
- data/spec/dummy/config/secrets.yml +0 -32
- data/spec/dummy/package.json +0 -5
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +0 -1
- data/spec/dummy/test/application_system_test_case.rb +0 -6
- data/spec/dummy/test/system/action_cable_subscription_test.rb +0 -45
- data/spec/dummy/test/test_helper.rb +0 -4
- data/spec/fixtures/upgrader/account.original.rb +0 -19
- data/spec/fixtures/upgrader/account.transformed.rb +0 -20
- data/spec/fixtures/upgrader/blame_range.original.rb +0 -43
- data/spec/fixtures/upgrader/blame_range.transformed.rb +0 -30
- data/spec/fixtures/upgrader/date_time.original.rb +0 -24
- data/spec/fixtures/upgrader/date_time.transformed.rb +0 -23
- data/spec/fixtures/upgrader/delete_project.original.rb +0 -28
- data/spec/fixtures/upgrader/delete_project.transformed.rb +0 -27
- data/spec/fixtures/upgrader/gist_order_field.original.rb +0 -14
- data/spec/fixtures/upgrader/gist_order_field.transformed.rb +0 -13
- data/spec/fixtures/upgrader/increment_count.original.rb +0 -59
- data/spec/fixtures/upgrader/increment_count.transformed.rb +0 -50
- data/spec/fixtures/upgrader/mutation.original.rb +0 -28
- data/spec/fixtures/upgrader/mutation.transformed.rb +0 -28
- data/spec/fixtures/upgrader/photo.original.rb +0 -10
- data/spec/fixtures/upgrader/photo.transformed.rb +0 -12
- data/spec/fixtures/upgrader/release_order.original.rb +0 -15
- data/spec/fixtures/upgrader/release_order.transformed.rb +0 -14
- data/spec/fixtures/upgrader/starrable.original.rb +0 -49
- data/spec/fixtures/upgrader/starrable.transformed.rb +0 -46
- data/spec/fixtures/upgrader/subscribable.original.rb +0 -55
- data/spec/fixtures/upgrader/subscribable.transformed.rb +0 -51
- data/spec/fixtures/upgrader/type_x.original.rb +0 -65
- data/spec/fixtures/upgrader/type_x.transformed.rb +0 -56
- data/spec/graphql/analysis/analyze_query_spec.rb +0 -261
- data/spec/graphql/analysis/ast/field_usage_spec.rb +0 -51
- data/spec/graphql/analysis/ast/max_query_complexity_spec.rb +0 -120
- data/spec/graphql/analysis/ast/max_query_depth_spec.rb +0 -134
- data/spec/graphql/analysis/ast/query_complexity_spec.rb +0 -299
- data/spec/graphql/analysis/ast/query_depth_spec.rb +0 -108
- data/spec/graphql/analysis/ast_spec.rb +0 -296
- data/spec/graphql/analysis/field_usage_spec.rb +0 -62
- data/spec/graphql/analysis/max_query_complexity_spec.rb +0 -102
- data/spec/graphql/analysis/max_query_depth_spec.rb +0 -103
- data/spec/graphql/analysis/query_complexity_spec.rb +0 -301
- data/spec/graphql/analysis/query_depth_spec.rb +0 -81
- data/spec/graphql/argument_spec.rb +0 -159
- data/spec/graphql/authorization_spec.rb +0 -974
- data/spec/graphql/backtrace_spec.rb +0 -206
- data/spec/graphql/base_type_spec.rb +0 -171
- data/spec/graphql/boolean_type_spec.rb +0 -21
- data/spec/graphql/compatibility/execution_specification_spec.rb +0 -4
- data/spec/graphql/compatibility/lazy_execution_specification_spec.rb +0 -4
- data/spec/graphql/compatibility/query_parser_specification_spec.rb +0 -6
- data/spec/graphql/compatibility/schema_parser_specification_spec.rb +0 -6
- data/spec/graphql/define/assign_argument_spec.rb +0 -61
- data/spec/graphql/define/instance_definable_spec.rb +0 -203
- data/spec/graphql/directive/skip_directive_spec.rb +0 -9
- data/spec/graphql/directive_spec.rb +0 -295
- data/spec/graphql/enum_type_spec.rb +0 -158
- data/spec/graphql/execution/execute_spec.rb +0 -303
- data/spec/graphql/execution/instrumentation_spec.rb +0 -212
- data/spec/graphql/execution/interpreter_spec.rb +0 -485
- data/spec/graphql/execution/lazy/lazy_method_map_spec.rb +0 -57
- data/spec/graphql/execution/lazy_spec.rb +0 -247
- data/spec/graphql/execution/lookahead_spec.rb +0 -390
- data/spec/graphql/execution/multiplex_spec.rb +0 -222
- data/spec/graphql/execution/typecast_spec.rb +0 -47
- data/spec/graphql/execution_error_spec.rb +0 -329
- data/spec/graphql/field_spec.rb +0 -246
- data/spec/graphql/float_type_spec.rb +0 -16
- data/spec/graphql/function_spec.rb +0 -152
- data/spec/graphql/id_type_spec.rb +0 -33
- data/spec/graphql/input_object_type_spec.rb +0 -25
- data/spec/graphql/int_type_spec.rb +0 -35
- data/spec/graphql/interface_type_spec.rb +0 -196
- data/spec/graphql/internal_representation/print_spec.rb +0 -41
- data/spec/graphql/internal_representation/rewrite_spec.rb +0 -381
- data/spec/graphql/introspection/directive_type_spec.rb +0 -66
- data/spec/graphql/introspection/input_value_type_spec.rb +0 -144
- data/spec/graphql/introspection/introspection_query_spec.rb +0 -64
- data/spec/graphql/introspection/schema_type_spec.rb +0 -57
- data/spec/graphql/introspection/type_type_spec.rb +0 -155
- data/spec/graphql/language/block_string_spec.rb +0 -70
- data/spec/graphql/language/definition_slice_spec.rb +0 -226
- data/spec/graphql/language/document_from_schema_definition_spec.rb +0 -770
- data/spec/graphql/language/equality_spec.rb +0 -84
- data/spec/graphql/language/generation_spec.rb +0 -38
- data/spec/graphql/language/lexer_spec.rb +0 -153
- data/spec/graphql/language/nodes_spec.rb +0 -67
- data/spec/graphql/language/parser_spec.rb +0 -183
- data/spec/graphql/language/printer_spec.rb +0 -215
- data/spec/graphql/language/visitor_spec.rb +0 -419
- data/spec/graphql/list_type_spec.rb +0 -57
- data/spec/graphql/non_null_type_spec.rb +0 -48
- data/spec/graphql/object_type_spec.rb +0 -197
- data/spec/graphql/query/arguments_spec.rb +0 -346
- data/spec/graphql/query/context_spec.rb +0 -292
- data/spec/graphql/query/executor_spec.rb +0 -341
- data/spec/graphql/query/literal_input_spec.rb +0 -91
- data/spec/graphql/query/result_spec.rb +0 -29
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +0 -109
- data/spec/graphql/query_spec.rb +0 -803
- data/spec/graphql/rake_task_spec.rb +0 -59
- data/spec/graphql/scalar_type_spec.rb +0 -66
- data/spec/graphql/schema/argument_spec.rb +0 -186
- data/spec/graphql/schema/build_from_definition_spec.rb +0 -1197
- data/spec/graphql/schema/catchall_middleware_spec.rb +0 -32
- data/spec/graphql/schema/directive/feature_spec.rb +0 -81
- data/spec/graphql/schema/directive/transform_spec.rb +0 -39
- data/spec/graphql/schema/enum_spec.rb +0 -83
- data/spec/graphql/schema/enum_value_spec.rb +0 -24
- data/spec/graphql/schema/field_extension_spec.rb +0 -159
- data/spec/graphql/schema/field_spec.rb +0 -319
- data/spec/graphql/schema/finder_spec.rb +0 -135
- data/spec/graphql/schema/input_object_spec.rb +0 -421
- data/spec/graphql/schema/instrumentation_spec.rb +0 -43
- data/spec/graphql/schema/interface_spec.rb +0 -215
- data/spec/graphql/schema/introspection_system_spec.rb +0 -80
- data/spec/graphql/schema/list_spec.rb +0 -73
- data/spec/graphql/schema/loader_spec.rb +0 -350
- data/spec/graphql/schema/member/accepts_definition_spec.rb +0 -115
- data/spec/graphql/schema/member/build_type_spec.rb +0 -63
- data/spec/graphql/schema/member/scoped_spec.rb +0 -217
- data/spec/graphql/schema/member/type_system_helpers_spec.rb +0 -63
- data/spec/graphql/schema/middleware_chain_spec.rb +0 -57
- data/spec/graphql/schema/mutation_spec.rb +0 -150
- data/spec/graphql/schema/non_null_spec.rb +0 -46
- data/spec/graphql/schema/object_spec.rb +0 -355
- data/spec/graphql/schema/printer_spec.rb +0 -883
- data/spec/graphql/schema/relay_classic_mutation_spec.rb +0 -252
- data/spec/graphql/schema/rescue_middleware_spec.rb +0 -88
- data/spec/graphql/schema/resolver_spec.rb +0 -743
- data/spec/graphql/schema/scalar_spec.rb +0 -101
- data/spec/graphql/schema/subscription_spec.rb +0 -505
- data/spec/graphql/schema/timeout_middleware_spec.rb +0 -188
- data/spec/graphql/schema/timeout_spec.rb +0 -206
- data/spec/graphql/schema/traversal_spec.rb +0 -222
- data/spec/graphql/schema/type_expression_spec.rb +0 -39
- data/spec/graphql/schema/union_spec.rb +0 -72
- data/spec/graphql/schema/unique_within_type_spec.rb +0 -44
- data/spec/graphql/schema/validation_spec.rb +0 -355
- data/spec/graphql/schema/warden_spec.rb +0 -926
- data/spec/graphql/schema_spec.rb +0 -169
- data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +0 -466
- data/spec/graphql/static_validation/rules/argument_names_are_unique_spec.rb +0 -44
- data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +0 -112
- data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +0 -35
- data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +0 -42
- data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +0 -167
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +0 -66
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +0 -740
- data/spec/graphql/static_validation/rules/fragment_names_are_unique_spec.rb +0 -28
- data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +0 -52
- data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +0 -42
- data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +0 -123
- data/spec/graphql/static_validation/rules/fragments_are_named_spec.rb +0 -24
- data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +0 -56
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +0 -61
- data/spec/graphql/static_validation/rules/mutation_root_exists_spec.rb +0 -39
- data/spec/graphql/static_validation/rules/no_definitions_are_present_spec.rb +0 -62
- data/spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb +0 -82
- data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +0 -98
- data/spec/graphql/static_validation/rules/required_input_object_attributes_are_present_spec.rb +0 -86
- data/spec/graphql/static_validation/rules/subscription_root_exists_spec.rb +0 -34
- data/spec/graphql/static_validation/rules/unique_directives_per_location_spec.rb +0 -188
- data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +0 -196
- data/spec/graphql/static_validation/rules/variable_names_are_unique_spec.rb +0 -23
- data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +0 -236
- data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +0 -78
- data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +0 -81
- data/spec/graphql/static_validation/type_stack_spec.rb +0 -29
- data/spec/graphql/static_validation/validator_spec.rb +0 -204
- data/spec/graphql/string_type_spec.rb +0 -80
- data/spec/graphql/subscriptions/serialize_spec.rb +0 -49
- data/spec/graphql/subscriptions_spec.rb +0 -540
- data/spec/graphql/tracing/new_relic_tracing_spec.rb +0 -84
- data/spec/graphql/tracing/platform_tracing_spec.rb +0 -141
- data/spec/graphql/tracing/prometheus_tracing_spec.rb +0 -42
- data/spec/graphql/tracing/scout_tracing_spec.rb +0 -17
- data/spec/graphql/tracing/skylight_tracing_spec.rb +0 -63
- data/spec/graphql/tracing_spec.rb +0 -52
- data/spec/graphql/types/big_int_spec.rb +0 -24
- data/spec/graphql/types/iso_8601_date_time_spec.rb +0 -137
- data/spec/graphql/types/relay/base_edge_spec.rb +0 -33
- data/spec/graphql/union_type_spec.rb +0 -211
- data/spec/graphql/upgrader/member_spec.rb +0 -583
- data/spec/graphql/upgrader/schema_spec.rb +0 -82
- data/spec/integration/mongoid/graphql/relay/mongo_relation_connection_spec.rb +0 -528
- data/spec/integration/mongoid/spec_helper.rb +0 -2
- data/spec/integration/mongoid/star_trek/data.rb +0 -126
- data/spec/integration/mongoid/star_trek/schema.rb +0 -424
- data/spec/integration/rails/data.rb +0 -110
- data/spec/integration/rails/generators/base_generator_test.rb +0 -7
- data/spec/integration/rails/generators/graphql/enum_generator_spec.rb +0 -30
- data/spec/integration/rails/generators/graphql/install_generator_spec.rb +0 -238
- data/spec/integration/rails/generators/graphql/interface_generator_spec.rb +0 -34
- data/spec/integration/rails/generators/graphql/loader_generator_spec.rb +0 -59
- data/spec/integration/rails/generators/graphql/mutation_generator_spec.rb +0 -71
- data/spec/integration/rails/generators/graphql/object_generator_spec.rb +0 -54
- data/spec/integration/rails/generators/graphql/scalar_generator_spec.rb +0 -28
- data/spec/integration/rails/generators/graphql/union_generator_spec.rb +0 -67
- data/spec/integration/rails/graphql/input_object_spec.rb +0 -19
- data/spec/integration/rails/graphql/input_object_type_spec.rb +0 -364
- data/spec/integration/rails/graphql/query/variables_spec.rb +0 -375
- data/spec/integration/rails/graphql/relay/array_connection_spec.rb +0 -309
- data/spec/integration/rails/graphql/relay/base_connection_spec.rb +0 -101
- data/spec/integration/rails/graphql/relay/connection_instrumentation_spec.rb +0 -80
- data/spec/integration/rails/graphql/relay/connection_resolve_spec.rb +0 -79
- data/spec/integration/rails/graphql/relay/connection_type_spec.rb +0 -106
- data/spec/integration/rails/graphql/relay/edge_spec.rb +0 -10
- data/spec/integration/rails/graphql/relay/mutation_spec.rb +0 -387
- data/spec/integration/rails/graphql/relay/node_spec.rb +0 -263
- data/spec/integration/rails/graphql/relay/page_info_spec.rb +0 -111
- data/spec/integration/rails/graphql/relay/range_add_spec.rb +0 -117
- data/spec/integration/rails/graphql/relay/relation_connection_spec.rb +0 -837
- data/spec/integration/rails/graphql/schema_spec.rb +0 -507
- data/spec/integration/rails/graphql/tracing/active_support_notifications_tracing_spec.rb +0 -62
- data/spec/integration/rails/spec_helper.rb +0 -25
- data/spec/spec_helper.rb +0 -116
- data/spec/support/dummy/data.rb +0 -45
- data/spec/support/dummy/schema.rb +0 -519
- data/spec/support/error_bubbling_helpers.rb +0 -23
- data/spec/support/global_id.rb +0 -23
- data/spec/support/jazz.rb +0 -778
- data/spec/support/lazy_helpers.rb +0 -192
- data/spec/support/magic_cards/schema.graphql +0 -33
- data/spec/support/minimum_input_object.rb +0 -21
- data/spec/support/new_relic.rb +0 -27
- data/spec/support/parser/filename_example.graphql +0 -5
- data/spec/support/parser/filename_example_error_1.graphql +0 -4
- data/spec/support/parser/filename_example_error_2.graphql +0 -5
- data/spec/support/parser/filename_example_invalid_utf8.graphql +0 -1
- data/spec/support/skylight.rb +0 -39
- data/spec/support/star_wars/schema.rb +0 -464
- data/spec/support/static_validation_helpers.rb +0 -32
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe GraphQL::Execution::Lazy::LazyMethodMap do
|
5
|
-
def self.test_lazy_method_map
|
6
|
-
it "handles multithreaded access" do
|
7
|
-
a = Class.new
|
8
|
-
b = Class.new(a)
|
9
|
-
c = Class.new(b)
|
10
|
-
lazy_method_map.set(a, :a)
|
11
|
-
threads = 1000.times.map do |i|
|
12
|
-
Thread.new {
|
13
|
-
d = Class.new(c)
|
14
|
-
assert_equal :a, lazy_method_map.get(d.new)
|
15
|
-
}
|
16
|
-
end
|
17
|
-
threads.map(&:join)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "dups" do
|
21
|
-
a = Class.new
|
22
|
-
b = Class.new(a)
|
23
|
-
c = Class.new(b)
|
24
|
-
lazy_method_map.set(a, :a)
|
25
|
-
lazy_method_map.get(b.new)
|
26
|
-
lazy_method_map.get(c.new)
|
27
|
-
|
28
|
-
dup_map = lazy_method_map.dup
|
29
|
-
assert_equal 3, dup_map.instance_variable_get(:@storage).size
|
30
|
-
assert_equal :a, dup_map.get(a.new)
|
31
|
-
assert_equal :a, dup_map.get(b.new)
|
32
|
-
assert_equal :a, dup_map.get(c.new)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "with a plain hash" do
|
37
|
-
let(:lazy_method_map) { GraphQL::Execution::Lazy::LazyMethodMap.new(use_concurrent: false) }
|
38
|
-
test_lazy_method_map
|
39
|
-
|
40
|
-
it "has a Ruby Hash inside" do
|
41
|
-
storage = lazy_method_map
|
42
|
-
.instance_variable_get(:@storage)
|
43
|
-
.instance_variable_get(:@storage)
|
44
|
-
assert_instance_of Hash, storage
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "with a Concurrent::Map" do
|
49
|
-
let(:lazy_method_map) { GraphQL::Execution::Lazy::LazyMethodMap.new(use_concurrent: true) }
|
50
|
-
test_lazy_method_map
|
51
|
-
|
52
|
-
it "has a Concurrent::Map inside" do
|
53
|
-
storage = lazy_method_map.instance_variable_get(:@storage)
|
54
|
-
assert_instance_of Concurrent::Map, storage
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,247 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe GraphQL::Execution::Lazy do
|
5
|
-
include LazyHelpers
|
6
|
-
|
7
|
-
describe "resolving" do
|
8
|
-
it "calls value handlers" do
|
9
|
-
res = run_query('{ int(value: 2, plus: 1) }')
|
10
|
-
assert_equal 3, res["data"]["int"]
|
11
|
-
end
|
12
|
-
|
13
|
-
it "Works with Query.new" do
|
14
|
-
query_str = '{ int(value: 2, plus: 1) }'
|
15
|
-
query = GraphQL::Query.new(LazyHelpers::LazySchema, query_str)
|
16
|
-
res = query.result
|
17
|
-
assert_equal 3, res["data"]["int"]
|
18
|
-
end
|
19
|
-
|
20
|
-
it "can do nested lazy values" do
|
21
|
-
res = run_query %|
|
22
|
-
{
|
23
|
-
a: nestedSum(value: 3) {
|
24
|
-
value
|
25
|
-
nestedSum(value: 7) {
|
26
|
-
value
|
27
|
-
nestedSum(value: 1) {
|
28
|
-
value
|
29
|
-
nestedSum(value: -50) {
|
30
|
-
value
|
31
|
-
}
|
32
|
-
}
|
33
|
-
}
|
34
|
-
}
|
35
|
-
b: nestedSum(value: 2) {
|
36
|
-
value
|
37
|
-
nestedSum(value: 11) {
|
38
|
-
value
|
39
|
-
nestedSum(value: 2) {
|
40
|
-
value
|
41
|
-
nestedSum(value: -50) {
|
42
|
-
value
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
c: listSum(values: [1,2]) {
|
49
|
-
nestedSum(value: 3) {
|
50
|
-
value
|
51
|
-
}
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
|
55
|
-
|
56
|
-
expected_data = {
|
57
|
-
"a"=>{"value"=>14, "nestedSum"=>{
|
58
|
-
"value"=>46,
|
59
|
-
"nestedSum"=>{
|
60
|
-
"value"=>95,
|
61
|
-
"nestedSum"=>{"value"=>90}
|
62
|
-
}
|
63
|
-
}},
|
64
|
-
"b"=>{"value"=>14, "nestedSum"=>{
|
65
|
-
"value"=>46,
|
66
|
-
"nestedSum"=>{
|
67
|
-
"value"=>95,
|
68
|
-
"nestedSum"=>{"value"=>90}
|
69
|
-
}
|
70
|
-
}},
|
71
|
-
"c"=>[
|
72
|
-
{"nestedSum"=>{"value"=>14}},
|
73
|
-
{"nestedSum"=>{"value"=>14}}
|
74
|
-
],
|
75
|
-
}
|
76
|
-
|
77
|
-
assert_equal expected_data, res["data"]
|
78
|
-
end
|
79
|
-
|
80
|
-
# This only works with the interpreter
|
81
|
-
if TESTING_INTERPRETER
|
82
|
-
[
|
83
|
-
[1, 2, LazyHelpers::MAGIC_NUMBER_WITH_LAZY_AUTHORIZED_HOOK],
|
84
|
-
[2, LazyHelpers::MAGIC_NUMBER_WITH_LAZY_AUTHORIZED_HOOK, 1],
|
85
|
-
[LazyHelpers::MAGIC_NUMBER_WITH_LAZY_AUTHORIZED_HOOK, 1, 2],
|
86
|
-
].each do |ordered_values|
|
87
|
-
it "resolves each field at one depth before proceeding to the next depth (using #{ordered_values})" do
|
88
|
-
res = run_query <<-GRAPHQL, variables: { values: ordered_values }
|
89
|
-
query($values: [Int!]!) {
|
90
|
-
listSum(values: $values) {
|
91
|
-
nestedSum(value: 3) {
|
92
|
-
value
|
93
|
-
}
|
94
|
-
}
|
95
|
-
}
|
96
|
-
GRAPHQL
|
97
|
-
|
98
|
-
# Even though magic number `44`'s `.authorized?` hook returns a lazy value,
|
99
|
-
# these fields should be resolved together and return the same value.
|
100
|
-
assert_equal 56, res["data"]["listSum"][0]["nestedSum"]["value"]
|
101
|
-
assert_equal 56, res["data"]["listSum"][1]["nestedSum"]["value"]
|
102
|
-
assert_equal 56, res["data"]["listSum"][2]["nestedSum"]["value"]
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
it "Handles fields that return nil" do
|
107
|
-
values = [
|
108
|
-
LazyHelpers::MAGIC_NUMBER_THAT_RETURNS_NIL,
|
109
|
-
LazyHelpers::MAGIC_NUMBER_WITH_LAZY_AUTHORIZED_HOOK,
|
110
|
-
1,
|
111
|
-
2,
|
112
|
-
]
|
113
|
-
|
114
|
-
res = run_query <<-GRAPHQL, variables: { values: values }
|
115
|
-
query($values: [Int!]!) {
|
116
|
-
listSum(values: $values) {
|
117
|
-
nullableNestedSum(value: 3) {
|
118
|
-
value
|
119
|
-
}
|
120
|
-
}
|
121
|
-
}
|
122
|
-
GRAPHQL
|
123
|
-
|
124
|
-
values = res["data"]["listSum"].map { |s| s && s["nullableNestedSum"]["value"] }
|
125
|
-
assert_equal [nil, 56, 56, 56], values
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
it "propagates nulls to the root" do
|
130
|
-
res = run_query %|
|
131
|
-
{
|
132
|
-
nestedSum(value: 1) {
|
133
|
-
value
|
134
|
-
nestedSum(value: 2) {
|
135
|
-
nestedSum(value: 13) {
|
136
|
-
value
|
137
|
-
}
|
138
|
-
}
|
139
|
-
}
|
140
|
-
}|
|
141
|
-
|
142
|
-
assert_equal(nil, res["data"])
|
143
|
-
assert_equal 1, res["errors"].length
|
144
|
-
end
|
145
|
-
|
146
|
-
it "propagates partial nulls" do
|
147
|
-
res = run_query %|
|
148
|
-
{
|
149
|
-
nullableNestedSum(value: 1) {
|
150
|
-
value
|
151
|
-
nullableNestedSum(value: 2) {
|
152
|
-
ns: nestedSum(value: 13) {
|
153
|
-
value
|
154
|
-
}
|
155
|
-
}
|
156
|
-
}
|
157
|
-
}|
|
158
|
-
|
159
|
-
expected_data = {
|
160
|
-
"nullableNestedSum" => {
|
161
|
-
"value" => 1,
|
162
|
-
"nullableNestedSum" => nil,
|
163
|
-
}
|
164
|
-
}
|
165
|
-
assert_equal(expected_data, res["data"])
|
166
|
-
assert_equal 1, res["errors"].length
|
167
|
-
end
|
168
|
-
|
169
|
-
it "handles raised errors" do
|
170
|
-
res = run_query %|
|
171
|
-
{
|
172
|
-
a: nullableNestedSum(value: 1) { value }
|
173
|
-
b: nullableNestedSum(value: 13) { value }
|
174
|
-
c: nullableNestedSum(value: 2) { value }
|
175
|
-
}|
|
176
|
-
|
177
|
-
expected_data = {
|
178
|
-
"a" => { "value" => 3 },
|
179
|
-
"b" => nil,
|
180
|
-
"c" => { "value" => 3 },
|
181
|
-
}
|
182
|
-
assert_equal expected_data, res["data"]
|
183
|
-
|
184
|
-
expected_errors = [{
|
185
|
-
"message"=>"13 is unlucky",
|
186
|
-
"locations"=>[{"line"=>4, "column"=>9}],
|
187
|
-
"path"=>["b"],
|
188
|
-
}]
|
189
|
-
assert_equal expected_errors, res["errors"]
|
190
|
-
end
|
191
|
-
|
192
|
-
it "resolves mutation fields right away" do
|
193
|
-
res = run_query %|
|
194
|
-
{
|
195
|
-
a: nestedSum(value: 2) { value }
|
196
|
-
b: nestedSum(value: 4) { value }
|
197
|
-
c: nestedSum(value: 6) { value }
|
198
|
-
}|
|
199
|
-
|
200
|
-
assert_equal [12, 12, 12], res["data"].values.map { |d| d["value"] }
|
201
|
-
|
202
|
-
res = run_query %|
|
203
|
-
mutation {
|
204
|
-
a: nestedSum(value: 2) { value }
|
205
|
-
b: nestedSum(value: 4) { value }
|
206
|
-
c: nestedSum(value: 6) { value }
|
207
|
-
}
|
208
|
-
|
|
209
|
-
|
210
|
-
assert_equal [2, 4, 6], res["data"].values.map { |d| d["value"] }
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
describe "Schema#sync_lazy(object)" do
|
215
|
-
it "Passes objects to that hook at runtime" do
|
216
|
-
res = run_query <<-GRAPHQL
|
217
|
-
{
|
218
|
-
a: nullableNestedSum(value: 1001) { value }
|
219
|
-
b: nullableNestedSum(value: 1013) { value }
|
220
|
-
c: nullableNestedSum(value: 1002) { value }
|
221
|
-
}
|
222
|
-
GRAPHQL
|
223
|
-
|
224
|
-
# This odd, non-adding behavior is hacked into `#sync_lazy`
|
225
|
-
assert_equal 101, res["data"]["a"]["value"]
|
226
|
-
assert_equal 113, res["data"]["b"]["value"]
|
227
|
-
assert_equal 102, res["data"]["c"]["value"]
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
describe "LazyMethodMap" do
|
232
|
-
class SubWrapper < LazyHelpers::Wrapper; end
|
233
|
-
|
234
|
-
let(:map) { GraphQL::Execution::Lazy::LazyMethodMap.new }
|
235
|
-
|
236
|
-
it "finds methods for classes and subclasses" do
|
237
|
-
map.set(LazyHelpers::Wrapper, :item)
|
238
|
-
map.set(LazyHelpers::SumAll, :value)
|
239
|
-
b = LazyHelpers::Wrapper.new(1)
|
240
|
-
sub_b = LazyHelpers::Wrapper.new(2)
|
241
|
-
s = LazyHelpers::SumAll.new(3)
|
242
|
-
assert_equal(:item, map.get(b))
|
243
|
-
assert_equal(:item, map.get(sub_b))
|
244
|
-
assert_equal(:value, map.get(s))
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
@@ -1,390 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe GraphQL::Execution::Lookahead do
|
5
|
-
module LookaheadTest
|
6
|
-
DATA = [
|
7
|
-
OpenStruct.new(name: "Cardinal", is_waterfowl: false, similar_species_names: ["Scarlet Tanager"], genus: OpenStruct.new(latin_name: "Piranga")),
|
8
|
-
OpenStruct.new(name: "Scarlet Tanager", is_waterfowl: false, similar_species_names: ["Cardinal"], genus: OpenStruct.new(latin_name: "Cardinalis")),
|
9
|
-
OpenStruct.new(name: "Great Egret", is_waterfowl: false, similar_species_names: ["Great Blue Heron"], genus: OpenStruct.new(latin_name: "Ardea")),
|
10
|
-
OpenStruct.new(name: "Great Blue Heron", is_waterfowl: true, similar_species_names: ["Great Egret"], genus: OpenStruct.new(latin_name: "Ardea")),
|
11
|
-
]
|
12
|
-
|
13
|
-
def DATA.find_by_name(name)
|
14
|
-
DATA.find { |b| b.name == name }
|
15
|
-
end
|
16
|
-
|
17
|
-
module Node
|
18
|
-
include GraphQL::Schema::Interface
|
19
|
-
field :id, ID, null: false
|
20
|
-
end
|
21
|
-
|
22
|
-
class BirdGenus < GraphQL::Schema::Object
|
23
|
-
field :name, String, null: false
|
24
|
-
field :latin_name, String, null: false
|
25
|
-
field :id, ID, null: false, method: :latin_name
|
26
|
-
end
|
27
|
-
|
28
|
-
class BirdSpecies < GraphQL::Schema::Object
|
29
|
-
field :name, String, null: false
|
30
|
-
field :id, ID, null: false, method: :name
|
31
|
-
field :is_waterfowl, Boolean, null: false
|
32
|
-
field :similar_species, [BirdSpecies], null: false
|
33
|
-
|
34
|
-
def similar_species
|
35
|
-
object.similar_species_names.map { |n| DATA.find_by_name(n) }
|
36
|
-
end
|
37
|
-
|
38
|
-
field :genus, BirdGenus, null: false,
|
39
|
-
extras: [:lookahead]
|
40
|
-
|
41
|
-
def genus(lookahead:)
|
42
|
-
if lookahead.selects?(:latin_name)
|
43
|
-
context[:lookahead_latin_name] += 1
|
44
|
-
end
|
45
|
-
object.genus
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class Query < GraphQL::Schema::Object
|
50
|
-
field :find_bird_species, BirdSpecies, null: true do
|
51
|
-
argument :by_name, String, required: true
|
52
|
-
end
|
53
|
-
|
54
|
-
def find_bird_species(by_name:)
|
55
|
-
DATA.find_by_name(by_name)
|
56
|
-
end
|
57
|
-
|
58
|
-
field :node, Node, null: true do
|
59
|
-
argument :id, ID, required: true
|
60
|
-
end
|
61
|
-
|
62
|
-
def node(id:)
|
63
|
-
if (node = DATA.find_by_name(id))
|
64
|
-
node
|
65
|
-
else
|
66
|
-
DATA.map { |d| d.genus }.select { |g| g.name == id }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class LookaheadInstrumenter
|
72
|
-
def self.before_query(query)
|
73
|
-
query.context[:root_lookahead_selections] = query.lookahead.selections
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.after_query(q)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class Schema < GraphQL::Schema
|
81
|
-
query(Query)
|
82
|
-
instrument :query, LookaheadInstrumenter
|
83
|
-
if TESTING_INTERPRETER
|
84
|
-
use GraphQL::Execution::Interpreter
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "looking ahead" do
|
90
|
-
let(:document) {
|
91
|
-
GraphQL.parse <<-GRAPHQL
|
92
|
-
query($name: String!){
|
93
|
-
findBirdSpecies(byName: $name) {
|
94
|
-
name
|
95
|
-
similarSpecies {
|
96
|
-
likesWater: isWaterfowl
|
97
|
-
}
|
98
|
-
}
|
99
|
-
t: __typename
|
100
|
-
}
|
101
|
-
GRAPHQL
|
102
|
-
}
|
103
|
-
let(:query) {
|
104
|
-
GraphQL::Query.new(LookaheadTest::Schema, document: document, variables: { name: "Cardinal" })
|
105
|
-
}
|
106
|
-
|
107
|
-
it "has a good test setup" do
|
108
|
-
res = query.result
|
109
|
-
assert_equal [false], res["data"]["findBirdSpecies"]["similarSpecies"].map { |s| s["likesWater"] }
|
110
|
-
end
|
111
|
-
|
112
|
-
it "can detect fields on objects with symbol or string" do
|
113
|
-
lookahead = query.lookahead.selection("findBirdSpecies")
|
114
|
-
assert_equal true, lookahead.selects?("similarSpecies")
|
115
|
-
assert_equal true, lookahead.selects?(:similar_species)
|
116
|
-
assert_equal false, lookahead.selects?("isWaterfowl")
|
117
|
-
assert_equal false, lookahead.selects?(:is_waterfowl)
|
118
|
-
end
|
119
|
-
|
120
|
-
it "detects by name, not by alias" do
|
121
|
-
assert_equal true, query.lookahead.selects?("__typename")
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "fields on interfaces" do
|
125
|
-
let(:document) {
|
126
|
-
GraphQL.parse <<-GRAPHQL
|
127
|
-
query {
|
128
|
-
node(id: "Cardinal") {
|
129
|
-
id
|
130
|
-
... on BirdSpecies {
|
131
|
-
name
|
132
|
-
}
|
133
|
-
...Other
|
134
|
-
}
|
135
|
-
}
|
136
|
-
fragment Other on BirdGenus {
|
137
|
-
latinName
|
138
|
-
}
|
139
|
-
GRAPHQL
|
140
|
-
}
|
141
|
-
|
142
|
-
it "finds fields on object types and interface types" do
|
143
|
-
node_lookahead = query.lookahead.selection("node")
|
144
|
-
assert_equal [:id, :name, :latin_name], node_lookahead.selections.map(&:name)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "inspect" do
|
149
|
-
it "works for root lookaheads" do
|
150
|
-
assert_includes query.lookahead.inspect, "#<GraphQL::Execution::Lookahead @root_type="
|
151
|
-
end
|
152
|
-
|
153
|
-
it "works for field lookaheads" do
|
154
|
-
assert_includes query.lookahead.selection(:find_bird_species).inspect, "#<GraphQL::Execution::Lookahead @field="
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe "constraints by arguments" do
|
159
|
-
let(:lookahead) do
|
160
|
-
query.lookahead
|
161
|
-
end
|
162
|
-
|
163
|
-
it "is true without constraints" do
|
164
|
-
assert_equal true, lookahead.selects?("findBirdSpecies")
|
165
|
-
end
|
166
|
-
|
167
|
-
it "is true when all given constraints are satisfied" do
|
168
|
-
assert_equal true, lookahead.selects?(:find_bird_species, arguments: { by_name: "Cardinal" })
|
169
|
-
assert_equal true, lookahead.selects?("findBirdSpecies", arguments: { "byName" => "Cardinal" })
|
170
|
-
end
|
171
|
-
|
172
|
-
it "is true when no constraints are given" do
|
173
|
-
assert_equal true, lookahead.selects?(:find_bird_species, arguments: {})
|
174
|
-
assert_equal true, lookahead.selects?("__typename", arguments: {})
|
175
|
-
end
|
176
|
-
|
177
|
-
it "is false when some given constraints aren't satisfied" do
|
178
|
-
assert_equal false, lookahead.selects?(:find_bird_species, arguments: { by_name: "Chickadee" })
|
179
|
-
assert_equal false, lookahead.selects?(:find_bird_species, arguments: { by_name: "Cardinal", other: "Nonsense" })
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "with literal values" do
|
183
|
-
let(:document) {
|
184
|
-
GraphQL.parse <<-GRAPHQL
|
185
|
-
{
|
186
|
-
findBirdSpecies(byName: "Great Blue Heron") {
|
187
|
-
isWaterfowl
|
188
|
-
}
|
189
|
-
}
|
190
|
-
GRAPHQL
|
191
|
-
}
|
192
|
-
|
193
|
-
it "works" do
|
194
|
-
assert_equal true, lookahead.selects?(:find_bird_species, arguments: { by_name: "Great Blue Heron" })
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
it "can do a chained lookahead" do
|
200
|
-
next_lookahead = query.lookahead.selection(:find_bird_species, arguments: { by_name: "Cardinal" })
|
201
|
-
assert_equal true, next_lookahead.selected?
|
202
|
-
nested_selection = next_lookahead.selection(:similar_species).selection(:is_waterfowl, arguments: {})
|
203
|
-
assert_equal true, nested_selection.selected?
|
204
|
-
assert_equal false, next_lookahead.selection(:similar_species).selection(:name).selected?
|
205
|
-
end
|
206
|
-
|
207
|
-
it "can detect fields on lists with symbol or string" do
|
208
|
-
assert_equal true, query.lookahead.selection(:find_bird_species).selection(:similar_species).selection(:is_waterfowl).selected?
|
209
|
-
assert_equal true, query.lookahead.selection("findBirdSpecies").selection("similarSpecies").selection("isWaterfowl").selected?
|
210
|
-
end
|
211
|
-
|
212
|
-
describe "merging branches and fragments" do
|
213
|
-
let(:document) {
|
214
|
-
GraphQL.parse <<-GRAPHQL
|
215
|
-
{
|
216
|
-
findBirdSpecies(name: "Cardinal") {
|
217
|
-
similarSpecies {
|
218
|
-
__typename
|
219
|
-
}
|
220
|
-
}
|
221
|
-
...F
|
222
|
-
... {
|
223
|
-
findBirdSpecies(name: "Cardinal") {
|
224
|
-
similarSpecies {
|
225
|
-
isWaterfowl
|
226
|
-
}
|
227
|
-
}
|
228
|
-
}
|
229
|
-
}
|
230
|
-
|
231
|
-
fragment F on Query {
|
232
|
-
findBirdSpecies(name: "Cardinal") {
|
233
|
-
similarSpecies {
|
234
|
-
name
|
235
|
-
}
|
236
|
-
}
|
237
|
-
}
|
238
|
-
GRAPHQL
|
239
|
-
}
|
240
|
-
|
241
|
-
it "finds selections using merging" do
|
242
|
-
merged_lookahead = query.lookahead.selection(:find_bird_species).selection(:similar_species)
|
243
|
-
assert merged_lookahead.selects?(:__typename)
|
244
|
-
assert merged_lookahead.selects?(:is_waterfowl)
|
245
|
-
assert merged_lookahead.selects?(:name)
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
describe "in queries" do
|
251
|
-
it "can be an extra" do
|
252
|
-
query_str = <<-GRAPHQL
|
253
|
-
{
|
254
|
-
cardinal: findBirdSpecies(byName: "Cardinal") {
|
255
|
-
genus { __typename }
|
256
|
-
}
|
257
|
-
scarletTanager: findBirdSpecies(byName: "Scarlet Tanager") {
|
258
|
-
genus { latinName }
|
259
|
-
}
|
260
|
-
greatBlueHeron: findBirdSpecies(byName: "Great Blue Heron") {
|
261
|
-
genus { latinName }
|
262
|
-
}
|
263
|
-
}
|
264
|
-
GRAPHQL
|
265
|
-
context = {lookahead_latin_name: 0}
|
266
|
-
res = LookaheadTest::Schema.execute(query_str, context: context)
|
267
|
-
refute res.key?("errors")
|
268
|
-
assert_equal 2, context[:lookahead_latin_name]
|
269
|
-
assert_equal [:find_bird_species], context[:root_lookahead_selections].map(&:name).uniq
|
270
|
-
assert_equal(
|
271
|
-
[{ by_name: "Cardinal" }, { by_name: "Scarlet Tanager" }, { by_name: "Great Blue Heron" }],
|
272
|
-
context[:root_lookahead_selections].map(&:arguments)
|
273
|
-
)
|
274
|
-
end
|
275
|
-
|
276
|
-
it "works for invalid queries" do
|
277
|
-
context = {lookahead_latin_name: 0}
|
278
|
-
res = LookaheadTest::Schema.execute("{ doesNotExist }", context: context)
|
279
|
-
assert res.key?("errors")
|
280
|
-
assert_equal 0, context[:lookahead_latin_name]
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
describe '#selections' do
|
285
|
-
let(:document) {
|
286
|
-
GraphQL.parse <<-GRAPHQL
|
287
|
-
query {
|
288
|
-
findBirdSpecies(byName: "Laughing Gull") {
|
289
|
-
name
|
290
|
-
similarSpecies {
|
291
|
-
likesWater: isWaterfowl
|
292
|
-
}
|
293
|
-
}
|
294
|
-
}
|
295
|
-
GRAPHQL
|
296
|
-
}
|
297
|
-
|
298
|
-
def query(doc = document)
|
299
|
-
GraphQL::Query.new(LookaheadTest::Schema, document: doc)
|
300
|
-
end
|
301
|
-
|
302
|
-
it "provides a list of all selections" do
|
303
|
-
ast_node = document.definitions.first.selections.first
|
304
|
-
field = LookaheadTest::Query.fields["findBirdSpecies"]
|
305
|
-
lookahead = GraphQL::Execution::Lookahead.new(query: query, ast_nodes: [ast_node], field: field)
|
306
|
-
assert_equal [:name, :similar_species], lookahead.selections.map(&:name)
|
307
|
-
end
|
308
|
-
|
309
|
-
it "filters outs selections which do not match arguments" do
|
310
|
-
ast_node = document.definitions.first
|
311
|
-
lookahead = GraphQL::Execution::Lookahead.new(query: query, ast_nodes: [ast_node], root_type: LookaheadTest::Query)
|
312
|
-
arguments = { by_name: "Cardinal" }
|
313
|
-
|
314
|
-
assert_equal lookahead.selections(arguments: arguments).map(&:name), []
|
315
|
-
end
|
316
|
-
|
317
|
-
it "includes selections which match arguments" do
|
318
|
-
ast_node = document.definitions.first
|
319
|
-
lookahead = GraphQL::Execution::Lookahead.new(query: query, ast_nodes: [ast_node], root_type: LookaheadTest::Query)
|
320
|
-
arguments = { by_name: "Laughing Gull" }
|
321
|
-
|
322
|
-
assert_equal lookahead.selections(arguments: arguments).map(&:name), [:find_bird_species]
|
323
|
-
end
|
324
|
-
|
325
|
-
it 'handles duplicate selections across fragments' do
|
326
|
-
doc = GraphQL.parse <<-GRAPHQL
|
327
|
-
query {
|
328
|
-
... on Query {
|
329
|
-
...MoreFields
|
330
|
-
}
|
331
|
-
}
|
332
|
-
|
333
|
-
fragment MoreFields on Query {
|
334
|
-
findBirdSpecies(byName: "Laughing Gull") {
|
335
|
-
name
|
336
|
-
}
|
337
|
-
findBirdSpecies(byName: "Laughing Gull") {
|
338
|
-
...EvenMoreFields
|
339
|
-
}
|
340
|
-
}
|
341
|
-
|
342
|
-
fragment EvenMoreFields on BirdSpecies {
|
343
|
-
similarSpecies {
|
344
|
-
likesWater: isWaterfowl
|
345
|
-
}
|
346
|
-
}
|
347
|
-
GRAPHQL
|
348
|
-
|
349
|
-
lookahead = query(doc).lookahead
|
350
|
-
|
351
|
-
root_selections = lookahead.selections
|
352
|
-
assert_equal [:find_bird_species], root_selections.map(&:name), "Selections are merged"
|
353
|
-
assert_equal 2, root_selections.first.ast_nodes.size, "It represents both nodes"
|
354
|
-
|
355
|
-
assert_equal [:name, :similar_species], root_selections.first.selections.map(&:name), "Subselections are merged"
|
356
|
-
end
|
357
|
-
|
358
|
-
it "avoids merging selections for same field name on distinct types" do
|
359
|
-
query = GraphQL::Query.new(LookaheadTest::Schema, <<-GRAPHQL)
|
360
|
-
query {
|
361
|
-
node(id: "Cardinal") {
|
362
|
-
... on BirdSpecies {
|
363
|
-
name
|
364
|
-
}
|
365
|
-
... on BirdGenus {
|
366
|
-
name
|
367
|
-
}
|
368
|
-
id
|
369
|
-
}
|
370
|
-
}
|
371
|
-
GRAPHQL
|
372
|
-
|
373
|
-
node_lookahead = query.lookahead.selection("node")
|
374
|
-
assert_equal(
|
375
|
-
[[LookaheadTest::Node, :id], [LookaheadTest::BirdSpecies, :name], [LookaheadTest::BirdGenus, :name]],
|
376
|
-
node_lookahead.selections.map { |s| [s.owner_type, s.name] }
|
377
|
-
)
|
378
|
-
end
|
379
|
-
|
380
|
-
it "works for missing selections" do
|
381
|
-
ast_node = document.definitions.first.selections.first
|
382
|
-
field = LookaheadTest::Query.fields["findBirdSpecies"]
|
383
|
-
lookahead = GraphQL::Execution::Lookahead.new(query: query, ast_nodes: [ast_node], field: field)
|
384
|
-
null_lookahead = lookahead.selection(:genus)
|
385
|
-
# This is an implementation detail, but I want to make sure the test is set up right
|
386
|
-
assert_instance_of GraphQL::Execution::Lookahead::NullLookahead, null_lookahead
|
387
|
-
assert_equal [], null_lookahead.selections
|
388
|
-
end
|
389
|
-
end
|
390
|
-
end
|