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
@@ -1,53 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
class Schema
|
3
|
-
# - Store a table of errors & handlers
|
4
|
-
# - Rescue errors in a middleware chain, then check for a handler
|
5
|
-
# - If a handler is found, use it & return a {GraphQL::ExecutionError}
|
6
|
-
# - If no handler is found, re-raise the error
|
7
|
-
class RescueMiddleware
|
8
|
-
# @return [Hash] `{class => proc}` pairs for handling errors
|
9
|
-
attr_reader :rescue_table
|
10
|
-
def initialize
|
11
|
-
@rescue_table = {}
|
12
|
-
end
|
13
|
-
|
14
|
-
# @example Rescue from not-found by telling the user
|
15
|
-
# MySchema.rescue_from(ActiveRecord::RecordNotFound) { "An item could not be found" }
|
16
|
-
#
|
17
|
-
# @param [Class] a class of error to rescue from
|
18
|
-
# @yield [err] A handler to return a message for this error instance
|
19
|
-
# @yieldparam [Exception] an error that was rescued
|
20
|
-
# @yieldreturn [String] message to put in GraphQL response
|
21
|
-
def rescue_from(error_class, &block)
|
22
|
-
rescue_table[error_class] = block
|
23
|
-
end
|
24
|
-
|
25
|
-
# Remove the handler for `error_class`
|
26
|
-
# @param [Class] the error class whose handler should be removed
|
27
|
-
def remove_handler(error_class)
|
28
|
-
rescue_table.delete(error_class)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Implement the requirement for {GraphQL::Schema::MiddlewareChain}
|
32
|
-
def call(*args, next_middleware)
|
33
|
-
begin
|
34
|
-
next_middleware.call
|
35
|
-
rescue StandardError => err
|
36
|
-
attempt_rescue(err)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def attempt_rescue(err)
|
43
|
-
handler = rescue_table[err.class]
|
44
|
-
if handler
|
45
|
-
message = handler.call(err)
|
46
|
-
GraphQL::ExecutionError.new(message)
|
47
|
-
else
|
48
|
-
raise(err)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
class Schema
|
3
|
-
# This middleware will stop resolving new fields after `max_seconds` have elapsed.
|
4
|
-
# After the time has passed, any remaining fields will be `nil`, with errors added
|
5
|
-
# to the `errors` key. Any already-resolved fields will be in the `data` key, so
|
6
|
-
# you'll get a partial response.
|
7
|
-
#
|
8
|
-
# You can provide a block which will be called with any timeout errors that occur.
|
9
|
-
#
|
10
|
-
# Note that this will stop a query _in between_ field resolutions, but
|
11
|
-
# it doesn't interrupt long-running `resolve` functions. Be sure to use
|
12
|
-
# timeout options for external connections. For more info, see
|
13
|
-
# www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/
|
14
|
-
#
|
15
|
-
# @example Stop resolving fields after 2 seconds
|
16
|
-
# MySchema.middleware << GraphQL::Schema::TimeoutMiddleware.new(max_seconds: 2)
|
17
|
-
#
|
18
|
-
# @example Notifying Bugsnag on a timeout
|
19
|
-
# MySchema.middleware << GraphQL::Schema::TimeoutMiddleware(max_seconds: 1.5) do |timeout_error, query|
|
20
|
-
# Bugsnag.notify(timeout_error, {query_string: query_ctx.query.query_string})
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
class TimeoutMiddleware
|
24
|
-
# This key is used for storing timeout data in the {Query::Context} instance
|
25
|
-
DEFAULT_CONTEXT_KEY = :__timeout_at__
|
26
|
-
# @param max_seconds [Numeric] how many seconds the query should be allowed to resolve new fields
|
27
|
-
# @param context_key [Symbol] what key should be used to read and write to the query context
|
28
|
-
def initialize(max_seconds:, context_key: DEFAULT_CONTEXT_KEY, &block)
|
29
|
-
@max_seconds = max_seconds
|
30
|
-
@context_key = context_key
|
31
|
-
@error_handler = block
|
32
|
-
end
|
33
|
-
|
34
|
-
def call(parent_type, parent_object, field_definition, field_args, query_context, next_middleware)
|
35
|
-
timeout_at = query_context[@context_key] ||= Time.now + @max_seconds
|
36
|
-
if timeout_at < Time.now
|
37
|
-
on_timeout(parent_type, parent_object, field_definition, field_args, query_context)
|
38
|
-
else
|
39
|
-
next_middleware.call
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# This is called when a field _would_ be resolved, except that we're over the time limit.
|
44
|
-
# @return [GraphQL::Schema::TimeoutMiddleware::TimeoutError] An error whose message will be added to the `errors` key
|
45
|
-
def on_timeout(parent_type, parent_object, field_definition, field_args, query_context)
|
46
|
-
err = GraphQL::Schema::TimeoutMiddleware::TimeoutError.new(parent_type, field_definition)
|
47
|
-
if @error_handler
|
48
|
-
@error_handler.call(err, query_context.query)
|
49
|
-
end
|
50
|
-
err
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# This error is raised when a query exceeds `max_seconds`.
|
55
|
-
# Since it's a child of {GraphQL::ExecutionError},
|
56
|
-
# its message will be added to the response's `errors` key.
|
57
|
-
#
|
58
|
-
# To raise an error that will stop query resolution, use a custom block
|
59
|
-
# to take this error and raise a new one which _doesn't_ descend from {GraphQL::ExecutionError},
|
60
|
-
# such as `RuntimeError`.
|
61
|
-
class GraphQL::Schema::TimeoutMiddleware::TimeoutError < GraphQL::ExecutionError
|
62
|
-
def initialize(parent_type, field_defn)
|
63
|
-
super("Timeout on #{parent_type.name}.#{field_defn.name}")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
class Schema
|
3
|
-
# Stores `{ name => type }` pairs for a given schema.
|
4
|
-
# It behaves like a hash except for a couple things:
|
5
|
-
# - if you use `[key]` and that key isn't defined, 💥!
|
6
|
-
# - if you try to define the same key twice, 💥!
|
7
|
-
#
|
8
|
-
# If you want a type, but want to handle the undefined case, use {#fetch}.
|
9
|
-
class TypeMap
|
10
|
-
extend Forwardable
|
11
|
-
def_delegators :@storage, :key?, :keys, :values, :to_h, :fetch
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
@storage = {}
|
15
|
-
end
|
16
|
-
|
17
|
-
def [](key)
|
18
|
-
@storage[key] || raise("No type found for '#{key}'")
|
19
|
-
end
|
20
|
-
|
21
|
-
def []=(key, value)
|
22
|
-
if @storage.key?(key)
|
23
|
-
raise("Duplicate type definition found for name '#{key}'")
|
24
|
-
else
|
25
|
-
@storage[key] = value
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
class Schema
|
3
|
-
# This module provides a function for validating GraphQL types.
|
4
|
-
#
|
5
|
-
# Its {RULES} contain objects that respond to `#call(type)`. Rules are
|
6
|
-
# looked up for given types (by class ancestry), then applied to
|
7
|
-
# the object until an error is returned.
|
8
|
-
class Validation
|
9
|
-
# Lookup the rules for `object` based on its class,
|
10
|
-
# Then returns an error message or `nil`
|
11
|
-
# @param object [Object] something to be validated
|
12
|
-
# @return [String, Nil] error message, if there was one
|
13
|
-
def self.validate(object)
|
14
|
-
rules = RULES.reduce([]) do |memo, (parent_class, validations)|
|
15
|
-
memo + (object.is_a?(parent_class) ? validations : [])
|
16
|
-
end
|
17
|
-
# Stops after the first error
|
18
|
-
rules.reduce(nil) { |memo, rule| memo || rule.call(object) }
|
19
|
-
end
|
20
|
-
|
21
|
-
module Rules
|
22
|
-
# @param property_name [Symbol] The method to validate
|
23
|
-
# @param allowed_classes [Class] Classes which the return value may be an instance of
|
24
|
-
# @return [Proc] A proc which will validate the input by calling `property_name` and asserting it is an instance of one of `allowed_classes`
|
25
|
-
def self.assert_property(property_name, *allowed_classes)
|
26
|
-
allowed_classes_message = allowed_classes.map(&:name).join(" or ")
|
27
|
-
-> (obj) {
|
28
|
-
property_value = obj.public_send(property_name)
|
29
|
-
is_valid_value = allowed_classes.any? { |allowed_class| property_value.is_a?(allowed_class) }
|
30
|
-
is_valid_value ? nil : "#{property_name} must return #{allowed_classes_message}, not #{property_value.class.name} (#{property_value.inspect})"
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
# @param property_name [Symbol] The method whose return value will be validated
|
35
|
-
# @param from_class [Class] The class for keys in the return value
|
36
|
-
# @param to_class [Class] The class for values in the return value
|
37
|
-
# @return [Proc] A proc to validate that validates the input by calling `property_name` and asserting that the return value is a Hash of `{from_class => to_class}` pairs
|
38
|
-
def self.assert_property_mapping(property_name, from_class, to_class)
|
39
|
-
-> (obj) {
|
40
|
-
property_value = obj.public_send(property_name)
|
41
|
-
error_message = nil
|
42
|
-
if !property_value.is_a?(Hash)
|
43
|
-
"#{property_name} must be a hash of {#{from_class.name} => #{to_class.name}}, not a #{property_value.class.name} (#{property_value.inspect})"
|
44
|
-
else
|
45
|
-
invalid_key, invalid_value = property_value.find { |key, value| !key.is_a?(from_class) || !value.is_a?(to_class) }
|
46
|
-
if invalid_key
|
47
|
-
"#{property_name} must map #{from_class} => #{to_class}, not #{invalid_key.class.name} => #{invalid_value.class.name} (#{invalid_key.inspect} => #{invalid_value.inspect})"
|
48
|
-
else
|
49
|
-
nil # OK
|
50
|
-
end
|
51
|
-
end
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
# @param property_name [Symbol] The method whose return value will be validated
|
56
|
-
# @param list_member_class [Class] The class which each member of the returned array should be an instance of
|
57
|
-
# @return [Proc] A proc to validate the input by calling `property_name` and asserting that the return is an Array of `list_member_class` instances
|
58
|
-
def self.assert_property_list_of(property_name, list_member_class)
|
59
|
-
-> (obj) {
|
60
|
-
property_value = obj.public_send(property_name)
|
61
|
-
if !property_value.is_a?(Array)
|
62
|
-
"#{property_name} must be an Array of #{list_member_class.name}, not a #{property_value.class.name} (#{property_value.inspect})"
|
63
|
-
else
|
64
|
-
invalid_member = property_value.find { |value| !value.is_a?(list_member_class) }
|
65
|
-
if invalid_member
|
66
|
-
"#{property_name} must contain #{list_member_class.name}, not #{invalid_member.class.name} (#{invalid_member.inspect})"
|
67
|
-
else
|
68
|
-
nil # OK
|
69
|
-
end
|
70
|
-
end
|
71
|
-
}
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.assert_named_items_are_valid(item_name, get_items_proc)
|
75
|
-
-> (type) {
|
76
|
-
items = get_items_proc.call(type)
|
77
|
-
error_message = nil
|
78
|
-
items.each do |item|
|
79
|
-
item_message = GraphQL::Schema::Validation.validate(item)
|
80
|
-
if item_message
|
81
|
-
error_message = "#{item_name} #{item.name.inspect} #{item_message}"
|
82
|
-
break
|
83
|
-
end
|
84
|
-
end
|
85
|
-
error_message
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
FIELDS_ARE_VALID = Rules.assert_named_items_are_valid("field", -> (type) { type.all_fields })
|
91
|
-
|
92
|
-
HAS_ONE_OR_MORE_POSSIBLE_TYPES = -> (type) {
|
93
|
-
type.possible_types.length >= 1 ? nil : "must have at least one possible type"
|
94
|
-
}
|
95
|
-
|
96
|
-
NAME_IS_STRING = Rules.assert_property(:name, String)
|
97
|
-
DESCRIPTION_IS_STRING_OR_NIL = Rules.assert_property(:description, String, NilClass)
|
98
|
-
ARGUMENTS_ARE_STRING_TO_ARGUMENT = Rules.assert_property_mapping(:arguments, String, GraphQL::Argument)
|
99
|
-
ARGUMENTS_ARE_VALID = Rules.assert_named_items_are_valid("argument", -> (type) { type.arguments.values })
|
100
|
-
|
101
|
-
DEFAULT_VALUE_IS_VALID_FOR_TYPE = -> (type) {
|
102
|
-
if !type.default_value.nil?
|
103
|
-
coerced_value = type.type.coerce_input(type.default_value)
|
104
|
-
if coerced_value.nil?
|
105
|
-
"default value #{type.default_value.inspect} is not valid for type #{type.type}"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
}
|
109
|
-
|
110
|
-
TYPE_IS_VALID_INPUT_TYPE = -> (type) {
|
111
|
-
outer_type = type.type
|
112
|
-
inner_type = outer_type.is_a?(GraphQL::BaseType) ? outer_type.unwrap : nil
|
113
|
-
|
114
|
-
case inner_type
|
115
|
-
when GraphQL::ScalarType, GraphQL::InputObjectType, GraphQL::EnumType
|
116
|
-
# OK
|
117
|
-
else
|
118
|
-
"type must be a valid input type (Scalar or InputObject), not #{outer_type.class} (#{outer_type})"
|
119
|
-
end
|
120
|
-
}
|
121
|
-
end
|
122
|
-
|
123
|
-
# A mapping of `{Class => [Proc, Proc...]}` pairs.
|
124
|
-
# To validate an instance, find entries where `object.is_a?(key)` is true.
|
125
|
-
# Then apply each rule from the matching values.
|
126
|
-
RULES = {
|
127
|
-
GraphQL::Field => [
|
128
|
-
Rules::NAME_IS_STRING,
|
129
|
-
Rules::DESCRIPTION_IS_STRING_OR_NIL,
|
130
|
-
Rules.assert_property(:deprecation_reason, String, NilClass),
|
131
|
-
Rules.assert_property(:type, GraphQL::BaseType),
|
132
|
-
Rules.assert_property(:property, Symbol, NilClass),
|
133
|
-
Rules::ARGUMENTS_ARE_STRING_TO_ARGUMENT,
|
134
|
-
Rules::ARGUMENTS_ARE_VALID,
|
135
|
-
],
|
136
|
-
GraphQL::Argument => [
|
137
|
-
Rules::NAME_IS_STRING,
|
138
|
-
Rules::DESCRIPTION_IS_STRING_OR_NIL,
|
139
|
-
Rules::TYPE_IS_VALID_INPUT_TYPE,
|
140
|
-
Rules::DEFAULT_VALUE_IS_VALID_FOR_TYPE,
|
141
|
-
],
|
142
|
-
GraphQL::BaseType => [
|
143
|
-
Rules::NAME_IS_STRING,
|
144
|
-
Rules::DESCRIPTION_IS_STRING_OR_NIL,
|
145
|
-
],
|
146
|
-
GraphQL::ObjectType => [
|
147
|
-
Rules.assert_property_list_of(:interfaces, GraphQL::InterfaceType),
|
148
|
-
Rules::FIELDS_ARE_VALID,
|
149
|
-
],
|
150
|
-
GraphQL::InputObjectType => [
|
151
|
-
Rules::ARGUMENTS_ARE_STRING_TO_ARGUMENT,
|
152
|
-
Rules::ARGUMENTS_ARE_VALID,
|
153
|
-
],
|
154
|
-
GraphQL::UnionType => [
|
155
|
-
Rules.assert_property_list_of(:possible_types, GraphQL::ObjectType),
|
156
|
-
Rules::HAS_ONE_OR_MORE_POSSIBLE_TYPES,
|
157
|
-
],
|
158
|
-
GraphQL::InterfaceType => [
|
159
|
-
Rules::FIELDS_ARE_VALID,
|
160
|
-
],
|
161
|
-
}
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module StaticValidation
|
3
|
-
# Implement validate_node
|
4
|
-
class ArgumentsValidator
|
5
|
-
include GraphQL::StaticValidation::Message::MessageHelper
|
6
|
-
|
7
|
-
def validate(context)
|
8
|
-
visitor = context.visitor
|
9
|
-
visitor[GraphQL::Language::Nodes::Argument] << -> (node, parent) {
|
10
|
-
if parent.is_a?(GraphQL::Language::Nodes::InputObject)
|
11
|
-
arg_defn = context.argument_definition
|
12
|
-
if arg_defn.nil?
|
13
|
-
return
|
14
|
-
else
|
15
|
-
parent_defn = arg_defn.type.unwrap
|
16
|
-
if parent_defn.is_a?(GraphQL::ScalarType)
|
17
|
-
return
|
18
|
-
end
|
19
|
-
end
|
20
|
-
elsif context.skip_field?(parent.name)
|
21
|
-
return
|
22
|
-
elsif parent.is_a?(GraphQL::Language::Nodes::Directive)
|
23
|
-
parent_defn = context.schema.directives[parent.name]
|
24
|
-
else
|
25
|
-
parent_defn = context.field_definition
|
26
|
-
end
|
27
|
-
validate_node(parent, node, parent_defn, context)
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def parent_name(parent, type_defn)
|
34
|
-
field_name = if parent.is_a?(GraphQL::Language::Nodes::Field)
|
35
|
-
parent.alias || parent.name
|
36
|
-
elsif parent.is_a?(GraphQL::Language::Nodes::InputObject)
|
37
|
-
type_defn.name
|
38
|
-
else
|
39
|
-
parent.name
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def node_type(parent)
|
44
|
-
parent.class.name.split("::").last
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module StaticValidation
|
3
|
-
# Generates GraphQL-compliant validation message.
|
4
|
-
# Only supports one "location", too bad :(
|
5
|
-
class Message
|
6
|
-
# Convenience for validators
|
7
|
-
module MessageHelper
|
8
|
-
# Error `message` is located at `node`
|
9
|
-
def message(message, node)
|
10
|
-
GraphQL::StaticValidation::Message.new(message, line: node.line, col: node.col)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
attr_reader :message, :line, :col
|
14
|
-
|
15
|
-
def initialize(message, line: nil, col: nil)
|
16
|
-
@message = message
|
17
|
-
@line = line
|
18
|
-
@col = col
|
19
|
-
end
|
20
|
-
|
21
|
-
# A hash representation of this Message
|
22
|
-
def to_h
|
23
|
-
{
|
24
|
-
"message" => message,
|
25
|
-
"locations" => locations
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def locations
|
32
|
-
@line.nil? && @col.nil? ? [] : [{"line" => @line, "column" => @col}]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/graphql/string_type.rb
DELETED
data/lib/graphql/union_type.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
# A collection of {ObjectType}s
|
3
|
-
#
|
4
|
-
# @example a union of types
|
5
|
-
#
|
6
|
-
# PetUnion = GraphQL::UnionType.define do
|
7
|
-
# name "Pet"
|
8
|
-
# description "Animals that live in your house"
|
9
|
-
# possible_types [DogType, CatType, FishType]
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
class UnionType < GraphQL::BaseType
|
13
|
-
include GraphQL::BaseType::HasPossibleTypes
|
14
|
-
attr_accessor :name, :description
|
15
|
-
accepts_definitions :possible_types, :resolve_type
|
16
|
-
|
17
|
-
def kind
|
18
|
-
GraphQL::TypeKinds::UNION
|
19
|
-
end
|
20
|
-
|
21
|
-
def include?(child_type_defn)
|
22
|
-
possible_types.include?(child_type_defn)
|
23
|
-
end
|
24
|
-
|
25
|
-
def possible_types=(new_possible_types)
|
26
|
-
@clean_possible_types = nil
|
27
|
-
@dirty_possible_types = new_possible_types
|
28
|
-
end
|
29
|
-
|
30
|
-
def possible_types
|
31
|
-
@clean_possible_types ||= begin
|
32
|
-
@dirty_possible_types.map { |type| GraphQL::BaseType.resolve_related_type(type) }
|
33
|
-
rescue
|
34
|
-
@dirty_possible_types
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::Analysis do
|
4
|
-
class TypeCollector
|
5
|
-
def initial_value(query)
|
6
|
-
[]
|
7
|
-
end
|
8
|
-
|
9
|
-
def call(memo, visit_type, irep_node)
|
10
|
-
if visit_type == :enter
|
11
|
-
memo + [irep_node.return_type]
|
12
|
-
else
|
13
|
-
memo
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".analyze_query" do
|
19
|
-
let(:node_counter) {
|
20
|
-
-> (memo, visit_type, irep_node) {
|
21
|
-
memo ||= Hash.new { |h,k| h[k] = 0 }
|
22
|
-
visit_type == :enter && memo[irep_node.ast_node.class] += 1
|
23
|
-
memo
|
24
|
-
}
|
25
|
-
}
|
26
|
-
let(:type_collector) { TypeCollector.new }
|
27
|
-
let(:analyzers) { [type_collector, node_counter] }
|
28
|
-
let(:reduce_result) { GraphQL::Analysis.analyze_query(query, analyzers) }
|
29
|
-
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
30
|
-
let(:query_string) {%|
|
31
|
-
{
|
32
|
-
cheese(id: 1) {
|
33
|
-
id
|
34
|
-
flavor
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|}
|
38
|
-
|
39
|
-
it "calls the defined analyzers" do
|
40
|
-
collected_types, node_counts = reduce_result
|
41
|
-
expected_visited_types = [QueryType, CheeseType, GraphQL::INT_TYPE, GraphQL::STRING_TYPE]
|
42
|
-
assert_equal expected_visited_types, collected_types
|
43
|
-
expected_node_counts = {
|
44
|
-
GraphQL::Language::Nodes::OperationDefinition => 1,
|
45
|
-
GraphQL::Language::Nodes::Field => 3,
|
46
|
-
}
|
47
|
-
assert_equal expected_node_counts, node_counts
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::Analysis::MaxQueryComplexity do
|
4
|
-
before do
|
5
|
-
@prev_max_complexity = DummySchema.max_complexity
|
6
|
-
end
|
7
|
-
|
8
|
-
after do
|
9
|
-
DummySchema.max_complexity = @prev_max_complexity
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
let(:result) { DummySchema.execute(query_string) }
|
14
|
-
let(:query_string) {%|
|
15
|
-
{
|
16
|
-
a: cheese(id: 1) { id }
|
17
|
-
b: cheese(id: 1) { id }
|
18
|
-
c: cheese(id: 1) { id }
|
19
|
-
d: cheese(id: 1) { id }
|
20
|
-
e: cheese(id: 1) { id }
|
21
|
-
}
|
22
|
-
|}
|
23
|
-
|
24
|
-
describe "when a query goes over max complexity" do
|
25
|
-
before do
|
26
|
-
DummySchema.max_complexity = 9
|
27
|
-
end
|
28
|
-
|
29
|
-
it "returns an error" do
|
30
|
-
assert_equal "Query has complexity of 10, which exceeds max complexity of 9", result["errors"][0]["message"]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "when there is no max complexity" do
|
35
|
-
before do
|
36
|
-
DummySchema.max_complexity = nil
|
37
|
-
end
|
38
|
-
it "doesn't error" do
|
39
|
-
assert_equal nil, result["errors"]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "when the query is less than the max complexity" do
|
44
|
-
before do
|
45
|
-
DummySchema.max_complexity = 99
|
46
|
-
end
|
47
|
-
it "doesn't error" do
|
48
|
-
assert_equal nil, result["errors"]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "when complexity is overriden at query-level" do
|
53
|
-
before do
|
54
|
-
DummySchema.max_complexity = 100
|
55
|
-
end
|
56
|
-
let(:result) { DummySchema.execute(query_string, max_complexity: 7) }
|
57
|
-
|
58
|
-
it "is applied" do
|
59
|
-
assert_equal "Query has complexity of 10, which exceeds max complexity of 7", result["errors"][0]["message"]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::Analysis::MaxQueryDepth do
|
4
|
-
before do
|
5
|
-
@prev_max_depth = DummySchema.max_depth
|
6
|
-
end
|
7
|
-
|
8
|
-
after do
|
9
|
-
DummySchema.max_depth = @prev_max_depth
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:result) { DummySchema.execute(query_string) }
|
13
|
-
let(:query_string) { "
|
14
|
-
{
|
15
|
-
cheese(id: 1) {
|
16
|
-
similarCheese(source: SHEEP) {
|
17
|
-
similarCheese(source: SHEEP) {
|
18
|
-
similarCheese(source: SHEEP) {
|
19
|
-
similarCheese(source: SHEEP) {
|
20
|
-
similarCheese(source: SHEEP) {
|
21
|
-
id
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|
25
|
-
}
|
26
|
-
}
|
27
|
-
}
|
28
|
-
}
|
29
|
-
"}
|
30
|
-
|
31
|
-
describe "when the query is deeper than max depth" do
|
32
|
-
it "adds an error message for a too-deep query" do
|
33
|
-
assert_equal "Query has depth of 7, which exceeds max depth of 5", result["errors"][0]["message"]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "when the query specifies a different max_depth" do
|
38
|
-
let(:result) { DummySchema.execute(query_string, max_depth: 100) }
|
39
|
-
|
40
|
-
it "obeys that max_depth" do
|
41
|
-
assert_equal nil, result["errors"]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "When the query is not deeper than max_depth" do
|
46
|
-
before do
|
47
|
-
DummySchema.max_depth = 100
|
48
|
-
end
|
49
|
-
|
50
|
-
it "doesn't add an error" do
|
51
|
-
assert_equal nil, result["errors"]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "when the max depth isn't set" do
|
56
|
-
before do
|
57
|
-
DummySchema.max_depth = nil
|
58
|
-
end
|
59
|
-
|
60
|
-
it "doesn't add an error message" do
|
61
|
-
assert_equal nil, result["errors"]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "when a fragment exceeds max depth" do
|
66
|
-
before do
|
67
|
-
DummySchema.max_depth = 4
|
68
|
-
end
|
69
|
-
|
70
|
-
let(:query_string) { "
|
71
|
-
{
|
72
|
-
cheese(id: 1) {
|
73
|
-
...moreFields
|
74
|
-
}
|
75
|
-
}
|
76
|
-
|
77
|
-
fragment moreFields on Cheese {
|
78
|
-
similarCheese(source: SHEEP) {
|
79
|
-
similarCheese(source: SHEEP) {
|
80
|
-
similarCheese(source: SHEEP) {
|
81
|
-
...evenMoreFields
|
82
|
-
}
|
83
|
-
}
|
84
|
-
}
|
85
|
-
}
|
86
|
-
|
87
|
-
fragment evenMoreFields on Cheese {
|
88
|
-
similarCheese(source: SHEEP) {
|
89
|
-
similarCheese(source: SHEEP) {
|
90
|
-
id
|
91
|
-
}
|
92
|
-
}
|
93
|
-
}
|
94
|
-
"}
|
95
|
-
|
96
|
-
it "adds an error message for a too-deep query" do
|
97
|
-
assert_equal 1, result["errors"].length
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|