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.
- 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,90 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Query
|
|
3
|
-
# Turn query string values into something useful for query execution
|
|
4
|
-
class LiteralInput
|
|
5
|
-
def self.coerce(type, value, variables)
|
|
6
|
-
if value.is_a?(Language::Nodes::VariableIdentifier)
|
|
7
|
-
variables[value.name]
|
|
8
|
-
elsif value.nil?
|
|
9
|
-
nil
|
|
10
|
-
else
|
|
11
|
-
LiteralKindCoercers::STRATEGIES.fetch(type.kind).coerce(value, type, variables)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def self.from_arguments(ast_arguments, argument_defns, variables)
|
|
16
|
-
values_hash = {}
|
|
17
|
-
argument_defns.each do |arg_name, arg_defn|
|
|
18
|
-
ast_arg = ast_arguments.find { |ast_arg| ast_arg.name == arg_name }
|
|
19
|
-
arg_value = nil
|
|
20
|
-
if ast_arg
|
|
21
|
-
arg_value = coerce(arg_defn.type, ast_arg.value, variables)
|
|
22
|
-
end
|
|
23
|
-
if arg_value.nil?
|
|
24
|
-
arg_value = arg_defn.type.coerce_input(arg_defn.default_value)
|
|
25
|
-
end
|
|
26
|
-
values_hash[arg_name] = arg_value
|
|
27
|
-
end
|
|
28
|
-
GraphQL::Query::Arguments.new(values_hash)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
module LiteralKindCoercers
|
|
32
|
-
module NonNullLiteral
|
|
33
|
-
def self.coerce(value, type, variables)
|
|
34
|
-
LiteralInput.coerce(type.of_type, value, variables)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
module ListLiteral
|
|
39
|
-
def self.coerce(value, type, variables)
|
|
40
|
-
if value.is_a?(Array)
|
|
41
|
-
value.map{ |element_ast| LiteralInput.coerce(type.of_type, element_ast, variables) }
|
|
42
|
-
else
|
|
43
|
-
[LiteralInput.coerce(type.of_type, value, variables)]
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
module InputObjectLiteral
|
|
49
|
-
def self.coerce(value, type, variables)
|
|
50
|
-
hash = {}
|
|
51
|
-
value.arguments.each do |arg|
|
|
52
|
-
field_type = type.input_fields[arg.name].type
|
|
53
|
-
hash[arg.name] = LiteralInput.coerce(field_type, arg.value, variables)
|
|
54
|
-
end
|
|
55
|
-
type.input_fields.each do |arg_name, arg_defn|
|
|
56
|
-
if hash[arg_name].nil?
|
|
57
|
-
value = LiteralInput.coerce(arg_defn.type, arg_defn.default_value, variables)
|
|
58
|
-
if !value.nil?
|
|
59
|
-
hash[arg_name] = value
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
Arguments.new(hash)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
module EnumLiteral
|
|
68
|
-
def self.coerce(value, type, variables)
|
|
69
|
-
type.coerce_input(value.name)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
module ScalarLiteral
|
|
74
|
-
def self.coerce(value, type, variables)
|
|
75
|
-
type.coerce_input(value)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
STRATEGIES = {
|
|
80
|
-
TypeKinds::NON_NULL => NonNullLiteral,
|
|
81
|
-
TypeKinds::LIST => ListLiteral,
|
|
82
|
-
TypeKinds::INPUT_OBJECT => InputObjectLiteral,
|
|
83
|
-
TypeKinds::ENUM => EnumLiteral,
|
|
84
|
-
TypeKinds::SCALAR => ScalarLiteral,
|
|
85
|
-
}
|
|
86
|
-
end
|
|
87
|
-
private_constant :LiteralKindCoercers
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Query
|
|
3
|
-
class SerialExecution
|
|
4
|
-
class ExecutionContext
|
|
5
|
-
attr_reader :query, :schema, :strategy
|
|
6
|
-
|
|
7
|
-
def initialize(query, strategy)
|
|
8
|
-
@query = query
|
|
9
|
-
@schema = query.schema
|
|
10
|
-
@strategy = strategy
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def get_type(type)
|
|
14
|
-
@schema.types[type]
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def get_fragment(name)
|
|
18
|
-
@query.fragments[name]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def get_field(type, name)
|
|
22
|
-
@schema.get_field(type, name)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def add_error(err)
|
|
26
|
-
@query.context.errors << err
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Query
|
|
3
|
-
class SerialExecution
|
|
4
|
-
class FieldResolution
|
|
5
|
-
attr_reader :irep_node, :parent_type, :target, :execution_context, :field, :arguments
|
|
6
|
-
|
|
7
|
-
def initialize(irep_node, parent_type, target, execution_context)
|
|
8
|
-
@irep_node = irep_node
|
|
9
|
-
@parent_type = parent_type
|
|
10
|
-
@target = target
|
|
11
|
-
@execution_context = execution_context
|
|
12
|
-
@field = execution_context.get_field(parent_type, irep_node.definition.name)
|
|
13
|
-
if @field.nil?
|
|
14
|
-
raise("No field found on #{parent_type.name} '#{parent_type}' for '#{ast_node.name}'")
|
|
15
|
-
end
|
|
16
|
-
@arguments = execution_context.query.arguments_for(irep_node)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def result
|
|
20
|
-
result_name = irep_node.name
|
|
21
|
-
begin
|
|
22
|
-
raw_value = get_raw_value
|
|
23
|
-
{ result_name => get_finished_value(raw_value) }
|
|
24
|
-
rescue GraphQL::InvalidNullError => err
|
|
25
|
-
if field.type.kind.non_null?
|
|
26
|
-
raise(err)
|
|
27
|
-
else
|
|
28
|
-
err.parent_error? || execution_context.add_error(err)
|
|
29
|
-
{result_name => nil}
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
private
|
|
35
|
-
|
|
36
|
-
# After getting the value from the field's resolve method,
|
|
37
|
-
# continue by "finishing" the value, eg. executing sub-fields or coercing values
|
|
38
|
-
def get_finished_value(raw_value)
|
|
39
|
-
if raw_value.is_a?(GraphQL::ExecutionError)
|
|
40
|
-
raw_value.ast_node = irep_node.ast_node
|
|
41
|
-
execution_context.add_error(raw_value)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
strategy_class = GraphQL::Query::SerialExecution::ValueResolution.get_strategy_for_kind(field.type.kind)
|
|
45
|
-
result_strategy = strategy_class.new(raw_value, field.type, target, parent_type, irep_node, execution_context)
|
|
46
|
-
result_strategy.result
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
# Get the result of:
|
|
51
|
-
# - Any middleware on this schema
|
|
52
|
-
# - The field's resolve method
|
|
53
|
-
# If the middleware chain returns a GraphQL::ExecutionError, its message
|
|
54
|
-
# is added to the "errors" key.
|
|
55
|
-
def get_raw_value
|
|
56
|
-
steps = execution_context.query.schema.middleware + [get_middleware_proc_from_field_resolve]
|
|
57
|
-
chain = GraphQL::Schema::MiddlewareChain.new(
|
|
58
|
-
steps: steps,
|
|
59
|
-
arguments: [parent_type, target, field, arguments, execution_context.query.context]
|
|
60
|
-
)
|
|
61
|
-
chain.call
|
|
62
|
-
rescue GraphQL::ExecutionError => err
|
|
63
|
-
err
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
# Execute the field's resolve method
|
|
68
|
-
# @return [Proc] suitable to be the last step in a middleware chain
|
|
69
|
-
def get_middleware_proc_from_field_resolve
|
|
70
|
-
-> (_parent_type, parent_object, field_definition, field_args, context, _next) {
|
|
71
|
-
context.ast_node = irep_node.ast_node
|
|
72
|
-
context.irep_node = irep_node
|
|
73
|
-
value = field_definition.resolve(parent_object, field_args, context)
|
|
74
|
-
context.ast_node = nil
|
|
75
|
-
context.irep_node = nil
|
|
76
|
-
value
|
|
77
|
-
}
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Query
|
|
3
|
-
class SerialExecution
|
|
4
|
-
class OperationResolution
|
|
5
|
-
attr_reader :target, :execution_context, :irep_node
|
|
6
|
-
|
|
7
|
-
def initialize(irep_node, target, execution_context)
|
|
8
|
-
@target = target
|
|
9
|
-
@irep_node = irep_node
|
|
10
|
-
@execution_context = execution_context
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def result
|
|
14
|
-
execution_context.strategy.selection_resolution.new(
|
|
15
|
-
execution_context.query.root_value,
|
|
16
|
-
target,
|
|
17
|
-
irep_node,
|
|
18
|
-
execution_context
|
|
19
|
-
).result
|
|
20
|
-
rescue GraphQL::InvalidNullError => err
|
|
21
|
-
err.parent_error? || execution_context.add_error(err)
|
|
22
|
-
nil
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Query
|
|
3
|
-
class SerialExecution
|
|
4
|
-
class SelectionResolution
|
|
5
|
-
attr_reader :target, :type, :irep_node, :execution_context
|
|
6
|
-
|
|
7
|
-
def initialize(target, type, irep_node, execution_context)
|
|
8
|
-
@target = target
|
|
9
|
-
@type = type
|
|
10
|
-
@irep_node = irep_node
|
|
11
|
-
@execution_context = execution_context
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def result
|
|
15
|
-
irep_node.children.each_with_object({}) do |(name, irep_node), memo|
|
|
16
|
-
if included_by_directives?(irep_node, execution_context.query) && applies_to_type?(irep_node, type, target)
|
|
17
|
-
field_result = execution_context.strategy.field_resolution.new(
|
|
18
|
-
irep_node,
|
|
19
|
-
type,
|
|
20
|
-
target,
|
|
21
|
-
execution_context
|
|
22
|
-
).result
|
|
23
|
-
memo.merge!(field_result)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
def included_by_directives?(irep_node, query)
|
|
31
|
-
GraphQL::Query::DirectiveResolution.include_node?(irep_node, query)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def applies_to_type?(irep_node, type, target)
|
|
35
|
-
irep_node.on_types.any? { |child_type|
|
|
36
|
-
GraphQL::Query::TypeResolver.new(target, child_type, type, execution_context.query.context).type
|
|
37
|
-
}
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Query
|
|
3
|
-
class SerialExecution
|
|
4
|
-
module ValueResolution
|
|
5
|
-
def self.get_strategy_for_kind(kind)
|
|
6
|
-
TYPE_KIND_STRATEGIES[kind] || raise("No value resolution strategy for #{kind}!")
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
class BaseResolution
|
|
10
|
-
attr_reader :value, :field_type, :target, :parent_type,
|
|
11
|
-
:irep_node, :execution_context
|
|
12
|
-
def initialize(value, field_type, target, parent_type, irep_node, execution_context)
|
|
13
|
-
@value = value
|
|
14
|
-
@field_type = field_type
|
|
15
|
-
@target = target
|
|
16
|
-
@parent_type = parent_type
|
|
17
|
-
@irep_node = irep_node
|
|
18
|
-
@execution_context = execution_context
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def result
|
|
22
|
-
return nil if value.nil? || value.is_a?(GraphQL::ExecutionError)
|
|
23
|
-
non_null_result
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def non_null_result
|
|
27
|
-
raise NotImplementedError, "Should return a value based on initialization params"
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def get_strategy_for_kind(*args)
|
|
31
|
-
GraphQL::Query::SerialExecution::ValueResolution.get_strategy_for_kind(*args)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
class ScalarResolution < BaseResolution
|
|
36
|
-
# Apply the scalar's defined `coerce_result` method to the value
|
|
37
|
-
def non_null_result
|
|
38
|
-
field_type.coerce_result(value)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
class ListResolution < BaseResolution
|
|
43
|
-
# For each item in the list,
|
|
44
|
-
# Resolve it with the "wrapped" type of this list
|
|
45
|
-
def non_null_result
|
|
46
|
-
wrapped_type = field_type.of_type
|
|
47
|
-
strategy_class = get_strategy_for_kind(wrapped_type.kind)
|
|
48
|
-
value.map do |item|
|
|
49
|
-
inner_strategy = strategy_class.new(item, wrapped_type, target, parent_type, irep_node, execution_context)
|
|
50
|
-
inner_strategy.result
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
class HasPossibleTypeResolution < BaseResolution
|
|
56
|
-
def non_null_result
|
|
57
|
-
resolved_type = field_type.resolve_type(value, execution_context)
|
|
58
|
-
|
|
59
|
-
unless resolved_type.is_a?(GraphQL::ObjectType)
|
|
60
|
-
raise GraphQL::ObjectType::UnresolvedTypeError.new(irep_node.definition.name, field_type, parent_type)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
strategy_class = get_strategy_for_kind(resolved_type.kind)
|
|
64
|
-
inner_strategy = strategy_class.new(value, resolved_type, target, parent_type, irep_node, execution_context)
|
|
65
|
-
inner_strategy.result
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
class ObjectResolution < BaseResolution
|
|
70
|
-
# Resolve the selections on this object
|
|
71
|
-
def non_null_result
|
|
72
|
-
execution_context.strategy.selection_resolution.new(
|
|
73
|
-
value,
|
|
74
|
-
field_type,
|
|
75
|
-
irep_node,
|
|
76
|
-
execution_context
|
|
77
|
-
).result
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
class NonNullResolution < BaseResolution
|
|
82
|
-
# Get the "wrapped" type and resolve the value according to that type
|
|
83
|
-
def result
|
|
84
|
-
if value.nil? || value.is_a?(GraphQL::ExecutionError)
|
|
85
|
-
raise GraphQL::InvalidNullError.new(irep_node.definition.name, value)
|
|
86
|
-
else
|
|
87
|
-
wrapped_type = field_type.of_type
|
|
88
|
-
strategy_class = get_strategy_for_kind(wrapped_type.kind)
|
|
89
|
-
inner_strategy = strategy_class.new(value, wrapped_type, target, parent_type, irep_node, execution_context)
|
|
90
|
-
inner_strategy.result
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
TYPE_KIND_STRATEGIES = {
|
|
96
|
-
GraphQL::TypeKinds::SCALAR => ScalarResolution,
|
|
97
|
-
GraphQL::TypeKinds::LIST => ListResolution,
|
|
98
|
-
GraphQL::TypeKinds::OBJECT => ObjectResolution,
|
|
99
|
-
GraphQL::TypeKinds::ENUM => ScalarResolution,
|
|
100
|
-
GraphQL::TypeKinds::NON_NULL => NonNullResolution,
|
|
101
|
-
GraphQL::TypeKinds::INTERFACE => HasPossibleTypeResolution,
|
|
102
|
-
GraphQL::TypeKinds::UNION => HasPossibleTypeResolution,
|
|
103
|
-
}
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Query
|
|
3
|
-
class SerialExecution
|
|
4
|
-
# This is the only required method for an Execution strategy.
|
|
5
|
-
# You could create a custom execution strategy and configure your schema to
|
|
6
|
-
# use that custom strategy instead.
|
|
7
|
-
#
|
|
8
|
-
# @param ast_operation [GraphQL::Language::Nodes::OperationDefinition] The operation definition to run
|
|
9
|
-
# @param root_type [GraphQL::ObjectType] either the query type or the mutation type
|
|
10
|
-
# @param query_obj [GraphQL::Query] the query object for this execution
|
|
11
|
-
# @return [Hash] a spec-compliant GraphQL result, as a hash
|
|
12
|
-
def execute(ast_operation, root_type, query_object)
|
|
13
|
-
irep_root = query_object.internal_representation[ast_operation.name]
|
|
14
|
-
|
|
15
|
-
operation_resolution.new(
|
|
16
|
-
irep_root,
|
|
17
|
-
root_type,
|
|
18
|
-
ExecutionContext.new(query_object, self)
|
|
19
|
-
).result
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def field_resolution
|
|
23
|
-
self.class::FieldResolution
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def operation_resolution
|
|
27
|
-
self.class::OperationResolution
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def selection_resolution
|
|
31
|
-
self.class::SelectionResolution
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
require "graphql/query/serial_execution/execution_context"
|
|
38
|
-
require "graphql/query/serial_execution/value_resolution"
|
|
39
|
-
require "graphql/query/serial_execution/field_resolution"
|
|
40
|
-
require "graphql/query/serial_execution/operation_resolution"
|
|
41
|
-
require "graphql/query/serial_execution/selection_resolution"
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Query
|
|
3
|
-
# Given an object, a type name (from the query) and a type object,
|
|
4
|
-
# Return the type that should be used for `object`
|
|
5
|
-
# or Return `nil` if it's a mismatch
|
|
6
|
-
class TypeResolver
|
|
7
|
-
attr_reader :type
|
|
8
|
-
def initialize(target, child_type, parent_type, query_ctx)
|
|
9
|
-
@type = if child_type.nil?
|
|
10
|
-
nil
|
|
11
|
-
elsif parent_type.kind.union?
|
|
12
|
-
parent_type.resolve_type(target)
|
|
13
|
-
elsif child_type.kind.union? && child_type.include?(parent_type)
|
|
14
|
-
parent_type
|
|
15
|
-
elsif child_type.kind.interface?
|
|
16
|
-
child_type.resolve_type(target, query_ctx)
|
|
17
|
-
elsif child_type == parent_type
|
|
18
|
-
parent_type
|
|
19
|
-
else
|
|
20
|
-
nil
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
data/lib/graphql/scalar_type.rb
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
# The parent type for scalars, eg {GraphQL::STRING_TYPE}, {GraphQL::INT_TYPE}
|
|
3
|
-
#
|
|
4
|
-
# @example defining a type for Time
|
|
5
|
-
# TimeType = GraphQL::ScalarType.define do
|
|
6
|
-
# name "Time"
|
|
7
|
-
# description "Time since epoch in seconds"
|
|
8
|
-
#
|
|
9
|
-
# coerce_input ->(value) { Time.at(Float(value)) }
|
|
10
|
-
# coerce_result ->(value) { value.to_f }
|
|
11
|
-
# end
|
|
12
|
-
#
|
|
13
|
-
class ScalarType < GraphQL::BaseType
|
|
14
|
-
accepts_definitions :coerce, :coerce_input, :coerce_result
|
|
15
|
-
|
|
16
|
-
def coerce=(proc)
|
|
17
|
-
self.coerce_input = proc
|
|
18
|
-
self.coerce_result = proc
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def validate_non_null_input(value)
|
|
22
|
-
result = Query::InputValidationResult.new
|
|
23
|
-
if coerce_non_null_input(value).nil?
|
|
24
|
-
result.add_problem("Could not coerce value #{JSON.dump(value)} to #{name}")
|
|
25
|
-
end
|
|
26
|
-
result
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def coerce_non_null_input(value)
|
|
30
|
-
@coerce_input_proc.call(value)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def coerce_input=(proc)
|
|
34
|
-
if !proc.nil?
|
|
35
|
-
@coerce_input_proc = proc
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def coerce_result(value)
|
|
40
|
-
@coerce_result_proc.call(value)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def coerce_result=(proc)
|
|
44
|
-
if !proc.nil?
|
|
45
|
-
@coerce_result_proc = proc
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def kind
|
|
50
|
-
GraphQL::TypeKinds::SCALAR
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Schema
|
|
3
|
-
# In early GraphQL versions, errors would be "automatically"
|
|
4
|
-
# rescued and replaced with `"Internal error"`. That behavior
|
|
5
|
-
# was undesirable but this middleware is offered for people who
|
|
6
|
-
# want to preserve it.
|
|
7
|
-
#
|
|
8
|
-
# It has a couple of differences from the previous behavior:
|
|
9
|
-
#
|
|
10
|
-
# - Other parts of the query _will_ be run (previously,
|
|
11
|
-
# execution would stop when the error was raised and the result
|
|
12
|
-
# would have no `"data"` key at all)
|
|
13
|
-
# - The entry in {Query::Context#errors} is a {GraphQL::ExecutionError}, _not_
|
|
14
|
-
# the originally-raised error.
|
|
15
|
-
# - The entry in the `"errors"` key includes the location of the field
|
|
16
|
-
# which raised the errors.
|
|
17
|
-
#
|
|
18
|
-
# @example Use CatchallMiddleware with your schema
|
|
19
|
-
# # All errors will be suppressed and replaced with "Internal error" messages
|
|
20
|
-
# MySchema.middleware << GraphQL::Schema::CatchallMiddleware
|
|
21
|
-
#
|
|
22
|
-
module CatchallMiddleware
|
|
23
|
-
MESSAGE = "Internal error"
|
|
24
|
-
|
|
25
|
-
# Rescue any error and replace it with a {GraphQL::ExecutionError}
|
|
26
|
-
# whose message is {MESSAGE}
|
|
27
|
-
def self.call(parent_type, parent_object, field_definition, field_args, query_context, next_middleware)
|
|
28
|
-
next_middleware.call
|
|
29
|
-
rescue StandardError => err
|
|
30
|
-
GraphQL::ExecutionError.new(MESSAGE)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Schema
|
|
3
|
-
# Given {steps} and {arguments}, call steps in order, passing `(*arguments, next_step)`.
|
|
4
|
-
#
|
|
5
|
-
# Steps should call `next_step.call` to continue the chain, or _not_ call it to stop the chain.
|
|
6
|
-
class MiddlewareChain
|
|
7
|
-
# @return [Array<#call(*args)>] Steps in this chain, will be called with arguments and `next_middleware`
|
|
8
|
-
attr_reader :steps
|
|
9
|
-
|
|
10
|
-
# @return [Array] Arguments passed to steps (followed by `next_middleware`)
|
|
11
|
-
attr_reader :arguments
|
|
12
|
-
|
|
13
|
-
def initialize(steps:, arguments:)
|
|
14
|
-
# We're gonna destroy this array, so copy it:
|
|
15
|
-
@steps = steps.dup
|
|
16
|
-
@arguments = arguments
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Run the next step in the chain, passing in arguments and handle to the next step
|
|
20
|
-
def call(next_arguments = @arguments)
|
|
21
|
-
@arguments = next_arguments
|
|
22
|
-
next_step = steps.shift
|
|
23
|
-
next_middleware = self
|
|
24
|
-
next_step.call(*arguments, next_middleware)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Schema
|
|
3
|
-
# Find the members of a union or interface within a given schema.
|
|
4
|
-
#
|
|
5
|
-
# (Although its members never change, unions are handled this way to simplify execution code.)
|
|
6
|
-
#
|
|
7
|
-
# Internally, the calculation is cached. It's assumed that schema members _don't_ change after creating the schema!
|
|
8
|
-
#
|
|
9
|
-
# @example Get an interface's possible types
|
|
10
|
-
# possible_types = GraphQL::Schema::PossibleTypes(MySchema)
|
|
11
|
-
# possible_types.possible_types(MyInterface)
|
|
12
|
-
# # => [MyObjectType, MyOtherObjectType]
|
|
13
|
-
class PossibleTypes
|
|
14
|
-
def initialize(schema)
|
|
15
|
-
@object_types = schema.types.values.select { |type| type.kind.object? }
|
|
16
|
-
|
|
17
|
-
@storage = Hash.new do |hash, key|
|
|
18
|
-
hash[key] = @object_types.select { |type| type.interfaces.include?(key) }.sort_by(&:name)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def possible_types(type_defn)
|
|
23
|
-
case type_defn
|
|
24
|
-
when GraphQL::UnionType
|
|
25
|
-
type_defn.possible_types
|
|
26
|
-
when GraphQL::InterfaceType
|
|
27
|
-
@storage[type_defn]
|
|
28
|
-
else
|
|
29
|
-
raise "#{type_defn} doesn't have possible types"
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
module GraphQL
|
|
2
|
-
class Schema
|
|
3
|
-
module ReduceTypes
|
|
4
|
-
# @param types [Array<GraphQL::BaseType>] members of a schema to crawl for all member types
|
|
5
|
-
# @return [GraphQL::Schema::TypeMap] `{name => Type}` pairs derived from `types`
|
|
6
|
-
def self.reduce(types)
|
|
7
|
-
type_map = GraphQL::Schema::TypeMap.new
|
|
8
|
-
types.each do |type|
|
|
9
|
-
reduce_type(type, type_map, type.name)
|
|
10
|
-
end
|
|
11
|
-
type_map
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
# Based on `type`, add members to `type_hash`.
|
|
17
|
-
# If `type` has already been visited, just return the `type_hash` as-is
|
|
18
|
-
def self.reduce_type(type, type_hash, context_description)
|
|
19
|
-
if !type.is_a?(GraphQL::BaseType)
|
|
20
|
-
message = "#{context_description} has an invalid type: must be an instance of GraphQL::BaseType, not #{type.class.inspect} (#{type.inspect})"
|
|
21
|
-
raise GraphQL::Schema::InvalidTypeError.new(message)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
type = type.unwrap
|
|
25
|
-
|
|
26
|
-
# Don't re-visit a type
|
|
27
|
-
if !type_hash.fetch(type.name, nil).equal?(type)
|
|
28
|
-
validate_type(type, context_description)
|
|
29
|
-
type_hash[type.name] = type
|
|
30
|
-
crawl_type(type, type_hash, context_description)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def self.crawl_type(type, type_hash, context_description)
|
|
35
|
-
if type.kind.fields?
|
|
36
|
-
type.all_fields.each do |field|
|
|
37
|
-
reduce_type(field.type, type_hash, "Field #{type.name}.#{field.name}")
|
|
38
|
-
field.arguments.each do |name, argument|
|
|
39
|
-
reduce_type(argument.type, type_hash, "Argument #{name} on #{type.name}.#{field.name}")
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
if type.kind.object?
|
|
44
|
-
type.interfaces.each do |interface|
|
|
45
|
-
reduce_type(interface, type_hash, "Interface on #{type.name}")
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
if type.kind.union?
|
|
49
|
-
type.possible_types.each do |possible_type|
|
|
50
|
-
reduce_type(possible_type, type_hash, "Possible type for #{type.name}")
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
if type.kind.input_object?
|
|
54
|
-
type.arguments.each do |argument_name, argument|
|
|
55
|
-
reduce_type(argument.type, type_hash, "Input field #{type.name}.#{argument_name}")
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def self.validate_type(type, context_description)
|
|
61
|
-
error_message = GraphQL::Schema::Validation.validate(type)
|
|
62
|
-
if error_message
|
|
63
|
-
raise GraphQL::Schema::InvalidTypeError.new("#{context_description} is invalid: #{error_message}")
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|