graphql 0.16.0 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of graphql might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.yardopts +5 -0
- data/lib/generators/graphql/core.rb +69 -0
- data/lib/generators/graphql/enum_generator.rb +27 -0
- data/lib/generators/graphql/field_extractor.rb +31 -0
- data/lib/generators/graphql/input_generator.rb +50 -0
- data/lib/generators/graphql/install/mutation_root_generator.rb +34 -0
- data/lib/generators/graphql/install/templates/base_mutation.erb +10 -0
- data/lib/generators/graphql/install/templates/mutation_type.erb +12 -0
- data/lib/generators/graphql/install_generator.rb +197 -0
- data/lib/generators/graphql/interface_generator.rb +27 -0
- data/lib/generators/graphql/loader_generator.rb +21 -0
- data/lib/generators/graphql/mutation_create_generator.rb +22 -0
- data/lib/generators/graphql/mutation_delete_generator.rb +22 -0
- data/lib/generators/graphql/mutation_generator.rb +30 -0
- data/lib/generators/graphql/mutation_update_generator.rb +22 -0
- data/lib/generators/graphql/object_generator.rb +50 -0
- data/lib/generators/graphql/orm_mutations_base.rb +40 -0
- data/lib/generators/graphql/relay.rb +49 -0
- data/lib/generators/graphql/relay_generator.rb +21 -0
- data/lib/generators/graphql/scalar_generator.rb +22 -0
- data/lib/generators/graphql/templates/base_argument.erb +6 -0
- data/lib/generators/graphql/templates/base_connection.erb +8 -0
- data/lib/generators/graphql/templates/base_edge.erb +8 -0
- data/lib/generators/graphql/templates/base_enum.erb +6 -0
- data/lib/generators/graphql/templates/base_field.erb +7 -0
- data/lib/generators/graphql/templates/base_input_object.erb +7 -0
- data/lib/generators/graphql/templates/base_interface.erb +9 -0
- data/lib/generators/graphql/templates/base_object.erb +7 -0
- data/lib/generators/graphql/templates/base_scalar.erb +6 -0
- data/lib/generators/graphql/templates/base_union.erb +6 -0
- data/lib/generators/graphql/templates/enum.erb +11 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +52 -0
- data/lib/generators/graphql/templates/input.erb +9 -0
- data/lib/generators/graphql/templates/interface.erb +10 -0
- data/lib/generators/graphql/templates/loader.erb +19 -0
- data/lib/generators/graphql/templates/mutation.erb +16 -0
- data/lib/generators/graphql/templates/mutation_create.erb +20 -0
- data/lib/generators/graphql/templates/mutation_delete.erb +20 -0
- data/lib/generators/graphql/templates/mutation_update.erb +21 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +10 -0
- data/lib/generators/graphql/templates/query_type.erb +15 -0
- data/lib/generators/graphql/templates/scalar.erb +17 -0
- data/lib/generators/graphql/templates/schema.erb +30 -0
- data/lib/generators/graphql/templates/union.erb +9 -0
- data/lib/generators/graphql/type_generator.rb +135 -0
- data/lib/generators/graphql/union_generator.rb +33 -0
- data/lib/graphql/analysis/ast/analyzer.rb +84 -0
- data/lib/graphql/analysis/ast/field_usage.rb +57 -0
- data/lib/graphql/analysis/ast/max_query_complexity.rb +22 -0
- data/lib/graphql/analysis/ast/max_query_depth.rb +22 -0
- data/lib/graphql/analysis/ast/query_complexity.rb +230 -0
- data/lib/graphql/analysis/ast/query_depth.rb +55 -0
- data/lib/graphql/analysis/ast/visitor.rb +269 -0
- data/lib/graphql/analysis/ast.rb +81 -0
- data/lib/graphql/analysis.rb +2 -5
- data/lib/graphql/analysis_error.rb +1 -0
- data/lib/graphql/backtrace/inspect_result.rb +50 -0
- data/lib/graphql/backtrace/table.rb +141 -0
- data/lib/graphql/backtrace/traced_error.rb +54 -0
- data/lib/graphql/backtrace/tracer.rb +80 -0
- data/lib/graphql/backtrace.rb +58 -0
- data/lib/graphql/coercion_error.rb +13 -0
- data/lib/graphql/dataloader/null_dataloader.rb +24 -0
- data/lib/graphql/dataloader/request.rb +19 -0
- data/lib/graphql/dataloader/request_all.rb +19 -0
- data/lib/graphql/dataloader/source.rb +164 -0
- data/lib/graphql/dataloader.rb +311 -0
- data/lib/graphql/date_encoding_error.rb +16 -0
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/dig.rb +19 -0
- data/lib/graphql/execution/directive_checks.rb +37 -0
- data/lib/graphql/execution/errors.rb +93 -0
- data/lib/graphql/execution/interpreter/argument_value.rb +28 -0
- data/lib/graphql/execution/interpreter/arguments.rb +88 -0
- data/lib/graphql/execution/interpreter/arguments_cache.rb +105 -0
- data/lib/graphql/execution/interpreter/execution_errors.rb +29 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +18 -0
- data/lib/graphql/execution/interpreter/resolve.rb +77 -0
- data/lib/graphql/execution/interpreter/runtime.rb +994 -0
- data/lib/graphql/execution/interpreter.rb +226 -0
- data/lib/graphql/execution/lazy/lazy_method_map.rb +98 -0
- data/lib/graphql/execution/lazy.rb +75 -0
- data/lib/graphql/execution/lookahead.rb +311 -0
- data/lib/graphql/execution/multiplex.rb +45 -0
- data/lib/graphql/execution.rb +18 -0
- data/lib/graphql/execution_error.rb +34 -1
- data/lib/graphql/filter.rb +53 -0
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +36 -0
- data/lib/graphql/introspection/base_object.rb +13 -0
- data/lib/graphql/introspection/directive_location_enum.rb +12 -5
- data/lib/graphql/introspection/directive_type.rb +30 -10
- data/lib/graphql/introspection/dynamic_fields.rb +12 -0
- data/lib/graphql/introspection/entry_points.rb +22 -0
- data/lib/graphql/introspection/enum_value_type.rb +21 -8
- data/lib/graphql/introspection/field_type.rb +26 -10
- data/lib/graphql/introspection/input_value_type.rb +64 -14
- data/lib/graphql/introspection/introspection_query.rb +7 -76
- data/lib/graphql/introspection/schema_type.rb +42 -17
- data/lib/graphql/introspection/type_kind_enum.rb +11 -5
- data/lib/graphql/introspection/type_type.rb +104 -16
- data/lib/graphql/introspection.rb +104 -13
- data/lib/graphql/invalid_name_error.rb +11 -0
- data/lib/graphql/invalid_null_error.rb +36 -8
- data/lib/graphql/language/block_string.rb +99 -0
- data/lib/graphql/language/cache.rb +37 -0
- data/lib/graphql/language/definition_slice.rb +41 -0
- data/lib/graphql/language/document_from_schema_definition.rb +335 -0
- data/lib/graphql/language/generation.rb +16 -86
- data/lib/graphql/language/lexer.rb +1436 -705
- data/lib/graphql/language/lexer.rl +172 -64
- data/lib/graphql/language/nodes.rb +617 -105
- data/lib/graphql/language/parser.rb +1524 -430
- data/lib/graphql/language/parser.y +348 -73
- data/lib/graphql/language/printer.rb +386 -0
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/token.rb +16 -3
- data/lib/graphql/language/visitor.rb +169 -25
- data/lib/graphql/language.rb +30 -0
- data/lib/graphql/load_application_object_failed_error.rb +22 -0
- data/lib/graphql/name_validator.rb +11 -0
- data/lib/graphql/pagination/active_record_relation_connection.rb +85 -0
- data/lib/graphql/pagination/array_connection.rb +79 -0
- data/lib/graphql/pagination/connection.rb +253 -0
- data/lib/graphql/pagination/connections.rb +135 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +228 -0
- data/lib/graphql/pagination/sequel_dataset_connection.rb +28 -0
- data/lib/graphql/pagination.rb +6 -0
- data/lib/graphql/parse_error.rb +24 -0
- data/lib/graphql/query/context.rb +266 -12
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +34 -7
- data/lib/graphql/query/null_context.rb +52 -0
- data/lib/graphql/query/result.rb +63 -0
- data/lib/graphql/query/validation_pipeline.rb +114 -0
- data/lib/graphql/query/variable_validation_error.rb +27 -3
- data/lib/graphql/query/variables.rb +75 -24
- data/lib/graphql/query.rb +359 -92
- data/lib/graphql/railtie.rb +13 -0
- data/lib/graphql/rake_task/validate.rb +63 -0
- data/lib/graphql/rake_task.rb +146 -0
- data/lib/graphql/relay/range_add.rb +52 -0
- data/lib/graphql/relay.rb +3 -0
- data/lib/graphql/rubocop/graphql/base_cop.rb +36 -0
- data/lib/graphql/rubocop/graphql/default_null_true.rb +43 -0
- data/lib/graphql/rubocop/graphql/default_required_true.rb +43 -0
- data/lib/graphql/rubocop.rb +4 -0
- data/lib/graphql/runtime_type_error.rb +5 -0
- data/lib/graphql/schema/addition.rb +245 -0
- data/lib/graphql/schema/argument.rb +395 -0
- data/lib/graphql/schema/base_64_bp.rb +26 -0
- data/lib/graphql/schema/base_64_encoder.rb +21 -0
- data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +47 -0
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +78 -0
- data/lib/graphql/schema/build_from_definition.rb +492 -0
- data/lib/graphql/schema/built_in_types.rb +12 -0
- data/lib/graphql/schema/directive/deprecated.rb +18 -0
- data/lib/graphql/schema/directive/feature.rb +66 -0
- data/lib/graphql/schema/directive/flagged.rb +57 -0
- data/lib/graphql/schema/directive/include.rb +25 -0
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/skip.rb +25 -0
- data/lib/graphql/schema/directive/transform.rb +60 -0
- data/lib/graphql/schema/directive.rb +212 -0
- data/lib/graphql/schema/enum.rb +176 -0
- data/lib/graphql/schema/enum_value.rb +77 -0
- data/lib/graphql/schema/field/connection_extension.rb +80 -0
- data/lib/graphql/schema/field/scope_extension.rb +22 -0
- data/lib/graphql/schema/field.rb +862 -0
- data/lib/graphql/schema/field_extension.rb +156 -0
- data/lib/graphql/schema/find_inherited_value.rb +36 -0
- data/lib/graphql/schema/finder.rb +155 -0
- data/lib/graphql/schema/input_object.rb +258 -0
- data/lib/graphql/schema/interface.rb +113 -0
- data/lib/graphql/schema/introspection_system.rb +164 -0
- data/lib/graphql/schema/invalid_type_error.rb +1 -0
- data/lib/graphql/schema/late_bound_type.rb +37 -0
- data/lib/graphql/schema/list.rb +86 -0
- data/lib/graphql/schema/loader.rb +228 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +124 -0
- data/lib/graphql/schema/member/build_type.rb +178 -0
- data/lib/graphql/schema/member/graphql_type_names.rb +21 -0
- data/lib/graphql/schema/member/has_arguments.rb +376 -0
- data/lib/graphql/schema/member/has_ast_node.rb +20 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +25 -0
- data/lib/graphql/schema/member/has_directives.rb +113 -0
- data/lib/graphql/schema/member/has_fields.rb +163 -0
- data/lib/graphql/schema/member/has_interfaces.rb +88 -0
- data/lib/graphql/schema/member/has_path.rb +25 -0
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +15 -0
- data/lib/graphql/schema/member/has_validators.rb +31 -0
- data/lib/graphql/schema/member/relay_shortcuts.rb +73 -0
- data/lib/graphql/schema/member/scoped.rb +21 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +38 -0
- data/lib/graphql/schema/member/validates_input.rb +33 -0
- data/lib/graphql/schema/member.rb +39 -0
- data/lib/graphql/schema/mutation.rb +85 -0
- data/lib/graphql/schema/non_null.rb +67 -0
- data/lib/graphql/schema/null_mask.rb +11 -0
- data/lib/graphql/schema/object.rb +117 -0
- data/lib/graphql/schema/printer.rb +72 -128
- data/lib/graphql/schema/relay_classic_mutation.rb +179 -0
- data/lib/graphql/schema/resolver/has_payload_type.rb +106 -0
- data/lib/graphql/schema/resolver.rb +402 -0
- data/lib/graphql/schema/scalar.rb +68 -0
- data/lib/graphql/schema/subscription.rb +148 -0
- data/lib/graphql/schema/timeout.rb +123 -0
- data/lib/graphql/schema/type_expression.rb +29 -5
- data/lib/graphql/schema/type_membership.rb +51 -0
- data/lib/graphql/schema/union.rb +81 -0
- data/lib/graphql/schema/unique_within_type.rb +34 -0
- data/lib/graphql/schema/validator/allow_blank_validator.rb +29 -0
- data/lib/graphql/schema/validator/allow_null_validator.rb +26 -0
- data/lib/graphql/schema/validator/exclusion_validator.rb +33 -0
- data/lib/graphql/schema/validator/format_validator.rb +48 -0
- data/lib/graphql/schema/validator/inclusion_validator.rb +35 -0
- data/lib/graphql/schema/validator/length_validator.rb +59 -0
- data/lib/graphql/schema/validator/numericality_validator.rb +82 -0
- data/lib/graphql/schema/validator/required_validator.rb +82 -0
- data/lib/graphql/schema/validator.rb +171 -0
- data/lib/graphql/schema/warden.rb +413 -0
- data/lib/graphql/schema/wrapper.rb +24 -0
- data/lib/graphql/schema.rb +1179 -104
- data/lib/graphql/static_validation/all_rules.rb +14 -0
- data/lib/graphql/static_validation/base_visitor.rb +200 -0
- data/lib/graphql/static_validation/definition_dependencies.rb +198 -0
- data/lib/graphql/static_validation/error.rb +46 -0
- data/lib/graphql/static_validation/interpreter_visitor.rb +14 -0
- data/lib/graphql/static_validation/literal_validator.rb +113 -22
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +59 -11
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +48 -0
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +31 -0
- data/lib/graphql/static_validation/rules/argument_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +62 -8
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +37 -0
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +20 -13
- data/lib/graphql/static_validation/rules/directives_are_defined_error.rb +29 -0
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +32 -26
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +21 -23
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type_error.rb +32 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +55 -18
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +390 -70
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +53 -0
- data/lib/graphql/static_validation/rules/fragment_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/fragment_names_are_unique_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +54 -37
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible_error.rb +35 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +26 -16
- data/lib/graphql/static_validation/rules/fragment_types_exist_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +13 -19
- data/lib/graphql/static_validation/rules/fragments_are_finite_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_named.rb +16 -0
- data/lib/graphql/static_validation/rules/fragments_are_named_error.rb +26 -0
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +25 -20
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types_error.rb +30 -0
- data/lib/graphql/static_validation/rules/fragments_are_used.rb +22 -33
- data/lib/graphql/static_validation/rules/fragments_are_used_error.rb +29 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +41 -0
- data/lib/graphql/static_validation/rules/no_definitions_are_present_error.rb +25 -0
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid.rb +66 -0
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -0
- data/lib/graphql/static_validation/rules/operation_names_are_valid.rb +36 -0
- data/lib/graphql/static_validation/rules/operation_names_are_valid_error.rb +28 -0
- data/lib/graphql/static_validation/rules/query_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/query_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +22 -21
- data/lib/graphql/static_validation/rules/required_arguments_are_present_error.rb +35 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +59 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present_error.rb +35 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +56 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location_error.rb +29 -0
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +36 -18
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb +39 -0
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +24 -0
- data/lib/graphql/static_validation/rules/variable_names_are_unique_error.rb +29 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +103 -39
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed_error.rb +38 -0
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +22 -14
- data/lib/graphql/static_validation/rules/variables_are_input_types_error.rb +32 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +92 -70
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb +37 -0
- data/lib/graphql/static_validation/type_stack.rb +85 -24
- data/lib/graphql/static_validation/validation_context.rb +25 -46
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +46 -15
- data/lib/graphql/static_validation.rb +6 -3
- data/lib/graphql/string_encoding_error.rb +20 -0
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +247 -0
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +81 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +58 -0
- data/lib/graphql/subscriptions/event.rb +144 -0
- data/lib/graphql/subscriptions/instrumentation.rb +28 -0
- data/lib/graphql/subscriptions/serialize.rb +158 -0
- data/lib/graphql/subscriptions.rb +306 -0
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +21 -0
- data/lib/graphql/tracing/appoptics_tracing.rb +173 -0
- data/lib/graphql/tracing/appsignal_tracing.rb +51 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +100 -0
- data/lib/graphql/tracing/instrumentation_tracing.rb +83 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +51 -0
- data/lib/graphql/tracing/notifications_tracing.rb +59 -0
- data/lib/graphql/tracing/platform_tracing.rb +122 -0
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +32 -0
- data/lib/graphql/tracing/prometheus_tracing.rb +67 -0
- data/lib/graphql/tracing/scout_tracing.rb +54 -0
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +94 -0
- data/lib/graphql/type_kinds.rb +50 -22
- data/lib/graphql/types/big_int.rb +23 -0
- data/lib/graphql/types/boolean.rb +18 -0
- data/lib/graphql/types/float.rb +19 -0
- data/lib/graphql/types/id.rb +24 -0
- data/lib/graphql/types/int.rb +36 -0
- data/lib/graphql/types/iso_8601_date.rb +45 -0
- data/lib/graphql/types/iso_8601_date_time.rb +76 -0
- data/lib/graphql/types/json.rb +25 -0
- data/lib/graphql/types/relay/base_connection.rb +49 -0
- data/lib/graphql/types/relay/base_edge.rb +29 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +154 -0
- data/lib/graphql/types/relay/default_relay.rb +21 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +64 -0
- data/lib/graphql/types/relay/has_node_field.rb +41 -0
- data/lib/graphql/types/relay/has_nodes_field.rb +41 -0
- data/lib/graphql/types/relay/node.rb +15 -0
- data/lib/graphql/types/relay/node_behaviors.rb +19 -0
- data/lib/graphql/types/relay/page_info.rb +11 -0
- data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
- data/lib/graphql/types/relay.rb +39 -0
- data/lib/graphql/types/string.rb +29 -0
- data/lib/graphql/types.rb +11 -0
- data/lib/graphql/unauthorized_error.rb +29 -0
- data/lib/graphql/unauthorized_field_error.rb +23 -0
- data/lib/graphql/unresolved_type_error.rb +35 -0
- data/lib/graphql/version.rb +2 -1
- data/lib/graphql.rb +86 -41
- data/readme.md +15 -101
- metadata +394 -279
- data/lib/graphql/analysis/analyze_query.rb +0 -73
- data/lib/graphql/analysis/max_query_complexity.rb +0 -25
- data/lib/graphql/analysis/max_query_depth.rb +0 -25
- data/lib/graphql/analysis/query_complexity.rb +0 -122
- data/lib/graphql/analysis/query_depth.rb +0 -54
- data/lib/graphql/argument.rb +0 -25
- data/lib/graphql/base_type.rb +0 -115
- data/lib/graphql/boolean_type.rb +0 -9
- data/lib/graphql/define/assign_argument.rb +0 -20
- data/lib/graphql/define/assign_enum_value.rb +0 -16
- data/lib/graphql/define/assign_object_field.rb +0 -21
- data/lib/graphql/define/assignment_dictionary.rb +0 -26
- data/lib/graphql/define/defined_object_proxy.rb +0 -32
- data/lib/graphql/define/instance_definable.rb +0 -79
- data/lib/graphql/define/non_null_with_bang.rb +0 -15
- data/lib/graphql/define/type_definer.rb +0 -30
- data/lib/graphql/define.rb +0 -8
- data/lib/graphql/directive/include_directive.rb +0 -10
- data/lib/graphql/directive/skip_directive.rb +0 -11
- data/lib/graphql/directive.rb +0 -49
- data/lib/graphql/enum_type.rb +0 -95
- data/lib/graphql/field.rb +0 -131
- data/lib/graphql/float_type.rb +0 -5
- data/lib/graphql/id_type.rb +0 -12
- data/lib/graphql/input_object_type.rb +0 -71
- data/lib/graphql/int_type.rb +0 -5
- data/lib/graphql/interface_type.rb +0 -38
- data/lib/graphql/internal_representation/node.rb +0 -81
- data/lib/graphql/internal_representation/rewrite.rb +0 -177
- data/lib/graphql/internal_representation.rb +0 -2
- data/lib/graphql/introspection/arguments_field.rb +0 -5
- data/lib/graphql/introspection/enum_values_field.rb +0 -13
- data/lib/graphql/introspection/fields_field.rb +0 -13
- data/lib/graphql/introspection/input_fields_field.rb +0 -12
- data/lib/graphql/introspection/interfaces_field.rb +0 -5
- data/lib/graphql/introspection/of_type_field.rb +0 -6
- data/lib/graphql/introspection/possible_types_field.rb +0 -11
- data/lib/graphql/introspection/schema_field.rb +0 -15
- data/lib/graphql/introspection/type_by_name_field.rb +0 -16
- data/lib/graphql/introspection/typename_field.rb +0 -15
- data/lib/graphql/list_type.rb +0 -46
- data/lib/graphql/non_null_type.rb +0 -43
- data/lib/graphql/object_type.rb +0 -93
- data/lib/graphql/query/arguments.rb +0 -76
- data/lib/graphql/query/directive_resolution.rb +0 -16
- data/lib/graphql/query/executor.rb +0 -45
- data/lib/graphql/query/literal_input.rb +0 -90
- data/lib/graphql/query/serial_execution/execution_context.rb +0 -31
- data/lib/graphql/query/serial_execution/field_resolution.rb +0 -82
- data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -27
- data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -42
- data/lib/graphql/query/serial_execution/value_resolution.rb +0 -107
- data/lib/graphql/query/serial_execution.rb +0 -41
- data/lib/graphql/query/type_resolver.rb +0 -25
- data/lib/graphql/scalar_type.rb +0 -53
- data/lib/graphql/schema/catchall_middleware.rb +0 -34
- data/lib/graphql/schema/middleware_chain.rb +0 -28
- data/lib/graphql/schema/possible_types.rb +0 -34
- data/lib/graphql/schema/reduce_types.rb +0 -68
- data/lib/graphql/schema/rescue_middleware.rb +0 -53
- data/lib/graphql/schema/timeout_middleware.rb +0 -67
- data/lib/graphql/schema/type_map.rb +0 -30
- data/lib/graphql/schema/validation.rb +0 -164
- data/lib/graphql/static_validation/arguments_validator.rb +0 -48
- data/lib/graphql/static_validation/message.rb +0 -36
- data/lib/graphql/string_type.rb +0 -5
- data/lib/graphql/union_type.rb +0 -38
- data/spec/graphql/analysis/analyze_query_spec.rb +0 -50
- data/spec/graphql/analysis/max_query_complexity_spec.rb +0 -62
- data/spec/graphql/analysis/max_query_depth_spec.rb +0 -100
- data/spec/graphql/analysis/query_complexity_spec.rb +0 -235
- data/spec/graphql/analysis/query_depth_spec.rb +0 -80
- data/spec/graphql/argument_spec.rb +0 -20
- data/spec/graphql/base_type_spec.rb +0 -24
- data/spec/graphql/boolean_type_spec.rb +0 -20
- data/spec/graphql/define/instance_definable_spec.rb +0 -55
- data/spec/graphql/directive_spec.rb +0 -77
- data/spec/graphql/enum_type_spec.rb +0 -31
- data/spec/graphql/execution_error_spec.rb +0 -61
- data/spec/graphql/field_spec.rb +0 -92
- data/spec/graphql/float_type_spec.rb +0 -15
- data/spec/graphql/id_type_spec.rb +0 -32
- data/spec/graphql/input_object_type_spec.rb +0 -162
- data/spec/graphql/int_type_spec.rb +0 -15
- data/spec/graphql/interface_type_spec.rb +0 -56
- data/spec/graphql/internal_representation/rewrite_spec.rb +0 -120
- data/spec/graphql/introspection/directive_type_spec.rb +0 -50
- data/spec/graphql/introspection/input_value_type_spec.rb +0 -42
- data/spec/graphql/introspection/introspection_query_spec.rb +0 -10
- data/spec/graphql/introspection/schema_type_spec.rb +0 -45
- data/spec/graphql/introspection/type_type_spec.rb +0 -122
- data/spec/graphql/language/generation_spec.rb +0 -42
- data/spec/graphql/language/parser_spec.rb +0 -442
- data/spec/graphql/language/visitor_spec.rb +0 -49
- data/spec/graphql/list_type_spec.rb +0 -32
- data/spec/graphql/non_null_type_spec.rb +0 -31
- data/spec/graphql/object_type_spec.rb +0 -42
- data/spec/graphql/query/arguments_spec.rb +0 -25
- data/spec/graphql/query/context_spec.rb +0 -83
- data/spec/graphql/query/executor_spec.rb +0 -273
- data/spec/graphql/query/serial_execution/execution_context_spec.rb +0 -53
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +0 -66
- data/spec/graphql/query/type_resolver_spec.rb +0 -8
- data/spec/graphql/query/variables_spec.rb +0 -28
- data/spec/graphql/query_spec.rb +0 -363
- data/spec/graphql/scalar_type_spec.rb +0 -61
- data/spec/graphql/schema/catchall_middleware_spec.rb +0 -32
- data/spec/graphql/schema/middleware_chain_spec.rb +0 -42
- data/spec/graphql/schema/printer_spec.rb +0 -190
- data/spec/graphql/schema/reduce_types_spec.rb +0 -102
- data/spec/graphql/schema/rescue_middleware_spec.rb +0 -33
- data/spec/graphql/schema/timeout_middleware_spec.rb +0 -180
- data/spec/graphql/schema/type_expression_spec.rb +0 -38
- data/spec/graphql/schema/validation_spec.rb +0 -219
- data/spec/graphql/schema_spec.rb +0 -23
- data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +0 -63
- data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +0 -48
- data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +0 -34
- data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +0 -39
- data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +0 -60
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +0 -31
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +0 -48
- data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +0 -47
- data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +0 -39
- data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +0 -44
- data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +0 -49
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +0 -25
- data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +0 -42
- data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +0 -44
- data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +0 -63
- data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +0 -37
- data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +0 -53
- data/spec/graphql/static_validation/type_stack_spec.rb +0 -37
- data/spec/graphql/static_validation/validator_spec.rb +0 -69
- data/spec/graphql/string_type_spec.rb +0 -15
- data/spec/graphql/union_type_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -18
- data/spec/support/dairy_app.rb +0 -309
- data/spec/support/dairy_data.rb +0 -23
- data/spec/support/minimum_input_object.rb +0 -16
- data/spec/support/star_wars_data.rb +0 -71
- data/spec/support/star_wars_schema.rb +0 -76
@@ -1,73 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module Analysis
|
3
|
-
module_function
|
4
|
-
# Visit `query`'s internal representation, calling `analyzers` along the way.
|
5
|
-
#
|
6
|
-
# - First, query analyzers are initialized by calling `.initial_value(query)`, if they respond to that method.
|
7
|
-
# - Then, they receive `.call(memo, visit_type, irep_node)`, where visit type is `:enter` or `:leave`.
|
8
|
-
# - Last, they receive `.final_value(memo)`, if they respond to that method.
|
9
|
-
#
|
10
|
-
# It returns an array of final `memo` values in the order that `analyzers` were passed in.
|
11
|
-
#
|
12
|
-
# @param query [GraphQL::Query]
|
13
|
-
# @param analyzers [Array<#call>] Objects that respond to `#call(memo, visit_type, irep_node)`
|
14
|
-
# @return [Array<Any>] Results from those analyzers
|
15
|
-
def analyze_query(query, analyzers)
|
16
|
-
analyzers_and_values = analyzers.map { |r| initialize_reducer(r, query) }
|
17
|
-
|
18
|
-
irep = query.internal_representation
|
19
|
-
|
20
|
-
irep.each do |name, op_node|
|
21
|
-
reduce_node(op_node, analyzers_and_values)
|
22
|
-
end
|
23
|
-
|
24
|
-
analyzers_and_values.map { |(r, value)| finalize_reducer(r, value) }
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
module_function
|
30
|
-
|
31
|
-
# Enter the node, visit its children, then leave the node.
|
32
|
-
def reduce_node(irep_node, analyzers_and_values)
|
33
|
-
visit_analyzers(:enter, irep_node, analyzers_and_values)
|
34
|
-
|
35
|
-
irep_node.children.each do |name, child_irep_node|
|
36
|
-
reduce_node(child_irep_node, analyzers_and_values)
|
37
|
-
end
|
38
|
-
|
39
|
-
visit_analyzers(:leave, irep_node, analyzers_and_values)
|
40
|
-
end
|
41
|
-
|
42
|
-
def visit_analyzers(visit_type, irep_node, analyzers_and_values)
|
43
|
-
analyzers_and_values.each do |reducer_and_value|
|
44
|
-
reducer = reducer_and_value[0]
|
45
|
-
memo = reducer_and_value[1]
|
46
|
-
next_memo = reducer.call(memo, visit_type, irep_node)
|
47
|
-
reducer_and_value[1] = next_memo
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# If the reducer has an `initial_value` method, call it and store
|
52
|
-
# the result as `memo`. Otherwise, use `nil` as memo.
|
53
|
-
# @return [Array<(#call, Any)>] reducer-memo pairs
|
54
|
-
def initialize_reducer(reducer, query)
|
55
|
-
if reducer.respond_to?(:initial_value)
|
56
|
-
[reducer, reducer.initial_value(query)]
|
57
|
-
else
|
58
|
-
[reducer, nil]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# If the reducer accepts `final_value`, send it the last memo value.
|
63
|
-
# Otherwise, use the last value from the traversal.
|
64
|
-
# @return [Any] final memo value
|
65
|
-
def finalize_reducer(reducer, reduced_value)
|
66
|
-
if reducer.respond_to?(:final_value)
|
67
|
-
reducer.final_value(reduced_value)
|
68
|
-
else
|
69
|
-
reduced_value
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative "./query_complexity"
|
2
|
-
module GraphQL
|
3
|
-
module Analysis
|
4
|
-
# Used under the hood to implement complexity validation,
|
5
|
-
# see {Schema#max_complexity} and {Query#max_complexity}
|
6
|
-
#
|
7
|
-
# @example Assert max complexity of 10
|
8
|
-
# # DON'T actually do this, graphql-ruby
|
9
|
-
# # Does this for you based on your `max_complexity` setting
|
10
|
-
# MySchema.query_analyzers << GraphQL::Analysis::MaxQueryComplexity.new(10)
|
11
|
-
#
|
12
|
-
class MaxQueryComplexity < GraphQL::Analysis::QueryComplexity
|
13
|
-
def initialize(max_complexity)
|
14
|
-
disallow_excessive_complexity = -> (query, complexity) {
|
15
|
-
if complexity > max_complexity
|
16
|
-
GraphQL::AnalysisError.new("Query has complexity of #{complexity}, which exceeds max complexity of #{max_complexity}")
|
17
|
-
else
|
18
|
-
nil
|
19
|
-
end
|
20
|
-
}
|
21
|
-
super(&disallow_excessive_complexity)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative "./query_depth"
|
2
|
-
module GraphQL
|
3
|
-
module Analysis
|
4
|
-
# Used under the hood to implement depth validation,
|
5
|
-
# see {Schema#max_depth} and {Query#max_depth}
|
6
|
-
#
|
7
|
-
# @example Assert max depth of 10
|
8
|
-
# # DON'T actually do this, graphql-ruby
|
9
|
-
# # Does this for you based on your `max_depth` setting
|
10
|
-
# MySchema.query_analyzers << GraphQL::Analysis::MaxQueryDepth.new(10)
|
11
|
-
#
|
12
|
-
class MaxQueryDepth < GraphQL::Analysis::QueryDepth
|
13
|
-
def initialize(max_depth)
|
14
|
-
disallow_excessive_depth = -> (query, depth) {
|
15
|
-
if depth > max_depth
|
16
|
-
GraphQL::AnalysisError.new("Query has depth of #{depth}, which exceeds max depth of #{max_depth}")
|
17
|
-
else
|
18
|
-
nil
|
19
|
-
end
|
20
|
-
}
|
21
|
-
super(&disallow_excessive_depth)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module Analysis
|
3
|
-
# Calculate the complexity of a query, using {Field#complexity} values.
|
4
|
-
#
|
5
|
-
# @example Log the complexity of incoming queries
|
6
|
-
# MySchema.query_analyzers << GraphQL::AnalysisQueryComplexity.new do |query, complexity|
|
7
|
-
# Rails.logger.info("Complexity: #{complexity}")
|
8
|
-
# end
|
9
|
-
#
|
10
|
-
class QueryComplexity
|
11
|
-
# @yield [query, complexity] Called for each query analyzed by the schema, before executing it
|
12
|
-
# @yieldparam query [GraphQL::Query] The query that was analyzed
|
13
|
-
# @yieldparam complexity [Numeric] The complexity for this query
|
14
|
-
def initialize(&block)
|
15
|
-
@complexity_handler = block
|
16
|
-
end
|
17
|
-
|
18
|
-
# State for the query complexity calcuation:
|
19
|
-
# - `query` is needed for variables, then passed to handler
|
20
|
-
# - `complexities_on_type` holds complexity scores for each type in an IRep node
|
21
|
-
def initial_value(query)
|
22
|
-
{
|
23
|
-
query: query,
|
24
|
-
complexities_on_type: [TypeComplexity.new],
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
# Implement the query analyzer API
|
29
|
-
def call(memo, visit_type, irep_node)
|
30
|
-
if irep_node.ast_node.is_a?(GraphQL::Language::Nodes::Field)
|
31
|
-
if visit_type == :enter
|
32
|
-
memo[:complexities_on_type].push(TypeComplexity.new)
|
33
|
-
else
|
34
|
-
type_complexities = memo[:complexities_on_type].pop
|
35
|
-
own_complexity = if GraphQL::Query::DirectiveResolution.include_node?(irep_node, memo[:query])
|
36
|
-
child_complexity = type_complexities.max_possible_complexity
|
37
|
-
get_complexity(irep_node, memo[:query], child_complexity)
|
38
|
-
else
|
39
|
-
0
|
40
|
-
end
|
41
|
-
memo[:complexities_on_type].last.merge(irep_node.on_types, own_complexity)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
memo
|
45
|
-
end
|
46
|
-
|
47
|
-
# Send the query and complexity to the block
|
48
|
-
# @return [Object, GraphQL::AnalysisError] Whatever the handler returns
|
49
|
-
def final_value(reduced_value)
|
50
|
-
total_complexity = reduced_value[:complexities_on_type].pop.max_possible_complexity
|
51
|
-
@complexity_handler.call(reduced_value[:query], total_complexity)
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
# Get a complexity value for a field,
|
57
|
-
# by getting the number or calling its proc
|
58
|
-
def get_complexity(irep_node, query, child_complexity)
|
59
|
-
field_defn = irep_node.definition
|
60
|
-
defined_complexity = field_defn.complexity
|
61
|
-
case defined_complexity
|
62
|
-
when Proc
|
63
|
-
args = query.arguments_for(irep_node)
|
64
|
-
defined_complexity.call(query.context, args, child_complexity)
|
65
|
-
when Numeric
|
66
|
-
defined_complexity + (child_complexity || 0)
|
67
|
-
else
|
68
|
-
raise("Invalid complexity: #{defined_complexity.inspect} on #{field_defn.name}")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Selections on an object may apply differently depending on what is _actually_ returned by the resolve function.
|
73
|
-
# Find the maximum possible complexity among those combinations.
|
74
|
-
class TypeComplexity
|
75
|
-
def initialize
|
76
|
-
@types = Hash.new { |h, k| h[k] = 0 }
|
77
|
-
end
|
78
|
-
|
79
|
-
# Return the max possible complexity for types in this selection
|
80
|
-
def max_possible_complexity
|
81
|
-
max_complexity = 0
|
82
|
-
|
83
|
-
@types.each do |type_defn, own_complexity|
|
84
|
-
type_complexity = @types.reduce(0) do |memo, (other_type, other_complexity)|
|
85
|
-
if types_overlap?(type_defn, other_type)
|
86
|
-
memo + other_complexity
|
87
|
-
else
|
88
|
-
memo
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
if type_complexity > max_complexity
|
93
|
-
max_complexity = type_complexity
|
94
|
-
end
|
95
|
-
end
|
96
|
-
max_complexity
|
97
|
-
end
|
98
|
-
|
99
|
-
# Store the complexity score for each of `types`
|
100
|
-
def merge(types, complexity)
|
101
|
-
types.each { |t| @types[t] += complexity }
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
# True if:
|
106
|
-
# - type_1 is type_2
|
107
|
-
# - type_1 is a member of type_2's possible types
|
108
|
-
def types_overlap?(type_1, type_2)
|
109
|
-
if type_1 == type_2
|
110
|
-
true
|
111
|
-
elsif type_2.kind.union?
|
112
|
-
type_2.include?(type_1)
|
113
|
-
elsif type_1.kind.object? && type_2.kind.interface?
|
114
|
-
type_1.interfaces.include?(type_2)
|
115
|
-
else
|
116
|
-
false
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module Analysis
|
3
|
-
# A query reducer for measuring the depth of a given query.
|
4
|
-
#
|
5
|
-
# @example Logging the depth of a query
|
6
|
-
# Schema.query_analyzers << GraphQL::Analysis::QueryDepth.new { |depth| puts "GraphQL query depth: #{depth}" }
|
7
|
-
# Schema.execute(query_str)
|
8
|
-
# # GraphQL query depth: 8
|
9
|
-
#
|
10
|
-
class QueryDepth
|
11
|
-
def initialize(&block)
|
12
|
-
@depth_handler = block
|
13
|
-
end
|
14
|
-
|
15
|
-
def initial_value(query)
|
16
|
-
{
|
17
|
-
max_depth: 0,
|
18
|
-
current_depth: 0,
|
19
|
-
skip_current_scope: false,
|
20
|
-
query: query,
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
def call(memo, visit_type, irep_node)
|
25
|
-
if irep_node.ast_node.is_a?(GraphQL::Language::Nodes::Field)
|
26
|
-
if visit_type == :enter
|
27
|
-
if GraphQL::Schema::DYNAMIC_FIELDS.include?(irep_node.definition.name)
|
28
|
-
# Don't validate introspection fields
|
29
|
-
memo[:skip_current_scope] = true
|
30
|
-
elsif memo[:skip_current_scope]
|
31
|
-
# we're inside an introspection query
|
32
|
-
elsif GraphQL::Query::DirectiveResolution.include_node?(irep_node, memo[:query])
|
33
|
-
memo[:current_depth] += 1
|
34
|
-
end
|
35
|
-
else
|
36
|
-
if GraphQL::Schema::DYNAMIC_FIELDS.include?(irep_node.definition.name)
|
37
|
-
memo[:skip_current_scope] = false
|
38
|
-
elsif GraphQL::Query::DirectiveResolution.include_node?(irep_node, memo[:query])
|
39
|
-
if memo[:max_depth] < memo[:current_depth]
|
40
|
-
memo[:max_depth] = memo[:current_depth]
|
41
|
-
end
|
42
|
-
memo[:current_depth] -= 1
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
memo
|
47
|
-
end
|
48
|
-
|
49
|
-
def final_value(memo)
|
50
|
-
@depth_handler.call(memo[:query], memo[:max_depth])
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/lib/graphql/argument.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
# Used for defined arguments ({Field}, {InputObjectType})
|
3
|
-
#
|
4
|
-
# {#name} must be a String.
|
5
|
-
#
|
6
|
-
# @example defining an argument for a field
|
7
|
-
# GraphQL::Field.define do
|
8
|
-
# # ...
|
9
|
-
# argument :favoriteFood, types.String, "Favorite thing to eat", default_value: "pizza"
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
# @example defining an input field for an {InputObjectType}
|
13
|
-
# GraphQL::InputObjectType.define do
|
14
|
-
# input_field :newName, !types.String
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
class Argument
|
18
|
-
include GraphQL::Define::InstanceDefinable
|
19
|
-
accepts_definitions :name, :type, :description, :default_value
|
20
|
-
attr_accessor :type, :description, :default_value
|
21
|
-
|
22
|
-
# @return [String] The name of this argument on its {GraphQL::Field} or {GraphQL::InputObjectType}
|
23
|
-
attr_accessor :name
|
24
|
-
end
|
25
|
-
end
|
data/lib/graphql/base_type.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
# The parent for all type classes.
|
3
|
-
class BaseType
|
4
|
-
include GraphQL::Define::NonNullWithBang
|
5
|
-
include GraphQL::Define::InstanceDefinable
|
6
|
-
attr_accessor :name, :description
|
7
|
-
accepts_definitions :name, :description
|
8
|
-
|
9
|
-
# @param other [GraphQL::BaseType] compare to this object
|
10
|
-
# @return [Boolean] are these types equivalent? (incl. non-null, list)
|
11
|
-
def ==(other)
|
12
|
-
if other.is_a?(GraphQL::BaseType)
|
13
|
-
self.to_s == other.to_s
|
14
|
-
else
|
15
|
-
super
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# If this type is modifying an underlying type,
|
20
|
-
# return the underlying type. (Otherwise, return `self`.)
|
21
|
-
def unwrap
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
# @return [GraphQL::NonNullType] a non-null version of this type
|
26
|
-
def to_non_null_type
|
27
|
-
GraphQL::NonNullType.new(of_type: self)
|
28
|
-
end
|
29
|
-
|
30
|
-
# @return [GraphQL::ListType] a list version of this type
|
31
|
-
def to_list_type
|
32
|
-
GraphQL::ListType.new(of_type: self)
|
33
|
-
end
|
34
|
-
|
35
|
-
module ModifiesAnotherType
|
36
|
-
def unwrap
|
37
|
-
self.of_type.unwrap
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Find out which possible type to use for `value`.
|
42
|
-
# Returns self if there are no possible types (ie, not Union or Interface)
|
43
|
-
def resolve_type(value)
|
44
|
-
self
|
45
|
-
end
|
46
|
-
|
47
|
-
module HasPossibleTypes
|
48
|
-
# Return the implementing type for `object`.
|
49
|
-
# The default implementation assumes that there's a type with the same name as `object.class.name`.
|
50
|
-
# Maybe you'll need to override this in your own interfaces!
|
51
|
-
#
|
52
|
-
# @param object [Object] the object which needs a type to expose it
|
53
|
-
# @param ctx [GraphQL::Query::Context]
|
54
|
-
# @return [GraphQL::ObjectType] the type which should expose `object`
|
55
|
-
def resolve_type(object, ctx)
|
56
|
-
instance_exec(object, ctx, &(@resolve_type_proc || DEFAULT_RESOLVE_TYPE))
|
57
|
-
end
|
58
|
-
|
59
|
-
# The default implementation of {#resolve_type} gets `object.class.name`
|
60
|
-
# and finds a type with the same name
|
61
|
-
DEFAULT_RESOLVE_TYPE = -> (object, ctx) {
|
62
|
-
type_name = object.class.name
|
63
|
-
ctx.schema.possible_types(self).find {|t| t.name == type_name}
|
64
|
-
}
|
65
|
-
|
66
|
-
def resolve_type=(new_proc)
|
67
|
-
@resolve_type_proc = new_proc || DEFAULT_RESOLVE_TYPE
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# Print the human-readable name of this type using the query-string naming pattern
|
72
|
-
def to_s
|
73
|
-
name
|
74
|
-
end
|
75
|
-
|
76
|
-
alias :inspect :to_s
|
77
|
-
|
78
|
-
def valid_input?(value)
|
79
|
-
validate_input(value).valid?
|
80
|
-
end
|
81
|
-
|
82
|
-
def validate_input(value)
|
83
|
-
return GraphQL::Query::InputValidationResult.new if value.nil?
|
84
|
-
validate_non_null_input(value)
|
85
|
-
end
|
86
|
-
|
87
|
-
def coerce_input(value)
|
88
|
-
return nil if value.nil?
|
89
|
-
coerce_non_null_input(value)
|
90
|
-
end
|
91
|
-
|
92
|
-
# Types with fields may override this
|
93
|
-
# @param name [String] field name to lookup for this type
|
94
|
-
# @return [GraphQL::Field, nil]
|
95
|
-
def get_field(name)
|
96
|
-
nil
|
97
|
-
end
|
98
|
-
|
99
|
-
# During schema definition, types can be defined inside procs or as strings.
|
100
|
-
# This function converts it to a type instance
|
101
|
-
# @return [GraphQL::BaseType]
|
102
|
-
def self.resolve_related_type(type_arg)
|
103
|
-
case type_arg
|
104
|
-
when Proc
|
105
|
-
# lazy-eval it
|
106
|
-
type_arg.call
|
107
|
-
when String
|
108
|
-
# Get a constant by this name
|
109
|
-
Object.const_get(type_arg)
|
110
|
-
else
|
111
|
-
type_arg
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
data/lib/graphql/boolean_type.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module Define
|
3
|
-
# Turn argument configs into a {GraphQL::Argument}.
|
4
|
-
module AssignArgument
|
5
|
-
def self.call(target, name, type = nil, description = nil, default_value: nil, &block)
|
6
|
-
argument = if block_given?
|
7
|
-
GraphQL::Argument.define(&block)
|
8
|
-
else
|
9
|
-
GraphQL::Argument.new
|
10
|
-
end
|
11
|
-
argument.name = name.to_s
|
12
|
-
type && argument.type = type
|
13
|
-
description && argument.description = description
|
14
|
-
!default_value.nil? && argument.default_value = default_value
|
15
|
-
|
16
|
-
target.arguments[name.to_s] = argument
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module Define
|
3
|
-
# Turn enum value configs into a {GraphQL::EnumType::EnumValue} and register it with the {GraphQL::EnumType}
|
4
|
-
module AssignEnumValue
|
5
|
-
def self.call(enum_type, name, desc = nil, deprecation_reason: nil, value: name)
|
6
|
-
enum_value = GraphQL::EnumType::EnumValue.new(
|
7
|
-
name: name,
|
8
|
-
description: desc,
|
9
|
-
deprecation_reason: deprecation_reason,
|
10
|
-
value: value
|
11
|
-
)
|
12
|
-
enum_type.add_value(enum_value)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module Define
|
3
|
-
# Turn field configs into a {GraphQL::Field} and attach it to a {GraphQL::ObjectType} or {GraphQL::InterfaceType}
|
4
|
-
module AssignObjectField
|
5
|
-
def self.call(fields_type, name, type = nil, desc = nil, field: nil, deprecation_reason: nil, property: nil, complexity: nil, &block)
|
6
|
-
if block_given?
|
7
|
-
field = GraphQL::Field.define(&block)
|
8
|
-
else
|
9
|
-
field ||= GraphQL::Field.new
|
10
|
-
end
|
11
|
-
type && field.type = type
|
12
|
-
desc && field.description = desc
|
13
|
-
property && field.property = property
|
14
|
-
complexity && field.complexity = complexity
|
15
|
-
deprecation_reason && field.deprecation_reason = deprecation_reason
|
16
|
-
field.name ||= name.to_s
|
17
|
-
fields_type.fields[name.to_s] = field
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module Define
|
3
|
-
# Create a hash of definitions out of provided arguments.
|
4
|
-
#
|
5
|
-
# @example Create definitions (some default, some custom)
|
6
|
-
# hash = AssignmentDictionary.create(:name, :description, field: (value, field_name) -> { value.create_field(field) })
|
7
|
-
#
|
8
|
-
module AssignmentDictionary
|
9
|
-
# Turn `keys` into a hash suitable for {GraphQL::Define::InstanceDefinable}
|
10
|
-
# @param Any number of symbols for default assignment, followed by an (optional) hash of custom assignment procs.
|
11
|
-
# @return [Hash] keys are attributes which may be defined. values are procs which assign values to the target object.
|
12
|
-
def self.create(*keys)
|
13
|
-
initial = if keys.last.is_a?(Hash)
|
14
|
-
keys.pop
|
15
|
-
else
|
16
|
-
{}
|
17
|
-
end
|
18
|
-
keys.inject(initial) do |memo, key|
|
19
|
-
assign_key = "#{key}="
|
20
|
-
memo[key] = -> (target, value) { target.public_send(assign_key, value) }
|
21
|
-
memo
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module Define
|
3
|
-
class DefinedObjectProxy
|
4
|
-
def initialize(target, dictionary)
|
5
|
-
@target = target
|
6
|
-
@dictionary = dictionary
|
7
|
-
end
|
8
|
-
|
9
|
-
def types
|
10
|
-
GraphQL::Define::TypeDefiner.instance
|
11
|
-
end
|
12
|
-
|
13
|
-
def method_missing(name, *args, &block)
|
14
|
-
definition = @dictionary[name]
|
15
|
-
if definition
|
16
|
-
definition.call(@target, *args, &block)
|
17
|
-
else
|
18
|
-
p "Failed to find config #{name} in #{inspect}"
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_s
|
24
|
-
inspect
|
25
|
-
end
|
26
|
-
|
27
|
-
def inspect
|
28
|
-
"<DefinedObjectProxy #{@target} (#{@dictionary.keys})>"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module Define
|
3
|
-
# This module provides the `.define { ... }` API for {GraphQL::BaseType}, {GraphQL::Field}, {GraphQL::Argument} and {GraphQL::Directive}.
|
4
|
-
#
|
5
|
-
# The goals are:
|
6
|
-
# - Minimal overhead in consuming classes
|
7
|
-
# - Independence between consuming classes
|
8
|
-
# - Extendable by third-party libraries without monkey-patching or other nastiness
|
9
|
-
#
|
10
|
-
# @example Make a class definable
|
11
|
-
# class Car
|
12
|
-
# attr_accessor :make, :model, :all_wheel_drive
|
13
|
-
#
|
14
|
-
# accepts_definitions(
|
15
|
-
# # These attrs will be defined with plain setters, `{attr}=`
|
16
|
-
# :make, :model,
|
17
|
-
# # This attr has a custom definition which applies the config to the target
|
18
|
-
# doors: -> (car, doors_count) { doors_count.times { car.doors << Door.new } }
|
19
|
-
# )
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# # Create an instance with `.define`:
|
23
|
-
# subaru_baja = Car.define do
|
24
|
-
# make "Subaru"
|
25
|
-
# model "Baja"
|
26
|
-
# doors 4
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# # The custom proc was applied:
|
30
|
-
# subaru_baja.doors #=> [<Door>, <Door>, <Door>, <Door>]
|
31
|
-
#
|
32
|
-
# @example Extending the definition of a class
|
33
|
-
# # Add some definitions:
|
34
|
-
# Car.accepts_definitions(:all_wheel_drive)
|
35
|
-
#
|
36
|
-
# # Use it in a definition
|
37
|
-
# subaru_baja = Car.define do
|
38
|
-
# # ...
|
39
|
-
# all_wheel_drive true
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
module InstanceDefinable
|
43
|
-
def self.included(base)
|
44
|
-
base.extend(ClassMethods)
|
45
|
-
end
|
46
|
-
|
47
|
-
module ClassMethods
|
48
|
-
# Define an instance of this class using its {.definitions}.
|
49
|
-
def define(&block)
|
50
|
-
instance = self.new
|
51
|
-
proxy = DefinedObjectProxy.new(instance, dictionary)
|
52
|
-
block && proxy.instance_eval(&block)
|
53
|
-
instance
|
54
|
-
end
|
55
|
-
|
56
|
-
# Attach definitions to this class.
|
57
|
-
# Each symbol in `accepts` will be assigned with `{key}=`.
|
58
|
-
# The last entry in accepts may be a hash of name-proc pairs for custom definitions.
|
59
|
-
def accepts_definitions(*accepts)
|
60
|
-
@own_dictionary = own_dictionary.merge(AssignmentDictionary.create(*accepts))
|
61
|
-
end
|
62
|
-
|
63
|
-
# @return [Hash] combined definitions for self and ancestors
|
64
|
-
def dictionary
|
65
|
-
if superclass.respond_to?(:dictionary)
|
66
|
-
own_dictionary.merge(superclass.dictionary)
|
67
|
-
else
|
68
|
-
own_dictionary
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# @return [Hash] definitions for this class only
|
73
|
-
def own_dictionary
|
74
|
-
@own_dictionary ||= {}
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module GraphQL
|
2
|
-
module Define
|
3
|
-
# Wrap the object in NonNullType in response to `!`
|
4
|
-
# @example required Int type
|
5
|
-
# !GraphQL::INT_TYPE
|
6
|
-
#
|
7
|
-
module NonNullWithBang
|
8
|
-
# Make the type non-null
|
9
|
-
# @return [GraphQL::NonNullType] a non-null type which wraps the original type
|
10
|
-
def !
|
11
|
-
to_non_null_type
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|