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,91 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe GraphQL::Query::LiteralInput do
|
5
|
-
describe ".from_arguments" do
|
6
|
-
describe "arguments are prepared" do
|
7
|
-
let(:schema) {
|
8
|
-
type = GraphQL::ObjectType.define do
|
9
|
-
name "SomeType"
|
10
|
-
|
11
|
-
field :addToArgumentValue do
|
12
|
-
type !types.Int
|
13
|
-
argument :value do
|
14
|
-
type types.Int
|
15
|
-
default_value 3
|
16
|
-
prepare ->(arg, ctx) do
|
17
|
-
return GraphQL::ExecutionError.new("Can't return more than 3 digits") if arg > 998
|
18
|
-
arg + ctx[:val]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
resolve ->(t, a, c) { a[:value] }
|
22
|
-
end
|
23
|
-
|
24
|
-
field :fieldWithArgumentThatIsBadByDefault do
|
25
|
-
type types.Int
|
26
|
-
argument :value do
|
27
|
-
type types.Int
|
28
|
-
default_value 7
|
29
|
-
prepare ->(arg, ctx) do
|
30
|
-
GraphQL::ExecutionError.new("Always bad")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
resolve ->(*args) { 42 }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
query = GraphQL::ObjectType.define do
|
39
|
-
name "Query"
|
40
|
-
|
41
|
-
field :top, type, resolve: ->(_, _, _) { true }
|
42
|
-
end
|
43
|
-
|
44
|
-
GraphQL::Schema.define(query: query)
|
45
|
-
}
|
46
|
-
|
47
|
-
it "prepares values from query literals" do
|
48
|
-
result = schema.execute("{ top { addToArgumentValue(value: 1) } }", context: { val: 1 })
|
49
|
-
assert_equal(result["data"]["top"]["addToArgumentValue"], 2)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "prepares default values" do
|
53
|
-
result = schema.execute("{ top { addToArgumentValue } }", context: { val: 4 })
|
54
|
-
assert_equal(7, result["data"]["top"]["addToArgumentValue"])
|
55
|
-
end
|
56
|
-
|
57
|
-
it "raises an execution error if the default value is bad" do
|
58
|
-
result = schema.execute("{ top { fieldWithArgumentThatIsBadByDefault } }", context: { })
|
59
|
-
assert_equal(result["data"], {
|
60
|
-
"top"=>{
|
61
|
-
"fieldWithArgumentThatIsBadByDefault"=>nil}
|
62
|
-
})
|
63
|
-
assert_equal(result["errors"], [
|
64
|
-
{"message"=>"Always bad",
|
65
|
-
"locations"=>[{"line"=>1, "column"=>9}],
|
66
|
-
"path"=>["top", "fieldWithArgumentThatIsBadByDefault"]}
|
67
|
-
])
|
68
|
-
end
|
69
|
-
|
70
|
-
it "prepares values from variables" do
|
71
|
-
result = schema.execute("query ($value: Int!) { top { addToArgumentValue(value: $value) } }", variables: { "value" => 1}, context: { val: 2 } )
|
72
|
-
assert_equal(result["data"]["top"]["addToArgumentValue"], 3)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "prepares values correctly if called multiple times with different arguments" do
|
76
|
-
result = schema.execute("{ top { first: addToArgumentValue(value: 1) second: addToArgumentValue(value: 2) } }", context: { val: 3 })
|
77
|
-
assert_equal(result["data"]["top"]["first"], 4)
|
78
|
-
assert_equal(result["data"]["top"]["second"], 5)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "adds message to errors key if an ExecutionError is returned from the prepare function" do
|
82
|
-
result = schema.execute("{ top { addToArgumentValue(value: 999) } }")
|
83
|
-
assert_equal(result["data"]["top"], nil)
|
84
|
-
assert_equal(result["errors"][0]["message"], "Can't return more than 3 digits")
|
85
|
-
assert_equal(result["errors"][0]["locations"][0]["line"], 1)
|
86
|
-
assert_equal(result["errors"][0]["locations"][0]["column"], 28)
|
87
|
-
assert_equal(result["errors"][0]["path"], ["top", "addToArgumentValue"])
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe GraphQL::Query::Result do
|
5
|
-
let(:query_string) { '{ __type(name: "Cheese") { name } }' }
|
6
|
-
let(:schema) { Dummy::Schema }
|
7
|
-
let(:result) { schema.execute(query_string, context: { a: :b }) }
|
8
|
-
|
9
|
-
it "exposes hash-like methods" do
|
10
|
-
assert_equal "Cheese", result["data"]["__type"]["name"]
|
11
|
-
refute result.key?("errors")
|
12
|
-
assert_equal ["data"], result.keys
|
13
|
-
end
|
14
|
-
|
15
|
-
it "is equal with hashes" do
|
16
|
-
hash_result = {"data" => { "__type" => { "name" => "Cheese" } } }
|
17
|
-
assert_equal hash_result, result
|
18
|
-
end
|
19
|
-
|
20
|
-
it "tells the kind of operation" do
|
21
|
-
assert result.query?
|
22
|
-
refute result.mutation?
|
23
|
-
end
|
24
|
-
|
25
|
-
it "exposes the context" do
|
26
|
-
assert_instance_of GraphQL::Query::Context, result.context
|
27
|
-
assert_equal({a: :b}, result.context.to_h)
|
28
|
-
end
|
29
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe GraphQL::Query::SerialExecution::ValueResolution do
|
5
|
-
let(:schema) {
|
6
|
-
day_of_week_enum = GraphQL::EnumType.define do
|
7
|
-
name "DayOfWeek"
|
8
|
-
value("MONDAY", value: 0)
|
9
|
-
value("TUESDAY", value: 1)
|
10
|
-
value("WEDNESDAY", value: 2)
|
11
|
-
value("THURSDAY", value: 3)
|
12
|
-
value("FRIDAY", value: 4)
|
13
|
-
value("SATURDAY", value: 5)
|
14
|
-
value("SUNDAY", value: 6)
|
15
|
-
end
|
16
|
-
|
17
|
-
interface = GraphQL::InterfaceType.define do
|
18
|
-
name "SomeInterface"
|
19
|
-
field :someField, !types.Int
|
20
|
-
end
|
21
|
-
|
22
|
-
some_object = GraphQL::ObjectType.define do
|
23
|
-
name "SomeObject"
|
24
|
-
interfaces [interface]
|
25
|
-
end
|
26
|
-
|
27
|
-
other_object = GraphQL::ObjectType.define do
|
28
|
-
name "OtherObject"
|
29
|
-
end
|
30
|
-
|
31
|
-
query_root = GraphQL::ObjectType.define do
|
32
|
-
name "Query"
|
33
|
-
field :tomorrow, day_of_week_enum do
|
34
|
-
argument :today, day_of_week_enum
|
35
|
-
resolve ->(obj, args, ctx) { (args["today"] + 1) % 7 }
|
36
|
-
end
|
37
|
-
field :resolvesToNilInterface, interface do
|
38
|
-
resolve ->(obj, args, ctx) { 1337 }
|
39
|
-
end
|
40
|
-
field :resolvesToWrongTypeInterface, interface do
|
41
|
-
resolve ->(obj, args, ctx) { :something }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
GraphQL::Schema.define do
|
46
|
-
query(query_root)
|
47
|
-
orphan_types [some_object]
|
48
|
-
resolve_type ->(type, obj, ctx) do
|
49
|
-
if obj.is_a?(Symbol)
|
50
|
-
other_object
|
51
|
-
else
|
52
|
-
nil
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
}
|
57
|
-
|
58
|
-
let(:result) { schema.execute(
|
59
|
-
query_string,
|
60
|
-
)}
|
61
|
-
|
62
|
-
describe "enum resolution" do
|
63
|
-
let(:query_string) { %|
|
64
|
-
{
|
65
|
-
tomorrow(today: FRIDAY)
|
66
|
-
}
|
67
|
-
|}
|
68
|
-
|
69
|
-
it "coerces enum input to the value and result to the name" do
|
70
|
-
expected = {
|
71
|
-
"data" => {
|
72
|
-
"tomorrow" => "SATURDAY"
|
73
|
-
}
|
74
|
-
}
|
75
|
-
assert_equal(expected, result)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "interface type resolution" do
|
80
|
-
describe "when type can't be resolved" do
|
81
|
-
let(:query_string) { %|
|
82
|
-
{
|
83
|
-
resolvesToNilInterface { someField }
|
84
|
-
}
|
85
|
-
|}
|
86
|
-
|
87
|
-
it "raises an error" do
|
88
|
-
err = assert_raises(GraphQL::UnresolvedTypeError) { result }
|
89
|
-
expected_message = "The value from \"resolvesToNilInterface\" on \"Query\" could not be resolved to \"SomeInterface\". (Received: `nil`, Expected: [SomeObject]) Make sure you have defined a `resolve_type` proc on your schema and that value `1337` gets resolved to a valid type. You may need to add your type to `orphan_types` if it implements an interface but isn't a return type of any other field."
|
90
|
-
assert_equal expected_message, err.message
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "when type resolves but is not a possible type of an interface" do
|
95
|
-
let(:query_string) { %|
|
96
|
-
{
|
97
|
-
resolvesToWrongTypeInterface { someField }
|
98
|
-
}
|
99
|
-
|}
|
100
|
-
|
101
|
-
it "raises an error" do
|
102
|
-
err = assert_raises(GraphQL::UnresolvedTypeError) { result }
|
103
|
-
expected_message = "The value from \"resolvesToWrongTypeInterface\" on \"Query\" could not be resolved to \"SomeInterface\". (Received: `OtherObject`, Expected: [SomeObject]) Make sure you have defined a `resolve_type` proc on your schema and that value `:something` gets resolved to a valid type. You may need to add your type to `orphan_types` if it implements an interface but isn't a return type of any other field."
|
104
|
-
assert_equal expected_message, err.message
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
end
|
data/spec/graphql/query_spec.rb
DELETED
@@ -1,803 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe GraphQL::Query do
|
5
|
-
let(:query_string) { %|
|
6
|
-
query getFlavor($cheeseId: Int!) {
|
7
|
-
brie: cheese(id: 1) { ...cheeseFields, taste: flavor },
|
8
|
-
cheese(id: $cheeseId) {
|
9
|
-
__typename,
|
10
|
-
id,
|
11
|
-
...cheeseFields,
|
12
|
-
... edibleFields,
|
13
|
-
... on Cheese { cheeseKind: flavor },
|
14
|
-
}
|
15
|
-
fromSource(source: COW) { id }
|
16
|
-
fromSheep: fromSource(source: SHEEP) { id }
|
17
|
-
firstSheep: searchDairy(product: [{source: SHEEP}]) {
|
18
|
-
__typename,
|
19
|
-
... dairyFields,
|
20
|
-
... milkFields
|
21
|
-
}
|
22
|
-
favoriteEdible { __typename, fatContent }
|
23
|
-
}
|
24
|
-
fragment cheeseFields on Cheese { flavor }
|
25
|
-
fragment edibleFields on Edible { fatContent }
|
26
|
-
fragment milkFields on Milk { source }
|
27
|
-
fragment dairyFields on AnimalProduct {
|
28
|
-
... on Cheese { flavor }
|
29
|
-
... on Milk { source }
|
30
|
-
}
|
31
|
-
|}
|
32
|
-
let(:operation_name) { nil }
|
33
|
-
let(:query_variables) { {"cheeseId" => 2} }
|
34
|
-
let(:schema) { Dummy::Schema }
|
35
|
-
let(:document) { GraphQL.parse(query_string) }
|
36
|
-
|
37
|
-
let(:query) { GraphQL::Query.new(
|
38
|
-
schema,
|
39
|
-
query_string,
|
40
|
-
variables: query_variables,
|
41
|
-
operation_name: operation_name
|
42
|
-
)}
|
43
|
-
let(:result) { query.result }
|
44
|
-
|
45
|
-
describe "when passed both a query string and a document" do
|
46
|
-
it "returns an error to the client when query kwarg is used" do
|
47
|
-
assert_raises ArgumentError do
|
48
|
-
GraphQL::Query.new(
|
49
|
-
schema,
|
50
|
-
query: "{ fromSource(source: COW) { id } }",
|
51
|
-
document: document
|
52
|
-
)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
it "returns an error to the client" do
|
57
|
-
assert_raises ArgumentError do
|
58
|
-
GraphQL::Query.new(
|
59
|
-
schema,
|
60
|
-
"{ fromSource(source: COW) { id } }",
|
61
|
-
document: document
|
62
|
-
)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "when passed no query string or document" do
|
68
|
-
it 'returns an error to the client' do
|
69
|
-
res = GraphQL::Query.new(
|
70
|
-
schema,
|
71
|
-
variables: query_variables,
|
72
|
-
operation_name: operation_name
|
73
|
-
).result
|
74
|
-
assert_equal 1, res["errors"].length
|
75
|
-
assert_equal "No query string was present", res["errors"][0]["message"]
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'can be assigned later' do
|
79
|
-
query = GraphQL::Query.new(
|
80
|
-
schema,
|
81
|
-
variables: query_variables,
|
82
|
-
operation_name: operation_name
|
83
|
-
)
|
84
|
-
query.query_string = '{ __type(name: """Cheese""") { name } }'
|
85
|
-
assert_equal "Cheese", query.result["data"] ["__type"]["name"]
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "#operation_name" do
|
90
|
-
describe "when provided" do
|
91
|
-
let(:query_string) { <<-GRAPHQL
|
92
|
-
query q1 { cheese(id: 1) { flavor } }
|
93
|
-
query q2 { cheese(id: 2) { flavor } }
|
94
|
-
GRAPHQL
|
95
|
-
}
|
96
|
-
let(:operation_name) { "q2" }
|
97
|
-
|
98
|
-
it "returns the provided name" do
|
99
|
-
assert_equal "q2", query.operation_name
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe "when inferred" do
|
104
|
-
let(:query_string) { <<-GRAPHQL
|
105
|
-
query q3 { cheese(id: 3) { flavor } }
|
106
|
-
GRAPHQL
|
107
|
-
}
|
108
|
-
|
109
|
-
it "returns nil" do
|
110
|
-
assert_nil query.operation_name
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe "#selected_operation_name" do
|
115
|
-
describe "when an operation isprovided" do
|
116
|
-
let(:query_string) { <<-GRAPHQL
|
117
|
-
query q1 { cheese(id: 1) { flavor } }
|
118
|
-
query q2 { cheese(id: 2) { flavor } }
|
119
|
-
GRAPHQL
|
120
|
-
}
|
121
|
-
let(:operation_name) { "q2" }
|
122
|
-
|
123
|
-
it "returns the provided name" do
|
124
|
-
assert_equal "q2", query.selected_operation_name
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "when operation is inferred" do
|
129
|
-
let(:query_string) { <<-GRAPHQL
|
130
|
-
query q3 { cheese(id: 3) { flavor } }
|
131
|
-
GRAPHQL
|
132
|
-
}
|
133
|
-
|
134
|
-
it "returns the inferred operation name" do
|
135
|
-
assert_equal "q3", query.selected_operation_name
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe "when there are no operations" do
|
140
|
-
let(:query_string) { <<-GRAPHQL
|
141
|
-
# Only Comments
|
142
|
-
# In this Query
|
143
|
-
GRAPHQL
|
144
|
-
}
|
145
|
-
|
146
|
-
it "returns the inferred operation name" do
|
147
|
-
assert_nil query.selected_operation_name
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe "assigning operation_name=" do
|
153
|
-
let(:query_string) { <<-GRAPHQL
|
154
|
-
query q3 { manchego: cheese(id: 3) { flavor } }
|
155
|
-
query q2 { gouda: cheese(id: 2) { flavor } }
|
156
|
-
GRAPHQL
|
157
|
-
}
|
158
|
-
|
159
|
-
it "runs the assigned name" do
|
160
|
-
query = GraphQL::Query.new(Dummy::Schema, query_string, operation_name: "q3")
|
161
|
-
query.operation_name = "q2"
|
162
|
-
res = query.result
|
163
|
-
assert_equal "Gouda", res["data"]["gouda"]["flavor"]
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
describe "when passed a document instance" do
|
169
|
-
let(:query) { GraphQL::Query.new(
|
170
|
-
schema,
|
171
|
-
document: document,
|
172
|
-
variables: query_variables,
|
173
|
-
operation_name: operation_name
|
174
|
-
)}
|
175
|
-
|
176
|
-
it "runs the query using the already parsed document" do
|
177
|
-
expected = {"data"=> {
|
178
|
-
"brie" => { "flavor" => "Brie", "taste" => "Brie" },
|
179
|
-
"cheese" => {
|
180
|
-
"__typename" => "Cheese",
|
181
|
-
"id" => 2,
|
182
|
-
"flavor" => "Gouda",
|
183
|
-
"fatContent" => 0.3,
|
184
|
-
"cheeseKind" => "Gouda",
|
185
|
-
},
|
186
|
-
"fromSource" => [{ "id" => 1 }, {"id" => 2}],
|
187
|
-
"fromSheep"=>[{"id"=>3}],
|
188
|
-
"firstSheep" => { "__typename" => "Cheese", "flavor" => "Manchego" },
|
189
|
-
"favoriteEdible"=>{"__typename"=>"Milk", "fatContent"=>0.04},
|
190
|
-
}}
|
191
|
-
assert_equal(expected, result)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe '#result' do
|
196
|
-
it "returns fields on objects" do
|
197
|
-
expected = {"data"=> {
|
198
|
-
"brie" => { "flavor" => "Brie", "taste" => "Brie" },
|
199
|
-
"cheese" => {
|
200
|
-
"__typename" => "Cheese",
|
201
|
-
"id" => 2,
|
202
|
-
"flavor" => "Gouda",
|
203
|
-
"fatContent" => 0.3,
|
204
|
-
"cheeseKind" => "Gouda",
|
205
|
-
},
|
206
|
-
"fromSource" => [{ "id" => 1 }, {"id" => 2}],
|
207
|
-
"fromSheep"=>[{"id"=>3}],
|
208
|
-
"firstSheep" => { "__typename" => "Cheese", "flavor" => "Manchego" },
|
209
|
-
"favoriteEdible"=>{"__typename"=>"Milk", "fatContent"=>0.04},
|
210
|
-
}}
|
211
|
-
assert_equal(expected, result)
|
212
|
-
end
|
213
|
-
|
214
|
-
describe "when it hits null objects" do
|
215
|
-
let(:query_string) {%|
|
216
|
-
{
|
217
|
-
maybeNull {
|
218
|
-
cheese {
|
219
|
-
flavor,
|
220
|
-
similarCheese(source: [SHEEP]) { flavor }
|
221
|
-
}
|
222
|
-
}
|
223
|
-
}
|
224
|
-
|}
|
225
|
-
|
226
|
-
it "skips null objects" do
|
227
|
-
expected = {"data"=> {
|
228
|
-
"maybeNull" => { "cheese" => nil }
|
229
|
-
}}
|
230
|
-
assert_equal(expected, result)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
describe "after_query hooks" do
|
235
|
-
module Instrumenter
|
236
|
-
ERROR_LOG = []
|
237
|
-
def self.before_query(q); end;
|
238
|
-
def self.after_query(q); ERROR_LOG << q.result["errors"]; end;
|
239
|
-
end
|
240
|
-
|
241
|
-
let(:schema) {
|
242
|
-
Dummy::Schema.redefine {
|
243
|
-
instrument(:query, Instrumenter)
|
244
|
-
}
|
245
|
-
}
|
246
|
-
it "can access #result" do
|
247
|
-
result
|
248
|
-
assert_equal [nil], Instrumenter::ERROR_LOG
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
describe "when an error propagated through execution" do
|
253
|
-
module ExtensionsInstrumenter
|
254
|
-
LOG = []
|
255
|
-
def self.before_query(q); end;
|
256
|
-
|
257
|
-
def self.after_query(q)
|
258
|
-
q.result["extensions"] = { "a" => 1 }
|
259
|
-
LOG << :ok
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
let(:schema) {
|
264
|
-
Dummy::Schema.redefine {
|
265
|
-
instrument(:query, ExtensionsInstrumenter)
|
266
|
-
}
|
267
|
-
}
|
268
|
-
|
269
|
-
it "can add to extensions" do
|
270
|
-
ExtensionsInstrumenter::LOG.clear
|
271
|
-
assert_raises(RuntimeError) do
|
272
|
-
schema.execute "{ error }"
|
273
|
-
end
|
274
|
-
assert_equal [:ok], ExtensionsInstrumenter::LOG
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
it "uses root_value as the object for the root type" do
|
280
|
-
result = GraphQL::Query.new(schema, '{ root }', root_value: "I am root").result
|
281
|
-
assert_equal 'I am root', result.fetch('data').fetch('root')
|
282
|
-
end
|
283
|
-
|
284
|
-
it "exposes fragments" do
|
285
|
-
assert_equal(GraphQL::Language::Nodes::FragmentDefinition, query.fragments["cheeseFields"].class)
|
286
|
-
end
|
287
|
-
|
288
|
-
it "exposes the original string" do
|
289
|
-
assert_equal(query_string, query.query_string)
|
290
|
-
end
|
291
|
-
|
292
|
-
describe "merging fragments with different keys" do
|
293
|
-
let(:query_string) { %|
|
294
|
-
query getCheeseFieldsThroughDairy {
|
295
|
-
... cheeseFrag3
|
296
|
-
dairy {
|
297
|
-
...flavorFragment
|
298
|
-
...fatContentFragment
|
299
|
-
}
|
300
|
-
}
|
301
|
-
fragment flavorFragment on Dairy {
|
302
|
-
cheese {
|
303
|
-
flavor
|
304
|
-
}
|
305
|
-
milks {
|
306
|
-
id
|
307
|
-
}
|
308
|
-
}
|
309
|
-
fragment fatContentFragment on Dairy {
|
310
|
-
cheese {
|
311
|
-
fatContent
|
312
|
-
}
|
313
|
-
milks {
|
314
|
-
fatContent
|
315
|
-
}
|
316
|
-
}
|
317
|
-
|
318
|
-
fragment cheeseFrag1 on Query {
|
319
|
-
cheese(id: 1) {
|
320
|
-
id
|
321
|
-
}
|
322
|
-
}
|
323
|
-
fragment cheeseFrag2 on Query {
|
324
|
-
cheese(id: 1) {
|
325
|
-
flavor
|
326
|
-
}
|
327
|
-
}
|
328
|
-
fragment cheeseFrag3 on Query {
|
329
|
-
... cheeseFrag2
|
330
|
-
... cheeseFrag1
|
331
|
-
}
|
332
|
-
|}
|
333
|
-
|
334
|
-
it "should include keys from each fragment" do
|
335
|
-
expected = {"data" => {
|
336
|
-
"dairy" => {
|
337
|
-
"cheese" => {
|
338
|
-
"flavor" => "Brie",
|
339
|
-
"fatContent" => 0.19
|
340
|
-
},
|
341
|
-
"milks" => [
|
342
|
-
{
|
343
|
-
"id" => "1",
|
344
|
-
"fatContent" => 0.04,
|
345
|
-
}
|
346
|
-
],
|
347
|
-
},
|
348
|
-
"cheese" => {
|
349
|
-
"id" => 1,
|
350
|
-
"flavor" => "Brie"
|
351
|
-
},
|
352
|
-
}}
|
353
|
-
assert_equal(expected, result)
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
describe "field argument default values" do
|
358
|
-
let(:query_string) {%|
|
359
|
-
query getCheeses(
|
360
|
-
$search: [DairyProductInput]
|
361
|
-
$searchWithDefault: [DairyProductInput] = [{source: COW}]
|
362
|
-
){
|
363
|
-
noVariable: searchDairy(product: $search) {
|
364
|
-
... cheeseFields
|
365
|
-
}
|
366
|
-
noArgument: searchDairy {
|
367
|
-
... cheeseFields
|
368
|
-
}
|
369
|
-
variableDefault: searchDairy(product: $searchWithDefault) {
|
370
|
-
... cheeseFields
|
371
|
-
}
|
372
|
-
convertedDefault: fromSource {
|
373
|
-
... cheeseFields
|
374
|
-
}
|
375
|
-
}
|
376
|
-
fragment cheeseFields on Cheese { flavor }
|
377
|
-
|}
|
378
|
-
|
379
|
-
it "has a default value" do
|
380
|
-
default_source = schema.query.fields["searchDairy"].arguments["product"].default_value[0]["source"]
|
381
|
-
assert_equal("SHEEP", default_source)
|
382
|
-
end
|
383
|
-
|
384
|
-
describe "when a variable is used, but not provided" do
|
385
|
-
it "uses the default_value" do
|
386
|
-
assert_equal("Manchego", result["data"]["noVariable"]["flavor"])
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
describe "when the argument isn't passed at all" do
|
391
|
-
it "uses the default value" do
|
392
|
-
assert_equal("Manchego", result["data"]["noArgument"]["flavor"])
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
|
-
describe "when the variable has a default" do
|
397
|
-
it "uses the variable default" do
|
398
|
-
assert_equal("Brie", result["data"]["variableDefault"]["flavor"])
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
describe "when the variable has a default needing conversion" do
|
403
|
-
it "uses the converted variable default" do
|
404
|
-
assert_equal([{"flavor" => "Brie"}, {"flavor" => "Gouda"}], result["data"]["convertedDefault"])
|
405
|
-
end
|
406
|
-
end
|
407
|
-
end
|
408
|
-
|
409
|
-
describe "query variables" do
|
410
|
-
let(:query_string) {%|
|
411
|
-
query getCheese($cheeseId: Int!){
|
412
|
-
cheese(id: $cheeseId) { flavor }
|
413
|
-
}
|
414
|
-
|}
|
415
|
-
|
416
|
-
describe "when they can be coerced" do
|
417
|
-
let(:query_variables) { {"cheeseId" => 2.0} }
|
418
|
-
|
419
|
-
it "coerces them on the way in" do
|
420
|
-
assert("Gouda", result["data"]["cheese"]["flavor"])
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
describe "when they can't be coerced" do
|
425
|
-
let(:query_variables) { {"cheeseId" => "2"} }
|
426
|
-
|
427
|
-
it "raises an error" do
|
428
|
-
expected = {
|
429
|
-
"errors" => [
|
430
|
-
{
|
431
|
-
"message" => "Variable cheeseId of type Int! was provided invalid value",
|
432
|
-
"locations"=>[{ "line" => 2, "column" => 23 }],
|
433
|
-
"extensions" => {
|
434
|
-
"value" => "2",
|
435
|
-
"problems" => [{ "path" => [], "explanation" => 'Could not coerce value "2" to Int' }]
|
436
|
-
}
|
437
|
-
}
|
438
|
-
]
|
439
|
-
}
|
440
|
-
assert_equal(expected, result)
|
441
|
-
end
|
442
|
-
end
|
443
|
-
|
444
|
-
describe "when they aren't provided" do
|
445
|
-
let(:query_variables) { {} }
|
446
|
-
|
447
|
-
it "raises an error" do
|
448
|
-
expected = {
|
449
|
-
"errors" => [
|
450
|
-
{
|
451
|
-
"message" => "Variable cheeseId of type Int! was provided invalid value",
|
452
|
-
"locations" => [{"line" => 2, "column" => 23}],
|
453
|
-
"extensions" => {
|
454
|
-
"value" => nil,
|
455
|
-
"problems" => [{ "path" => [], "explanation" => "Expected value to not be null" }]
|
456
|
-
}
|
457
|
-
}
|
458
|
-
]
|
459
|
-
}
|
460
|
-
assert_equal(expected, result)
|
461
|
-
end
|
462
|
-
end
|
463
|
-
|
464
|
-
describe "when they are non-null and provided a null value" do
|
465
|
-
let(:query_variables) { { "cheeseId" => nil } }
|
466
|
-
|
467
|
-
it "raises an error" do
|
468
|
-
expected = {
|
469
|
-
"errors" => [
|
470
|
-
{
|
471
|
-
"message" => "Variable cheeseId of type Int! was provided invalid value",
|
472
|
-
"locations" => [{"line" => 2, "column" => 23}],
|
473
|
-
"extensions" => {
|
474
|
-
"value" => nil,
|
475
|
-
"problems" => [{ "path" => [], "explanation" => "Expected value to not be null" }]
|
476
|
-
}
|
477
|
-
}
|
478
|
-
]
|
479
|
-
}
|
480
|
-
assert_equal(expected, result)
|
481
|
-
end
|
482
|
-
end
|
483
|
-
|
484
|
-
describe "when they're a string" do
|
485
|
-
let(:query_variables) { '{ "var" : 1 }' }
|
486
|
-
it "raises an error" do
|
487
|
-
assert_raises(ArgumentError) { result }
|
488
|
-
end
|
489
|
-
end
|
490
|
-
|
491
|
-
describe "default values" do
|
492
|
-
let(:query_string) {%|
|
493
|
-
query getCheese($cheeseId: Int = 3){
|
494
|
-
cheese(id: $cheeseId) { id, flavor }
|
495
|
-
}
|
496
|
-
|}
|
497
|
-
|
498
|
-
describe "when no value is provided" do
|
499
|
-
let(:query_variables) { {} }
|
500
|
-
|
501
|
-
it "uses the default" do
|
502
|
-
assert(3, result["data"]["cheese"]["id"])
|
503
|
-
assert("Manchego", result["data"]["cheese"]["flavor"])
|
504
|
-
end
|
505
|
-
end
|
506
|
-
|
507
|
-
describe "when a value is provided" do
|
508
|
-
it "uses the provided variable" do
|
509
|
-
assert(2, result["data"]["cheese"]["id"])
|
510
|
-
assert("Gouda", result["data"]["cheese"]["flavor"])
|
511
|
-
end
|
512
|
-
end
|
513
|
-
|
514
|
-
describe "when complex values" do
|
515
|
-
let(:query_variables) { {"search" => [{"source" => "COW"}]} }
|
516
|
-
let(:query_string) {%|
|
517
|
-
query getCheeses($search: [DairyProductInput]!){
|
518
|
-
cow: searchDairy(product: $search) {
|
519
|
-
... on Cheese {
|
520
|
-
flavor
|
521
|
-
}
|
522
|
-
}
|
523
|
-
}
|
524
|
-
|}
|
525
|
-
|
526
|
-
it "coerces recursively" do
|
527
|
-
assert_equal("Brie", result["data"]["cow"]["flavor"])
|
528
|
-
end
|
529
|
-
end
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
describe "max_depth" do
|
534
|
-
let(:query_string) {
|
535
|
-
<<-GRAPHQL
|
536
|
-
{
|
537
|
-
cheese(id: 1) {
|
538
|
-
similarCheese(source: SHEEP) {
|
539
|
-
similarCheese(source: SHEEP) {
|
540
|
-
similarCheese(source: SHEEP) {
|
541
|
-
similarCheese(source: SHEEP) {
|
542
|
-
id
|
543
|
-
}
|
544
|
-
}
|
545
|
-
}
|
546
|
-
}
|
547
|
-
}
|
548
|
-
}
|
549
|
-
GRAPHQL
|
550
|
-
}
|
551
|
-
|
552
|
-
it "defaults to the schema's max_depth" do
|
553
|
-
# Constrained by schema's setting of 5
|
554
|
-
assert_equal 1, result["errors"].length
|
555
|
-
end
|
556
|
-
|
557
|
-
describe "overriding max_depth" do
|
558
|
-
let(:query) {
|
559
|
-
GraphQL::Query.new(
|
560
|
-
schema,
|
561
|
-
query_string,
|
562
|
-
variables: query_variables,
|
563
|
-
operation_name: operation_name,
|
564
|
-
max_depth: 12
|
565
|
-
)
|
566
|
-
}
|
567
|
-
|
568
|
-
it "overrides the schema's max_depth" do
|
569
|
-
assert result["data"].key?("cheese")
|
570
|
-
assert_nil result["errors"]
|
571
|
-
end
|
572
|
-
end
|
573
|
-
end
|
574
|
-
|
575
|
-
describe "#provided_variables" do
|
576
|
-
it "returns the originally-provided object" do
|
577
|
-
assert_equal({"cheeseId" => 2}, query.provided_variables)
|
578
|
-
end
|
579
|
-
end
|
580
|
-
|
581
|
-
describe "parse errors" do
|
582
|
-
let(:invalid_query_string) {
|
583
|
-
<<-GRAPHQL
|
584
|
-
{
|
585
|
-
getStuff
|
586
|
-
nonsense
|
587
|
-
This is broken 1
|
588
|
-
}
|
589
|
-
GRAPHQL
|
590
|
-
}
|
591
|
-
it "adds an entry to the errors key" do
|
592
|
-
res = schema.execute(" { ")
|
593
|
-
assert_equal 1, res["errors"].length
|
594
|
-
assert_equal "Unexpected end of document", res["errors"][0]["message"]
|
595
|
-
assert_equal [], res["errors"][0]["locations"]
|
596
|
-
|
597
|
-
res = schema.execute(invalid_query_string)
|
598
|
-
assert_equal 1, res["errors"].length
|
599
|
-
assert_equal %|Parse error on "1" (INT) at [4, 26]|, res["errors"][0]["message"]
|
600
|
-
assert_equal({"line" => 4, "column" => 26}, res["errors"][0]["locations"][0])
|
601
|
-
end
|
602
|
-
|
603
|
-
it "can be configured to raise" do
|
604
|
-
raise_schema = schema.redefine(parse_error: ->(err, ctx) { raise err })
|
605
|
-
assert_raises(GraphQL::ParseError) {
|
606
|
-
raise_schema.execute(invalid_query_string)
|
607
|
-
}
|
608
|
-
end
|
609
|
-
end
|
610
|
-
|
611
|
-
describe "#mutation?" do
|
612
|
-
let(:query_string) { <<-GRAPHQL
|
613
|
-
query Q { __typename }
|
614
|
-
mutation M { pushValue(value: 1) }
|
615
|
-
GRAPHQL
|
616
|
-
}
|
617
|
-
|
618
|
-
it "returns true if the selected operation is a mutation" do
|
619
|
-
query_query = GraphQL::Query.new(schema, query_string, operation_name: "Q")
|
620
|
-
assert_equal false, query_query.mutation?
|
621
|
-
assert_equal true, query_query.query?
|
622
|
-
|
623
|
-
mutation_query = GraphQL::Query.new(schema, query_string, operation_name: "M")
|
624
|
-
assert_equal true, mutation_query.mutation?
|
625
|
-
assert_equal false, mutation_query.query?
|
626
|
-
end
|
627
|
-
end
|
628
|
-
|
629
|
-
describe "validate: false" do
|
630
|
-
it "doesn't validate the query" do
|
631
|
-
invalid_query_string = "{ nonExistantField }"
|
632
|
-
# Can assign attribute
|
633
|
-
query = GraphQL::Query.new(schema, invalid_query_string)
|
634
|
-
query.validate = false
|
635
|
-
assert_equal true, query.valid?
|
636
|
-
assert_equal 0, query.static_errors.length
|
637
|
-
|
638
|
-
# Can pass keyword argument
|
639
|
-
query = GraphQL::Query.new(schema, invalid_query_string, validate: false)
|
640
|
-
assert_equal true, query.valid?
|
641
|
-
assert_equal 0, query.static_errors.length
|
642
|
-
|
643
|
-
# Can pass `true`
|
644
|
-
query = GraphQL::Query.new(schema, invalid_query_string, validate: true)
|
645
|
-
assert_equal false, query.valid?
|
646
|
-
assert_equal 1, query.static_errors.length
|
647
|
-
end
|
648
|
-
end
|
649
|
-
|
650
|
-
describe "validating with optional arguments and variables: nil" do
|
651
|
-
it "works" do
|
652
|
-
query_str = <<-GRAPHQL
|
653
|
-
query($expiresAfter: Time) {
|
654
|
-
searchDairy(expiresAfter: $expiresAfter) {
|
655
|
-
__typename
|
656
|
-
}
|
657
|
-
}
|
658
|
-
GRAPHQL
|
659
|
-
query = GraphQL::Query.new(schema, query_str, variables: nil)
|
660
|
-
assert query.valid?
|
661
|
-
end
|
662
|
-
end
|
663
|
-
|
664
|
-
describe 'NullValue type arguments' do
|
665
|
-
let(:schema_definition) {
|
666
|
-
<<-GRAPHQL
|
667
|
-
type Query {
|
668
|
-
foo(id: [ID]): Int
|
669
|
-
}
|
670
|
-
GRAPHQL
|
671
|
-
}
|
672
|
-
let(:expected_args) { [] }
|
673
|
-
let(:default_resolver) do
|
674
|
-
{
|
675
|
-
'Query' => { 'foo' => ->(_obj, args, _ctx) { expected_args.push(args); 1 } },
|
676
|
-
}
|
677
|
-
end
|
678
|
-
let(:schema) { GraphQL::Schema.from_definition(schema_definition, default_resolve: default_resolver) }
|
679
|
-
|
680
|
-
it 'sets argument to nil when null is passed' do
|
681
|
-
query = <<-GRAPHQL
|
682
|
-
{
|
683
|
-
foo(id: null)
|
684
|
-
}
|
685
|
-
GRAPHQL
|
686
|
-
|
687
|
-
schema.execute(query)
|
688
|
-
|
689
|
-
assert(expected_args.first.key?('id'))
|
690
|
-
assert_nil(expected_args.first['id'])
|
691
|
-
end
|
692
|
-
|
693
|
-
it 'sets argument to nil when nil is passed via variable' do
|
694
|
-
query = <<-GRAPHQL
|
695
|
-
query baz($id: [ID]) {
|
696
|
-
foo(id: $id)
|
697
|
-
}
|
698
|
-
GRAPHQL
|
699
|
-
|
700
|
-
schema.execute(query, variables: { 'id' => nil })
|
701
|
-
|
702
|
-
assert(expected_args.first.key?('id'))
|
703
|
-
assert([nil], expected_args.first['id'])
|
704
|
-
end
|
705
|
-
|
706
|
-
it 'sets argument to [nil] when [null] is passed' do
|
707
|
-
query = <<-GRAPHQL
|
708
|
-
{
|
709
|
-
foo(id: [null])
|
710
|
-
}
|
711
|
-
GRAPHQL
|
712
|
-
|
713
|
-
schema.execute(query)
|
714
|
-
|
715
|
-
assert(expected_args.first.key?('id'))
|
716
|
-
assert_equal([nil], expected_args.first['id'])
|
717
|
-
end
|
718
|
-
|
719
|
-
it 'sets argument to [nil] when [nil] is passed via variable' do
|
720
|
-
query = <<-GRAPHQL
|
721
|
-
query baz($id: [ID]) {
|
722
|
-
foo(id: $id)
|
723
|
-
}
|
724
|
-
GRAPHQL
|
725
|
-
|
726
|
-
schema.execute(query, variables: { 'id' => [nil] })
|
727
|
-
|
728
|
-
assert(expected_args.first.key?('id'))
|
729
|
-
assert_equal([nil], expected_args.first['id'])
|
730
|
-
end
|
731
|
-
end
|
732
|
-
|
733
|
-
describe '#internal_representation' do
|
734
|
-
it "includes all definition roots" do
|
735
|
-
assert_kind_of GraphQL::InternalRepresentation::Node, query.internal_representation.operation_definitions["getFlavor"]
|
736
|
-
assert_kind_of GraphQL::InternalRepresentation::Node, query.internal_representation.fragment_definitions["cheeseFields"]
|
737
|
-
assert_kind_of GraphQL::InternalRepresentation::Node, query.internal_representation.fragment_definitions["edibleFields"]
|
738
|
-
assert_kind_of GraphQL::InternalRepresentation::Node, query.internal_representation.fragment_definitions["milkFields"]
|
739
|
-
assert_kind_of GraphQL::InternalRepresentation::Node, query.internal_representation.fragment_definitions["dairyFields"]
|
740
|
-
end
|
741
|
-
end
|
742
|
-
|
743
|
-
describe '#irep_selection' do
|
744
|
-
it "returns the irep for the selected operation" do
|
745
|
-
assert_kind_of GraphQL::InternalRepresentation::Node, query.irep_selection
|
746
|
-
assert_equal 'getFlavor', query.irep_selection.name
|
747
|
-
end
|
748
|
-
|
749
|
-
it "returns nil when there is no selected operation" do
|
750
|
-
query = GraphQL::Query.new(schema, '# Only a comment')
|
751
|
-
assert_nil query.irep_selection
|
752
|
-
end
|
753
|
-
end
|
754
|
-
|
755
|
-
describe "query_execution_strategy" do
|
756
|
-
let(:custom_execution_schema) {
|
757
|
-
schema.redefine do
|
758
|
-
query_execution_strategy DummyStrategy
|
759
|
-
instrument(:multiplex, DummyMultiplexInstrumenter)
|
760
|
-
end
|
761
|
-
}
|
762
|
-
|
763
|
-
class DummyStrategy
|
764
|
-
def execute(ast_operation, root_type, query_object)
|
765
|
-
{ "dummy" => true }
|
766
|
-
end
|
767
|
-
end
|
768
|
-
|
769
|
-
class DummyMultiplexInstrumenter
|
770
|
-
def self.before_multiplex(m)
|
771
|
-
m.queries.first.context[:before_multiplex] = true
|
772
|
-
end
|
773
|
-
|
774
|
-
def self.after_multiplex(m)
|
775
|
-
end
|
776
|
-
end
|
777
|
-
|
778
|
-
it "is used for running a query, if it's present and not the default" do
|
779
|
-
result = custom_execution_schema.execute(" { __typename }")
|
780
|
-
assert_equal({"data"=>{"dummy"=>true}}, result)
|
781
|
-
|
782
|
-
result = custom_execution_schema.execute(" mutation { __typename } ")
|
783
|
-
assert_equal({"data"=>{"__typename" => "Mutation"}}, result)
|
784
|
-
end
|
785
|
-
|
786
|
-
it "treats the query as a one-item multiplex" do
|
787
|
-
ctx = {}
|
788
|
-
custom_execution_schema.execute(" { __typename }", context: ctx)
|
789
|
-
assert_equal true, ctx[:before_multiplex]
|
790
|
-
end
|
791
|
-
|
792
|
-
it "can't run a multiplex" do
|
793
|
-
err = assert_raises ArgumentError do
|
794
|
-
custom_execution_schema.multiplex([
|
795
|
-
{query: " { __typename }"},
|
796
|
-
{query: " { __typename }"},
|
797
|
-
])
|
798
|
-
end
|
799
|
-
msg = "Multiplexing doesn't support custom execution strategies, run one query at a time instead"
|
800
|
-
assert_equal msg, err.message
|
801
|
-
end
|
802
|
-
end
|
803
|
-
end
|