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
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
class Argument
|
5
|
+
include GraphQL::Schema::Member::CachedGraphQLDefinition
|
6
|
+
include GraphQL::Schema::Member::AcceptsDefinition
|
7
|
+
|
8
|
+
NO_DEFAULT = :__no_default__
|
9
|
+
|
10
|
+
# @return [String] the GraphQL name for this argument, camelized unless `camelize: false` is provided
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
# @return [GraphQL::Schema::Field, Class] The field or input object this argument belongs to
|
14
|
+
attr_reader :owner
|
15
|
+
|
16
|
+
# @return [Symbol] A method to call to transform this value before sending it to field resolution method
|
17
|
+
attr_reader :prepare
|
18
|
+
|
19
|
+
# @return [Symbol] This argument's name in Ruby keyword arguments
|
20
|
+
attr_reader :keyword
|
21
|
+
|
22
|
+
# @param arg_name [Symbol]
|
23
|
+
# @param type_expr
|
24
|
+
# @param desc [String]
|
25
|
+
# @param required [Boolean] if true, this argument is non-null; if false, this argument is nullable
|
26
|
+
# @param description [String]
|
27
|
+
# @param default_value [Object]
|
28
|
+
# @param as [Symbol] Override the keyword name when passed to a method
|
29
|
+
# @param prepare [Symbol] A method to call to tranform this argument's valuebefore sending it to field resolution
|
30
|
+
# @param camelize [Boolean] if true, the name will be camelized when building the schema
|
31
|
+
def initialize(arg_name = nil, type_expr = nil, desc = nil, required:, type: nil, name: nil, description: nil, default_value: NO_DEFAULT, as: nil, camelize: true, prepare: nil, owner:, &definition_block)
|
32
|
+
arg_name ||= name
|
33
|
+
@name = camelize ? Member::BuildType.camelize(arg_name.to_s) : arg_name.to_s
|
34
|
+
@type_expr = type_expr || type
|
35
|
+
@description = desc || description
|
36
|
+
@null = !required
|
37
|
+
@default_value = default_value
|
38
|
+
@owner = owner
|
39
|
+
@as = as
|
40
|
+
@keyword = as || Schema::Member::BuildType.underscore(@name).to_sym
|
41
|
+
@prepare = prepare
|
42
|
+
|
43
|
+
if definition_block
|
44
|
+
instance_eval(&definition_block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def description(text = nil)
|
49
|
+
if text
|
50
|
+
@description = text
|
51
|
+
else
|
52
|
+
@description
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_graphql
|
57
|
+
argument = GraphQL::Argument.new
|
58
|
+
argument.name = @name
|
59
|
+
argument.type = -> { type }
|
60
|
+
argument.description = @description
|
61
|
+
argument.metadata[:type_class] = self
|
62
|
+
argument.as = @as
|
63
|
+
if NO_DEFAULT != @default_value
|
64
|
+
argument.default_value = @default_value
|
65
|
+
end
|
66
|
+
argument
|
67
|
+
end
|
68
|
+
|
69
|
+
def type
|
70
|
+
@type ||= Member::BuildType.parse_type(@type_expr, null: @null)
|
71
|
+
rescue StandardError => err
|
72
|
+
raise ArgumentError, "Couldn't build type for Argument #{@owner.name}.#{name}: #{err.class.name}: #{err.message}", err.backtrace
|
73
|
+
end
|
74
|
+
|
75
|
+
# Apply the {prepare} configuration to `value`, using methods from `obj`.
|
76
|
+
# Used by the runtime.
|
77
|
+
# @api private
|
78
|
+
def prepare_value(obj, value)
|
79
|
+
case @prepare
|
80
|
+
when nil
|
81
|
+
value
|
82
|
+
when Symbol, String
|
83
|
+
obj.public_send(@prepare, value)
|
84
|
+
when Proc
|
85
|
+
@prepare.call(value, obj.context)
|
86
|
+
else
|
87
|
+
raise "Invalid prepare for #{@owner.name}.name: #{@prepare.inspect}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -107,6 +107,8 @@ module GraphQL
|
|
107
107
|
directives directives.values
|
108
108
|
end
|
109
109
|
|
110
|
+
schema.ast_node = schema_definition if schema_definition
|
111
|
+
|
110
112
|
schema
|
111
113
|
end
|
112
114
|
|
@@ -117,18 +119,26 @@ module GraphQL
|
|
117
119
|
NullScalarCoerce = ->(val, _ctx) { val }
|
118
120
|
|
119
121
|
def build_enum_type(enum_type_definition, type_resolver)
|
120
|
-
GraphQL::EnumType.define(
|
122
|
+
enum = GraphQL::EnumType.define(
|
121
123
|
name: enum_type_definition.name,
|
122
124
|
description: enum_type_definition.description,
|
123
125
|
values: enum_type_definition.values.map do |enum_value_definition|
|
124
|
-
EnumType::EnumValue.define(
|
126
|
+
value = EnumType::EnumValue.define(
|
125
127
|
name: enum_value_definition.name,
|
126
128
|
value: enum_value_definition.name,
|
127
129
|
deprecation_reason: build_deprecation_reason(enum_value_definition.directives),
|
128
130
|
description: enum_value_definition.description,
|
129
131
|
)
|
132
|
+
|
133
|
+
value.ast_node = enum_value_definition
|
134
|
+
|
135
|
+
value
|
130
136
|
end
|
131
137
|
)
|
138
|
+
|
139
|
+
enum.ast_node = enum_type_definition
|
140
|
+
|
141
|
+
enum
|
132
142
|
end
|
133
143
|
|
134
144
|
def build_deprecation_reason(directives)
|
@@ -148,6 +158,8 @@ module GraphQL
|
|
148
158
|
coerce: NullScalarCoerce,
|
149
159
|
)
|
150
160
|
|
161
|
+
scalar_type.ast_node = scalar_type_definition
|
162
|
+
|
151
163
|
if default_resolve.respond_to?(:coerce_input)
|
152
164
|
scalar_type = scalar_type.redefine(
|
153
165
|
coerce_input: ->(val, ctx) { default_resolve.coerce_input(scalar_type, val, ctx) },
|
@@ -159,11 +171,15 @@ module GraphQL
|
|
159
171
|
end
|
160
172
|
|
161
173
|
def build_union_type(union_type_definition, type_resolver)
|
162
|
-
GraphQL::UnionType.define(
|
174
|
+
union = GraphQL::UnionType.define(
|
163
175
|
name: union_type_definition.name,
|
164
176
|
description: union_type_definition.description,
|
165
177
|
possible_types: union_type_definition.types.map{ |type_name| type_resolver.call(type_name) },
|
166
178
|
)
|
179
|
+
|
180
|
+
union.ast_node = union_type_definition
|
181
|
+
|
182
|
+
union
|
167
183
|
end
|
168
184
|
|
169
185
|
def build_object_type(object_type_definition, type_resolver, default_resolve:)
|
@@ -175,14 +191,20 @@ module GraphQL
|
|
175
191
|
fields: Hash[build_fields(object_type_definition.fields, type_resolver, default_resolve: typed_resolve_fn)],
|
176
192
|
interfaces: object_type_definition.interfaces.map{ |interface_name| type_resolver.call(interface_name) },
|
177
193
|
)
|
194
|
+
type_def.ast_node = object_type_definition
|
195
|
+
type_def
|
178
196
|
end
|
179
197
|
|
180
198
|
def build_input_object_type(input_object_type_definition, type_resolver)
|
181
|
-
GraphQL::InputObjectType.define(
|
199
|
+
input = GraphQL::InputObjectType.define(
|
182
200
|
name: input_object_type_definition.name,
|
183
201
|
description: input_object_type_definition.description,
|
184
202
|
arguments: Hash[build_input_arguments(input_object_type_definition, type_resolver)],
|
185
203
|
)
|
204
|
+
|
205
|
+
input.ast_node = input_object_type_definition
|
206
|
+
|
207
|
+
input
|
186
208
|
end
|
187
209
|
|
188
210
|
def build_default_value(default_value)
|
@@ -191,6 +213,10 @@ module GraphQL
|
|
191
213
|
default_value.name
|
192
214
|
when GraphQL::Language::Nodes::NullValue
|
193
215
|
nil
|
216
|
+
when GraphQL::Language::Nodes::InputObject
|
217
|
+
default_value.to_h
|
218
|
+
when Array
|
219
|
+
default_value.map { |v| build_default_value(v) }
|
194
220
|
else
|
195
221
|
default_value
|
196
222
|
end
|
@@ -204,25 +230,33 @@ module GraphQL
|
|
204
230
|
kwargs[:default_value] = build_default_value(input_argument.default_value)
|
205
231
|
end
|
206
232
|
|
233
|
+
argument = GraphQL::Argument.define(
|
234
|
+
name: input_argument.name,
|
235
|
+
type: type_resolver.call(input_argument.type),
|
236
|
+
description: input_argument.description,
|
237
|
+
**kwargs,
|
238
|
+
)
|
239
|
+
|
240
|
+
argument.ast_node = input_argument
|
241
|
+
|
207
242
|
[
|
208
243
|
input_argument.name,
|
209
|
-
|
210
|
-
name: input_argument.name,
|
211
|
-
type: type_resolver.call(input_argument.type),
|
212
|
-
description: input_argument.description,
|
213
|
-
**kwargs,
|
214
|
-
)
|
244
|
+
argument
|
215
245
|
]
|
216
246
|
end
|
217
247
|
end
|
218
248
|
|
219
249
|
def build_directive(directive_definition, type_resolver)
|
220
|
-
GraphQL::Directive.define(
|
250
|
+
directive = GraphQL::Directive.define(
|
221
251
|
name: directive_definition.name,
|
222
252
|
description: directive_definition.description,
|
223
253
|
arguments: Hash[build_directive_arguments(directive_definition, type_resolver)],
|
224
254
|
locations: directive_definition.locations.map(&:to_sym),
|
225
255
|
)
|
256
|
+
|
257
|
+
directive.ast_node = directive_definition
|
258
|
+
|
259
|
+
directive
|
226
260
|
end
|
227
261
|
|
228
262
|
def build_directive_arguments(directive_definition, type_resolver)
|
@@ -233,24 +267,32 @@ module GraphQL
|
|
233
267
|
kwargs[:default_value] = build_default_value(directive_argument.default_value)
|
234
268
|
end
|
235
269
|
|
270
|
+
argument = GraphQL::Argument.define(
|
271
|
+
name: directive_argument.name,
|
272
|
+
type: type_resolver.call(directive_argument.type),
|
273
|
+
description: directive_argument.description,
|
274
|
+
**kwargs,
|
275
|
+
)
|
276
|
+
|
277
|
+
argument.ast_node = directive_argument
|
278
|
+
|
236
279
|
[
|
237
280
|
directive_argument.name,
|
238
|
-
|
239
|
-
name: directive_argument.name,
|
240
|
-
type: type_resolver.call(directive_argument.type),
|
241
|
-
description: directive_argument.description,
|
242
|
-
**kwargs,
|
243
|
-
)
|
281
|
+
argument
|
244
282
|
]
|
245
283
|
end
|
246
284
|
end
|
247
285
|
|
248
286
|
def build_interface_type(interface_type_definition, type_resolver)
|
249
|
-
GraphQL::InterfaceType.define(
|
287
|
+
interface = GraphQL::InterfaceType.define(
|
250
288
|
name: interface_type_definition.name,
|
251
289
|
description: interface_type_definition.description,
|
252
290
|
fields: Hash[build_fields(interface_type_definition.fields, type_resolver, default_resolve: nil)],
|
253
291
|
)
|
292
|
+
|
293
|
+
interface.ast_node = interface_type_definition
|
294
|
+
|
295
|
+
interface
|
254
296
|
end
|
255
297
|
|
256
298
|
def build_fields(field_definitions, type_resolver, default_resolve:)
|
@@ -269,6 +311,8 @@ module GraphQL
|
|
269
311
|
**kwargs,
|
270
312
|
)
|
271
313
|
|
314
|
+
arg.ast_node = argument
|
315
|
+
|
272
316
|
[argument.name, arg]
|
273
317
|
end]
|
274
318
|
|
@@ -281,6 +325,8 @@ module GraphQL
|
|
281
325
|
deprecation_reason: build_deprecation_reason(field_definition.directives),
|
282
326
|
)
|
283
327
|
|
328
|
+
field.ast_node = field_definition
|
329
|
+
|
284
330
|
type_name = resolve_type_name(field_definition.type)
|
285
331
|
field.connection = type_name.end_with?("Connection")
|
286
332
|
[field_definition.name, field]
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
# Extend this class to define GraphQL enums in your schema.
|
5
|
+
#
|
6
|
+
# By default, GraphQL enum values are translated into Ruby strings.
|
7
|
+
# You can provide a custom value with the `value:` keyword.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # equivalent to
|
11
|
+
# # enum PizzaTopping {
|
12
|
+
# # MUSHROOMS
|
13
|
+
# # ONIONS
|
14
|
+
# # PEPPERS
|
15
|
+
# # }
|
16
|
+
# class PizzaTopping < GraphQL::Enum
|
17
|
+
# value :MUSHROOMS
|
18
|
+
# value :ONIONS
|
19
|
+
# value :PEPPERS
|
20
|
+
# end
|
21
|
+
class Schema
|
22
|
+
class Enum < GraphQL::Schema::Member
|
23
|
+
extend GraphQL::Schema::Member::AcceptsDefinition
|
24
|
+
|
25
|
+
class << self
|
26
|
+
extend Forwardable
|
27
|
+
def_delegators :graphql_definition, :coerce_isolated_input, :coerce_isolated_result
|
28
|
+
|
29
|
+
# Define a value for this enum
|
30
|
+
# @param graphql_name [String, Symbol] the GraphQL value for this, usually `SCREAMING_CASE`
|
31
|
+
# @param description [String], the GraphQL description for this value, present in documentation
|
32
|
+
# @param value [Object], the translated Ruby value for this object (defaults to `graphql_name`)
|
33
|
+
# @param deprecation_reason [String] if this object is deprecated, include a message here
|
34
|
+
# @return [void]
|
35
|
+
# @see {Schema::EnumValue} which handles these inputs by default
|
36
|
+
def value(*args, **kwargs, &block)
|
37
|
+
kwargs[:owner] = self
|
38
|
+
value = enum_value_class.new(*args, **kwargs, &block)
|
39
|
+
own_values[value.graphql_name] = value
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [Hash<String => GraphQL::Schema::Enum::Value>] Possible values of this enum, keyed by name
|
44
|
+
def values
|
45
|
+
inherited_values = superclass <= GraphQL::Schema::Enum ? superclass.values : {}
|
46
|
+
# Local values take precedence over inherited ones
|
47
|
+
inherited_values.merge(own_values)
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [GraphQL::EnumType]
|
51
|
+
def to_graphql
|
52
|
+
enum_type = GraphQL::EnumType.new
|
53
|
+
enum_type.name = graphql_name
|
54
|
+
enum_type.description = description
|
55
|
+
enum_type.introspection = introspection
|
56
|
+
values.each do |name, val|
|
57
|
+
enum_type.add_value(val.to_graphql)
|
58
|
+
end
|
59
|
+
enum_type.metadata[:type_class] = self
|
60
|
+
enum_type
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Class] for handling `value(...)` inputs and building `GraphQL::Enum::EnumValue`s out of them
|
64
|
+
def enum_value_class(new_enum_value_class = nil)
|
65
|
+
if new_enum_value_class
|
66
|
+
@enum_value_class = new_enum_value_class
|
67
|
+
end
|
68
|
+
@enum_value_class || (superclass <= GraphQL::Schema::Enum ? superclass.enum_value_class : nil)
|
69
|
+
end
|
70
|
+
|
71
|
+
def kind
|
72
|
+
GraphQL::TypeKinds::ENUM
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def own_values
|
78
|
+
@own_values ||= {}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
enum_value_class(GraphQL::Schema::EnumValue)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
# A possible value for an {Enum}.
|
6
|
+
#
|
7
|
+
# You can extend this class to customize enum values in your schema.
|
8
|
+
#
|
9
|
+
# @example custom enum value class
|
10
|
+
# # define a custom class:
|
11
|
+
# class CustomEnumValue < GraphQL::Schema::EnumValue
|
12
|
+
# def initialize(*args)
|
13
|
+
# # arguments to `value(...)` in Enum classes are passed here
|
14
|
+
# super
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# def to_graphql
|
18
|
+
# enum_value = super
|
19
|
+
# # customize the derived GraphQL::EnumValue here
|
20
|
+
# enum_value
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# class BaseEnum < GraphQL::Schema::Enum
|
25
|
+
# # use it for these enums:
|
26
|
+
# enum_value_class CustomEnumValue
|
27
|
+
# end
|
28
|
+
class EnumValue < GraphQL::Schema::Member
|
29
|
+
include GraphQL::Schema::Member::AcceptsDefinition
|
30
|
+
|
31
|
+
attr_reader :graphql_name
|
32
|
+
|
33
|
+
# @return [Class] The enum type that owns this value
|
34
|
+
attr_reader :owner
|
35
|
+
|
36
|
+
def initialize(graphql_name, desc = nil, owner:, description: nil, value: nil, deprecation_reason: nil, &block)
|
37
|
+
@graphql_name = graphql_name.to_s
|
38
|
+
@description = desc || description
|
39
|
+
@value = value || @graphql_name
|
40
|
+
@deprecation_reason = deprecation_reason
|
41
|
+
@owner = owner
|
42
|
+
|
43
|
+
if block_given?
|
44
|
+
instance_eval(&block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def description(new_desc = nil)
|
49
|
+
if new_desc
|
50
|
+
@description = new_desc
|
51
|
+
end
|
52
|
+
@description
|
53
|
+
end
|
54
|
+
|
55
|
+
def value(new_val = nil)
|
56
|
+
if new_val
|
57
|
+
@value = new_val
|
58
|
+
end
|
59
|
+
@value
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return [GraphQL::EnumType::EnumValue] A runtime-ready object derived from this object
|
63
|
+
def to_graphql
|
64
|
+
enum_value = GraphQL::EnumType::EnumValue.new
|
65
|
+
enum_value.name = @graphql_name
|
66
|
+
enum_value.description = @description
|
67
|
+
enum_value.value = @value
|
68
|
+
enum_value.deprecation_reason = @deprecation_reason
|
69
|
+
enum_value.metadata[:type_class] = self
|
70
|
+
enum_value
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|