graphql 1.7.6 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/function_generator.rb +1 -1
- data/lib/generators/graphql/install_generator.rb +14 -8
- data/lib/generators/graphql/loader_generator.rb +1 -1
- data/lib/generators/graphql/mutation_generator.rb +6 -1
- data/lib/generators/graphql/templates/function.erb +2 -2
- data/lib/generators/graphql/templates/loader.erb +2 -2
- data/lib/generators/graphql/templates/schema.erb +1 -1
- data/lib/graphql/argument.rb +25 -19
- data/lib/graphql/backtrace/tracer.rb +16 -22
- data/lib/graphql/backtrace.rb +1 -1
- data/lib/graphql/backwards_compatibility.rb +2 -3
- data/lib/graphql/base_type.rb +31 -31
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +14 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +117 -0
- data/lib/graphql/define/assign_object_field.rb +5 -12
- data/lib/graphql/deprecated_dsl.rb +42 -0
- data/lib/graphql/directive.rb +1 -0
- data/lib/graphql/enum_type.rb +3 -1
- data/lib/graphql/execution/execute.rb +21 -13
- data/lib/graphql/execution/instrumentation.rb +82 -0
- data/lib/graphql/execution/lazy/lazy_method_map.rb +1 -1
- data/lib/graphql/execution/lazy/resolve.rb +1 -3
- data/lib/graphql/execution/multiplex.rb +12 -29
- data/lib/graphql/execution.rb +1 -0
- data/lib/graphql/field.rb +21 -4
- data/lib/graphql/function.rb +14 -0
- data/lib/graphql/input_object_type.rb +3 -1
- data/lib/graphql/interface_type.rb +5 -3
- data/lib/graphql/internal_representation/node.rb +26 -14
- data/lib/graphql/internal_representation/visit.rb +3 -6
- data/lib/graphql/introspection/base_object.rb +16 -0
- data/lib/graphql/introspection/directive_location_enum.rb +11 -7
- data/lib/graphql/introspection/directive_type.rb +23 -16
- data/lib/graphql/introspection/dynamic_fields.rb +11 -0
- data/lib/graphql/introspection/entry_points.rb +29 -0
- data/lib/graphql/introspection/enum_value_type.rb +16 -11
- data/lib/graphql/introspection/field_type.rb +21 -12
- data/lib/graphql/introspection/input_value_type.rb +26 -23
- data/lib/graphql/introspection/schema_field.rb +7 -2
- data/lib/graphql/introspection/schema_type.rb +36 -22
- data/lib/graphql/introspection/type_by_name_field.rb +10 -2
- data/lib/graphql/introspection/type_kind_enum.rb +10 -6
- data/lib/graphql/introspection/type_type.rb +85 -23
- data/lib/graphql/introspection/typename_field.rb +1 -0
- data/lib/graphql/introspection.rb +3 -10
- data/lib/graphql/language/block_string.rb +47 -0
- data/lib/graphql/language/document_from_schema_definition.rb +280 -0
- data/lib/graphql/language/generation.rb +3 -182
- data/lib/graphql/language/lexer.rb +144 -69
- data/lib/graphql/language/lexer.rl +15 -4
- data/lib/graphql/language/nodes.rb +141 -78
- data/lib/graphql/language/parser.rb +677 -630
- data/lib/graphql/language/parser.y +18 -12
- data/lib/graphql/language/printer.rb +361 -0
- data/lib/graphql/language/token.rb +10 -3
- data/lib/graphql/language.rb +3 -0
- data/lib/graphql/non_null_type.rb +1 -1
- data/lib/graphql/object_type.rb +1 -6
- data/lib/graphql/query/arguments.rb +63 -32
- data/lib/graphql/query/context.rb +32 -2
- data/lib/graphql/query/literal_input.rb +4 -1
- data/lib/graphql/query/null_context.rb +1 -1
- data/lib/graphql/query/result.rb +1 -1
- data/lib/graphql/query/variables.rb +21 -3
- data/lib/graphql/query.rb +19 -6
- data/lib/graphql/railtie.rb +109 -0
- data/lib/graphql/relay/connection_resolve.rb +3 -0
- data/lib/graphql/relay/connection_type.rb +5 -3
- data/lib/graphql/relay/edge_type.rb +2 -1
- data/lib/graphql/relay/global_id_resolve.rb +5 -1
- data/lib/graphql/relay/mongo_relation_connection.rb +40 -0
- data/lib/graphql/relay/mutation/instrumentation.rb +1 -1
- data/lib/graphql/relay/mutation/resolve.rb +5 -1
- data/lib/graphql/relay/relation_connection.rb +14 -19
- data/lib/graphql/relay/type_extensions.rb +30 -0
- data/lib/graphql/relay.rb +2 -0
- data/lib/graphql/scalar_type.rb +14 -2
- data/lib/graphql/schema/argument.rb +92 -0
- data/lib/graphql/schema/build_from_definition.rb +64 -18
- data/lib/graphql/schema/enum.rb +85 -0
- data/lib/graphql/schema/enum_value.rb +74 -0
- data/lib/graphql/schema/field.rb +372 -0
- data/lib/graphql/schema/finder.rb +153 -0
- data/lib/graphql/schema/input_object.rb +87 -0
- data/lib/graphql/schema/interface.rb +105 -0
- data/lib/graphql/schema/introspection_system.rb +93 -0
- data/lib/graphql/schema/late_bound_type.rb +32 -0
- data/lib/graphql/schema/list.rb +32 -0
- data/lib/graphql/schema/loader.rb +2 -2
- data/lib/graphql/schema/member/accepts_definition.rb +152 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +100 -0
- data/lib/graphql/schema/member/build_type.rb +137 -0
- data/lib/graphql/schema/member/cached_graphql_definition.rb +26 -0
- data/lib/graphql/schema/member/graphql_type_names.rb +21 -0
- data/lib/graphql/schema/member/has_arguments.rb +50 -0
- data/lib/graphql/schema/member/has_fields.rb +130 -0
- data/lib/graphql/schema/member/instrumentation.rb +115 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +34 -0
- data/lib/graphql/schema/member.rb +28 -0
- data/lib/graphql/schema/middleware_chain.rb +5 -1
- data/lib/graphql/schema/mutation.rb +138 -0
- data/lib/graphql/schema/non_null.rb +38 -0
- data/lib/graphql/schema/object.rb +81 -0
- data/lib/graphql/schema/printer.rb +33 -266
- data/lib/graphql/schema/relay_classic_mutation.rb +87 -0
- data/lib/graphql/schema/rescue_middleware.rb +8 -7
- data/lib/graphql/schema/resolver.rb +122 -0
- data/lib/graphql/schema/scalar.rb +35 -0
- data/lib/graphql/schema/traversal.rb +102 -22
- data/lib/graphql/schema/union.rb +36 -0
- data/lib/graphql/schema/validation.rb +3 -2
- data/lib/graphql/schema.rb +381 -12
- data/lib/graphql/static_validation/definition_dependencies.rb +1 -1
- data/lib/graphql/static_validation/literal_validator.rb +16 -4
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +6 -6
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +5 -1
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +15 -8
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +11 -1
- data/lib/graphql/static_validation/validation_context.rb +1 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -5
- data/lib/graphql/subscriptions/instrumentation.rb +5 -1
- data/lib/graphql/subscriptions/serialize.rb +2 -0
- data/lib/graphql/subscriptions.rb +90 -16
- data/lib/graphql/tracing/data_dog_tracing.rb +49 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +26 -0
- data/lib/graphql/tracing/platform_tracing.rb +20 -7
- data/lib/graphql/tracing/scout_tracing.rb +2 -2
- data/lib/graphql/tracing.rb +1 -0
- data/lib/graphql/unresolved_type_error.rb +3 -2
- data/lib/graphql/upgrader/member.rb +894 -0
- data/lib/graphql/upgrader/schema.rb +37 -0
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +5 -25
- data/readme.md +2 -2
- data/spec/dummy/app/channels/graphql_channel.rb +23 -2
- data/spec/dummy/log/development.log +239 -0
- data/spec/dummy/log/test.log +410 -0
- data/spec/dummy/test/system/action_cable_subscription_test.rb +4 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-x/-xYZjAnuuzgR79fcznLTQtSdh6AARxu8FcQ_J6p7L3U.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/13/13HiV12xyoQvT-1L39ZzLwMZxjyaGMiENmfw7f-QTIc.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/3W/3Wtf5pCWdqq0AB-iB0Y9uUNrTkruRxIEf1XFn_BETU0.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5i/5iguGafb4hOn8262Kn8Q37ogNN9MxxQKGKNzHAzUcvI.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/8m/8mj2T6yy847Mc2Z7k3Xzh8O91hhVJt3NrPe8ASNDlIA.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/DT/DTQyMpr4ABZYQetsdRJ5A7S4jf1r3ie4FGOR7GZBNSs.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Dq/DqJ5_yJPrP5iLlOQyTQsjAVI5FE5LCVDkED0f7GgsSo.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/F8/F8MUNRzORGFgr329fNM0xLaoWCXdv3BIalT7dsvLfjs.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/KB/KB07ZaKNC5uXJ7TjLi-WqnY6g7dq8wWp_8N3HNjBNxg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Rw/RwDuCV-XpnCtjNkvhpJfBuxXMk0b5AD3L9eR6M-wcy0.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/UL/ULdjhhb0bRuqmaG7XSZlFYzGYCXTDnqZuJBTWRlzqgw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Up/UpPNgh0yYoUsyMDh5zWqe_U6qJIyTC6-dxMMAs1vvlM.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Wg/Wguh-szFGTI1gaL6npYwPekMXflugRei7F_mOyRucXg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/X-/X-khLYMA9mqFRPg3zAi86mREDxpKl4bdKYp3uF6WHos.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bi/BIkdhfxsezxM4q-HZ4oCNTq97WEJTigcq0tpX2cDvbY.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ff/FfxmA4CMHQZT7exx0G7NS1Wpcnny0vzp-Jhc2H36bp8.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/gE/gEiiG4GZNy_djEjK2pHm_NgA-gyhLZhdQvo0Yt96GqE.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/gn/gnA9ZSqpjccNL2m8pe_jBvY6SinXlCzXDWyop83Od8s.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lO/lOAan3cMwCE_Hli6gsDML88xFNfn0nxPmvrSkW7eEOw.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/m1/M1pv8MJEPLXGLvS8QxVh3DSO9cI4mRt5FHFWdrvUj6o.cache +2 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/m7/m77qH7ZqH0_0SmwJbiKGDd-aLau1Dav847DC6ge46zY.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/sj/sjRjnjRB37lH2vrgtkdJ8Cz84__IJ978IuKTM7HcztI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/um/um1JrirR4hJhK-1rE-HywlyCi5ibgxHVrReiujZBWJM.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/v4/v4fwVytD7ITcE0_GDbslZEYud8a5Okm85fV1o7SDl6g.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/v_/v_0PAQt0iipQjFP5zjgkkk9Stnpf4VzvnMv67d1Keuw.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/wd/wdT9U4MKxe1PyqNjVuCKMpCl3dxGCIRJIlwUTfh2DQU.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xI/xIaxut_fEIhKBDqljTNwYaADK9kj3gG0ESrfHs-5_og.cache +3 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/y0/y0SJOqIx2fn1SKqOkAihsQow0trRJrSIyAswufVuoA8.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zg/zgpzeaX-KZErHyGJ1aBH3ZusweNXMneVZule88XsIJI.cache +1 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v3.0/zy/zYFltDy-8VC-uKq2BVEiJJyYXNFvVzAKuMlR3ZIYZsk.cache +0 -0
- data/spec/dummy/tmp/screenshots/failures_test_it_handles_subscriptions.png +0 -0
- data/spec/fixtures/upgrader/account.original.rb +19 -0
- data/spec/fixtures/upgrader/account.transformed.rb +20 -0
- data/spec/fixtures/upgrader/blame_range.original.rb +43 -0
- data/spec/fixtures/upgrader/blame_range.transformed.rb +30 -0
- data/spec/fixtures/upgrader/date_time.original.rb +24 -0
- data/spec/fixtures/upgrader/date_time.transformed.rb +23 -0
- data/spec/fixtures/upgrader/delete_project.original.rb +28 -0
- data/spec/fixtures/upgrader/delete_project.transformed.rb +27 -0
- data/spec/fixtures/upgrader/gist_order_field.original.rb +14 -0
- data/spec/fixtures/upgrader/gist_order_field.transformed.rb +13 -0
- data/spec/fixtures/upgrader/increment_count.original.rb +59 -0
- data/spec/fixtures/upgrader/increment_count.transformed.rb +50 -0
- data/spec/fixtures/upgrader/photo.original.rb +10 -0
- data/spec/fixtures/upgrader/photo.transformed.rb +12 -0
- data/spec/fixtures/upgrader/release_order.original.rb +15 -0
- data/spec/fixtures/upgrader/release_order.transformed.rb +14 -0
- data/spec/fixtures/upgrader/starrable.original.rb +49 -0
- data/spec/fixtures/upgrader/starrable.transformed.rb +46 -0
- data/spec/fixtures/upgrader/subscribable.original.rb +55 -0
- data/spec/fixtures/upgrader/subscribable.transformed.rb +51 -0
- data/spec/fixtures/upgrader/type_x.original.rb +65 -0
- data/spec/fixtures/upgrader/type_x.transformed.rb +56 -0
- data/spec/generators/graphql/function_generator_spec.rb +26 -0
- data/spec/generators/graphql/install_generator_spec.rb +1 -1
- data/spec/generators/graphql/loader_generator_spec.rb +24 -0
- data/spec/graphql/analysis/max_query_complexity_spec.rb +3 -3
- data/spec/graphql/analysis/max_query_depth_spec.rb +3 -3
- data/spec/graphql/argument_spec.rb +21 -0
- data/spec/graphql/backtrace_spec.rb +10 -0
- data/spec/graphql/base_type_spec.rb +42 -0
- data/spec/graphql/boolean_type_spec.rb +3 -3
- data/spec/graphql/directive_spec.rb +3 -1
- data/spec/graphql/enum_type_spec.rb +18 -5
- data/spec/graphql/execution/execute_spec.rb +4 -4
- data/spec/graphql/execution/instrumentation_spec.rb +165 -0
- data/spec/graphql/execution/multiplex_spec.rb +2 -2
- data/spec/graphql/execution_error_spec.rb +18 -0
- data/spec/graphql/float_type_spec.rb +2 -2
- data/spec/graphql/id_type_spec.rb +1 -1
- data/spec/graphql/input_object_type_spec.rb +15 -2
- data/spec/graphql/int_type_spec.rb +2 -2
- data/spec/graphql/interface_type_spec.rb +12 -0
- data/spec/graphql/internal_representation/rewrite_spec.rb +2 -2
- data/spec/graphql/introspection/schema_type_spec.rb +2 -0
- data/spec/graphql/language/block_string_spec.rb +70 -0
- data/spec/graphql/language/document_from_schema_definition_spec.rb +770 -0
- data/spec/graphql/language/generation_spec.rb +21 -186
- data/spec/graphql/language/lexer_spec.rb +21 -1
- data/spec/graphql/language/nodes_spec.rb +21 -12
- data/spec/graphql/language/parser_spec.rb +1 -1
- data/spec/graphql/language/printer_spec.rb +203 -0
- data/spec/graphql/object_type_spec.rb +22 -0
- data/spec/graphql/query/arguments_spec.rb +25 -15
- data/spec/graphql/query/context_spec.rb +18 -0
- data/spec/graphql/query/executor_spec.rb +2 -1
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -8
- data/spec/graphql/query/variables_spec.rb +42 -1
- data/spec/graphql/query_spec.rb +31 -5
- data/spec/graphql/rake_task_spec.rb +3 -1
- data/spec/graphql/relay/base_connection_spec.rb +1 -1
- data/spec/graphql/relay/connection_instrumentation_spec.rb +2 -2
- data/spec/graphql/relay/connection_resolve_spec.rb +1 -1
- data/spec/graphql/relay/connection_type_spec.rb +1 -1
- data/spec/graphql/relay/mongo_relation_connection_spec.rb +474 -0
- data/spec/graphql/relay/mutation_spec.rb +9 -7
- data/spec/graphql/relay/range_add_spec.rb +5 -1
- data/spec/graphql/relay/relation_connection_spec.rb +65 -1
- data/spec/graphql/schema/argument_spec.rb +87 -0
- data/spec/graphql/schema/build_from_definition_spec.rb +89 -5
- data/spec/graphql/schema/enum_spec.rb +74 -0
- data/spec/graphql/schema/field_spec.rb +225 -0
- data/spec/graphql/schema/finder_spec.rb +135 -0
- data/spec/graphql/schema/input_object_spec.rb +111 -0
- data/spec/graphql/schema/instrumentation_spec.rb +40 -0
- data/spec/graphql/schema/interface_spec.rb +185 -0
- data/spec/graphql/schema/introspection_system_spec.rb +39 -0
- data/spec/graphql/schema/member/accepts_definition_spec.rb +111 -0
- data/spec/graphql/schema/member/build_type_spec.rb +17 -0
- data/spec/graphql/schema/member/has_fields_spec.rb +129 -0
- data/spec/graphql/schema/member/type_system_helpers_spec.rb +63 -0
- data/spec/graphql/schema/mutation_spec.rb +148 -0
- data/spec/graphql/schema/object_spec.rb +175 -0
- data/spec/graphql/schema/printer_spec.rb +111 -15
- data/spec/graphql/schema/relay_classic_mutation_spec.rb +38 -0
- data/spec/graphql/schema/rescue_middleware_spec.rb +11 -0
- data/spec/graphql/schema/resolver_spec.rb +131 -0
- data/spec/graphql/schema/scalar_spec.rb +95 -0
- data/spec/graphql/schema/traversal_spec.rb +31 -0
- data/spec/graphql/schema/union_spec.rb +65 -0
- data/spec/graphql/schema/validation_spec.rb +1 -1
- data/spec/graphql/schema/warden_spec.rb +11 -11
- data/spec/graphql/schema_spec.rb +55 -12
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +10 -2
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -2
- data/spec/graphql/string_type_spec.rb +3 -3
- data/spec/graphql/subscriptions_spec.rb +273 -184
- data/spec/graphql/tracing/active_support_notifications_tracing_spec.rb +1 -1
- data/spec/graphql/tracing/new_relic_tracing_spec.rb +47 -0
- data/spec/graphql/tracing/platform_tracing_spec.rb +60 -1
- data/spec/graphql/union_type_spec.rb +1 -1
- data/spec/graphql/upgrader/member_spec.rb +516 -0
- data/spec/graphql/upgrader/schema_spec.rb +82 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/dummy/schema.rb +53 -24
- data/spec/support/jazz.rb +544 -0
- data/spec/support/lazy_helpers.rb +21 -23
- data/spec/support/new_relic.rb +24 -0
- data/spec/support/star_trek/data.rb +109 -0
- data/spec/support/star_trek/schema.rb +388 -0
- data/spec/support/star_wars/data.rb +6 -7
- data/spec/support/star_wars/schema.rb +127 -171
- metadata +233 -11
- data/lib/graphql/introspection/arguments_field.rb +0 -7
- data/lib/graphql/introspection/enum_values_field.rb +0 -18
- data/lib/graphql/introspection/fields_field.rb +0 -13
- data/lib/graphql/introspection/input_fields_field.rb +0 -12
- data/lib/graphql/introspection/interfaces_field.rb +0 -11
- data/lib/graphql/introspection/of_type_field.rb +0 -6
- data/lib/graphql/introspection/possible_types_field.rb +0 -11
@@ -0,0 +1,135 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe GraphQL::Schema::Finder do
|
5
|
+
let(:finder) { GraphQL::Schema::Finder.new(Jazz::Schema) }
|
6
|
+
|
7
|
+
describe "#find" do
|
8
|
+
it "finds a valid object type" do
|
9
|
+
type = finder.find("Ensemble")
|
10
|
+
assert_equal "Ensemble", type.name
|
11
|
+
end
|
12
|
+
|
13
|
+
it "raises when finding an invalid object type" do
|
14
|
+
exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
|
15
|
+
finder.find("DoesNotExist")
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_match /Could not find type `DoesNotExist` in schema./, exception.message
|
19
|
+
end
|
20
|
+
|
21
|
+
it "finds a valid directive" do
|
22
|
+
directive = finder.find("@include")
|
23
|
+
assert_equal "include", directive.name
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises when finding an invalid directive" do
|
27
|
+
exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
|
28
|
+
finder.find("@yolo")
|
29
|
+
end
|
30
|
+
|
31
|
+
assert_match /Could not find directive `@yolo` in schema./, exception.message
|
32
|
+
end
|
33
|
+
|
34
|
+
it "finds a valid field" do
|
35
|
+
field = finder.find("Ensemble.musicians")
|
36
|
+
assert_equal "musicians", field.name
|
37
|
+
end
|
38
|
+
|
39
|
+
it "finds a meta field" do
|
40
|
+
field = finder.find("Ensemble.__typename")
|
41
|
+
assert_equal "__typename", field.name
|
42
|
+
end
|
43
|
+
|
44
|
+
it "raises when finding an in valid field" do
|
45
|
+
exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
|
46
|
+
finder.find("Ensemble.nope")
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_match /Could not find field `nope` on object type `Ensemble`./, exception.message
|
50
|
+
end
|
51
|
+
|
52
|
+
it "finds a valid argument" do
|
53
|
+
arg = finder.find("Query.find.id")
|
54
|
+
assert_equal "id", arg.name
|
55
|
+
end
|
56
|
+
|
57
|
+
it "raises when finding an invalid argument" do
|
58
|
+
exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
|
59
|
+
finder.find("Query.find.thisArgumentIsInvalid")
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_match /Could not find argument `thisArgumentIsInvalid` on field `find`./, exception.message
|
63
|
+
end
|
64
|
+
|
65
|
+
it "raises when selecting on an argument" do
|
66
|
+
exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
|
67
|
+
finder.find("Query.find.id.whyYouDoThis")
|
68
|
+
end
|
69
|
+
|
70
|
+
assert_match /Cannot select member `whyYouDoThis` on a field./, exception.message
|
71
|
+
end
|
72
|
+
|
73
|
+
it "finds a valid interface" do
|
74
|
+
type = finder.find("NamedEntity")
|
75
|
+
assert_equal "NamedEntity", type.name
|
76
|
+
end
|
77
|
+
|
78
|
+
it "finds a valid input type" do
|
79
|
+
type = finder.find("LegacyInput")
|
80
|
+
assert_equal "LegacyInput", type.name
|
81
|
+
end
|
82
|
+
|
83
|
+
it "finds a valid input field" do
|
84
|
+
input_field = finder.find("LegacyInput.intValue")
|
85
|
+
assert_equal "intValue", input_field.name
|
86
|
+
end
|
87
|
+
|
88
|
+
it "raises when finding an invalid input field" do
|
89
|
+
exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
|
90
|
+
finder.find("LegacyInput.wat")
|
91
|
+
end
|
92
|
+
|
93
|
+
assert_match /Could not find input field `wat` on input object type `LegacyInput`./, exception.message
|
94
|
+
end
|
95
|
+
|
96
|
+
it "finds a valid union type" do
|
97
|
+
type = finder.find("PerformingAct")
|
98
|
+
assert_equal "PerformingAct", type.name
|
99
|
+
end
|
100
|
+
|
101
|
+
it "raises when selecting a possible type" do
|
102
|
+
exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
|
103
|
+
finder.find("PerformingAct.Musician")
|
104
|
+
end
|
105
|
+
|
106
|
+
assert_match /Cannot select union possible type `Musician`. Select the type directly instead./, exception.message
|
107
|
+
end
|
108
|
+
|
109
|
+
it "finds a valid enum type" do
|
110
|
+
type = finder.find("Family")
|
111
|
+
assert_equal "Family", type.name
|
112
|
+
end
|
113
|
+
|
114
|
+
it "finds a valid enum value" do
|
115
|
+
value = finder.find("Family.BRASS")
|
116
|
+
assert_equal "BRASS", value.name
|
117
|
+
end
|
118
|
+
|
119
|
+
it "raises when finding an invalid enum value" do
|
120
|
+
exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
|
121
|
+
finder.find("Family.THISISNOTASTATUS")
|
122
|
+
end
|
123
|
+
|
124
|
+
assert_match /Could not find enum value `THISISNOTASTATUS` on enum type `Family`./, exception.message
|
125
|
+
end
|
126
|
+
|
127
|
+
it "raises when selecting on an enum value" do
|
128
|
+
exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
|
129
|
+
finder.find("Family.BRASS.wat")
|
130
|
+
end
|
131
|
+
|
132
|
+
assert_match /Cannot select member `wat` on an enum value./, exception.message
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe GraphQL::Schema::InputObject do
|
5
|
+
let(:input_object) { Jazz::EnsembleInput }
|
6
|
+
describe "type info" do
|
7
|
+
it "has it" do
|
8
|
+
assert_equal "EnsembleInput", input_object.graphql_name
|
9
|
+
assert_equal nil, input_object.description
|
10
|
+
assert_equal 1, input_object.arguments.size
|
11
|
+
end
|
12
|
+
|
13
|
+
it "is the #owner of its arguments" do
|
14
|
+
argument = input_object.arguments["name"]
|
15
|
+
assert_equal input_object, argument.owner
|
16
|
+
end
|
17
|
+
|
18
|
+
it "inherits arguments" do
|
19
|
+
base_class = Class.new(GraphQL::Schema::InputObject) do
|
20
|
+
argument :arg1, String, required: true
|
21
|
+
argument :arg2, String, required: true
|
22
|
+
end
|
23
|
+
|
24
|
+
subclass = Class.new(base_class) do
|
25
|
+
argument :arg2, Integer, required: true
|
26
|
+
argument :arg3, Integer, required: true
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_equal 3, subclass.arguments.size
|
30
|
+
assert_equal ["arg1", "arg2", "arg3"], subclass.arguments.keys
|
31
|
+
assert_equal ["String!", "Int!", "Int!"], subclass.arguments.values.map { |a| a.type.to_s }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".to_graphql" do
|
36
|
+
it "assigns itself as the arguments_class" do
|
37
|
+
assert_equal input_object, input_object.to_graphql.arguments_class
|
38
|
+
end
|
39
|
+
|
40
|
+
it "accepts description: kwarg" do
|
41
|
+
input_obj_class = Jazz::InspectableInput
|
42
|
+
input_obj_type = input_obj_class.to_graphql
|
43
|
+
assert_equal "Test description kwarg", input_obj_type.arguments["stringValue"].description
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "prepare: / as:" do
|
48
|
+
module InputObjectPrepareTest
|
49
|
+
class InputObj < GraphQL::Schema::InputObject
|
50
|
+
argument :a, Integer, required: true
|
51
|
+
argument :b, Integer, required: true, as: :b2
|
52
|
+
argument :c, Integer, required: true, prepare: :prep
|
53
|
+
argument :d, Integer, required: true, prepare: :prep, as: :d2
|
54
|
+
argument :e, Integer, required: true, prepare: ->(val, ctx) { val * ctx[:multiply_by] * 2 }, as: :e2
|
55
|
+
|
56
|
+
def prep(val)
|
57
|
+
val * context[:multiply_by]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Query < GraphQL::Schema::Object
|
62
|
+
field :inputs, String, null: false do
|
63
|
+
argument :input, InputObj, required: true
|
64
|
+
end
|
65
|
+
|
66
|
+
def inputs(input:)
|
67
|
+
input.to_kwargs.inspect
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Schema < GraphQL::Schema
|
72
|
+
query(Query)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "calls methods on the input object" do
|
77
|
+
query_str = <<-GRAPHQL
|
78
|
+
{ inputs(input: { a: 1, b: 2, c: 3, d: 4, e: 5 }) }
|
79
|
+
GRAPHQL
|
80
|
+
|
81
|
+
res = InputObjectPrepareTest::Schema.execute(query_str, context: { multiply_by: 3 })
|
82
|
+
expected_obj = { a: 1, b2: 2, c: 9, d2: 12, e2: 30 }.inspect
|
83
|
+
assert_equal expected_obj, res["data"]["inputs"]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "in queries" do
|
88
|
+
it "is passed to the field method" do
|
89
|
+
query_str = <<-GRAPHQL
|
90
|
+
{
|
91
|
+
inspectInput(input: {
|
92
|
+
stringValue: "ABC",
|
93
|
+
legacyInput: { intValue: 4 },
|
94
|
+
nestedInput: { stringValue: "xyz"}
|
95
|
+
})
|
96
|
+
}
|
97
|
+
GRAPHQL
|
98
|
+
|
99
|
+
res = Jazz::Schema.execute(query_str, context: { message: "hi" })
|
100
|
+
expected_info = [
|
101
|
+
"Jazz::InspectableInput",
|
102
|
+
"hi, ABC, 4, (hi, xyz, -, (-))",
|
103
|
+
"ABC",
|
104
|
+
"ABC",
|
105
|
+
"true",
|
106
|
+
"ABC",
|
107
|
+
]
|
108
|
+
assert_equal expected_info, res["data"]["inspectInput"]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
module InstrumentationSpec
|
5
|
+
module SomeInterface
|
6
|
+
include GraphQL::Schema::Interface
|
7
|
+
field :never_called, String, null: false
|
8
|
+
|
9
|
+
def never_called
|
10
|
+
"should never be called"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class SomeType < GraphQL::Schema::Object
|
15
|
+
implements SomeInterface
|
16
|
+
end
|
17
|
+
|
18
|
+
class Query < GraphQL::Schema::Object
|
19
|
+
field :some_field, [SomeInterface], null: true
|
20
|
+
|
21
|
+
def some_field
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Schema < GraphQL::Schema
|
27
|
+
query Query
|
28
|
+
orphan_types [SomeType]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe GraphQL::Schema::Member::Instrumentation do
|
33
|
+
describe "resolving nullable interface lists to nil" do
|
34
|
+
let(:query) { "query { someField { neverCalled } }"}
|
35
|
+
it "returns nil instead of failing" do
|
36
|
+
result = InstrumentationSpec::Schema.execute(query)
|
37
|
+
assert_nil(result["someField"])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe GraphQL::Schema::Interface do
|
5
|
+
let(:interface) { Jazz::GloballyIdentifiableType }
|
6
|
+
|
7
|
+
describe "type info" do
|
8
|
+
it "tells its type info" do
|
9
|
+
assert_equal "GloballyIdentifiable", interface.graphql_name
|
10
|
+
assert_equal 2, interface.fields.size
|
11
|
+
end
|
12
|
+
|
13
|
+
module NewInterface1
|
14
|
+
include Jazz::GloballyIdentifiableType
|
15
|
+
end
|
16
|
+
|
17
|
+
module NewInterface2
|
18
|
+
include Jazz::GloballyIdentifiableType
|
19
|
+
def new_method
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can override methods" do
|
24
|
+
new_object_1 = Class.new(GraphQL::Schema::Object) do
|
25
|
+
implements NewInterface1
|
26
|
+
end
|
27
|
+
|
28
|
+
assert_equal 2, new_object_1.fields.size
|
29
|
+
assert new_object_1.method_defined?(:id)
|
30
|
+
|
31
|
+
new_object_2 = Class.new(GraphQL::Schema::Object) do
|
32
|
+
graphql_name "XYZ"
|
33
|
+
implements NewInterface2
|
34
|
+
field :id, "ID", null: false, description: "The ID !!!!!"
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_equal 2, new_object_2.fields.size
|
38
|
+
# It got the new method
|
39
|
+
assert new_object_2.method_defined?(:new_method)
|
40
|
+
# And the inherited method
|
41
|
+
assert new_object_2.method_defined?(:id)
|
42
|
+
|
43
|
+
# It gets an overridden description:
|
44
|
+
assert_equal "The ID !!!!!", new_object_2.graphql_definition.fields["id"].description
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ".to_graphql" do
|
49
|
+
it "creates an InterfaceType" do
|
50
|
+
interface_type = interface.to_graphql
|
51
|
+
assert_equal "GloballyIdentifiable", interface_type.name
|
52
|
+
field = interface_type.all_fields.first
|
53
|
+
assert_equal "id", field.name
|
54
|
+
assert_equal GraphQL::ID_TYPE.to_non_null_type, field.type
|
55
|
+
assert_equal "A unique identifier for this object", field.description
|
56
|
+
assert_nil interface_type.resolve_type_proc
|
57
|
+
assert_empty interface_type.orphan_types
|
58
|
+
end
|
59
|
+
|
60
|
+
it "can specify a resolve_type method" do
|
61
|
+
interface = Module.new do
|
62
|
+
include GraphQL::Schema::Interface
|
63
|
+
graphql_name "MyInterface"
|
64
|
+
|
65
|
+
module self::DefinitionMethods # rubocop:disable Style/ClassAndModuleChildren
|
66
|
+
def resolve_type(_object, _context)
|
67
|
+
"MyType"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
interface_type = interface.to_graphql
|
73
|
+
assert_equal "MyType", interface_type.resolve_type_proc.call(nil, nil)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "can specify orphan types" do
|
77
|
+
interface = Module.new do
|
78
|
+
include GraphQL::Schema::Interface
|
79
|
+
graphql_name "MyInterface"
|
80
|
+
orphan_types Dummy::CheeseType, Dummy::HoneyType
|
81
|
+
end
|
82
|
+
|
83
|
+
interface_type = interface.to_graphql
|
84
|
+
assert_equal [Dummy::CheeseType, Dummy::HoneyType], interface_type.orphan_types
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'supports global_id_field' do
|
89
|
+
object = Module.new do
|
90
|
+
include GraphQL::Schema::Interface
|
91
|
+
graphql_name 'GlobalIdFieldTest'
|
92
|
+
global_id_field :uuid
|
93
|
+
end.to_graphql
|
94
|
+
|
95
|
+
uuid_field = object.fields["uuid"]
|
96
|
+
|
97
|
+
assert_equal GraphQL::NonNullType, uuid_field.type.class
|
98
|
+
assert_equal GraphQL::ScalarType, uuid_field.type.unwrap.class
|
99
|
+
assert_equal(
|
100
|
+
GraphQL::Schema::Member::GraphQLTypeNames::ID,
|
101
|
+
uuid_field.type.unwrap.name
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "using `include`" do
|
106
|
+
it "raises" do
|
107
|
+
err = assert_raises RuntimeError do
|
108
|
+
Class.new(GraphQL::Schema::Object) do
|
109
|
+
include(Jazz::GloballyIdentifiableType)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
assert_includes err.message, "implements(Jazz::GloballyIdentifiableType)"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "in queries" do
|
118
|
+
it "works" do
|
119
|
+
query_str = <<-GRAPHQL
|
120
|
+
{
|
121
|
+
piano: find(id: "Instrument/Piano") {
|
122
|
+
id
|
123
|
+
upcasedId
|
124
|
+
... on Instrument {
|
125
|
+
family
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
GRAPHQL
|
130
|
+
|
131
|
+
res = Jazz::Schema.execute(query_str)
|
132
|
+
expected_piano = {
|
133
|
+
"id" => "Instrument/Piano",
|
134
|
+
"upcasedId" => "INSTRUMENT/PIANO",
|
135
|
+
"family" => "KEYS",
|
136
|
+
}
|
137
|
+
assert_equal(expected_piano, res["data"]["piano"])
|
138
|
+
end
|
139
|
+
|
140
|
+
it "applies custom field attributes" do
|
141
|
+
query_str = <<-GRAPHQL
|
142
|
+
{
|
143
|
+
find(id: "Ensemble/Bela Fleck and the Flecktones") {
|
144
|
+
upcasedId
|
145
|
+
... on Ensemble {
|
146
|
+
name
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
GRAPHQL
|
151
|
+
|
152
|
+
res = Jazz::Schema.execute(query_str)
|
153
|
+
expected_data = {
|
154
|
+
"upcasedId" => "ENSEMBLE/BELA FLECK AND THE FLECKTONES",
|
155
|
+
"name" => "Bela Fleck and the Flecktones"
|
156
|
+
}
|
157
|
+
assert_equal(expected_data, res["data"]["find"])
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe ':DefinitionMethods' do
|
162
|
+
module InterfaceA
|
163
|
+
include GraphQL::Schema::Interface
|
164
|
+
end
|
165
|
+
|
166
|
+
module InterfaceB
|
167
|
+
include GraphQL::Schema::Interface
|
168
|
+
end
|
169
|
+
|
170
|
+
module InterfaceC
|
171
|
+
include GraphQL::Schema::Interface
|
172
|
+
end
|
173
|
+
|
174
|
+
it "doesn't overwrite them when including multiple interfaces" do
|
175
|
+
def_methods = InterfaceC::DefinitionMethods
|
176
|
+
|
177
|
+
InterfaceC.module_eval do
|
178
|
+
include InterfaceA
|
179
|
+
include InterfaceB
|
180
|
+
end
|
181
|
+
|
182
|
+
assert_equal(InterfaceC::DefinitionMethods, def_methods)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe GraphQL::Schema::IntrospectionSystem do
|
5
|
+
describe "custom introspection" do
|
6
|
+
it "serves custom fields on types" do
|
7
|
+
res = Jazz::Schema.execute("{ __schema { isJazzy } }")
|
8
|
+
assert_equal true, res["data"]["__schema"]["isJazzy"]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "serves overridden fields on types" do
|
12
|
+
res = Jazz::Schema.execute(%|{ __type(name: "Ensemble") { name } }|)
|
13
|
+
assert_equal "ENSEMBLE", res["data"]["__type"]["name"]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "serves custom entry points" do
|
17
|
+
res = Jazz::Schema.execute("{ __classname }", root_value: Set.new)
|
18
|
+
assert_equal "Set", res["data"]["__classname"]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "serves custom dynamic fields" do
|
22
|
+
res = Jazz::Schema.execute("{ nowPlaying { __typename __typenameLength __astNodeClass } }")
|
23
|
+
assert_equal "Ensemble", res["data"]["nowPlaying"]["__typename"]
|
24
|
+
assert_equal 8, res["data"]["nowPlaying"]["__typenameLength"]
|
25
|
+
assert_equal "GraphQL::Language::Nodes::Field", res["data"]["nowPlaying"]["__astNodeClass"]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "doesn't affect other schemas" do
|
29
|
+
res = Dummy::Schema.execute("{ __schema { isJazzy } }")
|
30
|
+
assert_equal 1, res["errors"].length
|
31
|
+
|
32
|
+
res = Dummy::Schema.execute("{ __classname }", root_value: Set.new)
|
33
|
+
assert_equal 1, res["errors"].length
|
34
|
+
|
35
|
+
res = Dummy::Schema.execute("{ ensembles { __typenameLength } }")
|
36
|
+
assert_equal 1, res["errors"].length
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe GraphQL::Schema::Member::AcceptsDefinition do
|
5
|
+
class AcceptsDefinitionSchema < GraphQL::Schema
|
6
|
+
accepts_definition :set_metadata
|
7
|
+
set_metadata :a, 999
|
8
|
+
|
9
|
+
class BaseField < GraphQL::Schema::Field
|
10
|
+
class BaseField < GraphQL::Schema::Argument
|
11
|
+
accepts_definition :metadata
|
12
|
+
end
|
13
|
+
argument_class BaseField
|
14
|
+
accepts_definition :metadata
|
15
|
+
end
|
16
|
+
|
17
|
+
GraphQL::Schema::Object.accepts_definition(:metadata2)
|
18
|
+
|
19
|
+
class BaseObject < GraphQL::Schema::Object
|
20
|
+
field_class BaseField
|
21
|
+
accepts_definition :metadata
|
22
|
+
end
|
23
|
+
|
24
|
+
GraphQL::Schema::Interface.accepts_definition(:metadata2)
|
25
|
+
|
26
|
+
module BaseInterface
|
27
|
+
include GraphQL::Schema::Interface
|
28
|
+
field_class BaseField
|
29
|
+
accepts_definition :metadata
|
30
|
+
end
|
31
|
+
|
32
|
+
class Option < GraphQL::Schema::Enum
|
33
|
+
class EnumValue < GraphQL::Schema::EnumValue
|
34
|
+
accepts_definition :metadata
|
35
|
+
end
|
36
|
+
enum_value_class EnumValue
|
37
|
+
accepts_definition :metadata
|
38
|
+
metadata :a, 123
|
39
|
+
value "A", metadata: [:a, 456]
|
40
|
+
value "B"
|
41
|
+
end
|
42
|
+
|
43
|
+
module Thing
|
44
|
+
include BaseInterface
|
45
|
+
metadata :z, 888
|
46
|
+
metadata2 :a, :bc
|
47
|
+
end
|
48
|
+
|
49
|
+
module Thing2
|
50
|
+
include Thing
|
51
|
+
end
|
52
|
+
|
53
|
+
class SomeObject < BaseObject
|
54
|
+
metadata :a, :aaa
|
55
|
+
end
|
56
|
+
|
57
|
+
class SomeObject2 < SomeObject
|
58
|
+
end
|
59
|
+
|
60
|
+
class Query < BaseObject
|
61
|
+
metadata :a, :abc
|
62
|
+
metadata2 :xyz, :zyx
|
63
|
+
|
64
|
+
field :option, Option, null: false do
|
65
|
+
metadata :a, :def
|
66
|
+
argument :value, Integer, required: true, metadata: [:a, :ghi]
|
67
|
+
end
|
68
|
+
|
69
|
+
field :thing, Thing, null: false
|
70
|
+
field :thing2, Thing2, null: false
|
71
|
+
field :some_object, SomeObject, null: false
|
72
|
+
field :some_object2, SomeObject2, null: false
|
73
|
+
end
|
74
|
+
|
75
|
+
query(Query)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "passes along configs for types" do
|
79
|
+
assert_equal [:a, 123], AcceptsDefinitionSchema::Option.metadata
|
80
|
+
assert_equal 123, AcceptsDefinitionSchema::Option.graphql_definition.metadata[:a]
|
81
|
+
assert_equal [:a, :abc], AcceptsDefinitionSchema::Query.metadata
|
82
|
+
assert_equal :abc, AcceptsDefinitionSchema::Query.graphql_definition.metadata[:a]
|
83
|
+
assert_equal :zyx, AcceptsDefinitionSchema::Query.graphql_definition.metadata[:xyz]
|
84
|
+
|
85
|
+
assert_equal [:z, 888], AcceptsDefinitionSchema::Thing.metadata
|
86
|
+
assert_equal 888, AcceptsDefinitionSchema::Thing.graphql_definition.metadata[:z]
|
87
|
+
assert_equal :bc, AcceptsDefinitionSchema::Thing.graphql_definition.metadata[:a]
|
88
|
+
# Interface inheritance
|
89
|
+
assert_equal [:z, 888], AcceptsDefinitionSchema::Thing2.metadata
|
90
|
+
assert_equal 888, AcceptsDefinitionSchema::Thing2.graphql_definition.metadata[:z]
|
91
|
+
assert_equal :bc, AcceptsDefinitionSchema::Thing2.graphql_definition.metadata[:a]
|
92
|
+
|
93
|
+
# Object inheritance
|
94
|
+
assert_equal :aaa, AcceptsDefinitionSchema::SomeObject.graphql_definition.metadata[:a]
|
95
|
+
assert_equal :aaa, AcceptsDefinitionSchema::SomeObject2.graphql_definition.metadata[:a]
|
96
|
+
end
|
97
|
+
|
98
|
+
it "passes along configs for fields and arguments" do
|
99
|
+
assert_equal :def, AcceptsDefinitionSchema.find("Query.option").metadata[:a]
|
100
|
+
assert_equal :ghi, AcceptsDefinitionSchema.find("Query.option.value").metadata[:a]
|
101
|
+
end
|
102
|
+
|
103
|
+
it "passes along configs for enum values" do
|
104
|
+
assert_equal 456, AcceptsDefinitionSchema.find("Option.A").metadata[:a]
|
105
|
+
assert_nil AcceptsDefinitionSchema.find("Option.B").metadata[:a]
|
106
|
+
end
|
107
|
+
|
108
|
+
it "passes along configs for schemas" do
|
109
|
+
assert_equal 999, AcceptsDefinitionSchema.graphql_definition.metadata[:a]
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe GraphQL::Schema::Member::BuildType do
|
5
|
+
describe ".to_type_name" do
|
6
|
+
it "works with lists and non-nulls" do
|
7
|
+
t = Class.new(GraphQL::Schema::Object) do
|
8
|
+
graphql_name "T"
|
9
|
+
end
|
10
|
+
|
11
|
+
req_t = GraphQL::Schema::NonNull.new(t)
|
12
|
+
list_req_t = GraphQL::Schema::List.new(req_t)
|
13
|
+
|
14
|
+
assert_equal "T", GraphQL::Schema::Member::BuildType.to_type_name(list_req_t)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|