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::Schema::MiddlewareChain do
|
5
|
-
let(:step_1) { ->(step_values, &next_step) { step_values << 1; next_step.call } }
|
6
|
-
let(:step_2) { ->(step_values, &next_step) { step_values << 2; next_step.call } }
|
7
|
-
let(:step_3) { ->(step_values, &next_step) { step_values << 3; :return_value } }
|
8
|
-
let(:steps) { [step_1, step_2, step_3] }
|
9
|
-
let(:step_values) { [] }
|
10
|
-
let(:arguments) { [step_values] }
|
11
|
-
let(:middleware_chain) { GraphQL::Schema::MiddlewareChain.new(steps: steps)}
|
12
|
-
|
13
|
-
describe "#invoke" do
|
14
|
-
it "runs steps in order" do
|
15
|
-
middleware_chain.invoke(arguments)
|
16
|
-
assert_equal([1,2,3], step_values)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "returns the value of the last middleware" do
|
20
|
-
assert_equal(:return_value, middleware_chain.invoke(arguments))
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "when there is a final step" do
|
24
|
-
let(:final_step) { ->(step_values) { step_values << :final; :final_value } }
|
25
|
-
let(:middleware_chain) { GraphQL::Schema::MiddlewareChain.new(steps: [step_1, step_2], final_step: final_step) }
|
26
|
-
|
27
|
-
it "calls the final step" do
|
28
|
-
middleware_chain.invoke(arguments)
|
29
|
-
assert_equal([1, 2, :final], step_values)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "returns the value from the final step" do
|
33
|
-
assert_equal(:final_value, middleware_chain.invoke(arguments))
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "when a step returns early" do
|
38
|
-
let(:early_return_step) { ->(step_values, &next_step) { :early_return } }
|
39
|
-
it "doesn't continue the chain" do
|
40
|
-
steps.insert(2, early_return_step)
|
41
|
-
assert_equal(:early_return, middleware_chain.invoke(arguments))
|
42
|
-
assert_equal([1,2], step_values)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "when a step provides alternate arguments" do
|
47
|
-
it "passes the new arguments to the next step" do
|
48
|
-
step_1 = ->(test_arg, &next_step) { assert_equal(test_arg, 'HELLO'); next_step.call(['WORLD']) }
|
49
|
-
step_2 = ->(test_arg, &next_step) { assert_equal(test_arg, 'WORLD'); test_arg }
|
50
|
-
|
51
|
-
chain = GraphQL::Schema::MiddlewareChain.new(steps: [step_1, step_2])
|
52
|
-
result = chain.invoke(['HELLO'])
|
53
|
-
assert_equal(result, 'WORLD')
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,150 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
# Make sure that `!` has no effect
|
5
|
-
using GraphQL::DeprecatedDSL
|
6
|
-
|
7
|
-
describe GraphQL::Schema::Mutation do
|
8
|
-
let(:mutation) { Jazz::AddInstrument }
|
9
|
-
after do
|
10
|
-
Jazz::Models.reset
|
11
|
-
end
|
12
|
-
|
13
|
-
it "Doesn't override !" do
|
14
|
-
assert_equal false, !mutation
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "definition" do
|
18
|
-
it "passes along description" do
|
19
|
-
assert_equal "Register a new musical instrument in the database", mutation.field_options[:description]
|
20
|
-
assert_equal "Autogenerated return type of AddInstrument", mutation.payload_type.description
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "argument prepare" do
|
25
|
-
it "calls methods on the mutation, uses `as:`" do
|
26
|
-
query_str = "mutation { prepareInput(input: 4) }"
|
27
|
-
res = Jazz::Schema.execute(query_str)
|
28
|
-
assert_equal 16, res["data"]["prepareInput"], "It's squared by the prepare method"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "a derived field" do
|
33
|
-
it "has a reference to the mutation" do
|
34
|
-
f = GraphQL::Schema::Field.from_options(name: "x", **mutation.field_options)
|
35
|
-
assert_equal mutation, f.mutation
|
36
|
-
|
37
|
-
# Make sure it's also present in the schema
|
38
|
-
f2 = Jazz::Schema.find("Mutation.addInstrument")
|
39
|
-
assert_equal mutation, f2.mutation
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe ".payload_type" do
|
44
|
-
it "has a reference to the mutation" do
|
45
|
-
assert_equal mutation, mutation.payload_type.mutation
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe ".field" do
|
50
|
-
it "raises a nice error when called without args" do
|
51
|
-
err = assert_raises(ArgumentError) { mutation.field }
|
52
|
-
assert_includes err.message, "Use `mutation: Jazz::AddInstrument` to attach this mutation instead."
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe ".object_class" do
|
57
|
-
it "can override & inherit the parent class" do
|
58
|
-
obj_class = Class.new(GraphQL::Schema::Object)
|
59
|
-
mutation_class = Class.new(GraphQL::Schema::Mutation) do
|
60
|
-
object_class(obj_class)
|
61
|
-
end
|
62
|
-
mutation_subclass = Class.new(mutation_class)
|
63
|
-
|
64
|
-
assert_equal(GraphQL::Schema::Object, GraphQL::Schema::Mutation.object_class)
|
65
|
-
assert_equal(obj_class, mutation_class.object_class)
|
66
|
-
assert_equal(obj_class, mutation_subclass.object_class)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe ".argument_class" do
|
71
|
-
it "can override & inherit the parent class" do
|
72
|
-
arg_class = Class.new(GraphQL::Schema::Argument)
|
73
|
-
mutation_class = Class.new(GraphQL::Schema::Mutation) do
|
74
|
-
argument_class(arg_class)
|
75
|
-
end
|
76
|
-
|
77
|
-
mutation_subclass = Class.new(mutation_class)
|
78
|
-
|
79
|
-
assert_equal(GraphQL::Schema::Argument, GraphQL::Schema::Mutation.argument_class)
|
80
|
-
assert_equal(arg_class, mutation_class.argument_class)
|
81
|
-
assert_equal(arg_class, mutation_subclass.argument_class)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "evaluation" do
|
86
|
-
it "runs mutations" do
|
87
|
-
query_str = <<-GRAPHQL
|
88
|
-
mutation {
|
89
|
-
addInstrument(name: "Trombone", family: BRASS) {
|
90
|
-
instrument {
|
91
|
-
name
|
92
|
-
family
|
93
|
-
}
|
94
|
-
entries {
|
95
|
-
name
|
96
|
-
}
|
97
|
-
ee
|
98
|
-
}
|
99
|
-
}
|
100
|
-
GRAPHQL
|
101
|
-
|
102
|
-
response = Jazz::Schema.execute(query_str)
|
103
|
-
assert_equal "Trombone", response["data"]["addInstrument"]["instrument"]["name"]
|
104
|
-
assert_equal "BRASS", response["data"]["addInstrument"]["instrument"]["family"]
|
105
|
-
errors_class = TESTING_INTERPRETER ? "GraphQL::Execution::Interpreter::ExecutionErrors" : "GraphQL::Query::Context::ExecutionErrors"
|
106
|
-
assert_equal errors_class, response["data"]["addInstrument"]["ee"]
|
107
|
-
assert_equal 7, response["data"]["addInstrument"]["entries"].size
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe ".null" do
|
112
|
-
it "overrides whether or not the field can be null" do
|
113
|
-
non_nullable_mutation_class = Class.new(GraphQL::Schema::Mutation) do
|
114
|
-
graphql_name "Thing1"
|
115
|
-
null(false)
|
116
|
-
end
|
117
|
-
|
118
|
-
nullable_mutation_class = Class.new(GraphQL::Schema::Mutation) do
|
119
|
-
graphql_name "Thing2"
|
120
|
-
null(true)
|
121
|
-
end
|
122
|
-
|
123
|
-
default_mutation_class = Class.new(GraphQL::Schema::Mutation) do
|
124
|
-
graphql_name "Thing3"
|
125
|
-
end
|
126
|
-
|
127
|
-
assert default_mutation_class.field_options[:null]
|
128
|
-
assert nullable_mutation_class.field_options[:null]
|
129
|
-
refute non_nullable_mutation_class.field_options[:null]
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should inherit and override in subclasses" do
|
133
|
-
base_mutation = Class.new(GraphQL::Schema::Mutation) do
|
134
|
-
null(false)
|
135
|
-
end
|
136
|
-
|
137
|
-
inheriting_mutation = Class.new(base_mutation) do
|
138
|
-
graphql_name "Thing"
|
139
|
-
end
|
140
|
-
|
141
|
-
override_mutation = Class.new(base_mutation) do
|
142
|
-
graphql_name "Thing2"
|
143
|
-
null(true)
|
144
|
-
end
|
145
|
-
|
146
|
-
assert_equal false, inheriting_mutation.field_options[:null]
|
147
|
-
assert override_mutation.field_options[:null]
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe GraphQL::Schema::NonNull do
|
6
|
-
let(:of_type) { Jazz::Musician }
|
7
|
-
let(:non_null_type) { GraphQL::Schema::NonNull.new(of_type) }
|
8
|
-
|
9
|
-
it "returns list? to be false" do
|
10
|
-
refute non_null_type.list?
|
11
|
-
end
|
12
|
-
|
13
|
-
it "returns non_null? to be true" do
|
14
|
-
assert non_null_type.non_null?
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns kind to be GraphQL::TypeKinds::NON_NULL" do
|
18
|
-
assert_equal GraphQL::TypeKinds::NON_NULL, non_null_type.kind
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns correct type signature" do
|
22
|
-
assert_equal "Musician!", non_null_type.to_type_signature
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "comparison operator" do
|
26
|
-
it "will return false if list types 'of_type' are different" do
|
27
|
-
new_of_type = Jazz::InspectableKey
|
28
|
-
new_non_null_type = GraphQL::Schema::NonNull.new(new_of_type)
|
29
|
-
|
30
|
-
refute_equal non_null_type, new_non_null_type
|
31
|
-
end
|
32
|
-
|
33
|
-
it "will return true if list types 'of_type' are the same" do
|
34
|
-
new_of_type = Jazz::Musician
|
35
|
-
new_non_null_type = GraphQL::Schema::NonNull.new(new_of_type)
|
36
|
-
|
37
|
-
assert_equal non_null_type, new_non_null_type
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "to_graphql" do
|
42
|
-
it "will return a non null type" do
|
43
|
-
assert_kind_of GraphQL::NonNullType, non_null_type.to_graphql
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,355 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe GraphQL::Schema::Object do
|
5
|
-
describe "class attributes" do
|
6
|
-
let(:object_class) { Jazz::Ensemble }
|
7
|
-
|
8
|
-
it "tells type data" do
|
9
|
-
assert_equal "Ensemble", object_class.graphql_name
|
10
|
-
assert_equal "A group of musicians playing together", object_class.description
|
11
|
-
assert_equal 6, object_class.fields.size
|
12
|
-
assert_equal 3, object_class.interfaces.size
|
13
|
-
# Compatibility methods are delegated to the underlying BaseType
|
14
|
-
assert object_class.respond_to?(:connection_type)
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "path" do
|
18
|
-
it "is the type name" do
|
19
|
-
assert_equal "Ensemble", object_class.path
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it "inherits fields and interfaces" do
|
24
|
-
new_object_class = Class.new(object_class) do
|
25
|
-
field :newField, String, null: true
|
26
|
-
field :name, String, description: "The new description", null: true
|
27
|
-
end
|
28
|
-
|
29
|
-
# one more than the parent class
|
30
|
-
assert_equal 7, new_object_class.fields.size
|
31
|
-
# inherited interfaces are present
|
32
|
-
assert_equal 3, new_object_class.interfaces.size
|
33
|
-
# The new field is present
|
34
|
-
assert new_object_class.fields.key?("newField")
|
35
|
-
# The overridden field is present:
|
36
|
-
name_field = new_object_class.fields["name"]
|
37
|
-
assert_equal "The new description", name_field.description
|
38
|
-
end
|
39
|
-
|
40
|
-
it "inherits name and description" do
|
41
|
-
# Manually assign a name since `.name` isn't populated for dynamic classes
|
42
|
-
new_subclass_1 = Class.new(object_class) do
|
43
|
-
graphql_name "NewSubclass"
|
44
|
-
end
|
45
|
-
new_subclass_2 = Class.new(new_subclass_1)
|
46
|
-
assert_equal "NewSubclass", new_subclass_1.graphql_name
|
47
|
-
assert_equal "NewSubclass", new_subclass_2.graphql_name
|
48
|
-
assert_equal object_class.description, new_subclass_2.description
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should take Ruby name (without Type suffix) as default graphql name" do
|
52
|
-
TestingClassType = Class.new(GraphQL::Schema::Object)
|
53
|
-
assert_equal "TestingClass", TestingClassType.graphql_name
|
54
|
-
end
|
55
|
-
|
56
|
-
it "raise on anonymous class without declared graphql name" do
|
57
|
-
anonymous_class = Class.new(GraphQL::Schema::Object)
|
58
|
-
assert_raises NotImplementedError do
|
59
|
-
anonymous_class.graphql_name
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class OverrideNameObject < GraphQL::Schema::Object
|
64
|
-
class << self
|
65
|
-
def default_graphql_name
|
66
|
-
"Override"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
it "can override the default graphql_name" do
|
72
|
-
override_name_object = OverrideNameObject
|
73
|
-
|
74
|
-
assert_equal "Override", override_name_object.graphql_name
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "implementing interfaces" do
|
79
|
-
it "raises an error when trying to implement a non-interface module" do
|
80
|
-
object_type = Class.new(GraphQL::Schema::Object)
|
81
|
-
|
82
|
-
module NotAnInterface
|
83
|
-
end
|
84
|
-
|
85
|
-
err = assert_raises do
|
86
|
-
object_type.implements(NotAnInterface)
|
87
|
-
end
|
88
|
-
|
89
|
-
message = "NotAnInterface cannot be implemented since it's not a GraphQL Interface. Use `include` for plain Ruby modules."
|
90
|
-
assert_equal message, err.message
|
91
|
-
end
|
92
|
-
|
93
|
-
it "does not inherit singleton methods from base interface when implementing another interface" do
|
94
|
-
object_type = Class.new(GraphQL::Schema::Object)
|
95
|
-
methods = object_type.singleton_methods
|
96
|
-
method_defs = Hash[methods.zip(methods.map{|method| object_type.method(method.to_sym)})]
|
97
|
-
|
98
|
-
module InterfaceType
|
99
|
-
include GraphQL::Schema::Interface
|
100
|
-
end
|
101
|
-
|
102
|
-
object_type.implements(InterfaceType)
|
103
|
-
new_method_defs = Hash[methods.zip(methods.map{|method| object_type.method(method.to_sym)})]
|
104
|
-
assert_equal method_defs, new_method_defs
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "using GraphQL::Function" do
|
109
|
-
new_test_func_payload = Class.new(GraphQL::Schema::Object) do
|
110
|
-
graphql_name "TestFuncPayload"
|
111
|
-
field :name, String, null: false
|
112
|
-
end
|
113
|
-
|
114
|
-
it "returns data on a field" do
|
115
|
-
new_func_class = Class.new(GraphQL::Function) do
|
116
|
-
argument :name, GraphQL::STRING_TYPE
|
117
|
-
type new_test_func_payload
|
118
|
-
|
119
|
-
def call(o, a, c)
|
120
|
-
{ name: a[:name] }
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
new_object_class = Class.new(GraphQL::Schema::Object) do
|
125
|
-
graphql_name "GraphQL"
|
126
|
-
field :test, function: new_func_class.new
|
127
|
-
end
|
128
|
-
|
129
|
-
schema = Class.new(GraphQL::Schema) do
|
130
|
-
query(new_object_class)
|
131
|
-
end
|
132
|
-
|
133
|
-
query_str = <<-GRAPHQL
|
134
|
-
{
|
135
|
-
test(name: "graphql") {
|
136
|
-
name
|
137
|
-
}
|
138
|
-
}
|
139
|
-
GRAPHQL
|
140
|
-
res = schema.execute(query_str)
|
141
|
-
assert_equal "graphql", res["data"]["test"]["name"]
|
142
|
-
end
|
143
|
-
|
144
|
-
it "returns data on a connection" do
|
145
|
-
new_func_class = Class.new(GraphQL::Function) do
|
146
|
-
argument :name, GraphQL::STRING_TYPE
|
147
|
-
type new_test_func_payload.connection_type
|
148
|
-
|
149
|
-
def call(o, a, c)
|
150
|
-
[{ name: a[:name] }]
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
new_object_class = Class.new(GraphQL::Schema::Object) do
|
155
|
-
graphql_name "GraphQL"
|
156
|
-
field :test_conn, function: new_func_class.new
|
157
|
-
end
|
158
|
-
|
159
|
-
schema = Class.new(GraphQL::Schema) do
|
160
|
-
query(new_object_class)
|
161
|
-
end
|
162
|
-
|
163
|
-
query_str = <<-GRAPHQL
|
164
|
-
{
|
165
|
-
testConn(name: "graphql") {
|
166
|
-
edges {
|
167
|
-
node {
|
168
|
-
name
|
169
|
-
}
|
170
|
-
}
|
171
|
-
}
|
172
|
-
}
|
173
|
-
GRAPHQL
|
174
|
-
res = schema.execute(query_str)
|
175
|
-
assert_equal "graphql", res["data"]["testConn"]["edges"][0]["node"]["name"]
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
describe "wrapping a Hash" do
|
180
|
-
it "automatically looks up symbol and string keys" do
|
181
|
-
query_str = <<-GRAPHQL
|
182
|
-
{
|
183
|
-
hashyEnsemble {
|
184
|
-
musicians { name }
|
185
|
-
formedAt
|
186
|
-
}
|
187
|
-
}
|
188
|
-
GRAPHQL
|
189
|
-
res = Jazz::Schema.execute(query_str)
|
190
|
-
ensemble = res["data"]["hashyEnsemble"]
|
191
|
-
assert_equal ["Jerry Garcia"], ensemble["musicians"].map { |m| m["name"] }
|
192
|
-
assert_equal "May 5, 1965", ensemble["formedAt"]
|
193
|
-
end
|
194
|
-
|
195
|
-
it "works with strings and symbols" do
|
196
|
-
query_str = <<-GRAPHQL
|
197
|
-
{
|
198
|
-
hashByString { falsey }
|
199
|
-
hashBySym { falsey }
|
200
|
-
}
|
201
|
-
GRAPHQL
|
202
|
-
res = Jazz::Schema.execute(query_str)
|
203
|
-
assert_equal false, res["data"]["hashByString"]["falsey"]
|
204
|
-
assert_equal false, res["data"]["hashBySym"]["falsey"]
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
describe "wrapping `nil`" do
|
209
|
-
it "doesn't wrap nil in lists" do
|
210
|
-
query_str = <<-GRAPHQL
|
211
|
-
{
|
212
|
-
namedEntities {
|
213
|
-
name
|
214
|
-
}
|
215
|
-
}
|
216
|
-
GRAPHQL
|
217
|
-
|
218
|
-
res = Jazz::Schema.execute(query_str)
|
219
|
-
expected_items = [{"name" => "Bela Fleck and the Flecktones"}, nil]
|
220
|
-
assert_equal expected_items, res["data"]["namedEntities"]
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
describe ".to_graphql" do
|
225
|
-
let(:obj_type) { Jazz::Ensemble.to_graphql }
|
226
|
-
it "returns a matching GraphQL::ObjectType" do
|
227
|
-
assert_equal "Ensemble", obj_type.name
|
228
|
-
assert_equal "A group of musicians playing together", obj_type.description
|
229
|
-
assert_equal 6, obj_type.all_fields.size
|
230
|
-
|
231
|
-
name_field = obj_type.all_fields[2]
|
232
|
-
assert_equal "name", name_field.name
|
233
|
-
assert_equal GraphQL::STRING_TYPE.to_non_null_type, name_field.type
|
234
|
-
assert_equal nil, name_field.description
|
235
|
-
end
|
236
|
-
|
237
|
-
it "has a custom implementation" do
|
238
|
-
assert_equal obj_type.metadata[:config], :configged
|
239
|
-
end
|
240
|
-
|
241
|
-
it "uses the custom field class" do
|
242
|
-
query_str = <<-GRAPHQL
|
243
|
-
{
|
244
|
-
ensembles { upcaseName }
|
245
|
-
}
|
246
|
-
GRAPHQL
|
247
|
-
|
248
|
-
res = Jazz::Schema.execute(query_str)
|
249
|
-
assert_equal ["BELA FLECK AND THE FLECKTONES", "ROBERT GLASPER EXPERIMENT"], res["data"]["ensembles"].map { |e| e["upcaseName"] }
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
|
254
|
-
describe "in queries" do
|
255
|
-
after {
|
256
|
-
Jazz::Models.reset
|
257
|
-
}
|
258
|
-
|
259
|
-
it "returns data" do
|
260
|
-
query_str = <<-GRAPHQL
|
261
|
-
{
|
262
|
-
ensembles { name }
|
263
|
-
instruments { name }
|
264
|
-
}
|
265
|
-
GRAPHQL
|
266
|
-
res = Jazz::Schema.execute(query_str)
|
267
|
-
expected_ensembles = [
|
268
|
-
{"name" => "Bela Fleck and the Flecktones"},
|
269
|
-
{"name" => "ROBERT GLASPER Experiment"},
|
270
|
-
]
|
271
|
-
assert_equal expected_ensembles, res["data"]["ensembles"]
|
272
|
-
assert_equal({"name" => "Banjo"}, res["data"]["instruments"].first)
|
273
|
-
end
|
274
|
-
|
275
|
-
it "does mutations" do
|
276
|
-
mutation_str = <<-GRAPHQL
|
277
|
-
mutation AddEnsemble($name: String!) {
|
278
|
-
addEnsemble(input: { name: $name }) {
|
279
|
-
id
|
280
|
-
}
|
281
|
-
}
|
282
|
-
GRAPHQL
|
283
|
-
|
284
|
-
query_str = <<-GRAPHQL
|
285
|
-
query($id: ID!) {
|
286
|
-
find(id: $id) {
|
287
|
-
... on Ensemble {
|
288
|
-
name
|
289
|
-
}
|
290
|
-
}
|
291
|
-
}
|
292
|
-
GRAPHQL
|
293
|
-
|
294
|
-
res = Jazz::Schema.execute(mutation_str, variables: { name: "Miles Davis Quartet" })
|
295
|
-
new_id = res["data"]["addEnsemble"]["id"]
|
296
|
-
|
297
|
-
res2 = Jazz::Schema.execute(query_str, variables: { id: new_id })
|
298
|
-
assert_equal "Miles Davis Quartet", res2["data"]["find"]["name"]
|
299
|
-
end
|
300
|
-
|
301
|
-
it "initializes root wrappers once" do
|
302
|
-
query_str = " { oid1: objectId oid2: objectId }"
|
303
|
-
res = Jazz::Schema.execute(query_str)
|
304
|
-
assert_equal res["data"]["oid1"], res["data"]["oid2"]
|
305
|
-
end
|
306
|
-
|
307
|
-
it "skips fields properly" do
|
308
|
-
query_str = "{ find(id: \"MagicalSkipId\") { __typename } }"
|
309
|
-
res = Jazz::Schema.execute(query_str)
|
310
|
-
# TBH I think `{}` is probably righter than `nil`, I guess we'll see.
|
311
|
-
skip_value = TESTING_INTERPRETER ? {} : nil
|
312
|
-
assert_equal({"data" => skip_value }, res.to_h)
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
describe "when fields conflict with built-ins" do
|
317
|
-
it "warns when no override" do
|
318
|
-
expected_warning = "X's `field :method` conflicts with a built-in method, use `resolver_method:` to pick a different resolver method for this field (for example, `resolver_method: :resolve_method` and `def resolve_method`)\n"
|
319
|
-
assert_output "", expected_warning do
|
320
|
-
Class.new(GraphQL::Schema::Object) do
|
321
|
-
graphql_name "X"
|
322
|
-
field :method, String, null: true
|
323
|
-
end
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
it "warns when override matches field name" do
|
328
|
-
expected_warning = "X's `field :object` conflicts with a built-in method, use `resolver_method:` to pick a different resolver method for this field (for example, `resolver_method: :resolve_object` and `def resolve_object`)\n"
|
329
|
-
assert_output "", expected_warning do
|
330
|
-
Class.new(GraphQL::Schema::Object) do
|
331
|
-
graphql_name "X"
|
332
|
-
field :object, String, null: true, resolver_method: :object
|
333
|
-
end
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
it "doesn't warn with an override" do
|
338
|
-
assert_output "", "" do
|
339
|
-
Class.new(GraphQL::Schema::Object) do
|
340
|
-
graphql_name "X"
|
341
|
-
field :method, String, null: true, resolver_method: :resolve_method
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
it "doesn't warn when passing object through using resolver_method" do
|
347
|
-
assert_output "", "" do
|
348
|
-
Class.new(GraphQL::Schema::Object) do
|
349
|
-
graphql_name "X"
|
350
|
-
field :thing, String, null: true, resolver_method: :object
|
351
|
-
end
|
352
|
-
end
|
353
|
-
end
|
354
|
-
end
|
355
|
-
end
|