graphql 1.7.6 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +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
@@ -41,10 +41,10 @@ describe GraphQL::Tracing::PlatformTracing do
|
|
41
41
|
schema.execute(" { cheese(id: 1) { flavor } }")
|
42
42
|
expected_trace = [
|
43
43
|
"em",
|
44
|
-
"am",
|
45
44
|
"l",
|
46
45
|
"p",
|
47
46
|
"v",
|
47
|
+
"am",
|
48
48
|
"aq",
|
49
49
|
"eq",
|
50
50
|
"Q.c", # notice that the flavor is skipped
|
@@ -53,4 +53,63 @@ describe GraphQL::Tracing::PlatformTracing do
|
|
53
53
|
assert_equal expected_trace, CustomPlatformTracer::TRACE
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
describe "by default, scalar fields are not traced" do
|
58
|
+
let(:schema) {
|
59
|
+
Dummy::Schema.redefine {
|
60
|
+
use(CustomPlatformTracer)
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
before do
|
65
|
+
CustomPlatformTracer::TRACE.clear
|
66
|
+
end
|
67
|
+
|
68
|
+
it "only traces traceTrue, not traceFalse or traceNil" do
|
69
|
+
schema.execute(" { tracingScalar { traceNil traceFalse traceTrue } }")
|
70
|
+
expected_trace = [
|
71
|
+
"em",
|
72
|
+
"l",
|
73
|
+
"p",
|
74
|
+
"v",
|
75
|
+
"am",
|
76
|
+
"aq",
|
77
|
+
"eq",
|
78
|
+
"Q.t",
|
79
|
+
"T.t",
|
80
|
+
"eql",
|
81
|
+
]
|
82
|
+
assert_equal expected_trace, CustomPlatformTracer::TRACE
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "when scalar fields are traced by default, they are unless specified" do
|
87
|
+
let(:schema) {
|
88
|
+
Dummy::Schema.redefine {
|
89
|
+
use(CustomPlatformTracer, trace_scalars: true)
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
before do
|
94
|
+
CustomPlatformTracer::TRACE.clear
|
95
|
+
end
|
96
|
+
|
97
|
+
it "traces traceTrue and traceNil but not traceFalse" do
|
98
|
+
schema.execute(" { tracingScalar { traceNil traceFalse traceTrue } }")
|
99
|
+
expected_trace = [
|
100
|
+
"em",
|
101
|
+
"l",
|
102
|
+
"p",
|
103
|
+
"v",
|
104
|
+
"am",
|
105
|
+
"aq",
|
106
|
+
"eq",
|
107
|
+
"Q.t",
|
108
|
+
"T.t",
|
109
|
+
"T.t",
|
110
|
+
"eql",
|
111
|
+
]
|
112
|
+
assert_equal expected_trace, CustomPlatformTracer::TRACE
|
113
|
+
end
|
114
|
+
end
|
56
115
|
end
|
@@ -150,7 +150,7 @@ describe GraphQL::UnionType do
|
|
150
150
|
end
|
151
151
|
|
152
152
|
describe "#dup" do
|
153
|
-
it "copies possible types without affecting the
|
153
|
+
it "copies possible types without affecting the original" do
|
154
154
|
union.possible_types # load the internal cache
|
155
155
|
union_2 = union.dup
|
156
156
|
union_2.possible_types << type_3
|
@@ -0,0 +1,516 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require './lib/graphql/upgrader/member.rb'
|
5
|
+
|
6
|
+
describe GraphQL::Upgrader::Member do
|
7
|
+
def upgrade(old)
|
8
|
+
GraphQL::Upgrader::Member.new(old).upgrade
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'field arguments' do
|
12
|
+
it 'upgrades' do
|
13
|
+
old = %{argument :status, !TodoStatus, "Restrict items to this status"}
|
14
|
+
new = %{argument :status, TodoStatus, "Restrict items to this status", required: true}
|
15
|
+
|
16
|
+
assert_equal new, upgrade(old)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "property / method upgrade" do
|
21
|
+
it 'upgrades the property definition to method' do
|
22
|
+
old = %{field :name, String, property: :full_name}
|
23
|
+
new = %{field :name, String, method: :full_name, null: true}
|
24
|
+
|
25
|
+
assert_equal new, upgrade(old)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'upgrades the property definition in a block to method' do
|
29
|
+
old = %{field :name, String do\n property :full_name\nend}
|
30
|
+
new = %{field :name, String, method: :full_name, null: true}
|
31
|
+
assert_equal new, upgrade(old)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "removes property when redundant" do
|
35
|
+
old = %{field :name, String do\n property "name" \nend}
|
36
|
+
new = %{field :name, String, null: true}
|
37
|
+
assert_equal new, upgrade(old)
|
38
|
+
|
39
|
+
old = %{field :name, String, property: :name}
|
40
|
+
new = %{field :name, String, null: true}
|
41
|
+
assert_equal new, upgrade(old)
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "hash_key" do
|
47
|
+
it "it moves configuration to kwarg" do
|
48
|
+
old = %{field :name, String do\n hash_key :full_name\nend}
|
49
|
+
new = %{field :name, String, hash_key: :full_name, null: true}
|
50
|
+
assert_equal new, upgrade(old)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "removes it if it's redundant" do
|
54
|
+
old = %{field :name, String do\n hash_key :name\nend}
|
55
|
+
new = %{field :name, String, null: true}
|
56
|
+
assert_equal new, upgrade(old)
|
57
|
+
|
58
|
+
old = %{field :name, String, hash_key: :name}
|
59
|
+
new = %{field :name, String, null: true}
|
60
|
+
assert_equal new, upgrade(old)
|
61
|
+
|
62
|
+
old = %{field :name, String do\n hash_key "name"\nend}
|
63
|
+
new = %{field :name, String, null: true}
|
64
|
+
assert_equal new, upgrade(old)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'name' do
|
69
|
+
it 'removes the name field if it can be inferred from the class' do
|
70
|
+
old = %{
|
71
|
+
UserType = GraphQL::ObjectType.define do
|
72
|
+
name "User"
|
73
|
+
end
|
74
|
+
}
|
75
|
+
new = %{
|
76
|
+
class UserType < Types::BaseObject
|
77
|
+
end
|
78
|
+
}
|
79
|
+
assert_equal new, upgrade(old)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'removes the name field if it can be inferred from the class and under a module' do
|
83
|
+
old = %{
|
84
|
+
Types::UserType = GraphQL::ObjectType.define do
|
85
|
+
name "User"
|
86
|
+
end
|
87
|
+
}
|
88
|
+
new = %{
|
89
|
+
class Types::UserType < Types::BaseObject
|
90
|
+
end
|
91
|
+
}
|
92
|
+
assert_equal new, upgrade(old)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'upgrades the name into graphql_name if it can\'t be inferred from the class' do
|
96
|
+
old = %{
|
97
|
+
TeamType = GraphQL::ObjectType.define do
|
98
|
+
name "User"
|
99
|
+
end
|
100
|
+
}
|
101
|
+
new = %{
|
102
|
+
class TeamType < Types::BaseObject
|
103
|
+
graphql_name "User"
|
104
|
+
end
|
105
|
+
}
|
106
|
+
assert_equal new, upgrade(old)
|
107
|
+
|
108
|
+
old = %{
|
109
|
+
UserInterface = GraphQL::InterfaceType.define do
|
110
|
+
name "User"
|
111
|
+
end
|
112
|
+
}
|
113
|
+
new = %{
|
114
|
+
module UserInterface
|
115
|
+
include Types::BaseInterface
|
116
|
+
graphql_name "User"
|
117
|
+
end
|
118
|
+
}
|
119
|
+
|
120
|
+
assert_equal new, upgrade(old)
|
121
|
+
|
122
|
+
old = %{
|
123
|
+
UserEnum = GraphQL::EnumType.define do
|
124
|
+
name "User"
|
125
|
+
end
|
126
|
+
}
|
127
|
+
new = %{
|
128
|
+
class UserEnum < Types::BaseEnum
|
129
|
+
graphql_name "User"
|
130
|
+
end
|
131
|
+
}
|
132
|
+
assert_equal new, upgrade(old)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe 'definition' do
|
137
|
+
it 'upgrades the .define into class based definition' do
|
138
|
+
old = %{UserType = GraphQL::ObjectType.define do
|
139
|
+
end}
|
140
|
+
new = %{class UserType < Types::BaseObject
|
141
|
+
end}
|
142
|
+
assert_equal new, upgrade(old)
|
143
|
+
|
144
|
+
old = <<-RUBY
|
145
|
+
UserInterface = GraphQL::InterfaceType.define do
|
146
|
+
end
|
147
|
+
RUBY
|
148
|
+
new = <<-RUBY
|
149
|
+
module UserInterface
|
150
|
+
include Types::BaseInterface
|
151
|
+
end
|
152
|
+
RUBY
|
153
|
+
|
154
|
+
assert_equal new, upgrade(old)
|
155
|
+
|
156
|
+
old = %{UserUnion = GraphQL::UnionType.define do
|
157
|
+
end}
|
158
|
+
new = %{class UserUnion < Types::BaseUnion
|
159
|
+
end}
|
160
|
+
assert_equal new, upgrade(old)
|
161
|
+
|
162
|
+
old = %{UserEnum = GraphQL::EnumType.define do
|
163
|
+
end}
|
164
|
+
new = %{class UserEnum < Types::BaseEnum
|
165
|
+
end}
|
166
|
+
assert_equal new, upgrade(old)
|
167
|
+
|
168
|
+
old = %{UserInput = GraphQL::InputObjectType.define do
|
169
|
+
end}
|
170
|
+
new = %{class UserInput < Types::BaseInputObject
|
171
|
+
end}
|
172
|
+
assert_equal new, upgrade(old)
|
173
|
+
|
174
|
+
old = %{UserScalar = GraphQL::ScalarType.define do
|
175
|
+
end}
|
176
|
+
new = %{class UserScalar < Types::BaseScalar
|
177
|
+
end}
|
178
|
+
assert_equal new, upgrade(old)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'upgrades including the module' do
|
182
|
+
old = %{Module::UserType = GraphQL::ObjectType.define do
|
183
|
+
end}
|
184
|
+
new = %{class Module::UserType < Types::BaseObject
|
185
|
+
end}
|
186
|
+
assert_equal new, upgrade(old)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe 'fields' do
|
191
|
+
it 'underscorizes field name' do
|
192
|
+
old = %{field :firstName, !types.String}
|
193
|
+
new = %{field :first_name, String, null: false}
|
194
|
+
assert_equal new, upgrade(old)
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "resolve proc to method" do
|
198
|
+
it "converts @object and @context" do
|
199
|
+
old = %{
|
200
|
+
field :firstName, !types.String do
|
201
|
+
resolve ->(obj, arg, ctx) {
|
202
|
+
ctx.something
|
203
|
+
other_ctx # test combined identifiers
|
204
|
+
|
205
|
+
obj[ctx] + obj
|
206
|
+
obj.given_name
|
207
|
+
}
|
208
|
+
end
|
209
|
+
}
|
210
|
+
new = %{
|
211
|
+
field :first_name, String, null: false
|
212
|
+
|
213
|
+
def first_name
|
214
|
+
@context.something
|
215
|
+
other_ctx # test combined identifiers
|
216
|
+
|
217
|
+
@object[@context] + @object
|
218
|
+
@object.given_name
|
219
|
+
end
|
220
|
+
}
|
221
|
+
assert_equal new, upgrade(old)
|
222
|
+
end
|
223
|
+
|
224
|
+
it "handles `_` var names" do
|
225
|
+
old = %{
|
226
|
+
field :firstName, !types.String do
|
227
|
+
resolve ->(obj, _, _) {
|
228
|
+
obj.given_name
|
229
|
+
}
|
230
|
+
end
|
231
|
+
}
|
232
|
+
new = %{
|
233
|
+
field :first_name, String, null: false
|
234
|
+
|
235
|
+
def first_name
|
236
|
+
@object.given_name
|
237
|
+
end
|
238
|
+
}
|
239
|
+
assert_equal new, upgrade(old)
|
240
|
+
end
|
241
|
+
|
242
|
+
it "creates **arguments if necessary" do
|
243
|
+
old = %{
|
244
|
+
field :firstName, !types.String do
|
245
|
+
argument :ctx, types.String, default_value: "abc"
|
246
|
+
resolve ->(obj, args, ctx) {
|
247
|
+
args[:ctx]
|
248
|
+
}
|
249
|
+
end
|
250
|
+
}
|
251
|
+
new = %{
|
252
|
+
field :first_name, String, null: false do
|
253
|
+
argument :ctx, String, default_value: "abc", required: false
|
254
|
+
end
|
255
|
+
|
256
|
+
def first_name(**args)
|
257
|
+
args[:ctx]
|
258
|
+
end
|
259
|
+
}
|
260
|
+
assert_equal new, upgrade(old)
|
261
|
+
end
|
262
|
+
|
263
|
+
it "fixes argument access: string -> sym, camel -> underscore" do
|
264
|
+
old = %{
|
265
|
+
field :firstName, !types.String do
|
266
|
+
argument :someArg, types.String, default_value: "abc"
|
267
|
+
argument :someArg2, types.String, default_value: "abc"
|
268
|
+
resolve ->(obj, args, ctx) {
|
269
|
+
args["someArg"] if args.key?("someArg")
|
270
|
+
args[:someArg2]
|
271
|
+
}
|
272
|
+
end
|
273
|
+
}
|
274
|
+
new = %{
|
275
|
+
field :first_name, String, null: false do
|
276
|
+
argument :some_arg, String, default_value: "abc", required: false
|
277
|
+
argument :some_arg2, String, default_value: "abc", required: false
|
278
|
+
end
|
279
|
+
|
280
|
+
def first_name(**args)
|
281
|
+
args[:some_arg] if args.key?(:some_arg)
|
282
|
+
args[:some_arg2]
|
283
|
+
end
|
284
|
+
}
|
285
|
+
assert_equal new, upgrade(old)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
|
290
|
+
it 'upgrades to the new definition' do
|
291
|
+
old = %{field :name, !types.String}
|
292
|
+
new = %{field :name, String, null: false}
|
293
|
+
assert_equal new, upgrade(old)
|
294
|
+
|
295
|
+
old = %{field :name, !types.String, "description", method: :name_full}
|
296
|
+
new = %{field :name, String, "description", method: :name_full, null: false}
|
297
|
+
assert_equal new, upgrade(old)
|
298
|
+
|
299
|
+
old = %{field :name, -> { !types.String }}
|
300
|
+
new = %{field :name, String, null: false}
|
301
|
+
assert_equal new, upgrade(old)
|
302
|
+
|
303
|
+
old = %{connection :name, Name.connection_type, "names"}
|
304
|
+
new = %{field :name, Name.connection_type, "names", null: true, connection: true}
|
305
|
+
assert_equal new, upgrade(old)
|
306
|
+
|
307
|
+
old = %{connection :name, !Name.connection_type, "names"}
|
308
|
+
new = %{field :name, Name.connection_type, "names", null: false, connection: true}
|
309
|
+
assert_equal new, upgrade(old)
|
310
|
+
|
311
|
+
old = %{field :names, types[!types.String]}
|
312
|
+
new = %{field :names, [String], null: true}
|
313
|
+
assert_equal new, upgrade(old)
|
314
|
+
|
315
|
+
old = %{field :names, !types[types.String]}
|
316
|
+
new = %{field :names, [String, null: true], null: false}
|
317
|
+
assert_equal new, upgrade(old)
|
318
|
+
|
319
|
+
old = %{
|
320
|
+
field :name, types.String do
|
321
|
+
end
|
322
|
+
}
|
323
|
+
new = %{
|
324
|
+
field :name, String, null: true
|
325
|
+
}
|
326
|
+
assert_equal new, upgrade(old)
|
327
|
+
|
328
|
+
old = %{
|
329
|
+
field :name, !types.String do
|
330
|
+
description "abc"
|
331
|
+
end
|
332
|
+
|
333
|
+
field :name2, !types.Int do
|
334
|
+
description "def"
|
335
|
+
end
|
336
|
+
}
|
337
|
+
new = %{
|
338
|
+
field :name, String, description: "abc", null: false
|
339
|
+
|
340
|
+
field :name2, Integer, description: "def", null: false
|
341
|
+
}
|
342
|
+
assert_equal new, upgrade(old)
|
343
|
+
|
344
|
+
old = %{
|
345
|
+
field :name, -> { !types.String } do
|
346
|
+
end
|
347
|
+
}
|
348
|
+
new = %{
|
349
|
+
field :name, String, null: false
|
350
|
+
}
|
351
|
+
assert_equal new, upgrade(old)
|
352
|
+
|
353
|
+
old = %{
|
354
|
+
field :name do
|
355
|
+
type -> { String }
|
356
|
+
end
|
357
|
+
}
|
358
|
+
new = %{
|
359
|
+
field :name, String, null: true
|
360
|
+
}
|
361
|
+
assert_equal new, upgrade(old)
|
362
|
+
|
363
|
+
old = %{
|
364
|
+
field :name do
|
365
|
+
type !String
|
366
|
+
end
|
367
|
+
|
368
|
+
field :name2 do
|
369
|
+
type !String
|
370
|
+
end
|
371
|
+
}
|
372
|
+
new = %{
|
373
|
+
field :name, String, null: false
|
374
|
+
|
375
|
+
field :name2, String, null: false
|
376
|
+
}
|
377
|
+
assert_equal new, upgrade(old)
|
378
|
+
|
379
|
+
old = %{
|
380
|
+
field :name, -> { types.String },
|
381
|
+
"newline description" do
|
382
|
+
end
|
383
|
+
}
|
384
|
+
new = %{
|
385
|
+
field :name, String, "newline description", null: true
|
386
|
+
}
|
387
|
+
assert_equal new, upgrade(old)
|
388
|
+
|
389
|
+
old = %{
|
390
|
+
field :name, -> { !types.String },
|
391
|
+
"newline description" do
|
392
|
+
end
|
393
|
+
}
|
394
|
+
new = %{
|
395
|
+
field :name, String, "newline description", null: false
|
396
|
+
}
|
397
|
+
assert_equal new, upgrade(old)
|
398
|
+
|
399
|
+
old = %{
|
400
|
+
field :name, String,
|
401
|
+
field: SomeField do
|
402
|
+
end
|
403
|
+
}
|
404
|
+
new = %{
|
405
|
+
field :name, String, field: SomeField, null: true
|
406
|
+
}
|
407
|
+
assert_equal new, upgrade(old)
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
describe 'multi-line field with property/method' do
|
412
|
+
it 'upgrades without breaking syntax' do
|
413
|
+
old = %{
|
414
|
+
field :is_example_field, types.Boolean,
|
415
|
+
property: :example_field?
|
416
|
+
}
|
417
|
+
new = %{
|
418
|
+
field :is_example_field, Boolean, method: :example_field?, null: true
|
419
|
+
}
|
420
|
+
|
421
|
+
assert_equal new, upgrade(old)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
describe 'multi-line connection with property/method' do
|
426
|
+
it 'upgrades without breaking syntax' do
|
427
|
+
old = %{
|
428
|
+
connection :example_connection, -> { ExampleConnectionType },
|
429
|
+
property: :example_connections
|
430
|
+
}
|
431
|
+
new = %{
|
432
|
+
field :example_connection, ExampleConnectionType, method: :example_connections, null: true, connection: true
|
433
|
+
}
|
434
|
+
|
435
|
+
assert_equal new, upgrade(old)
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
describe 'input_field' do
|
440
|
+
it 'upgrades to argument' do
|
441
|
+
old = %{input_field :id, !types.ID}
|
442
|
+
new = %{argument :id, ID, required: true}
|
443
|
+
assert_equal new, upgrade(old)
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
describe 'implements' do
|
448
|
+
it 'upgrades interfaces to implements' do
|
449
|
+
old = %{
|
450
|
+
interfaces [Types::SearchableType, Types::CommentableType]
|
451
|
+
interfaces [Types::ShareableType]
|
452
|
+
}
|
453
|
+
new = %{
|
454
|
+
implements Types::SearchableType
|
455
|
+
implements Types::CommentableType
|
456
|
+
implements Types::ShareableType
|
457
|
+
}
|
458
|
+
assert_equal new, upgrade(old)
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
describe "fixtures" do
|
463
|
+
class ActiveRecordTypeToClassTransform < GraphQL::Upgrader::Transform
|
464
|
+
def initialize
|
465
|
+
@find_pattern = /^( +)([a-zA-Z_0-9:]*) = define_active_record_type\(-> ?\{ ?:{0,2}([a-zA-Z_0-9:]*) ?\} ?\) do/
|
466
|
+
@replace_pattern = "\\1class \\2 < Platform::Objects::Base\n\\1 model_name \"\\3\""
|
467
|
+
end
|
468
|
+
|
469
|
+
def apply(input_text)
|
470
|
+
input_text.sub(@find_pattern, @replace_pattern)
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
# Modify the default output to match the custom structure
|
475
|
+
class InputObjectsToInputsTransform < GraphQL::Upgrader::Transform
|
476
|
+
def apply(input_text)
|
477
|
+
input_text.gsub("Platform::InputObjects::", "Platform::Inputs::")
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
def custom_upgrade(original_text)
|
482
|
+
# Replace the default one with a custom one:
|
483
|
+
type_transforms = GraphQL::Upgrader::Member::DEFAULT_TYPE_TRANSFORMS.map { |t|
|
484
|
+
if t == GraphQL::Upgrader::TypeDefineToClassTransform
|
485
|
+
GraphQL::Upgrader::TypeDefineToClassTransform.new(base_class_pattern: "Platform::\\3s::Base")
|
486
|
+
else
|
487
|
+
t
|
488
|
+
end
|
489
|
+
}
|
490
|
+
|
491
|
+
type_transforms.unshift(ActiveRecordTypeToClassTransform)
|
492
|
+
type_transforms.push(InputObjectsToInputsTransform)
|
493
|
+
field_transforms = GraphQL::Upgrader::Member::DEFAULT_FIELD_TRANSFORMS.dup
|
494
|
+
field_transforms.unshift(GraphQL::Upgrader::ConfigurationToKwargTransform.new(kwarg: "visibility"))
|
495
|
+
upgrader = GraphQL::Upgrader::Member.new(original_text, type_transforms: type_transforms, field_transforms: field_transforms)
|
496
|
+
upgrader.upgrade
|
497
|
+
end
|
498
|
+
|
499
|
+
original_files = Dir.glob("spec/fixtures/upgrader/*.original.rb")
|
500
|
+
original_files.each do |original_file|
|
501
|
+
transformed_file = original_file.sub(".original.", ".transformed.")
|
502
|
+
original_text = File.read(original_file)
|
503
|
+
expected_text = File.read(transformed_file)
|
504
|
+
|
505
|
+
it "transforms #{original_file} -> #{transformed_file}" do
|
506
|
+
transformed_text = custom_upgrade(original_text)
|
507
|
+
assert_equal(expected_text, transformed_text)
|
508
|
+
end
|
509
|
+
|
510
|
+
it "is idempotent on #{transformed_file}" do
|
511
|
+
retransformed_text = custom_upgrade(expected_text)
|
512
|
+
assert_equal(expected_text, retransformed_text)
|
513
|
+
end
|
514
|
+
end
|
515
|
+
end
|
516
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require './lib/graphql/upgrader/schema.rb'
|
5
|
+
|
6
|
+
describe GraphQL::Upgrader::Schema do
|
7
|
+
def upgrade(old)
|
8
|
+
GraphQL::Upgrader::Schema.new(old).upgrade
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'updates the definition' do
|
12
|
+
old = %{
|
13
|
+
StarWarsSchema = GraphQL::Schema.define do
|
14
|
+
end
|
15
|
+
}
|
16
|
+
new = %{
|
17
|
+
class StarWarsSchema < GraphQL::Schema
|
18
|
+
end
|
19
|
+
}
|
20
|
+
|
21
|
+
assert_equal upgrade(old), new
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'updates the resolve_type' do
|
25
|
+
old = %{
|
26
|
+
StarWarsSchema = GraphQL::Schema.define do
|
27
|
+
resolve_type ->(obj, ctx) do
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
}
|
32
|
+
new = %{
|
33
|
+
class StarWarsSchema < GraphQL::Schema
|
34
|
+
def self.resolve_type(obj, ctx)
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
}
|
39
|
+
|
40
|
+
assert_equal upgrade(old), new
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'updates the object_from_id' do
|
44
|
+
old = %{
|
45
|
+
StarWarsSchema = GraphQL::Schema.define do
|
46
|
+
object_from_id ->(id, ctx) do
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
}
|
51
|
+
new = %{
|
52
|
+
class StarWarsSchema < GraphQL::Schema
|
53
|
+
def self.object_from_id(id, ctx)
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
}
|
58
|
+
|
59
|
+
assert_equal upgrade(old), new
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'updates the id_from_object' do
|
63
|
+
old = %{
|
64
|
+
StarWarsSchema = GraphQL::Schema.define do
|
65
|
+
id_from_object -> (object, type_definition, ctx) do
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
}
|
70
|
+
new = %{
|
71
|
+
class StarWarsSchema < GraphQL::Schema
|
72
|
+
def self.id_from_object(object, type_definition, ctx)
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
}
|
77
|
+
|
78
|
+
assert_equal upgrade(old), new
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,6 +16,7 @@ if rails_should_be_installed?
|
|
16
16
|
require "jdbc/sqlite3" if RUBY_ENGINE == 'jruby'
|
17
17
|
require "sqlite3" if RUBY_ENGINE == 'ruby'
|
18
18
|
require "pg" if RUBY_ENGINE == 'ruby'
|
19
|
+
require "mongoid" if RUBY_ENGINE == 'ruby'
|
19
20
|
require "sequel"
|
20
21
|
end
|
21
22
|
|
@@ -38,7 +39,9 @@ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
|
38
39
|
# This is for convenient access to metadata in test definitions
|
39
40
|
assign_metadata_key = ->(target, key, value) { target.metadata[key] = value }
|
40
41
|
assign_metadata_flag = ->(target, flag) { target.metadata[flag] = true }
|
42
|
+
GraphQL::Schema.accepts_definitions(set_metadata: assign_metadata_key)
|
41
43
|
GraphQL::BaseType.accepts_definitions(metadata: assign_metadata_key)
|
44
|
+
GraphQL::BaseType.accepts_definitions(metadata2: assign_metadata_key)
|
42
45
|
GraphQL::Field.accepts_definitions(metadata: assign_metadata_key)
|
43
46
|
GraphQL::Argument.accepts_definitions(metadata: assign_metadata_key)
|
44
47
|
GraphQL::Argument.accepts_definitions(metadata_flag: assign_metadata_flag)
|
@@ -61,11 +64,16 @@ NO_OP_RESOLVE_TYPE = ->(type, obj, ctx) {
|
|
61
64
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
|
62
65
|
unless rails_should_be_installed?
|
63
66
|
next if f.end_with?('star_wars/data.rb')
|
67
|
+
next if f.end_with?('star_trek/data.rb')
|
64
68
|
next if f.end_with?('base_generator_test.rb')
|
65
69
|
end
|
66
70
|
require f
|
67
71
|
end
|
68
72
|
|
73
|
+
def star_trek_query(string, variables={}, context: {})
|
74
|
+
StarTrek::Schema.execute(string, variables: variables, context: context)
|
75
|
+
end
|
76
|
+
|
69
77
|
def star_wars_query(string, variables={}, context: {})
|
70
78
|
StarWars::Schema.execute(string, variables: variables, context: context)
|
71
79
|
end
|