graphql 0.16.0 → 2.0.15
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.
Potentially problematic release.
This version of graphql might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.yardopts +5 -0
- data/lib/generators/graphql/core.rb +69 -0
- data/lib/generators/graphql/enum_generator.rb +27 -0
- data/lib/generators/graphql/field_extractor.rb +31 -0
- data/lib/generators/graphql/input_generator.rb +50 -0
- data/lib/generators/graphql/install/mutation_root_generator.rb +34 -0
- data/lib/generators/graphql/install/templates/base_mutation.erb +10 -0
- data/lib/generators/graphql/install/templates/mutation_type.erb +12 -0
- data/lib/generators/graphql/install_generator.rb +197 -0
- data/lib/generators/graphql/interface_generator.rb +27 -0
- data/lib/generators/graphql/loader_generator.rb +21 -0
- data/lib/generators/graphql/mutation_create_generator.rb +22 -0
- data/lib/generators/graphql/mutation_delete_generator.rb +22 -0
- data/lib/generators/graphql/mutation_generator.rb +30 -0
- data/lib/generators/graphql/mutation_update_generator.rb +22 -0
- data/lib/generators/graphql/object_generator.rb +50 -0
- data/lib/generators/graphql/orm_mutations_base.rb +40 -0
- data/lib/generators/graphql/relay.rb +49 -0
- data/lib/generators/graphql/relay_generator.rb +21 -0
- data/lib/generators/graphql/scalar_generator.rb +22 -0
- data/lib/generators/graphql/templates/base_argument.erb +6 -0
- data/lib/generators/graphql/templates/base_connection.erb +8 -0
- data/lib/generators/graphql/templates/base_edge.erb +8 -0
- data/lib/generators/graphql/templates/base_enum.erb +6 -0
- data/lib/generators/graphql/templates/base_field.erb +7 -0
- data/lib/generators/graphql/templates/base_input_object.erb +7 -0
- data/lib/generators/graphql/templates/base_interface.erb +9 -0
- data/lib/generators/graphql/templates/base_object.erb +7 -0
- data/lib/generators/graphql/templates/base_scalar.erb +6 -0
- data/lib/generators/graphql/templates/base_union.erb +6 -0
- data/lib/generators/graphql/templates/enum.erb +11 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +52 -0
- data/lib/generators/graphql/templates/input.erb +9 -0
- data/lib/generators/graphql/templates/interface.erb +10 -0
- data/lib/generators/graphql/templates/loader.erb +19 -0
- data/lib/generators/graphql/templates/mutation.erb +16 -0
- data/lib/generators/graphql/templates/mutation_create.erb +20 -0
- data/lib/generators/graphql/templates/mutation_delete.erb +20 -0
- data/lib/generators/graphql/templates/mutation_update.erb +21 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +10 -0
- data/lib/generators/graphql/templates/query_type.erb +15 -0
- data/lib/generators/graphql/templates/scalar.erb +17 -0
- data/lib/generators/graphql/templates/schema.erb +30 -0
- data/lib/generators/graphql/templates/union.erb +9 -0
- data/lib/generators/graphql/type_generator.rb +135 -0
- data/lib/generators/graphql/union_generator.rb +33 -0
- data/lib/graphql/analysis/ast/analyzer.rb +84 -0
- data/lib/graphql/analysis/ast/field_usage.rb +57 -0
- data/lib/graphql/analysis/ast/max_query_complexity.rb +22 -0
- data/lib/graphql/analysis/ast/max_query_depth.rb +22 -0
- data/lib/graphql/analysis/ast/query_complexity.rb +230 -0
- data/lib/graphql/analysis/ast/query_depth.rb +55 -0
- data/lib/graphql/analysis/ast/visitor.rb +269 -0
- data/lib/graphql/analysis/ast.rb +81 -0
- data/lib/graphql/analysis.rb +2 -5
- data/lib/graphql/analysis_error.rb +1 -0
- data/lib/graphql/backtrace/inspect_result.rb +50 -0
- data/lib/graphql/backtrace/table.rb +141 -0
- data/lib/graphql/backtrace/traced_error.rb +54 -0
- data/lib/graphql/backtrace/tracer.rb +80 -0
- data/lib/graphql/backtrace.rb +58 -0
- data/lib/graphql/coercion_error.rb +13 -0
- data/lib/graphql/dataloader/null_dataloader.rb +24 -0
- data/lib/graphql/dataloader/request.rb +19 -0
- data/lib/graphql/dataloader/request_all.rb +19 -0
- data/lib/graphql/dataloader/source.rb +164 -0
- data/lib/graphql/dataloader.rb +311 -0
- data/lib/graphql/date_encoding_error.rb +16 -0
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/dig.rb +19 -0
- data/lib/graphql/execution/directive_checks.rb +37 -0
- data/lib/graphql/execution/errors.rb +93 -0
- data/lib/graphql/execution/interpreter/argument_value.rb +28 -0
- data/lib/graphql/execution/interpreter/arguments.rb +88 -0
- data/lib/graphql/execution/interpreter/arguments_cache.rb +105 -0
- data/lib/graphql/execution/interpreter/execution_errors.rb +29 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +18 -0
- data/lib/graphql/execution/interpreter/resolve.rb +77 -0
- data/lib/graphql/execution/interpreter/runtime.rb +994 -0
- data/lib/graphql/execution/interpreter.rb +226 -0
- data/lib/graphql/execution/lazy/lazy_method_map.rb +98 -0
- data/lib/graphql/execution/lazy.rb +75 -0
- data/lib/graphql/execution/lookahead.rb +311 -0
- data/lib/graphql/execution/multiplex.rb +45 -0
- data/lib/graphql/execution.rb +18 -0
- data/lib/graphql/execution_error.rb +34 -1
- data/lib/graphql/filter.rb +53 -0
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +36 -0
- data/lib/graphql/introspection/base_object.rb +13 -0
- data/lib/graphql/introspection/directive_location_enum.rb +12 -5
- data/lib/graphql/introspection/directive_type.rb +30 -10
- data/lib/graphql/introspection/dynamic_fields.rb +12 -0
- data/lib/graphql/introspection/entry_points.rb +22 -0
- data/lib/graphql/introspection/enum_value_type.rb +21 -8
- data/lib/graphql/introspection/field_type.rb +26 -10
- data/lib/graphql/introspection/input_value_type.rb +64 -14
- data/lib/graphql/introspection/introspection_query.rb +7 -76
- data/lib/graphql/introspection/schema_type.rb +42 -17
- data/lib/graphql/introspection/type_kind_enum.rb +11 -5
- data/lib/graphql/introspection/type_type.rb +104 -16
- data/lib/graphql/introspection.rb +104 -13
- data/lib/graphql/invalid_name_error.rb +11 -0
- data/lib/graphql/invalid_null_error.rb +36 -8
- data/lib/graphql/language/block_string.rb +99 -0
- data/lib/graphql/language/cache.rb +37 -0
- data/lib/graphql/language/definition_slice.rb +41 -0
- data/lib/graphql/language/document_from_schema_definition.rb +335 -0
- data/lib/graphql/language/generation.rb +16 -86
- data/lib/graphql/language/lexer.rb +1436 -705
- data/lib/graphql/language/lexer.rl +172 -64
- data/lib/graphql/language/nodes.rb +617 -105
- data/lib/graphql/language/parser.rb +1524 -430
- data/lib/graphql/language/parser.y +348 -73
- data/lib/graphql/language/printer.rb +386 -0
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/token.rb +16 -3
- data/lib/graphql/language/visitor.rb +169 -25
- data/lib/graphql/language.rb +30 -0
- data/lib/graphql/load_application_object_failed_error.rb +22 -0
- data/lib/graphql/name_validator.rb +11 -0
- data/lib/graphql/pagination/active_record_relation_connection.rb +85 -0
- data/lib/graphql/pagination/array_connection.rb +79 -0
- data/lib/graphql/pagination/connection.rb +253 -0
- data/lib/graphql/pagination/connections.rb +135 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +228 -0
- data/lib/graphql/pagination/sequel_dataset_connection.rb +28 -0
- data/lib/graphql/pagination.rb +6 -0
- data/lib/graphql/parse_error.rb +24 -0
- data/lib/graphql/query/context.rb +266 -12
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +34 -7
- data/lib/graphql/query/null_context.rb +52 -0
- data/lib/graphql/query/result.rb +63 -0
- data/lib/graphql/query/validation_pipeline.rb +114 -0
- data/lib/graphql/query/variable_validation_error.rb +27 -3
- data/lib/graphql/query/variables.rb +75 -24
- data/lib/graphql/query.rb +359 -92
- data/lib/graphql/railtie.rb +13 -0
- data/lib/graphql/rake_task/validate.rb +63 -0
- data/lib/graphql/rake_task.rb +146 -0
- data/lib/graphql/relay/range_add.rb +52 -0
- data/lib/graphql/relay.rb +3 -0
- data/lib/graphql/rubocop/graphql/base_cop.rb +36 -0
- data/lib/graphql/rubocop/graphql/default_null_true.rb +43 -0
- data/lib/graphql/rubocop/graphql/default_required_true.rb +43 -0
- data/lib/graphql/rubocop.rb +4 -0
- data/lib/graphql/runtime_type_error.rb +5 -0
- data/lib/graphql/schema/addition.rb +245 -0
- data/lib/graphql/schema/argument.rb +395 -0
- data/lib/graphql/schema/base_64_bp.rb +26 -0
- data/lib/graphql/schema/base_64_encoder.rb +21 -0
- data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +47 -0
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +78 -0
- data/lib/graphql/schema/build_from_definition.rb +492 -0
- data/lib/graphql/schema/built_in_types.rb +12 -0
- data/lib/graphql/schema/directive/deprecated.rb +18 -0
- data/lib/graphql/schema/directive/feature.rb +66 -0
- data/lib/graphql/schema/directive/flagged.rb +57 -0
- data/lib/graphql/schema/directive/include.rb +25 -0
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/skip.rb +25 -0
- data/lib/graphql/schema/directive/transform.rb +60 -0
- data/lib/graphql/schema/directive.rb +212 -0
- data/lib/graphql/schema/enum.rb +176 -0
- data/lib/graphql/schema/enum_value.rb +77 -0
- data/lib/graphql/schema/field/connection_extension.rb +80 -0
- data/lib/graphql/schema/field/scope_extension.rb +22 -0
- data/lib/graphql/schema/field.rb +862 -0
- data/lib/graphql/schema/field_extension.rb +156 -0
- data/lib/graphql/schema/find_inherited_value.rb +36 -0
- data/lib/graphql/schema/finder.rb +155 -0
- data/lib/graphql/schema/input_object.rb +258 -0
- data/lib/graphql/schema/interface.rb +113 -0
- data/lib/graphql/schema/introspection_system.rb +164 -0
- data/lib/graphql/schema/invalid_type_error.rb +1 -0
- data/lib/graphql/schema/late_bound_type.rb +37 -0
- data/lib/graphql/schema/list.rb +86 -0
- data/lib/graphql/schema/loader.rb +228 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +124 -0
- data/lib/graphql/schema/member/build_type.rb +178 -0
- data/lib/graphql/schema/member/graphql_type_names.rb +21 -0
- data/lib/graphql/schema/member/has_arguments.rb +376 -0
- data/lib/graphql/schema/member/has_ast_node.rb +20 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +25 -0
- data/lib/graphql/schema/member/has_directives.rb +113 -0
- data/lib/graphql/schema/member/has_fields.rb +163 -0
- data/lib/graphql/schema/member/has_interfaces.rb +88 -0
- data/lib/graphql/schema/member/has_path.rb +25 -0
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +15 -0
- data/lib/graphql/schema/member/has_validators.rb +31 -0
- data/lib/graphql/schema/member/relay_shortcuts.rb +73 -0
- data/lib/graphql/schema/member/scoped.rb +21 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +38 -0
- data/lib/graphql/schema/member/validates_input.rb +33 -0
- data/lib/graphql/schema/member.rb +39 -0
- data/lib/graphql/schema/mutation.rb +85 -0
- data/lib/graphql/schema/non_null.rb +67 -0
- data/lib/graphql/schema/null_mask.rb +11 -0
- data/lib/graphql/schema/object.rb +117 -0
- data/lib/graphql/schema/printer.rb +72 -128
- data/lib/graphql/schema/relay_classic_mutation.rb +179 -0
- data/lib/graphql/schema/resolver/has_payload_type.rb +106 -0
- data/lib/graphql/schema/resolver.rb +402 -0
- data/lib/graphql/schema/scalar.rb +68 -0
- data/lib/graphql/schema/subscription.rb +148 -0
- data/lib/graphql/schema/timeout.rb +123 -0
- data/lib/graphql/schema/type_expression.rb +29 -5
- data/lib/graphql/schema/type_membership.rb +51 -0
- data/lib/graphql/schema/union.rb +81 -0
- data/lib/graphql/schema/unique_within_type.rb +34 -0
- data/lib/graphql/schema/validator/allow_blank_validator.rb +29 -0
- data/lib/graphql/schema/validator/allow_null_validator.rb +26 -0
- data/lib/graphql/schema/validator/exclusion_validator.rb +33 -0
- data/lib/graphql/schema/validator/format_validator.rb +48 -0
- data/lib/graphql/schema/validator/inclusion_validator.rb +35 -0
- data/lib/graphql/schema/validator/length_validator.rb +59 -0
- data/lib/graphql/schema/validator/numericality_validator.rb +82 -0
- data/lib/graphql/schema/validator/required_validator.rb +82 -0
- data/lib/graphql/schema/validator.rb +171 -0
- data/lib/graphql/schema/warden.rb +413 -0
- data/lib/graphql/schema/wrapper.rb +24 -0
- data/lib/graphql/schema.rb +1179 -104
- data/lib/graphql/static_validation/all_rules.rb +14 -0
- data/lib/graphql/static_validation/base_visitor.rb +200 -0
- data/lib/graphql/static_validation/definition_dependencies.rb +198 -0
- data/lib/graphql/static_validation/error.rb +46 -0
- data/lib/graphql/static_validation/interpreter_visitor.rb +14 -0
- data/lib/graphql/static_validation/literal_validator.rb +113 -22
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +59 -11
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +48 -0
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +31 -0
- data/lib/graphql/static_validation/rules/argument_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +62 -8
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +37 -0
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +20 -13
- data/lib/graphql/static_validation/rules/directives_are_defined_error.rb +29 -0
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +32 -26
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +21 -23
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type_error.rb +32 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +55 -18
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +390 -70
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +53 -0
- data/lib/graphql/static_validation/rules/fragment_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/fragment_names_are_unique_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +54 -37
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible_error.rb +35 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +26 -16
- data/lib/graphql/static_validation/rules/fragment_types_exist_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +13 -19
- data/lib/graphql/static_validation/rules/fragments_are_finite_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_named.rb +16 -0
- data/lib/graphql/static_validation/rules/fragments_are_named_error.rb +26 -0
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +25 -20
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types_error.rb +30 -0
- data/lib/graphql/static_validation/rules/fragments_are_used.rb +22 -33
- data/lib/graphql/static_validation/rules/fragments_are_used_error.rb +29 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +41 -0
- data/lib/graphql/static_validation/rules/no_definitions_are_present_error.rb +25 -0
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
- data/lib/graphql/static_validation/rules/operation_names_are_valid.rb +36 -0
- data/lib/graphql/static_validation/rules/operation_names_are_valid_error.rb +28 -0
- data/lib/graphql/static_validation/rules/query_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/query_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +22 -21
- data/lib/graphql/static_validation/rules/required_arguments_are_present_error.rb +35 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +59 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present_error.rb +35 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +56 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location_error.rb +29 -0
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +36 -18
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb +39 -0
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +24 -0
- data/lib/graphql/static_validation/rules/variable_names_are_unique_error.rb +29 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +103 -39
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed_error.rb +38 -0
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +22 -14
- data/lib/graphql/static_validation/rules/variables_are_input_types_error.rb +32 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +92 -70
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb +37 -0
- data/lib/graphql/static_validation/type_stack.rb +85 -24
- data/lib/graphql/static_validation/validation_context.rb +25 -46
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +46 -15
- data/lib/graphql/static_validation.rb +6 -3
- data/lib/graphql/string_encoding_error.rb +20 -0
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +247 -0
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +81 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +58 -0
- data/lib/graphql/subscriptions/event.rb +144 -0
- data/lib/graphql/subscriptions/instrumentation.rb +28 -0
- data/lib/graphql/subscriptions/serialize.rb +158 -0
- data/lib/graphql/subscriptions.rb +306 -0
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +21 -0
- data/lib/graphql/tracing/appoptics_tracing.rb +173 -0
- data/lib/graphql/tracing/appsignal_tracing.rb +51 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +100 -0
- data/lib/graphql/tracing/instrumentation_tracing.rb +83 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +51 -0
- data/lib/graphql/tracing/notifications_tracing.rb +59 -0
- data/lib/graphql/tracing/platform_tracing.rb +122 -0
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +32 -0
- data/lib/graphql/tracing/prometheus_tracing.rb +67 -0
- data/lib/graphql/tracing/scout_tracing.rb +54 -0
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +94 -0
- data/lib/graphql/type_kinds.rb +50 -22
- data/lib/graphql/types/big_int.rb +23 -0
- data/lib/graphql/types/boolean.rb +18 -0
- data/lib/graphql/types/float.rb +19 -0
- data/lib/graphql/types/id.rb +24 -0
- data/lib/graphql/types/int.rb +36 -0
- data/lib/graphql/types/iso_8601_date.rb +45 -0
- data/lib/graphql/types/iso_8601_date_time.rb +76 -0
- data/lib/graphql/types/json.rb +25 -0
- data/lib/graphql/types/relay/base_connection.rb +49 -0
- data/lib/graphql/types/relay/base_edge.rb +29 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +154 -0
- data/lib/graphql/types/relay/default_relay.rb +21 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +64 -0
- data/lib/graphql/types/relay/has_node_field.rb +41 -0
- data/lib/graphql/types/relay/has_nodes_field.rb +41 -0
- data/lib/graphql/types/relay/node.rb +15 -0
- data/lib/graphql/types/relay/node_behaviors.rb +19 -0
- data/lib/graphql/types/relay/page_info.rb +11 -0
- data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
- data/lib/graphql/types/relay.rb +39 -0
- data/lib/graphql/types/string.rb +29 -0
- data/lib/graphql/types.rb +11 -0
- data/lib/graphql/unauthorized_error.rb +29 -0
- data/lib/graphql/unauthorized_field_error.rb +23 -0
- data/lib/graphql/unresolved_type_error.rb +35 -0
- data/lib/graphql/version.rb +2 -1
- data/lib/graphql.rb +86 -41
- data/readme.md +15 -101
- metadata +394 -279
- data/lib/graphql/analysis/analyze_query.rb +0 -73
- data/lib/graphql/analysis/max_query_complexity.rb +0 -25
- data/lib/graphql/analysis/max_query_depth.rb +0 -25
- data/lib/graphql/analysis/query_complexity.rb +0 -122
- data/lib/graphql/analysis/query_depth.rb +0 -54
- data/lib/graphql/argument.rb +0 -25
- data/lib/graphql/base_type.rb +0 -115
- data/lib/graphql/boolean_type.rb +0 -9
- data/lib/graphql/define/assign_argument.rb +0 -20
- data/lib/graphql/define/assign_enum_value.rb +0 -16
- data/lib/graphql/define/assign_object_field.rb +0 -21
- data/lib/graphql/define/assignment_dictionary.rb +0 -26
- data/lib/graphql/define/defined_object_proxy.rb +0 -32
- data/lib/graphql/define/instance_definable.rb +0 -79
- data/lib/graphql/define/non_null_with_bang.rb +0 -15
- data/lib/graphql/define/type_definer.rb +0 -30
- data/lib/graphql/define.rb +0 -8
- data/lib/graphql/directive/include_directive.rb +0 -10
- data/lib/graphql/directive/skip_directive.rb +0 -11
- data/lib/graphql/directive.rb +0 -49
- data/lib/graphql/enum_type.rb +0 -95
- data/lib/graphql/field.rb +0 -131
- data/lib/graphql/float_type.rb +0 -5
- data/lib/graphql/id_type.rb +0 -12
- data/lib/graphql/input_object_type.rb +0 -71
- data/lib/graphql/int_type.rb +0 -5
- data/lib/graphql/interface_type.rb +0 -38
- data/lib/graphql/internal_representation/node.rb +0 -81
- data/lib/graphql/internal_representation/rewrite.rb +0 -177
- data/lib/graphql/internal_representation.rb +0 -2
- data/lib/graphql/introspection/arguments_field.rb +0 -5
- data/lib/graphql/introspection/enum_values_field.rb +0 -13
- 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 -5
- data/lib/graphql/introspection/of_type_field.rb +0 -6
- data/lib/graphql/introspection/possible_types_field.rb +0 -11
- data/lib/graphql/introspection/schema_field.rb +0 -15
- data/lib/graphql/introspection/type_by_name_field.rb +0 -16
- data/lib/graphql/introspection/typename_field.rb +0 -15
- data/lib/graphql/list_type.rb +0 -46
- data/lib/graphql/non_null_type.rb +0 -43
- data/lib/graphql/object_type.rb +0 -93
- data/lib/graphql/query/arguments.rb +0 -76
- data/lib/graphql/query/directive_resolution.rb +0 -16
- data/lib/graphql/query/executor.rb +0 -45
- data/lib/graphql/query/literal_input.rb +0 -90
- data/lib/graphql/query/serial_execution/execution_context.rb +0 -31
- data/lib/graphql/query/serial_execution/field_resolution.rb +0 -82
- data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -27
- data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -42
- data/lib/graphql/query/serial_execution/value_resolution.rb +0 -107
- data/lib/graphql/query/serial_execution.rb +0 -41
- data/lib/graphql/query/type_resolver.rb +0 -25
- data/lib/graphql/scalar_type.rb +0 -53
- data/lib/graphql/schema/catchall_middleware.rb +0 -34
- data/lib/graphql/schema/middleware_chain.rb +0 -28
- data/lib/graphql/schema/possible_types.rb +0 -34
- data/lib/graphql/schema/reduce_types.rb +0 -68
- data/lib/graphql/schema/rescue_middleware.rb +0 -53
- data/lib/graphql/schema/timeout_middleware.rb +0 -67
- data/lib/graphql/schema/type_map.rb +0 -30
- data/lib/graphql/schema/validation.rb +0 -164
- data/lib/graphql/static_validation/arguments_validator.rb +0 -48
- data/lib/graphql/static_validation/message.rb +0 -36
- data/lib/graphql/string_type.rb +0 -5
- data/lib/graphql/union_type.rb +0 -38
- data/spec/graphql/analysis/analyze_query_spec.rb +0 -50
- data/spec/graphql/analysis/max_query_complexity_spec.rb +0 -62
- data/spec/graphql/analysis/max_query_depth_spec.rb +0 -100
- data/spec/graphql/analysis/query_complexity_spec.rb +0 -235
- data/spec/graphql/analysis/query_depth_spec.rb +0 -80
- data/spec/graphql/argument_spec.rb +0 -20
- data/spec/graphql/base_type_spec.rb +0 -24
- data/spec/graphql/boolean_type_spec.rb +0 -20
- data/spec/graphql/define/instance_definable_spec.rb +0 -55
- data/spec/graphql/directive_spec.rb +0 -77
- data/spec/graphql/enum_type_spec.rb +0 -31
- data/spec/graphql/execution_error_spec.rb +0 -61
- data/spec/graphql/field_spec.rb +0 -92
- data/spec/graphql/float_type_spec.rb +0 -15
- data/spec/graphql/id_type_spec.rb +0 -32
- data/spec/graphql/input_object_type_spec.rb +0 -162
- data/spec/graphql/int_type_spec.rb +0 -15
- data/spec/graphql/interface_type_spec.rb +0 -56
- data/spec/graphql/internal_representation/rewrite_spec.rb +0 -120
- data/spec/graphql/introspection/directive_type_spec.rb +0 -50
- data/spec/graphql/introspection/input_value_type_spec.rb +0 -42
- data/spec/graphql/introspection/introspection_query_spec.rb +0 -10
- data/spec/graphql/introspection/schema_type_spec.rb +0 -45
- data/spec/graphql/introspection/type_type_spec.rb +0 -122
- data/spec/graphql/language/generation_spec.rb +0 -42
- data/spec/graphql/language/parser_spec.rb +0 -442
- data/spec/graphql/language/visitor_spec.rb +0 -49
- data/spec/graphql/list_type_spec.rb +0 -32
- data/spec/graphql/non_null_type_spec.rb +0 -31
- data/spec/graphql/object_type_spec.rb +0 -42
- data/spec/graphql/query/arguments_spec.rb +0 -25
- data/spec/graphql/query/context_spec.rb +0 -83
- data/spec/graphql/query/executor_spec.rb +0 -273
- data/spec/graphql/query/serial_execution/execution_context_spec.rb +0 -53
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +0 -66
- data/spec/graphql/query/type_resolver_spec.rb +0 -8
- data/spec/graphql/query/variables_spec.rb +0 -28
- data/spec/graphql/query_spec.rb +0 -363
- data/spec/graphql/scalar_type_spec.rb +0 -61
- data/spec/graphql/schema/catchall_middleware_spec.rb +0 -32
- data/spec/graphql/schema/middleware_chain_spec.rb +0 -42
- data/spec/graphql/schema/printer_spec.rb +0 -190
- data/spec/graphql/schema/reduce_types_spec.rb +0 -102
- data/spec/graphql/schema/rescue_middleware_spec.rb +0 -33
- data/spec/graphql/schema/timeout_middleware_spec.rb +0 -180
- data/spec/graphql/schema/type_expression_spec.rb +0 -38
- data/spec/graphql/schema/validation_spec.rb +0 -219
- data/spec/graphql/schema_spec.rb +0 -23
- data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +0 -63
- data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +0 -48
- data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +0 -34
- data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +0 -39
- data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +0 -60
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +0 -31
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +0 -48
- data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +0 -47
- data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +0 -39
- data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +0 -44
- data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +0 -49
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +0 -25
- data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +0 -42
- data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +0 -44
- data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +0 -63
- data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +0 -37
- data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +0 -53
- data/spec/graphql/static_validation/type_stack_spec.rb +0 -37
- data/spec/graphql/static_validation/validator_spec.rb +0 -69
- data/spec/graphql/string_type_spec.rb +0 -15
- data/spec/graphql/union_type_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -18
- data/spec/support/dairy_app.rb +0 -309
- data/spec/support/dairy_data.rb +0 -23
- data/spec/support/minimum_input_object.rb +0 -16
- data/spec/support/star_wars_data.rb +0 -71
- data/spec/support/star_wars_schema.rb +0 -76
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
class Directive < GraphQL::Schema::Member
|
5
|
+
class Skip < Schema::Directive
|
6
|
+
description "Directs the executor to skip this field or fragment when the `if` argument is true."
|
7
|
+
|
8
|
+
locations(
|
9
|
+
GraphQL::Schema::Directive::FIELD,
|
10
|
+
GraphQL::Schema::Directive::FRAGMENT_SPREAD,
|
11
|
+
GraphQL::Schema::Directive::INLINE_FRAGMENT
|
12
|
+
)
|
13
|
+
|
14
|
+
argument :if, Boolean,
|
15
|
+
description: "Skipped when true."
|
16
|
+
|
17
|
+
default_directive true
|
18
|
+
|
19
|
+
def self.static_include?(args, ctx)
|
20
|
+
!args[:if]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
class Directive < GraphQL::Schema::Member
|
5
|
+
# An example directive to show how you might interact with the runtime.
|
6
|
+
#
|
7
|
+
# This directive takes the return value of the tagged part of the query,
|
8
|
+
# and if the named transform is whitelisted and applies to the return value,
|
9
|
+
# it's applied by calling a method with that name.
|
10
|
+
#
|
11
|
+
# @example Installing the directive
|
12
|
+
# class MySchema < GraphQL::Schema
|
13
|
+
# directive(GraphQL::Schema::Directive::Transform)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# @example Transforming strings
|
17
|
+
# viewer {
|
18
|
+
# username @transform(by: "upcase")
|
19
|
+
# }
|
20
|
+
class Transform < Schema::Directive
|
21
|
+
description "Directs the executor to run named transform on the return value."
|
22
|
+
|
23
|
+
locations(
|
24
|
+
GraphQL::Schema::Directive::FIELD,
|
25
|
+
)
|
26
|
+
|
27
|
+
argument :by, String,
|
28
|
+
description: "The name of the transform to run if applicable"
|
29
|
+
|
30
|
+
TRANSFORMS = [
|
31
|
+
"upcase",
|
32
|
+
"downcase",
|
33
|
+
# ??
|
34
|
+
]
|
35
|
+
# Implement the Directive API
|
36
|
+
def self.resolve(object, arguments, context)
|
37
|
+
path = context.namespace(:interpreter)[:current_path]
|
38
|
+
return_value = yield
|
39
|
+
transform_name = arguments[:by]
|
40
|
+
if TRANSFORMS.include?(transform_name) && return_value.respond_to?(transform_name)
|
41
|
+
return_value = return_value.public_send(transform_name)
|
42
|
+
response = context.namespace(:interpreter_runtime)[:runtime].final_result
|
43
|
+
*keys, last = path
|
44
|
+
keys.each do |key|
|
45
|
+
if response && (response = response[key])
|
46
|
+
next
|
47
|
+
else
|
48
|
+
break
|
49
|
+
end
|
50
|
+
end
|
51
|
+
if response
|
52
|
+
response[last] = return_value
|
53
|
+
end
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,212 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
# Subclasses of this can influence how {GraphQL::Execution::Interpreter} runs queries.
|
6
|
+
#
|
7
|
+
# - {.include?}: if it returns `false`, the field or fragment will be skipped altogether, as if it were absent
|
8
|
+
# - {.resolve}: Wraps field resolution (so it should call `yield` to continue)
|
9
|
+
class Directive < GraphQL::Schema::Member
|
10
|
+
extend GraphQL::Schema::Member::HasArguments
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# Directives aren't types, they don't have kinds.
|
14
|
+
undef_method :kind
|
15
|
+
|
16
|
+
def path
|
17
|
+
"@#{super}"
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return a name based on the class name,
|
21
|
+
# but downcase the first letter.
|
22
|
+
def default_graphql_name
|
23
|
+
@default_graphql_name ||= begin
|
24
|
+
camelized_name = super
|
25
|
+
camelized_name[0] = camelized_name[0].downcase
|
26
|
+
camelized_name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def locations(*new_locations)
|
31
|
+
if new_locations.any?
|
32
|
+
new_locations.each do |new_loc|
|
33
|
+
if !LOCATIONS.include?(new_loc.to_sym)
|
34
|
+
raise ArgumentError, "#{self} (#{self.graphql_name}) has an invalid directive location: `locations #{new_loc}` "
|
35
|
+
end
|
36
|
+
end
|
37
|
+
@locations = new_locations
|
38
|
+
else
|
39
|
+
@locations ||= (superclass.respond_to?(:locations) ? superclass.locations : [])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def default_directive(new_default_directive = nil)
|
44
|
+
if new_default_directive != nil
|
45
|
+
@default_directive = new_default_directive
|
46
|
+
elsif @default_directive.nil?
|
47
|
+
@default_directive = (superclass.respond_to?(:default_directive) ? superclass.default_directive : false)
|
48
|
+
else
|
49
|
+
!!@default_directive
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def default_directive?
|
54
|
+
default_directive
|
55
|
+
end
|
56
|
+
|
57
|
+
# If false, this part of the query won't be evaluated
|
58
|
+
def include?(_object, arguments, context)
|
59
|
+
static_include?(arguments, context)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Determines whether {Execution::Lookahead} considers the field to be selected
|
63
|
+
def static_include?(_arguments, _context)
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
# Continuing is passed as a block; `yield` to continue
|
68
|
+
def resolve(object, arguments, context)
|
69
|
+
yield
|
70
|
+
end
|
71
|
+
|
72
|
+
# Continuing is passed as a block, yield to continue.
|
73
|
+
def resolve_each(object, arguments, context)
|
74
|
+
yield
|
75
|
+
end
|
76
|
+
|
77
|
+
def on_field?
|
78
|
+
locations.include?(FIELD)
|
79
|
+
end
|
80
|
+
|
81
|
+
def on_fragment?
|
82
|
+
locations.include?(FRAGMENT_SPREAD) && locations.include?(INLINE_FRAGMENT)
|
83
|
+
end
|
84
|
+
|
85
|
+
def on_operation?
|
86
|
+
locations.include?(QUERY) && locations.include?(MUTATION) && locations.include?(SUBSCRIPTION)
|
87
|
+
end
|
88
|
+
|
89
|
+
def repeatable?
|
90
|
+
!!@repeatable
|
91
|
+
end
|
92
|
+
|
93
|
+
def repeatable(new_value)
|
94
|
+
@repeatable = new_value
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# @return [GraphQL::Schema::Field, GraphQL::Schema::Argument, Class, Module]
|
99
|
+
attr_reader :owner
|
100
|
+
|
101
|
+
# @return [GraphQL::Interpreter::Arguments]
|
102
|
+
attr_reader :arguments
|
103
|
+
|
104
|
+
def initialize(owner, **arguments)
|
105
|
+
@owner = owner
|
106
|
+
assert_valid_owner
|
107
|
+
# It's be nice if we had the real context here, but we don't. What we _would_ get is:
|
108
|
+
# - error handling
|
109
|
+
# - lazy resolution
|
110
|
+
# Probably, those won't be needed here, since these are configuration arguments,
|
111
|
+
# not runtime arguments.
|
112
|
+
@arguments = self.class.coerce_arguments(nil, arguments, Query::NullContext)
|
113
|
+
end
|
114
|
+
|
115
|
+
def graphql_name
|
116
|
+
self.class.graphql_name
|
117
|
+
end
|
118
|
+
|
119
|
+
LOCATIONS = [
|
120
|
+
QUERY = :QUERY,
|
121
|
+
MUTATION = :MUTATION,
|
122
|
+
SUBSCRIPTION = :SUBSCRIPTION,
|
123
|
+
FIELD = :FIELD,
|
124
|
+
FRAGMENT_DEFINITION = :FRAGMENT_DEFINITION,
|
125
|
+
FRAGMENT_SPREAD = :FRAGMENT_SPREAD,
|
126
|
+
INLINE_FRAGMENT = :INLINE_FRAGMENT,
|
127
|
+
SCHEMA = :SCHEMA,
|
128
|
+
SCALAR = :SCALAR,
|
129
|
+
OBJECT = :OBJECT,
|
130
|
+
FIELD_DEFINITION = :FIELD_DEFINITION,
|
131
|
+
ARGUMENT_DEFINITION = :ARGUMENT_DEFINITION,
|
132
|
+
INTERFACE = :INTERFACE,
|
133
|
+
UNION = :UNION,
|
134
|
+
ENUM = :ENUM,
|
135
|
+
ENUM_VALUE = :ENUM_VALUE,
|
136
|
+
INPUT_OBJECT = :INPUT_OBJECT,
|
137
|
+
INPUT_FIELD_DEFINITION = :INPUT_FIELD_DEFINITION,
|
138
|
+
VARIABLE_DEFINITION = :VARIABLE_DEFINITION,
|
139
|
+
]
|
140
|
+
|
141
|
+
DEFAULT_DEPRECATION_REASON = 'No longer supported'
|
142
|
+
LOCATION_DESCRIPTIONS = {
|
143
|
+
QUERY: 'Location adjacent to a query operation.',
|
144
|
+
MUTATION: 'Location adjacent to a mutation operation.',
|
145
|
+
SUBSCRIPTION: 'Location adjacent to a subscription operation.',
|
146
|
+
FIELD: 'Location adjacent to a field.',
|
147
|
+
FRAGMENT_DEFINITION: 'Location adjacent to a fragment definition.',
|
148
|
+
FRAGMENT_SPREAD: 'Location adjacent to a fragment spread.',
|
149
|
+
INLINE_FRAGMENT: 'Location adjacent to an inline fragment.',
|
150
|
+
SCHEMA: 'Location adjacent to a schema definition.',
|
151
|
+
SCALAR: 'Location adjacent to a scalar definition.',
|
152
|
+
OBJECT: 'Location adjacent to an object type definition.',
|
153
|
+
FIELD_DEFINITION: 'Location adjacent to a field definition.',
|
154
|
+
ARGUMENT_DEFINITION: 'Location adjacent to an argument definition.',
|
155
|
+
INTERFACE: 'Location adjacent to an interface definition.',
|
156
|
+
UNION: 'Location adjacent to a union definition.',
|
157
|
+
ENUM: 'Location adjacent to an enum definition.',
|
158
|
+
ENUM_VALUE: 'Location adjacent to an enum value definition.',
|
159
|
+
INPUT_OBJECT: 'Location adjacent to an input object type definition.',
|
160
|
+
INPUT_FIELD_DEFINITION: 'Location adjacent to an input object field definition.',
|
161
|
+
VARIABLE_DEFINITION: 'Location adjacent to a variable definition.',
|
162
|
+
}
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
def assert_valid_owner
|
167
|
+
case @owner
|
168
|
+
when Class
|
169
|
+
if @owner < GraphQL::Schema::Object
|
170
|
+
assert_has_location(OBJECT)
|
171
|
+
elsif @owner < GraphQL::Schema::Union
|
172
|
+
assert_has_location(UNION)
|
173
|
+
elsif @owner < GraphQL::Schema::Enum
|
174
|
+
assert_has_location(ENUM)
|
175
|
+
elsif @owner < GraphQL::Schema::InputObject
|
176
|
+
assert_has_location(INPUT_OBJECT)
|
177
|
+
elsif @owner < GraphQL::Schema::Scalar
|
178
|
+
assert_has_location(SCALAR)
|
179
|
+
elsif @owner < GraphQL::Schema
|
180
|
+
assert_has_location(SCHEMA)
|
181
|
+
else
|
182
|
+
raise "Unexpected directive owner class: #{@owner}"
|
183
|
+
end
|
184
|
+
when Module
|
185
|
+
assert_has_location(INTERFACE)
|
186
|
+
when GraphQL::Schema::Argument
|
187
|
+
if @owner.owner.is_a?(GraphQL::Schema::Field)
|
188
|
+
assert_has_location(ARGUMENT_DEFINITION)
|
189
|
+
else
|
190
|
+
assert_has_location(INPUT_FIELD_DEFINITION)
|
191
|
+
end
|
192
|
+
when GraphQL::Schema::Field
|
193
|
+
assert_has_location(FIELD_DEFINITION)
|
194
|
+
when GraphQL::Schema::EnumValue
|
195
|
+
assert_has_location(ENUM_VALUE)
|
196
|
+
else
|
197
|
+
raise "Unexpected directive owner: #{@owner.inspect}"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def assert_has_location(location)
|
202
|
+
if !self.class.locations.include?(location)
|
203
|
+
raise ArgumentError, <<-MD
|
204
|
+
Directive `@#{self.class.graphql_name}` can't be attached to #{@owner.graphql_name} because #{location} isn't included in its locations (#{self.class.locations.join(", ")}).
|
205
|
+
|
206
|
+
Use `locations(#{location})` to update this directive's definition, or remove it from #{@owner.graphql_name}.
|
207
|
+
MD
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
@@ -0,0 +1,176 @@
|
|
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::ValidatesInput
|
24
|
+
|
25
|
+
class UnresolvedValueError < GraphQL::Error
|
26
|
+
def initialize(value:, enum:, context:)
|
27
|
+
fix_message = ", but this isn't a valid value for `#{enum.graphql_name}`. Update the field or resolver to return one of `#{enum.graphql_name}`'s values instead."
|
28
|
+
message = if (cp = context[:current_path]) && (cf = context[:current_field])
|
29
|
+
"`#{cf.path}` returned `#{value.inspect}` at `#{cp.join(".")}`#{fix_message}"
|
30
|
+
else
|
31
|
+
"`#{value.inspect}` was returned for `#{enum.graphql_name}`#{fix_message}"
|
32
|
+
end
|
33
|
+
super(message)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class << self
|
38
|
+
# Define a value for this enum
|
39
|
+
# @param graphql_name [String, Symbol] the GraphQL value for this, usually `SCREAMING_CASE`
|
40
|
+
# @param description [String], the GraphQL description for this value, present in documentation
|
41
|
+
# @param value [Object], the translated Ruby value for this object (defaults to `graphql_name`)
|
42
|
+
# @param deprecation_reason [String] if this object is deprecated, include a message here
|
43
|
+
# @return [void]
|
44
|
+
# @see {Schema::EnumValue} which handles these inputs by default
|
45
|
+
def value(*args, **kwargs, &block)
|
46
|
+
kwargs[:owner] = self
|
47
|
+
value = enum_value_class.new(*args, **kwargs, &block)
|
48
|
+
key = value.graphql_name
|
49
|
+
prev_value = own_values[key]
|
50
|
+
case prev_value
|
51
|
+
when nil
|
52
|
+
own_values[key] = value
|
53
|
+
when GraphQL::Schema::EnumValue
|
54
|
+
own_values[key] = [prev_value, value]
|
55
|
+
when Array
|
56
|
+
prev_value << value
|
57
|
+
else
|
58
|
+
raise "Invariant: Unexpected enum value for #{key.inspect}: #{prev_value.inspect}"
|
59
|
+
end
|
60
|
+
value
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Array<GraphQL::Schema::EnumValue>] Possible values of this enum
|
64
|
+
def enum_values(context = GraphQL::Query::NullContext)
|
65
|
+
inherited_values = superclass.respond_to?(:enum_values) ? superclass.enum_values(context) : nil
|
66
|
+
visible_values = []
|
67
|
+
warden = Warden.from_context(context)
|
68
|
+
own_values.each do |key, values_entry|
|
69
|
+
if (v = Warden.visible_entry?(:visible_enum_value?, values_entry, context, warden))
|
70
|
+
visible_values << v
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
if inherited_values
|
75
|
+
# Local values take precedence over inherited ones
|
76
|
+
inherited_values.each do |i_val|
|
77
|
+
if !visible_values.any? { |v| v.graphql_name == i_val.graphql_name }
|
78
|
+
visible_values << i_val
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
visible_values
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Array<Schema::EnumValue>] An unfiltered list of all definitions
|
87
|
+
def all_enum_value_definitions
|
88
|
+
all_defns = if superclass.respond_to?(:all_enum_value_definitions)
|
89
|
+
superclass.all_enum_value_definitions
|
90
|
+
else
|
91
|
+
[]
|
92
|
+
end
|
93
|
+
|
94
|
+
@own_values && @own_values.each do |_key, value|
|
95
|
+
if value.is_a?(Array)
|
96
|
+
all_defns.concat(value)
|
97
|
+
else
|
98
|
+
all_defns << value
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
all_defns
|
103
|
+
end
|
104
|
+
|
105
|
+
# @return [Hash<String => GraphQL::Schema::EnumValue>] Possible values of this enum, keyed by name.
|
106
|
+
def values(context = GraphQL::Query::NullContext)
|
107
|
+
enum_values(context).each_with_object({}) { |val, obj| obj[val.graphql_name] = val }
|
108
|
+
end
|
109
|
+
|
110
|
+
# @return [Class] for handling `value(...)` inputs and building `GraphQL::Enum::EnumValue`s out of them
|
111
|
+
def enum_value_class(new_enum_value_class = nil)
|
112
|
+
if new_enum_value_class
|
113
|
+
@enum_value_class = new_enum_value_class
|
114
|
+
elsif defined?(@enum_value_class) && @enum_value_class
|
115
|
+
@enum_value_class
|
116
|
+
else
|
117
|
+
superclass <= GraphQL::Schema::Enum ? superclass.enum_value_class : nil
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def kind
|
122
|
+
GraphQL::TypeKinds::ENUM
|
123
|
+
end
|
124
|
+
|
125
|
+
def validate_non_null_input(value_name, ctx, max_errors: nil)
|
126
|
+
allowed_values = ctx.warden.enum_values(self)
|
127
|
+
matching_value = allowed_values.find { |v| v.graphql_name == value_name }
|
128
|
+
|
129
|
+
if matching_value.nil?
|
130
|
+
GraphQL::Query::InputValidationResult.from_problem("Expected #{GraphQL::Language.serialize(value_name)} to be one of: #{allowed_values.map(&:graphql_name).join(', ')}")
|
131
|
+
else
|
132
|
+
nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def coerce_result(value, ctx)
|
137
|
+
warden = ctx.warden
|
138
|
+
all_values = warden ? warden.enum_values(self) : values.each_value
|
139
|
+
enum_value = all_values.find { |val| val.value == value }
|
140
|
+
if enum_value
|
141
|
+
enum_value.graphql_name
|
142
|
+
else
|
143
|
+
raise self::UnresolvedValueError.new(enum: self, value: value, context: ctx)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def coerce_input(value_name, ctx)
|
148
|
+
all_values = ctx.warden ? ctx.warden.enum_values(self) : values.each_value
|
149
|
+
|
150
|
+
if v = all_values.find { |val| val.graphql_name == value_name }
|
151
|
+
v.value
|
152
|
+
elsif v = all_values.find { |val| val.value == value_name }
|
153
|
+
# this is for matching default values, which are "inputs", but they're
|
154
|
+
# the Ruby value, not the GraphQL string.
|
155
|
+
v.value
|
156
|
+
else
|
157
|
+
nil
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def inherited(child_class)
|
162
|
+
child_class.const_set(:UnresolvedValueError, Class.new(Schema::Enum::UnresolvedValueError))
|
163
|
+
super
|
164
|
+
end
|
165
|
+
|
166
|
+
private
|
167
|
+
|
168
|
+
def own_values
|
169
|
+
@own_values ||= {}
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
enum_value_class(GraphQL::Schema::EnumValue)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,77 @@
|
|
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
|
+
# end
|
17
|
+
#
|
18
|
+
# class BaseEnum < GraphQL::Schema::Enum
|
19
|
+
# # use it for these enums:
|
20
|
+
# enum_value_class CustomEnumValue
|
21
|
+
# end
|
22
|
+
class EnumValue < GraphQL::Schema::Member
|
23
|
+
include GraphQL::Schema::Member::HasPath
|
24
|
+
include GraphQL::Schema::Member::HasAstNode
|
25
|
+
include GraphQL::Schema::Member::HasDirectives
|
26
|
+
include GraphQL::Schema::Member::HasDeprecationReason
|
27
|
+
|
28
|
+
attr_reader :graphql_name
|
29
|
+
|
30
|
+
# @return [Class] The enum type that owns this value
|
31
|
+
attr_reader :owner
|
32
|
+
|
33
|
+
def initialize(graphql_name, desc = nil, owner:, ast_node: nil, directives: nil, description: nil, value: nil, deprecation_reason: nil, &block)
|
34
|
+
@graphql_name = graphql_name.to_s
|
35
|
+
GraphQL::NameValidator.validate!(@graphql_name)
|
36
|
+
@description = desc || description
|
37
|
+
@value = value.nil? ? @graphql_name : value
|
38
|
+
if deprecation_reason
|
39
|
+
self.deprecation_reason = deprecation_reason
|
40
|
+
end
|
41
|
+
@owner = owner
|
42
|
+
@ast_node = ast_node
|
43
|
+
if directives
|
44
|
+
directives.each do |dir_class, dir_options|
|
45
|
+
directive(dir_class, **dir_options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
if block_given?
|
50
|
+
instance_eval(&block)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def description(new_desc = nil)
|
55
|
+
if new_desc
|
56
|
+
@description = new_desc
|
57
|
+
end
|
58
|
+
@description
|
59
|
+
end
|
60
|
+
|
61
|
+
def value(new_val = nil)
|
62
|
+
unless new_val.nil?
|
63
|
+
@value = new_val
|
64
|
+
end
|
65
|
+
@value
|
66
|
+
end
|
67
|
+
|
68
|
+
def inspect
|
69
|
+
"#<#{self.class} #{path} @value=#{@value.inspect}#{description ? " @description=#{description.inspect}" : ""}>"
|
70
|
+
end
|
71
|
+
|
72
|
+
def visible?(_ctx); true; end
|
73
|
+
def accessible?(_ctx); true; end
|
74
|
+
def authorized?(_ctx); true; end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
class Field
|
6
|
+
class ConnectionExtension < GraphQL::Schema::FieldExtension
|
7
|
+
def apply
|
8
|
+
field.argument :after, "String", "Returns the elements in the list that come after the specified cursor.", required: false
|
9
|
+
field.argument :before, "String", "Returns the elements in the list that come before the specified cursor.", required: false
|
10
|
+
field.argument :first, "Int", "Returns the first _n_ elements from the list.", required: false
|
11
|
+
field.argument :last, "Int", "Returns the last _n_ elements from the list.", required: false
|
12
|
+
end
|
13
|
+
|
14
|
+
# Remove pagination args before passing it to a user method
|
15
|
+
def resolve(object:, arguments:, context:)
|
16
|
+
next_args = arguments.dup
|
17
|
+
next_args.delete(:first)
|
18
|
+
next_args.delete(:last)
|
19
|
+
next_args.delete(:before)
|
20
|
+
next_args.delete(:after)
|
21
|
+
yield(object, next_args, arguments)
|
22
|
+
end
|
23
|
+
|
24
|
+
def after_resolve(value:, object:, arguments:, context:, memo:)
|
25
|
+
original_arguments = memo
|
26
|
+
# rename some inputs to avoid conflicts inside the block
|
27
|
+
maybe_lazy = value
|
28
|
+
value = nil
|
29
|
+
context.schema.after_lazy(maybe_lazy) do |resolved_value|
|
30
|
+
value = resolved_value
|
31
|
+
if value.is_a? GraphQL::ExecutionError
|
32
|
+
# This isn't even going to work because context doesn't have ast_node anymore
|
33
|
+
context.add_error(value)
|
34
|
+
nil
|
35
|
+
elsif value.nil?
|
36
|
+
nil
|
37
|
+
elsif value.is_a?(GraphQL::Pagination::Connection)
|
38
|
+
# update the connection with some things that may not have been provided
|
39
|
+
value.context ||= context
|
40
|
+
value.parent ||= object.object
|
41
|
+
value.first_value ||= original_arguments[:first]
|
42
|
+
value.after_value ||= original_arguments[:after]
|
43
|
+
value.last_value ||= original_arguments[:last]
|
44
|
+
value.before_value ||= original_arguments[:before]
|
45
|
+
value.arguments ||= original_arguments # rubocop:disable Development/ContextIsPassedCop -- unrelated .arguments method
|
46
|
+
value.field ||= field
|
47
|
+
if field.has_max_page_size? && !value.has_max_page_size_override?
|
48
|
+
value.max_page_size = field.max_page_size
|
49
|
+
end
|
50
|
+
if field.has_default_page_size? && !value.has_default_page_size_override?
|
51
|
+
value.default_page_size = field.default_page_size
|
52
|
+
end
|
53
|
+
if context.schema.new_connections? && (custom_t = context.schema.connections.edge_class_for_field(@field))
|
54
|
+
value.edge_class = custom_t
|
55
|
+
end
|
56
|
+
value
|
57
|
+
elsif context.schema.new_connections?
|
58
|
+
context.namespace(:connections)[:all_wrappers] ||= context.schema.connections.all_wrappers
|
59
|
+
context.schema.connections.wrap(field, object.object, value, original_arguments, context)
|
60
|
+
else
|
61
|
+
if object.is_a?(GraphQL::Schema::Object)
|
62
|
+
object = object.object
|
63
|
+
end
|
64
|
+
connection_class = GraphQL::Relay::BaseConnection.connection_for_nodes(value)
|
65
|
+
connection_class.new(
|
66
|
+
value,
|
67
|
+
original_arguments,
|
68
|
+
field: field,
|
69
|
+
max_page_size: field.max_page_size,
|
70
|
+
default_page_size: field.default_page_size,
|
71
|
+
parent: object,
|
72
|
+
context: context,
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
class Field
|
6
|
+
class ScopeExtension < GraphQL::Schema::FieldExtension
|
7
|
+
def after_resolve(object:, arguments:, context:, value:, memo:)
|
8
|
+
if value.nil?
|
9
|
+
value
|
10
|
+
else
|
11
|
+
ret_type = @field.type.unwrap
|
12
|
+
if ret_type.respond_to?(:scope_items)
|
13
|
+
ret_type.scope_items(value, context)
|
14
|
+
else
|
15
|
+
value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|