graphql 0.16.0 → 2.0.15
Sign up to get free protection for your applications and to get access to all the features.
- 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,102 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::Schema::ReduceTypes do
|
4
|
-
def reduce_types(types)
|
5
|
-
GraphQL::Schema::ReduceTypes.reduce(types)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "finds types from a single type and its fields" do
|
9
|
-
expected = {
|
10
|
-
"Cheese" => CheeseType,
|
11
|
-
"Float" => GraphQL::FLOAT_TYPE,
|
12
|
-
"String" => GraphQL::STRING_TYPE,
|
13
|
-
"DairyAnimal" => DairyAnimalEnum,
|
14
|
-
"Int" => GraphQL::INT_TYPE,
|
15
|
-
"Edible" => EdibleInterface,
|
16
|
-
"AnimalProduct" => AnimalProductInterface,
|
17
|
-
}
|
18
|
-
result = reduce_types([CheeseType])
|
19
|
-
assert_equal(expected.keys, result.keys)
|
20
|
-
assert_equal(expected, result.to_h)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "finds type from arguments" do
|
24
|
-
result = reduce_types([QueryType])
|
25
|
-
assert_equal(DairyProductInputType, result["DairyProductInput"])
|
26
|
-
end
|
27
|
-
|
28
|
-
it "finds types from nested InputObjectTypes" do
|
29
|
-
type_child = GraphQL::InputObjectType.define do
|
30
|
-
name "InputTypeChild"
|
31
|
-
input_field :someField, GraphQL::STRING_TYPE
|
32
|
-
end
|
33
|
-
|
34
|
-
type_parent = GraphQL::InputObjectType.define do
|
35
|
-
name "InputTypeParent"
|
36
|
-
input_field :child, type_child
|
37
|
-
end
|
38
|
-
|
39
|
-
result = reduce_types([type_parent])
|
40
|
-
expected = {
|
41
|
-
"InputTypeParent" => type_parent,
|
42
|
-
"InputTypeChild" => type_child,
|
43
|
-
"String" => GraphQL::STRING_TYPE
|
44
|
-
}
|
45
|
-
assert_equal(expected, result.to_h)
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "when a type is invalid" do
|
49
|
-
let(:invalid_type) {
|
50
|
-
GraphQL::ObjectType.define do
|
51
|
-
name "InvalidType"
|
52
|
-
field :someField
|
53
|
-
end
|
54
|
-
}
|
55
|
-
|
56
|
-
let(:another_invalid_type) {
|
57
|
-
GraphQL::ObjectType.define do
|
58
|
-
name "AnotherInvalidType"
|
59
|
-
field :someField, String
|
60
|
-
end
|
61
|
-
}
|
62
|
-
|
63
|
-
it "raises an InvalidTypeError when passed nil" do
|
64
|
-
assert_raises(GraphQL::Schema::InvalidTypeError) { reduce_types([invalid_type]) }
|
65
|
-
end
|
66
|
-
|
67
|
-
it "raises an InvalidTypeError when passed an object that isnt a GraphQL::BaseType" do
|
68
|
-
assert_raises(GraphQL::Schema::InvalidTypeError) { reduce_types([another_invalid_type]) }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "when a schema has multiple types with the same name" do
|
73
|
-
let(:type_1) {
|
74
|
-
GraphQL::ObjectType.define do
|
75
|
-
name "MyType"
|
76
|
-
end
|
77
|
-
}
|
78
|
-
let(:type_2) {
|
79
|
-
GraphQL::ObjectType.define do
|
80
|
-
name "MyType"
|
81
|
-
end
|
82
|
-
}
|
83
|
-
it "raises an error" do
|
84
|
-
assert_raises(RuntimeError) {
|
85
|
-
reduce_types([type_1, type_2])
|
86
|
-
}
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "when getting a type which doesnt exist" do
|
91
|
-
it "raises an error" do
|
92
|
-
type_map = reduce_types([])
|
93
|
-
assert_raises(RuntimeError) { type_map["SomeType"] }
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "when a field is only accessible through an interface" do
|
98
|
-
it "is found through Schema.new(types:)" do
|
99
|
-
assert_equal HoneyType, DummySchema.types["Honey"]
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
class SpecExampleError < StandardError; end
|
4
|
-
|
5
|
-
describe GraphQL::Schema::RescueMiddleware do
|
6
|
-
let(:error_middleware) { -> (next_middleware) { raise(error_class) } }
|
7
|
-
|
8
|
-
let(:rescue_middleware) do
|
9
|
-
middleware = GraphQL::Schema::RescueMiddleware.new
|
10
|
-
middleware.rescue_from(SpecExampleError) { |err| "there was an example error: #{err.class.name}" }
|
11
|
-
middleware
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:steps) { [rescue_middleware, error_middleware] }
|
15
|
-
|
16
|
-
let(:middleware_chain) { GraphQL::Schema::MiddlewareChain.new(steps: steps, arguments: [])}
|
17
|
-
|
18
|
-
describe "known errors" do
|
19
|
-
let(:error_class) { SpecExampleError }
|
20
|
-
it "handles them as execution errors" do
|
21
|
-
result = middleware_chain.call
|
22
|
-
assert_equal("there was an example error: SpecExampleError", result.message)
|
23
|
-
assert_equal(GraphQL::ExecutionError, result.class)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "unknown errors" do
|
28
|
-
let(:error_class) { RuntimeError }
|
29
|
-
it "re-raises them" do
|
30
|
-
assert_raises(RuntimeError) { middleware_chain.call }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::Schema::TimeoutMiddleware do
|
4
|
-
let(:max_seconds) { 2 }
|
5
|
-
let(:timeout_middleware) { GraphQL::Schema::TimeoutMiddleware.new(max_seconds: 2) }
|
6
|
-
let(:timeout_schema) {
|
7
|
-
|
8
|
-
sleep_for_seconds_resolve = -> (obj, args, ctx) {
|
9
|
-
sleep(args[:seconds])
|
10
|
-
args[:seconds]
|
11
|
-
}
|
12
|
-
|
13
|
-
nested_sleep_type = GraphQL::ObjectType.define do
|
14
|
-
name "NestedSleep"
|
15
|
-
field :seconds, types.Float do
|
16
|
-
resolve -> (obj, args, ctx) { obj }
|
17
|
-
end
|
18
|
-
|
19
|
-
field :nestedSleep, -> { nested_sleep_type } do
|
20
|
-
argument :seconds, !types.Float
|
21
|
-
resolve(sleep_for_seconds_resolve)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
query_type = GraphQL::ObjectType.define do
|
26
|
-
name "Query"
|
27
|
-
field :sleepFor, types.Float do
|
28
|
-
argument :seconds, !types.Float
|
29
|
-
resolve(sleep_for_seconds_resolve)
|
30
|
-
end
|
31
|
-
|
32
|
-
field :nestedSleep, nested_sleep_type do
|
33
|
-
argument :seconds, !types.Float
|
34
|
-
resolve(sleep_for_seconds_resolve)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
schema = GraphQL::Schema.new(query: query_type)
|
39
|
-
schema.middleware << timeout_middleware
|
40
|
-
schema
|
41
|
-
}
|
42
|
-
|
43
|
-
let(:result) { timeout_schema.execute(query_string) }
|
44
|
-
|
45
|
-
describe "timeout part-way through" do
|
46
|
-
let(:query_string) {%|
|
47
|
-
{
|
48
|
-
a: sleepFor(seconds: 0.7)
|
49
|
-
b: sleepFor(seconds: 0.7)
|
50
|
-
c: sleepFor(seconds: 0.7)
|
51
|
-
d: sleepFor(seconds: 0.7)
|
52
|
-
e: sleepFor(seconds: 0.7)
|
53
|
-
}
|
54
|
-
|}
|
55
|
-
it "returns a partial response and error messages" do
|
56
|
-
expected_data = {
|
57
|
-
"a"=>0.7,
|
58
|
-
"b"=>0.7,
|
59
|
-
"c"=>0.7,
|
60
|
-
"d"=>nil,
|
61
|
-
"e"=>nil,
|
62
|
-
}
|
63
|
-
|
64
|
-
expected_errors = [
|
65
|
-
{
|
66
|
-
"message"=>"Timeout on Query.sleepFor",
|
67
|
-
"locations"=>[{"line"=>6, "column"=>9}]
|
68
|
-
},
|
69
|
-
{
|
70
|
-
"message"=>"Timeout on Query.sleepFor",
|
71
|
-
"locations"=>[{"line"=>7, "column"=>9}]
|
72
|
-
},
|
73
|
-
]
|
74
|
-
assert_equal expected_data, result["data"]
|
75
|
-
assert_equal expected_errors, result["errors"]
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "timeout in nested fields" do
|
80
|
-
let(:query_string) {%|
|
81
|
-
{
|
82
|
-
a: nestedSleep(seconds: 1) {
|
83
|
-
seconds
|
84
|
-
b: nestedSleep(seconds: 0.4) {
|
85
|
-
seconds
|
86
|
-
c: nestedSleep(seconds: 0.4) {
|
87
|
-
seconds
|
88
|
-
d: nestedSleep(seconds: 0.4) {
|
89
|
-
seconds
|
90
|
-
e: nestedSleep(seconds: 0.4) {
|
91
|
-
seconds
|
92
|
-
}
|
93
|
-
}
|
94
|
-
}
|
95
|
-
}
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|}
|
99
|
-
it "returns a partial response and error messages" do
|
100
|
-
expected_data = {
|
101
|
-
"a" => {
|
102
|
-
"seconds" => 1.0,
|
103
|
-
"b" => {
|
104
|
-
"seconds" => 0.4,
|
105
|
-
"c" => {
|
106
|
-
"seconds"=>0.4,
|
107
|
-
"d" => {
|
108
|
-
"seconds"=>nil,
|
109
|
-
"e"=>nil
|
110
|
-
}
|
111
|
-
}
|
112
|
-
}
|
113
|
-
}
|
114
|
-
}
|
115
|
-
expected_errors = [
|
116
|
-
{
|
117
|
-
"message"=>"Timeout on NestedSleep.seconds",
|
118
|
-
"locations"=>[{"line"=>10, "column"=>15}]
|
119
|
-
},
|
120
|
-
{
|
121
|
-
"message"=>"Timeout on NestedSleep.nestedSleep",
|
122
|
-
"locations"=>[{"line"=>11, "column"=>15}]
|
123
|
-
},
|
124
|
-
]
|
125
|
-
|
126
|
-
assert_equal expected_data, result["data"]
|
127
|
-
assert_equal expected_errors, result["errors"]
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "long-running fields" do
|
132
|
-
let(:query_string) {%|
|
133
|
-
{
|
134
|
-
a: sleepFor(seconds: 0.7)
|
135
|
-
b: sleepFor(seconds: 0.7)
|
136
|
-
c: sleepFor(seconds: 1.5)
|
137
|
-
d: sleepFor(seconds: 0.1)
|
138
|
-
}
|
139
|
-
|}
|
140
|
-
it "doesn't terminate long-running field execution" do
|
141
|
-
expected_data = {
|
142
|
-
"a"=>0.7,
|
143
|
-
"b"=>0.7,
|
144
|
-
"c"=>1.5,
|
145
|
-
"d"=>nil,
|
146
|
-
}
|
147
|
-
|
148
|
-
expected_errors = [
|
149
|
-
{
|
150
|
-
"message"=>"Timeout on Query.sleepFor",
|
151
|
-
"locations"=>[{"line"=>6, "column"=>9}]
|
152
|
-
},
|
153
|
-
]
|
154
|
-
|
155
|
-
assert_equal expected_data, result["data"]
|
156
|
-
assert_equal expected_errors, result["errors"]
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "with a custom block" do
|
161
|
-
let(:timeout_middleware) {
|
162
|
-
GraphQL::Schema::TimeoutMiddleware.new(max_seconds: 2) do |err, query|
|
163
|
-
raise("Query timed out after 2s: #{query.class.name}")
|
164
|
-
end
|
165
|
-
}
|
166
|
-
let(:query_string) {%|
|
167
|
-
{
|
168
|
-
a: sleepFor(seconds: 0.7)
|
169
|
-
b: sleepFor(seconds: 0.7)
|
170
|
-
c: sleepFor(seconds: 0.7)
|
171
|
-
d: sleepFor(seconds: 0.7)
|
172
|
-
e: sleepFor(seconds: 0.7)
|
173
|
-
}
|
174
|
-
|}
|
175
|
-
|
176
|
-
it "calls the block" do
|
177
|
-
assert_raises(RuntimeError) { result }
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::Schema::TypeExpression do
|
4
|
-
let(:schema) { DummySchema }
|
5
|
-
let(:ast_node) {
|
6
|
-
document = GraphQL.parse("query dostuff($var: #{type_name}) { id } ")
|
7
|
-
document.definitions.first.variables.first.type
|
8
|
-
}
|
9
|
-
let(:type_expression_result) { GraphQL::Schema::TypeExpression.build_type(schema, ast_node) }
|
10
|
-
|
11
|
-
describe "#type" do
|
12
|
-
describe "simple types" do
|
13
|
-
let(:type_name) { "DairyProductInput" }
|
14
|
-
it "it gets types from the schema" do
|
15
|
-
assert_equal(DairyProductInputType, type_expression_result)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "non-null types" do
|
20
|
-
let(:type_name) { "String!"}
|
21
|
-
it "makes non-null types" do
|
22
|
-
assert_equal(GraphQL::STRING_TYPE.to_non_null_type,type_expression_result)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "list types" do
|
27
|
-
let(:type_name) { "[DairyAnimal!]!" }
|
28
|
-
|
29
|
-
it "makes list types" do
|
30
|
-
expected = DairyAnimalEnum
|
31
|
-
.to_non_null_type
|
32
|
-
.to_list_type
|
33
|
-
.to_non_null_type
|
34
|
-
assert_equal(expected, type_expression_result)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,219 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::Schema::Validation do
|
4
|
-
def assert_error_includes(object, error_substring)
|
5
|
-
validation_error = GraphQL::Schema::Validation.validate(object)
|
6
|
-
assert_includes validation_error, error_substring
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "validating Fields" do
|
10
|
-
let(:unnamed_field) {
|
11
|
-
GraphQL::Field.define do
|
12
|
-
type GraphQL::STRING_TYPE
|
13
|
-
end
|
14
|
-
}
|
15
|
-
|
16
|
-
let(:untyped_field) {
|
17
|
-
GraphQL::Field.define do
|
18
|
-
name "Untyped"
|
19
|
-
type :something_invalid
|
20
|
-
end
|
21
|
-
}
|
22
|
-
|
23
|
-
let(:bad_arguments_field) {
|
24
|
-
field = GraphQL::Field.define do
|
25
|
-
name "BadArgs"
|
26
|
-
type !GraphQL::BOOLEAN_TYPE
|
27
|
-
end
|
28
|
-
field.arguments[:bad_key] = :bad_value
|
29
|
-
field
|
30
|
-
}
|
31
|
-
|
32
|
-
let(:invalid_argument_member_field) {
|
33
|
-
GraphQL::Field.define do
|
34
|
-
name "InvalidArgument"
|
35
|
-
type !types[!GraphQL::INT_TYPE]
|
36
|
-
argument :invalid do
|
37
|
-
type GraphQL::STRING_TYPE
|
38
|
-
default_value [1,2,3]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
}
|
42
|
-
|
43
|
-
it "requires a String for name" do
|
44
|
-
assert_error_includes unnamed_field, "must return String, not NilClass"
|
45
|
-
end
|
46
|
-
|
47
|
-
it "requires a BaseType for type" do
|
48
|
-
assert_error_includes untyped_field, "must return GraphQL::BaseType, not Symbol"
|
49
|
-
end
|
50
|
-
|
51
|
-
it "requires String => Argument arguments" do
|
52
|
-
assert_error_includes bad_arguments_field, "must map String => GraphQL::Argument, not Symbol => Symbol"
|
53
|
-
end
|
54
|
-
|
55
|
-
it "applies validation to its member Arguments" do
|
56
|
-
assert_error_includes invalid_argument_member_field, "default value [1, 2, 3] is not valid for type String"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "validating BaseType" do
|
61
|
-
let(:unnamed_type) {
|
62
|
-
GraphQL::BaseType.define do
|
63
|
-
name :invalid_name
|
64
|
-
end
|
65
|
-
}
|
66
|
-
|
67
|
-
let(:wrongly_described_type) {
|
68
|
-
GraphQL::BaseType.define do
|
69
|
-
name "WronglyDescribed"
|
70
|
-
description 12345
|
71
|
-
end
|
72
|
-
}
|
73
|
-
it "requires a String name" do
|
74
|
-
assert_error_includes unnamed_type, "must return String, not Symbol"
|
75
|
-
end
|
76
|
-
|
77
|
-
it "requires String-or-nil description" do
|
78
|
-
assert_error_includes wrongly_described_type, "must return String or NilClass, not Fixnum"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "validating ObjectTypes" do
|
83
|
-
let(:invalid_interfaces_object) {
|
84
|
-
GraphQL::ObjectType.define do
|
85
|
-
name "InvalidInterfaces"
|
86
|
-
interfaces(55)
|
87
|
-
end
|
88
|
-
}
|
89
|
-
let(:invalid_interface_member_object) {
|
90
|
-
GraphQL::ObjectType.define do
|
91
|
-
name "InvalidInterfaceMember"
|
92
|
-
interfaces [:not_an_interface]
|
93
|
-
end
|
94
|
-
}
|
95
|
-
|
96
|
-
let(:invalid_field_object) {
|
97
|
-
GraphQL::ObjectType.define do
|
98
|
-
name "InvalidField"
|
99
|
-
field :invalid, :nonsense
|
100
|
-
end
|
101
|
-
}
|
102
|
-
|
103
|
-
it "requires an Array for interfaces" do
|
104
|
-
assert_error_includes invalid_interfaces_object, "must be an Array of GraphQL::InterfaceType, not a Fixnum"
|
105
|
-
assert_error_includes invalid_interface_member_object, "must contain GraphQL::InterfaceType, not Symbol"
|
106
|
-
end
|
107
|
-
|
108
|
-
it "validates the fields" do
|
109
|
-
assert_error_includes invalid_field_object, "must return GraphQL::BaseType, not Symbol"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe "validating UnionTypes" do
|
114
|
-
let(:non_array_union) {
|
115
|
-
GraphQL::UnionType.define do
|
116
|
-
name "NonArray"
|
117
|
-
possible_types 55
|
118
|
-
end
|
119
|
-
}
|
120
|
-
|
121
|
-
let(:non_object_type_union) {
|
122
|
-
GraphQL::UnionType.define do
|
123
|
-
name "NonObjectTypes"
|
124
|
-
possible_types [
|
125
|
-
GraphQL::InterfaceType.new
|
126
|
-
]
|
127
|
-
end
|
128
|
-
}
|
129
|
-
|
130
|
-
let(:no_possible_types_union) {
|
131
|
-
GraphQL::UnionType.define do
|
132
|
-
name "NoPossibleTypes"
|
133
|
-
possible_types []
|
134
|
-
end
|
135
|
-
}
|
136
|
-
|
137
|
-
it "requires an array of ObjectTypes for possible_types" do
|
138
|
-
assert_error_includes non_array_union, "must be an Array of GraphQL::ObjectType, not a Fixnum"
|
139
|
-
|
140
|
-
assert_error_includes non_object_type_union, "must contain GraphQL::ObjectType, not GraphQL::InterfaceType"
|
141
|
-
end
|
142
|
-
|
143
|
-
it "requires at least one possible_types" do
|
144
|
-
assert_error_includes no_possible_types_union, "must have at least one possible type"
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "validating InputObjectTypes" do
|
149
|
-
let(:invalid_arguments_input) {
|
150
|
-
input = GraphQL::InputObjectType.define do
|
151
|
-
name "InvalidArgumentsHash"
|
152
|
-
end
|
153
|
-
input.arguments[123] = :nonsense
|
154
|
-
input
|
155
|
-
}
|
156
|
-
|
157
|
-
let(:invalid_argument_member_input) {
|
158
|
-
GraphQL::InputObjectType.define do
|
159
|
-
name "InvalidArgumentMember"
|
160
|
-
argument :nonsense do
|
161
|
-
type GraphQL::FLOAT_TYPE
|
162
|
-
default_value "xyz"
|
163
|
-
end
|
164
|
-
end
|
165
|
-
}
|
166
|
-
|
167
|
-
it "requires {String => Argument} arguments" do
|
168
|
-
assert_error_includes invalid_arguments_input, "map String => GraphQL::Argument, not Fixnum => Symbol"
|
169
|
-
end
|
170
|
-
|
171
|
-
it "applies validation to its member Arguments" do
|
172
|
-
assert_error_includes invalid_argument_member_input, "default value \"xyz\" is not valid for type Float"
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "validating InterfaceTypes" do
|
177
|
-
let(:invalid_field_interface) {
|
178
|
-
GraphQL::InterfaceType.define do
|
179
|
-
name "InvalidField"
|
180
|
-
field :invalid do
|
181
|
-
type GraphQL::BOOLEAN_TYPE
|
182
|
-
argument :invalid do
|
183
|
-
type GraphQL::STRING_TYPE
|
184
|
-
default_value 4.56
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
}
|
189
|
-
|
190
|
-
it "validates fields" do
|
191
|
-
assert_error_includes invalid_field_interface, "default value 4.56 is not valid for type String"
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe "validating Arguments" do
|
196
|
-
let(:untyped_argument) {
|
197
|
-
GraphQL::Argument.define do
|
198
|
-
name "Untyped"
|
199
|
-
type :Bogus
|
200
|
-
end
|
201
|
-
}
|
202
|
-
|
203
|
-
let(:invalid_default_argument) {
|
204
|
-
GraphQL::Argument.define do
|
205
|
-
name "InvalidDefault"
|
206
|
-
type GraphQL::INT_TYPE
|
207
|
-
default_value "abc"
|
208
|
-
end
|
209
|
-
}
|
210
|
-
|
211
|
-
it "requires the type is a Base type" do
|
212
|
-
assert_error_includes untyped_argument, "must be a valid input type (Scalar or InputObject), not Symbol"
|
213
|
-
end
|
214
|
-
|
215
|
-
it "requires the default value is compatible" do
|
216
|
-
assert_error_includes invalid_default_argument, 'default value "abc" is not valid for type Int'
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
data/spec/graphql/schema_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::Schema do
|
4
|
-
let(:schema) { DummySchema }
|
5
|
-
|
6
|
-
describe "#rescue_from" do
|
7
|
-
let(:rescue_middleware) { schema.middleware.first }
|
8
|
-
|
9
|
-
it "adds handlers to the rescue middleware" do
|
10
|
-
assert_equal(1, rescue_middleware.rescue_table.length)
|
11
|
-
# normally, you'd use a real class, not a symbol:
|
12
|
-
schema.rescue_from(:error_class) { "my custom message" }
|
13
|
-
assert_equal(2, rescue_middleware.rescue_table.length)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#subscription" do
|
18
|
-
it "calls fields on the subscription type" do
|
19
|
-
res = schema.execute("subscription { test }")
|
20
|
-
assert_equal("Test", res["data"]["test"])
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::StaticValidation::ArgumentLiteralsAreCompatible do
|
4
|
-
let(:query_string) {%|
|
5
|
-
query getCheese {
|
6
|
-
cheese(id: "aasdlkfj") { source }
|
7
|
-
cheese(id: 1) { source @skip(if: {id: 1})}
|
8
|
-
yakSource: searchDairy(product: [{source: COW, fatContent: 1.1}]) { source }
|
9
|
-
badSource: searchDairy(product: [{source: 1.1}]) { source }
|
10
|
-
missingSource: searchDairy(product: [{fatContent: 1.1}]) { source }
|
11
|
-
listCoerce: cheese(id: 1) { similarCheese(source: YAK) }
|
12
|
-
missingInputField: searchDairy(product: [{source: YAK, wacky: 1}])
|
13
|
-
}
|
14
|
-
|
15
|
-
fragment cheeseFields on Cheese {
|
16
|
-
similarCheese(source: 4.5)
|
17
|
-
}
|
18
|
-
|}
|
19
|
-
|
20
|
-
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::ArgumentLiteralsAreCompatible]) }
|
21
|
-
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
22
|
-
let(:errors) { validator.validate(query)[:errors] }
|
23
|
-
|
24
|
-
it "finds undefined or missing-required arguments to fields and directives" do
|
25
|
-
assert_equal(6, errors.length)
|
26
|
-
|
27
|
-
query_root_error = {
|
28
|
-
"message"=>"Argument 'id' on Field 'cheese' has an invalid value",
|
29
|
-
"locations"=>[{"line"=>3, "column"=>7}]
|
30
|
-
}
|
31
|
-
assert_includes(errors, query_root_error)
|
32
|
-
|
33
|
-
directive_error = {
|
34
|
-
"message"=>"Argument 'if' on Directive 'skip' has an invalid value",
|
35
|
-
"locations"=>[{"line"=>4, "column"=>30}]
|
36
|
-
}
|
37
|
-
assert_includes(errors, directive_error)
|
38
|
-
|
39
|
-
input_object_error = {
|
40
|
-
"message"=>"Argument 'product' on Field 'badSource' has an invalid value",
|
41
|
-
"locations"=>[{"line"=>6, "column"=>7}]
|
42
|
-
}
|
43
|
-
assert_includes(errors, input_object_error)
|
44
|
-
|
45
|
-
input_object_field_error = {
|
46
|
-
"message"=>"Argument 'source' on InputObject 'DairyProductInput' has an invalid value",
|
47
|
-
"locations"=>[{"line"=>6, "column"=>40}]
|
48
|
-
}
|
49
|
-
assert_includes(errors, input_object_field_error)
|
50
|
-
|
51
|
-
missing_required_field_error = {
|
52
|
-
"message"=>"Argument 'product' on Field 'missingSource' has an invalid value",
|
53
|
-
"locations"=>[{"line"=>7, "column"=>7}]
|
54
|
-
}
|
55
|
-
assert_includes(errors, missing_required_field_error)
|
56
|
-
|
57
|
-
fragment_error = {
|
58
|
-
"message"=>"Argument 'source' on Field 'similarCheese' has an invalid value",
|
59
|
-
"locations"=>[{"line"=>13, "column"=>7}]
|
60
|
-
}
|
61
|
-
assert_includes(errors, fragment_error)
|
62
|
-
end
|
63
|
-
end
|