graphql_cody 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +5 -0
- data/MIT-LICENSE +20 -0
- data/lib/generators/graphql/core.rb +74 -0
- data/lib/generators/graphql/enum_generator.rb +33 -0
- data/lib/generators/graphql/install_generator.rb +190 -0
- data/lib/generators/graphql/interface_generator.rb +27 -0
- data/lib/generators/graphql/loader_generator.rb +21 -0
- data/lib/generators/graphql/mutation_generator.rb +55 -0
- data/lib/generators/graphql/object_generator.rb +79 -0
- data/lib/generators/graphql/relay.rb +63 -0
- data/lib/generators/graphql/relay_generator.rb +21 -0
- data/lib/generators/graphql/scalar_generator.rb +20 -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_mutation.erb +10 -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 +7 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +52 -0
- data/lib/generators/graphql/templates/interface.erb +8 -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_type.erb +12 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +8 -0
- data/lib/generators/graphql/templates/query_type.erb +15 -0
- data/lib/generators/graphql/templates/scalar.erb +15 -0
- data/lib/generators/graphql/templates/schema.erb +27 -0
- data/lib/generators/graphql/templates/union.erb +7 -0
- data/lib/generators/graphql/type_generator.rb +98 -0
- data/lib/generators/graphql/union_generator.rb +33 -0
- data/lib/graphql/analysis/analyze_query.rb +98 -0
- data/lib/graphql/analysis/ast/analyzer.rb +84 -0
- data/lib/graphql/analysis/ast/field_usage.rb +51 -0
- data/lib/graphql/analysis/ast/max_query_complexity.rb +23 -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 +56 -0
- data/lib/graphql/analysis/ast/visitor.rb +268 -0
- data/lib/graphql/analysis/ast.rb +91 -0
- data/lib/graphql/analysis/field_usage.rb +45 -0
- data/lib/graphql/analysis/max_query_complexity.rb +26 -0
- data/lib/graphql/analysis/max_query_depth.rb +26 -0
- data/lib/graphql/analysis/query_complexity.rb +88 -0
- data/lib/graphql/analysis/query_depth.rb +43 -0
- data/lib/graphql/analysis/reducer_state.rb +48 -0
- data/lib/graphql/analysis.rb +9 -0
- data/lib/graphql/analysis_error.rb +5 -0
- data/lib/graphql/argument.rb +131 -0
- data/lib/graphql/authorization.rb +82 -0
- data/lib/graphql/backtrace/inspect_result.rb +50 -0
- data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
- data/lib/graphql/backtrace/table.rb +159 -0
- data/lib/graphql/backtrace/traced_error.rb +54 -0
- data/lib/graphql/backtrace/tracer.rb +81 -0
- data/lib/graphql/backtrace.rb +64 -0
- data/lib/graphql/backwards_compatibility.rb +61 -0
- data/lib/graphql/base_type.rb +230 -0
- data/lib/graphql/boolean_type.rb +2 -0
- data/lib/graphql/coercion_error.rb +13 -0
- data/lib/graphql/compatibility/execution_specification/counter_schema.rb +53 -0
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +200 -0
- data/lib/graphql/compatibility/execution_specification.rb +436 -0
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +111 -0
- data/lib/graphql/compatibility/lazy_execution_specification.rb +215 -0
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +87 -0
- data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +79 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +266 -0
- data/lib/graphql/compatibility/schema_parser_specification.rb +682 -0
- data/lib/graphql/compatibility.rb +5 -0
- data/lib/graphql/dataloader/null_dataloader.rb +22 -0
- data/lib/graphql/dataloader/request.rb +19 -0
- data/lib/graphql/dataloader/request_all.rb +19 -0
- data/lib/graphql/dataloader/source.rb +155 -0
- data/lib/graphql/dataloader.rb +308 -0
- data/lib/graphql/define/assign_argument.rb +12 -0
- data/lib/graphql/define/assign_connection.rb +13 -0
- data/lib/graphql/define/assign_enum_value.rb +18 -0
- data/lib/graphql/define/assign_global_id_field.rb +11 -0
- data/lib/graphql/define/assign_mutation_function.rb +34 -0
- data/lib/graphql/define/assign_object_field.rb +42 -0
- data/lib/graphql/define/defined_object_proxy.rb +53 -0
- data/lib/graphql/define/instance_definable.rb +240 -0
- data/lib/graphql/define/no_definition_error.rb +7 -0
- data/lib/graphql/define/non_null_with_bang.rb +16 -0
- data/lib/graphql/define/type_definer.rb +31 -0
- data/lib/graphql/define.rb +31 -0
- data/lib/graphql/deprecated_dsl.rb +55 -0
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/dig.rb +19 -0
- data/lib/graphql/directive/deprecated_directive.rb +2 -0
- data/lib/graphql/directive/include_directive.rb +2 -0
- data/lib/graphql/directive/skip_directive.rb +2 -0
- data/lib/graphql/directive.rb +107 -0
- data/lib/graphql/enum_type.rb +133 -0
- data/lib/graphql/execution/directive_checks.rb +37 -0
- data/lib/graphql/execution/errors.rb +163 -0
- data/lib/graphql/execution/execute.rb +333 -0
- data/lib/graphql/execution/flatten.rb +40 -0
- data/lib/graphql/execution/instrumentation.rb +92 -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 +103 -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 +70 -0
- data/lib/graphql/execution/interpreter/runtime.rb +949 -0
- data/lib/graphql/execution/interpreter.rb +122 -0
- data/lib/graphql/execution/lazy/lazy_method_map.rb +98 -0
- data/lib/graphql/execution/lazy/resolve.rb +91 -0
- data/lib/graphql/execution/lazy.rb +83 -0
- data/lib/graphql/execution/lookahead.rb +307 -0
- data/lib/graphql/execution/multiplex.rb +214 -0
- data/lib/graphql/execution/typecast.rb +50 -0
- data/lib/graphql/execution.rb +11 -0
- data/lib/graphql/execution_error.rb +58 -0
- data/lib/graphql/field/resolve.rb +59 -0
- data/lib/graphql/field.rb +226 -0
- data/lib/graphql/filter.rb +53 -0
- data/lib/graphql/float_type.rb +2 -0
- data/lib/graphql/function.rb +128 -0
- data/lib/graphql/id_type.rb +2 -0
- data/lib/graphql/input_object_type.rb +138 -0
- data/lib/graphql/int_type.rb +2 -0
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +36 -0
- data/lib/graphql/interface_type.rb +72 -0
- data/lib/graphql/internal_representation/document.rb +27 -0
- data/lib/graphql/internal_representation/node.rb +206 -0
- data/lib/graphql/internal_representation/print.rb +51 -0
- data/lib/graphql/internal_representation/rewrite.rb +184 -0
- data/lib/graphql/internal_representation/scope.rb +88 -0
- data/lib/graphql/internal_representation/visit.rb +36 -0
- data/lib/graphql/internal_representation.rb +7 -0
- data/lib/graphql/introspection/base_object.rb +13 -0
- data/lib/graphql/introspection/directive_location_enum.rb +15 -0
- data/lib/graphql/introspection/directive_type.rb +29 -0
- data/lib/graphql/introspection/dynamic_fields.rb +17 -0
- data/lib/graphql/introspection/entry_points.rb +35 -0
- data/lib/graphql/introspection/enum_value_type.rb +23 -0
- data/lib/graphql/introspection/field_type.rb +28 -0
- data/lib/graphql/introspection/input_value_type.rb +67 -0
- data/lib/graphql/introspection/introspection_query.rb +7 -0
- data/lib/graphql/introspection/schema_type.rb +44 -0
- data/lib/graphql/introspection/type_kind_enum.rb +13 -0
- data/lib/graphql/introspection/type_type.rb +95 -0
- data/lib/graphql/introspection.rb +114 -0
- data/lib/graphql/invalid_name_error.rb +11 -0
- data/lib/graphql/invalid_null_error.rb +50 -0
- 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 +347 -0
- data/lib/graphql/language/generation.rb +24 -0
- data/lib/graphql/language/lexer.rb +1467 -0
- data/lib/graphql/language/lexer.rl +258 -0
- data/lib/graphql/language/nodes.rb +707 -0
- data/lib/graphql/language/parser.rb +1974 -0
- data/lib/graphql/language/parser.y +544 -0
- data/lib/graphql/language/printer.rb +366 -0
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/token.rb +34 -0
- data/lib/graphql/language/visitor.rb +242 -0
- data/lib/graphql/language.rb +36 -0
- data/lib/graphql/list_type.rb +80 -0
- data/lib/graphql/load_application_object_failed_error.rb +22 -0
- data/lib/graphql/name_validator.rb +11 -0
- data/lib/graphql/non_null_type.rb +71 -0
- data/lib/graphql/object_type.rb +130 -0
- data/lib/graphql/pagination/active_record_relation_connection.rb +48 -0
- data/lib/graphql/pagination/array_connection.rb +77 -0
- data/lib/graphql/pagination/connection.rb +226 -0
- data/lib/graphql/pagination/connections.rb +160 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +196 -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/arguments.rb +189 -0
- data/lib/graphql/query/arguments_cache.rb +24 -0
- data/lib/graphql/query/context.rb +371 -0
- data/lib/graphql/query/executor.rb +52 -0
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +43 -0
- data/lib/graphql/query/literal_input.rb +136 -0
- data/lib/graphql/query/null_context.rb +55 -0
- data/lib/graphql/query/result.rb +63 -0
- data/lib/graphql/query/serial_execution/field_resolution.rb +92 -0
- data/lib/graphql/query/serial_execution/operation_resolution.rb +19 -0
- data/lib/graphql/query/serial_execution/selection_resolution.rb +23 -0
- data/lib/graphql/query/serial_execution/value_resolution.rb +87 -0
- data/lib/graphql/query/serial_execution.rb +40 -0
- data/lib/graphql/query/validation_pipeline.rb +139 -0
- data/lib/graphql/query/variable_validation_error.rb +44 -0
- data/lib/graphql/query/variables.rb +78 -0
- data/lib/graphql/query.rb +454 -0
- data/lib/graphql/railtie.rb +117 -0
- data/lib/graphql/rake_task/validate.rb +63 -0
- data/lib/graphql/rake_task.rb +145 -0
- data/lib/graphql/relay/array_connection.rb +83 -0
- data/lib/graphql/relay/base_connection.rb +189 -0
- data/lib/graphql/relay/connection_instrumentation.rb +54 -0
- data/lib/graphql/relay/connection_resolve.rb +43 -0
- data/lib/graphql/relay/connection_type.rb +41 -0
- data/lib/graphql/relay/edge.rb +27 -0
- data/lib/graphql/relay/edge_type.rb +19 -0
- data/lib/graphql/relay/edges_instrumentation.rb +39 -0
- data/lib/graphql/relay/global_id_resolve.rb +18 -0
- data/lib/graphql/relay/mongo_relation_connection.rb +50 -0
- data/lib/graphql/relay/mutation/instrumentation.rb +23 -0
- data/lib/graphql/relay/mutation/resolve.rb +56 -0
- data/lib/graphql/relay/mutation/result.rb +38 -0
- data/lib/graphql/relay/mutation.rb +106 -0
- data/lib/graphql/relay/node.rb +39 -0
- data/lib/graphql/relay/page_info.rb +7 -0
- data/lib/graphql/relay/range_add.rb +59 -0
- data/lib/graphql/relay/relation_connection.rb +188 -0
- data/lib/graphql/relay/type_extensions.rb +32 -0
- data/lib/graphql/relay.rb +18 -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/scalar_type.rb +91 -0
- data/lib/graphql/schema/addition.rb +247 -0
- data/lib/graphql/schema/argument.rb +383 -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 +477 -0
- data/lib/graphql/schema/built_in_types.rb +12 -0
- data/lib/graphql/schema/catchall_middleware.rb +35 -0
- data/lib/graphql/schema/default_parse_error.rb +10 -0
- data/lib/graphql/schema/default_type_error.rb +17 -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/skip.rb +25 -0
- data/lib/graphql/schema/directive/transform.rb +60 -0
- data/lib/graphql/schema/directive.rb +210 -0
- data/lib/graphql/schema/enum.rb +193 -0
- data/lib/graphql/schema/enum_value.rb +97 -0
- data/lib/graphql/schema/field/connection_extension.rb +76 -0
- data/lib/graphql/schema/field/scope_extension.rb +22 -0
- data/lib/graphql/schema/field.rb +880 -0
- data/lib/graphql/schema/field_extension.rb +69 -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 +253 -0
- data/lib/graphql/schema/interface.rb +136 -0
- data/lib/graphql/schema/introspection_system.rb +169 -0
- data/lib/graphql/schema/invalid_type_error.rb +7 -0
- data/lib/graphql/schema/late_bound_type.rb +33 -0
- data/lib/graphql/schema/list.rb +75 -0
- data/lib/graphql/schema/loader.rb +226 -0
- data/lib/graphql/schema/member/accepts_definition.rb +159 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +129 -0
- data/lib/graphql/schema/member/build_type.rb +180 -0
- data/lib/graphql/schema/member/cached_graphql_definition.rb +31 -0
- data/lib/graphql/schema/member/graphql_type_names.rb +21 -0
- data/lib/graphql/schema/member/has_arguments.rb +332 -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 +98 -0
- data/lib/graphql/schema/member/has_fields.rb +163 -0
- data/lib/graphql/schema/member/has_interfaces.rb +90 -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/instrumentation.rb +131 -0
- data/lib/graphql/schema/member/relay_shortcuts.rb +47 -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 +161 -0
- data/lib/graphql/schema/middleware_chain.rb +82 -0
- data/lib/graphql/schema/mutation.rb +94 -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 +150 -0
- data/lib/graphql/schema/possible_types.rb +44 -0
- data/lib/graphql/schema/printer.rb +100 -0
- data/lib/graphql/schema/relay_classic_mutation.rb +160 -0
- data/lib/graphql/schema/rescue_middleware.rb +60 -0
- data/lib/graphql/schema/resolver/has_payload_type.rb +96 -0
- data/lib/graphql/schema/resolver.rb +397 -0
- data/lib/graphql/schema/scalar.rb +69 -0
- data/lib/graphql/schema/subscription.rb +155 -0
- data/lib/graphql/schema/timeout.rb +123 -0
- data/lib/graphql/schema/timeout_middleware.rb +88 -0
- data/lib/graphql/schema/traversal.rb +228 -0
- data/lib/graphql/schema/type_expression.rb +43 -0
- data/lib/graphql/schema/type_membership.rb +48 -0
- data/lib/graphql/schema/union.rb +95 -0
- data/lib/graphql/schema/unique_within_type.rb +34 -0
- data/lib/graphql/schema/validation.rb +313 -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 +68 -0
- data/lib/graphql/schema/validator.rb +174 -0
- data/lib/graphql/schema/warden.rb +409 -0
- data/lib/graphql/schema/wrapper.rb +29 -0
- data/lib/graphql/schema.rb +1945 -0
- data/lib/graphql/static_validation/all_rules.rb +40 -0
- data/lib/graphql/static_validation/base_visitor.rb +217 -0
- data/lib/graphql/static_validation/default_visitor.rb +15 -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 +139 -0
- data/lib/graphql/static_validation/no_validate_visitor.rb +10 -0
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +66 -0
- 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 +71 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +37 -0
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +23 -0
- 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 +65 -0
- 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 +30 -0
- 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 +73 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +418 -0
- 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 +73 -0
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible_error.rb +35 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +39 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +21 -0
- 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 +37 -0
- 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 +32 -0
- 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/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/required_arguments_are_present.rb +37 -0
- 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 +50 -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 +46 -0
- 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 +153 -0
- 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 +39 -0
- 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 +155 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb +37 -0
- data/lib/graphql/static_validation/type_stack.rb +216 -0
- data/lib/graphql/static_validation/validation_context.rb +49 -0
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +96 -0
- data/lib/graphql/static_validation.rb +19 -0
- data/lib/graphql/string_encoding_error.rb +20 -0
- data/lib/graphql/string_type.rb +2 -0
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +245 -0
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +81 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +21 -0
- data/lib/graphql/subscriptions/event.rb +144 -0
- data/lib/graphql/subscriptions/instrumentation.rb +79 -0
- data/lib/graphql/subscriptions/serialize.rb +138 -0
- data/lib/graphql/subscriptions/subscription_root.rb +76 -0
- data/lib/graphql/subscriptions.rb +299 -0
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +35 -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 +76 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +51 -0
- data/lib/graphql/tracing/platform_tracing.rb +139 -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/skylight_tracing.rb +70 -0
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +95 -0
- data/lib/graphql/type_kinds.rb +77 -0
- 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 +34 -0
- data/lib/graphql/types/iso_8601_date_time.rb +65 -0
- data/lib/graphql/types/json.rb +25 -0
- data/lib/graphql/types/relay/base_connection.rb +39 -0
- data/lib/graphql/types/relay/base_edge.rb +29 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +156 -0
- data/lib/graphql/types/relay/default_relay.rb +27 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +53 -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 +15 -0
- data/lib/graphql/types/relay/node_field.rb +25 -0
- data/lib/graphql/types/relay/nodes_field.rb +27 -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 +41 -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/union_type.rb +115 -0
- data/lib/graphql/unresolved_type_error.rb +35 -0
- data/lib/graphql/upgrader/member.rb +937 -0
- data/lib/graphql/upgrader/schema.rb +38 -0
- data/lib/graphql/version.rb +4 -0
- data/lib/graphql.rb +168 -0
- data/readme.md +49 -0
- metadata +714 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
# @api deprecated
|
4
|
+
class EnumType < GraphQL::BaseType
|
5
|
+
extend Define::InstanceDefinable::DeprecatedDefine
|
6
|
+
|
7
|
+
accepts_definitions :values, value: GraphQL::Define::AssignEnumValue
|
8
|
+
ensure_defined(:values, :validate_non_null_input, :coerce_non_null_input, :coerce_result)
|
9
|
+
attr_accessor :ast_node
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@values_by_name = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize_copy(other)
|
17
|
+
super
|
18
|
+
self.values = other.values.values
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param new_values [Array<EnumValue>] The set of values contained in this type
|
22
|
+
def values=(new_values)
|
23
|
+
@values_by_name = {}
|
24
|
+
new_values.each { |enum_value| add_value(enum_value) }
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param enum_value [EnumValue] A value to add to this type's set of values
|
28
|
+
def add_value(enum_value)
|
29
|
+
if @values_by_name.key?(enum_value.name)
|
30
|
+
raise "Enum value names must be unique. Value `#{enum_value.name}` already exists on Enum `#{name}`."
|
31
|
+
end
|
32
|
+
|
33
|
+
@values_by_name[enum_value.name] = enum_value
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Hash<String => EnumValue>] `{name => value}` pairs contained in this type
|
37
|
+
def values(_context = nil)
|
38
|
+
@values_by_name
|
39
|
+
end
|
40
|
+
|
41
|
+
def enum_values(_context = nil)
|
42
|
+
values.values
|
43
|
+
end
|
44
|
+
|
45
|
+
def kind
|
46
|
+
GraphQL::TypeKinds::ENUM
|
47
|
+
end
|
48
|
+
|
49
|
+
def coerce_result(value, ctx = nil)
|
50
|
+
if ctx.nil?
|
51
|
+
warn_deprecated_coerce("coerce_isolated_result")
|
52
|
+
ctx = GraphQL::Query::NullContext
|
53
|
+
end
|
54
|
+
|
55
|
+
warden = ctx.warden
|
56
|
+
all_values = warden ? warden.enum_values(self) : @values_by_name.each_value
|
57
|
+
enum_value = all_values.find { |val| val.value == value }
|
58
|
+
if enum_value
|
59
|
+
enum_value.name
|
60
|
+
else
|
61
|
+
raise(UnresolvedValueError, "Can't resolve enum #{name} for #{value.inspect}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_s
|
66
|
+
name
|
67
|
+
end
|
68
|
+
|
69
|
+
# A value within an {EnumType}
|
70
|
+
#
|
71
|
+
# Created with the `value` helper
|
72
|
+
class EnumValue
|
73
|
+
include GraphQL::Define::InstanceDefinable
|
74
|
+
ATTRIBUTES = [:name, :description, :deprecation_reason, :value]
|
75
|
+
accepts_definitions(*ATTRIBUTES)
|
76
|
+
attr_accessor(*ATTRIBUTES)
|
77
|
+
attr_accessor :ast_node
|
78
|
+
ensure_defined(*ATTRIBUTES)
|
79
|
+
|
80
|
+
undef name=
|
81
|
+
def name=(new_name)
|
82
|
+
# Validate that the name is correct
|
83
|
+
GraphQL::NameValidator.validate!(new_name)
|
84
|
+
@name = new_name
|
85
|
+
end
|
86
|
+
|
87
|
+
def graphql_name
|
88
|
+
name
|
89
|
+
end
|
90
|
+
|
91
|
+
def type_class
|
92
|
+
metadata[:type_class]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class UnresolvedValueError < GraphQL::Error
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
# Get the underlying value for this enum value
|
102
|
+
#
|
103
|
+
# @example get episode value from Enum
|
104
|
+
# episode = EpisodeEnum.coerce("NEWHOPE")
|
105
|
+
# episode # => 6
|
106
|
+
#
|
107
|
+
# @param value_name [String] the string representation of this enum value
|
108
|
+
# @return [Object] the underlying value for this enum value
|
109
|
+
def coerce_non_null_input(value_name, ctx)
|
110
|
+
if @values_by_name.key?(value_name)
|
111
|
+
@values_by_name.fetch(value_name).value
|
112
|
+
elsif match_by_value = @values_by_name.find { |k, v| v.value == value_name }
|
113
|
+
# this is for matching default values, which are "inputs", but they're
|
114
|
+
# the Ruby value, not the GraphQL string.
|
115
|
+
match_by_value[1].value
|
116
|
+
else
|
117
|
+
nil
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def validate_non_null_input(value_name, ctx)
|
122
|
+
result = GraphQL::Query::InputValidationResult.new
|
123
|
+
allowed_values = ctx.warden.enum_values(self)
|
124
|
+
matching_value = allowed_values.find { |v| v.name == value_name }
|
125
|
+
|
126
|
+
if matching_value.nil?
|
127
|
+
result.add_problem("Expected #{GraphQL::Language.serialize(value_name)} to be one of: #{allowed_values.map(&:name).join(', ')}")
|
128
|
+
end
|
129
|
+
|
130
|
+
result
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Execution
|
4
|
+
# Boolean checks for how an AST node's directives should
|
5
|
+
# influence its execution
|
6
|
+
# @api private
|
7
|
+
module DirectiveChecks
|
8
|
+
SKIP = "skip"
|
9
|
+
INCLUDE = "include"
|
10
|
+
|
11
|
+
module_function
|
12
|
+
|
13
|
+
# @return [Boolean] Should this node be included in the query?
|
14
|
+
def include?(directive_ast_nodes, query)
|
15
|
+
directive_ast_nodes.each do |directive_ast_node|
|
16
|
+
name = directive_ast_node.name
|
17
|
+
directive_defn = query.schema.directives[name]
|
18
|
+
case name
|
19
|
+
when SKIP
|
20
|
+
args = query.arguments_for(directive_ast_node, directive_defn)
|
21
|
+
if args[:if] == true
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
when INCLUDE
|
25
|
+
args = query.arguments_for(directive_ast_node, directive_defn)
|
26
|
+
if args[:if] == false
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
else
|
30
|
+
# Undefined directive, or one we don't care about
|
31
|
+
end
|
32
|
+
end
|
33
|
+
true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Execution
|
5
|
+
# A plugin that wraps query execution with error handling.
|
6
|
+
# Supports class-based schemas and the new {Interpreter} runtime only.
|
7
|
+
#
|
8
|
+
# @example Handling ActiveRecord::NotFound
|
9
|
+
#
|
10
|
+
# class MySchema < GraphQL::Schema
|
11
|
+
# use GraphQL::Execution::Errors
|
12
|
+
#
|
13
|
+
# rescue_from(ActiveRecord::NotFound) do |err, obj, args, ctx, field|
|
14
|
+
# ErrorTracker.log("Not Found: #{err.message}")
|
15
|
+
# nil
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
class Errors
|
20
|
+
def self.use(schema)
|
21
|
+
definition_line = caller(2, 1).first
|
22
|
+
GraphQL::Deprecation.warn("GraphQL::Execution::Errors is now installed by default, remove `use GraphQL::Execution::Errors` from #{definition_line}")
|
23
|
+
end
|
24
|
+
|
25
|
+
NEW_HANDLER_HASH = ->(h, k) {
|
26
|
+
h[k] = {
|
27
|
+
class: k,
|
28
|
+
handler: nil,
|
29
|
+
subclass_handlers: Hash.new(&NEW_HANDLER_HASH),
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
def initialize(schema)
|
34
|
+
@schema = schema
|
35
|
+
@handlers = {
|
36
|
+
class: nil,
|
37
|
+
handler: nil,
|
38
|
+
subclass_handlers: Hash.new(&NEW_HANDLER_HASH),
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
# @api private
|
43
|
+
def each_rescue
|
44
|
+
handlers = @handlers.values
|
45
|
+
while (handler = handlers.shift) do
|
46
|
+
yield(handler[:class], handler[:handler])
|
47
|
+
handlers.concat(handler[:subclass_handlers].values)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Register this handler, updating the
|
52
|
+
# internal handler index to maintain least-to-most specific.
|
53
|
+
#
|
54
|
+
# @param error_class [Class<Exception>]
|
55
|
+
# @param error_handler [Proc]
|
56
|
+
# @return [void]
|
57
|
+
def rescue_from(error_class, error_handler)
|
58
|
+
subclasses_handlers = {}
|
59
|
+
this_level_subclasses = []
|
60
|
+
# During this traversal, do two things:
|
61
|
+
# - Identify any already-registered subclasses of this error class
|
62
|
+
# and gather them up to be inserted _under_ this class
|
63
|
+
# - Find the point in the index where this handler should be inserted
|
64
|
+
# (That is, _under_ any superclasses, or at top-level, if there are no superclasses registered)
|
65
|
+
handlers = @handlers[:subclass_handlers]
|
66
|
+
while (handlers) do
|
67
|
+
this_level_subclasses.clear
|
68
|
+
# First, identify already-loaded handlers that belong
|
69
|
+
# _under_ this one. (That is, they're handlers
|
70
|
+
# for subclasses of `error_class`.)
|
71
|
+
handlers.each do |err_class, handler|
|
72
|
+
if err_class < error_class
|
73
|
+
subclasses_handlers[err_class] = handler
|
74
|
+
this_level_subclasses << err_class
|
75
|
+
end
|
76
|
+
end
|
77
|
+
# Any handlers that we'll be moving, delete them from this point in the index
|
78
|
+
this_level_subclasses.each do |err_class|
|
79
|
+
handlers.delete(err_class)
|
80
|
+
end
|
81
|
+
|
82
|
+
# See if any keys in this hash are superclasses of this new class:
|
83
|
+
next_index_point = handlers.find { |err_class, handler| error_class < err_class }
|
84
|
+
if next_index_point
|
85
|
+
handlers = next_index_point[1][:subclass_handlers]
|
86
|
+
else
|
87
|
+
# this new handler doesn't belong to any sub-handlers,
|
88
|
+
# so insert it in the current set of `handlers`
|
89
|
+
break
|
90
|
+
end
|
91
|
+
end
|
92
|
+
# Having found the point at which to insert this handler,
|
93
|
+
# register it and merge any subclass handlers back in at this point.
|
94
|
+
this_class_handlers = handlers[error_class]
|
95
|
+
this_class_handlers[:handler] = error_handler
|
96
|
+
this_class_handlers[:subclass_handlers].merge!(subclasses_handlers)
|
97
|
+
nil
|
98
|
+
end
|
99
|
+
|
100
|
+
# Call the given block with the schema's configured error handlers.
|
101
|
+
#
|
102
|
+
# If the block returns a lazy value, it's not wrapped with error handling. That area will have to be wrapped itself.
|
103
|
+
#
|
104
|
+
# @param ctx [GraphQL::Query::Context]
|
105
|
+
# @return [Object] Either the result of the given block, or some object to replace the result, in case of error handling.
|
106
|
+
def with_error_handling(ctx)
|
107
|
+
yield
|
108
|
+
rescue StandardError => err
|
109
|
+
handler = find_handler_for(err.class)
|
110
|
+
if handler
|
111
|
+
runtime_info = ctx.namespace(:interpreter) || {}
|
112
|
+
obj = runtime_info[:current_object]
|
113
|
+
args = runtime_info[:current_arguments]
|
114
|
+
args = args && args.keyword_arguments
|
115
|
+
field = runtime_info[:current_field]
|
116
|
+
if obj.is_a?(GraphQL::Schema::Object)
|
117
|
+
obj = obj.object
|
118
|
+
end
|
119
|
+
handler[:handler].call(err, obj, args, ctx, field)
|
120
|
+
else
|
121
|
+
raise err
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# @return [Proc, nil] The handler for `error_class`, if one was registered on this schema or inherited
|
126
|
+
def find_handler_for(error_class)
|
127
|
+
handlers = @handlers[:subclass_handlers]
|
128
|
+
handler = nil
|
129
|
+
while (handlers) do
|
130
|
+
_err_class, next_handler = handlers.find { |err_class, handler| error_class <= err_class }
|
131
|
+
if next_handler
|
132
|
+
handlers = next_handler[:subclass_handlers]
|
133
|
+
handler = next_handler
|
134
|
+
else
|
135
|
+
# Don't reassign `handler` --
|
136
|
+
# let the previous assignment carry over outside this block.
|
137
|
+
break
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# check for a handler from a parent class:
|
142
|
+
if @schema.superclass.respond_to?(:error_handler) && (parent_errors = @schema.superclass.error_handler)
|
143
|
+
parent_handler = parent_errors.find_handler_for(error_class)
|
144
|
+
end
|
145
|
+
|
146
|
+
# If the inherited handler is more specific than the one defined here,
|
147
|
+
# use it.
|
148
|
+
# If it's a tie (or there is no parent handler), use the one defined here.
|
149
|
+
# If there's an inherited one, but not one defined here, use the inherited one.
|
150
|
+
# Otherwise, there's no handler for this error, return `nil`.
|
151
|
+
if parent_handler && handler && parent_handler[:class] < handler[:class]
|
152
|
+
parent_handler
|
153
|
+
elsif handler
|
154
|
+
handler
|
155
|
+
elsif parent_handler
|
156
|
+
parent_handler
|
157
|
+
else
|
158
|
+
nil
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,333 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Execution
|
4
|
+
# A valid execution strategy
|
5
|
+
# @api private
|
6
|
+
class Execute
|
7
|
+
|
8
|
+
# @api private
|
9
|
+
class Skip < GraphQL::Error; end
|
10
|
+
|
11
|
+
# Just a singleton for implementing {Query::Context#skip}
|
12
|
+
# @api private
|
13
|
+
SKIP = Skip.new
|
14
|
+
|
15
|
+
# @api private
|
16
|
+
class PropagateNull
|
17
|
+
end
|
18
|
+
# @api private
|
19
|
+
PROPAGATE_NULL = PropagateNull.new
|
20
|
+
|
21
|
+
def self.use(schema_class)
|
22
|
+
schema_class.query_execution_strategy(self)
|
23
|
+
schema_class.mutation_execution_strategy(self)
|
24
|
+
schema_class.subscription_execution_strategy(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute(ast_operation, root_type, query)
|
28
|
+
GraphQL::Deprecation.warn "#{self.class} will be removed in GraphQL-Ruby 2.0, please upgrade to the Interpreter: https://graphql-ruby.org/queries/interpreter.html"
|
29
|
+
result = resolve_root_selection(query)
|
30
|
+
lazy_resolve_root_selection(result, **{query: query})
|
31
|
+
GraphQL::Execution::Flatten.call(query.context)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.begin_multiplex(_multiplex)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.begin_query(query, _multiplex)
|
38
|
+
ExecutionFunctions.resolve_root_selection(query)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.finish_multiplex(results, multiplex)
|
42
|
+
ExecutionFunctions.lazy_resolve_root_selection(results, multiplex: multiplex)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.finish_query(query, _multiplex)
|
46
|
+
{
|
47
|
+
"data" => Execution::Flatten.call(query.context)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
# @api private
|
52
|
+
module ExecutionFunctions
|
53
|
+
module_function
|
54
|
+
|
55
|
+
def resolve_root_selection(query)
|
56
|
+
query.trace("execute_query", query: query) do
|
57
|
+
operation = query.selected_operation
|
58
|
+
op_type = operation.operation_type
|
59
|
+
root_type = query.root_type_for_operation(op_type)
|
60
|
+
if query.context[:__root_unauthorized]
|
61
|
+
# This was set by member/instrumentation.rb so that we wouldn't continue.
|
62
|
+
else
|
63
|
+
resolve_selection(
|
64
|
+
query.root_value,
|
65
|
+
root_type,
|
66
|
+
query.context,
|
67
|
+
mutation: query.mutation?
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def lazy_resolve_root_selection(result, query: nil, multiplex: nil)
|
74
|
+
if query.nil? && multiplex.queries.length == 1
|
75
|
+
query = multiplex.queries[0]
|
76
|
+
end
|
77
|
+
|
78
|
+
tracer = (query || multiplex)
|
79
|
+
tracer.trace("execute_query_lazy", {multiplex: multiplex, query: query}) do
|
80
|
+
GraphQL::Execution::Lazy.resolve(result)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def resolve_selection(object, current_type, current_ctx, mutation: false )
|
85
|
+
# Assign this _before_ resolving the children
|
86
|
+
# so that when a child propagates null, the selection result is
|
87
|
+
# ready for it.
|
88
|
+
current_ctx.value = {}
|
89
|
+
|
90
|
+
selections_on_type = current_ctx.irep_node.typed_children[current_type]
|
91
|
+
|
92
|
+
selections_on_type.each do |name, child_irep_node|
|
93
|
+
field_ctx = current_ctx.spawn_child(
|
94
|
+
key: name,
|
95
|
+
object: object,
|
96
|
+
irep_node: child_irep_node,
|
97
|
+
)
|
98
|
+
|
99
|
+
field_result = resolve_field(
|
100
|
+
object,
|
101
|
+
field_ctx
|
102
|
+
)
|
103
|
+
|
104
|
+
if field_result.is_a?(Skip)
|
105
|
+
next
|
106
|
+
end
|
107
|
+
|
108
|
+
if mutation
|
109
|
+
GraphQL::Execution::Lazy.resolve(field_ctx)
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
# If the last subselection caused a null to propagate to _this_ selection,
|
114
|
+
# then we may as well quit executing fields because they
|
115
|
+
# won't be in the response
|
116
|
+
if current_ctx.invalid_null?
|
117
|
+
break
|
118
|
+
else
|
119
|
+
current_ctx.value[name] = field_ctx
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
current_ctx.value
|
124
|
+
end
|
125
|
+
|
126
|
+
def resolve_field(object, field_ctx)
|
127
|
+
query = field_ctx.query
|
128
|
+
irep_node = field_ctx.irep_node
|
129
|
+
parent_type = irep_node.owner_type
|
130
|
+
field = field_ctx.field
|
131
|
+
|
132
|
+
raw_value = begin
|
133
|
+
begin
|
134
|
+
arguments = query.arguments_for(irep_node, field)
|
135
|
+
field_ctx.trace("execute_field", { context: field_ctx }) do
|
136
|
+
field_ctx.schema.middleware.invoke([parent_type, object, field, arguments, field_ctx])
|
137
|
+
end
|
138
|
+
rescue GraphQL::UnauthorizedFieldError => err
|
139
|
+
err.field ||= field
|
140
|
+
field_ctx.schema.unauthorized_field(err)
|
141
|
+
rescue GraphQL::UnauthorizedError => err
|
142
|
+
field_ctx.schema.unauthorized_object(err)
|
143
|
+
end
|
144
|
+
rescue GraphQL::ExecutionError => err
|
145
|
+
err
|
146
|
+
end
|
147
|
+
|
148
|
+
if field_ctx.schema.lazy?(raw_value)
|
149
|
+
field_ctx.value = Execution::Lazy.new {
|
150
|
+
inner_value = field_ctx.trace("execute_field_lazy", {context: field_ctx}) {
|
151
|
+
begin
|
152
|
+
begin
|
153
|
+
field_ctx.field.lazy_resolve(raw_value, arguments, field_ctx)
|
154
|
+
rescue GraphQL::UnauthorizedError => err
|
155
|
+
field_ctx.schema.unauthorized_object(err)
|
156
|
+
end
|
157
|
+
rescue GraphQL::ExecutionError => err
|
158
|
+
err
|
159
|
+
end
|
160
|
+
}
|
161
|
+
continue_or_wait(inner_value, field_ctx.type, field_ctx)
|
162
|
+
}
|
163
|
+
else
|
164
|
+
continue_or_wait(raw_value, field_ctx.type, field_ctx)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# If the returned object is lazy (unfinished),
|
169
|
+
# assign the lazy object to `.value=` so we can resolve it later.
|
170
|
+
# When we resolve it later, reassign it to `.value=` so that
|
171
|
+
# the finished value replaces the unfinished one.
|
172
|
+
#
|
173
|
+
# If the returned object is finished, continue to coerce
|
174
|
+
# and resolve child fields
|
175
|
+
def continue_or_wait(raw_value, field_type, field_ctx)
|
176
|
+
if field_ctx.schema.lazy?(raw_value)
|
177
|
+
field_ctx.value = Execution::Lazy.new {
|
178
|
+
inner_value = begin
|
179
|
+
begin
|
180
|
+
field_ctx.schema.sync_lazy(raw_value)
|
181
|
+
rescue GraphQL::UnauthorizedError => err
|
182
|
+
field_ctx.schema.unauthorized_object(err)
|
183
|
+
end
|
184
|
+
rescue GraphQL::ExecutionError => err
|
185
|
+
err
|
186
|
+
end
|
187
|
+
|
188
|
+
field_ctx.value = continue_or_wait(inner_value, field_type, field_ctx)
|
189
|
+
}
|
190
|
+
else
|
191
|
+
field_ctx.value = continue_resolve_field(raw_value, field_type, field_ctx)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def continue_resolve_field(raw_value, field_type, field_ctx)
|
196
|
+
if field_ctx.parent.invalid_null?
|
197
|
+
return nil
|
198
|
+
end
|
199
|
+
query = field_ctx.query
|
200
|
+
|
201
|
+
case raw_value
|
202
|
+
when GraphQL::ExecutionError
|
203
|
+
raw_value.ast_node ||= field_ctx.ast_node
|
204
|
+
raw_value.path = field_ctx.path
|
205
|
+
query.context.errors.push(raw_value)
|
206
|
+
when Array
|
207
|
+
if field_type.non_null?
|
208
|
+
# List type errors are handled above, this is for the case of fields returning an array of errors
|
209
|
+
list_errors = raw_value.each_with_index.select { |value, _| value.is_a?(GraphQL::ExecutionError) }
|
210
|
+
if list_errors.any?
|
211
|
+
list_errors.each do |error, index|
|
212
|
+
error.ast_node = field_ctx.ast_node
|
213
|
+
error.path = field_ctx.path + (field_ctx.type.list? ? [index] : [])
|
214
|
+
query.context.errors.push(error)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
resolve_value(
|
221
|
+
raw_value,
|
222
|
+
field_type,
|
223
|
+
field_ctx,
|
224
|
+
)
|
225
|
+
end
|
226
|
+
|
227
|
+
def resolve_value(value, field_type, field_ctx)
|
228
|
+
field_defn = field_ctx.field
|
229
|
+
|
230
|
+
if value.nil?
|
231
|
+
if field_type.kind.non_null?
|
232
|
+
parent_type = field_ctx.irep_node.owner_type
|
233
|
+
type_error = GraphQL::InvalidNullError.new(parent_type, field_defn, value)
|
234
|
+
field_ctx.schema.type_error(type_error, field_ctx)
|
235
|
+
PROPAGATE_NULL
|
236
|
+
else
|
237
|
+
nil
|
238
|
+
end
|
239
|
+
elsif value.is_a?(GraphQL::ExecutionError)
|
240
|
+
if field_type.kind.non_null?
|
241
|
+
PROPAGATE_NULL
|
242
|
+
else
|
243
|
+
nil
|
244
|
+
end
|
245
|
+
elsif value.is_a?(Array) && value.any? && value.all? {|v| v.is_a?(GraphQL::ExecutionError)}
|
246
|
+
if field_type.kind.non_null?
|
247
|
+
PROPAGATE_NULL
|
248
|
+
else
|
249
|
+
nil
|
250
|
+
end
|
251
|
+
elsif value.is_a?(Skip)
|
252
|
+
field_ctx.value = value
|
253
|
+
else
|
254
|
+
case field_type.kind
|
255
|
+
when GraphQL::TypeKinds::SCALAR, GraphQL::TypeKinds::ENUM
|
256
|
+
field_type.coerce_result(value, field_ctx)
|
257
|
+
when GraphQL::TypeKinds::LIST
|
258
|
+
inner_type = field_type.of_type
|
259
|
+
i = 0
|
260
|
+
result = []
|
261
|
+
field_ctx.value = result
|
262
|
+
|
263
|
+
value.each do |inner_value|
|
264
|
+
inner_ctx = field_ctx.spawn_child(
|
265
|
+
key: i,
|
266
|
+
object: inner_value,
|
267
|
+
irep_node: field_ctx.irep_node,
|
268
|
+
)
|
269
|
+
|
270
|
+
inner_result = continue_or_wait(
|
271
|
+
inner_value,
|
272
|
+
inner_type,
|
273
|
+
inner_ctx,
|
274
|
+
)
|
275
|
+
|
276
|
+
return PROPAGATE_NULL if inner_result == PROPAGATE_NULL
|
277
|
+
|
278
|
+
result << inner_ctx
|
279
|
+
i += 1
|
280
|
+
end
|
281
|
+
|
282
|
+
result
|
283
|
+
when GraphQL::TypeKinds::NON_NULL
|
284
|
+
inner_type = field_type.of_type
|
285
|
+
resolve_value(
|
286
|
+
value,
|
287
|
+
inner_type,
|
288
|
+
field_ctx,
|
289
|
+
)
|
290
|
+
when GraphQL::TypeKinds::OBJECT
|
291
|
+
resolve_selection(
|
292
|
+
value,
|
293
|
+
field_type,
|
294
|
+
field_ctx
|
295
|
+
)
|
296
|
+
when GraphQL::TypeKinds::UNION, GraphQL::TypeKinds::INTERFACE
|
297
|
+
query = field_ctx.query
|
298
|
+
resolved_type_or_lazy = field_type.resolve_type(value, field_ctx)
|
299
|
+
query.schema.after_lazy(resolved_type_or_lazy) do |resolved_type|
|
300
|
+
possible_types = query.possible_types(field_type)
|
301
|
+
|
302
|
+
if !possible_types.include?(resolved_type)
|
303
|
+
parent_type = field_ctx.irep_node.owner_type
|
304
|
+
type_error = GraphQL::UnresolvedTypeError.new(value, field_defn, parent_type, resolved_type, possible_types)
|
305
|
+
field_ctx.schema.type_error(type_error, field_ctx)
|
306
|
+
PROPAGATE_NULL
|
307
|
+
else
|
308
|
+
resolve_value(
|
309
|
+
value,
|
310
|
+
resolved_type,
|
311
|
+
field_ctx,
|
312
|
+
)
|
313
|
+
end
|
314
|
+
end
|
315
|
+
else
|
316
|
+
raise("Unknown type kind: #{field_type.kind}")
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
include ExecutionFunctions
|
323
|
+
|
324
|
+
# A `.call`-able suitable to be the last step in a middleware chain
|
325
|
+
module FieldResolveStep
|
326
|
+
# Execute the field's resolve method
|
327
|
+
def self.call(_parent_type, parent_object, field_definition, field_args, context, _next = nil)
|
328
|
+
field_definition.resolve(parent_object, field_args, context)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Execution
|
4
|
+
# Starting from a root context,
|
5
|
+
# create a hash out of the context tree.
|
6
|
+
# @api private
|
7
|
+
module Flatten
|
8
|
+
def self.call(ctx)
|
9
|
+
flatten(ctx)
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
private
|
14
|
+
|
15
|
+
def flatten(obj)
|
16
|
+
case obj
|
17
|
+
when Hash
|
18
|
+
flattened = {}
|
19
|
+
obj.each do |key, val|
|
20
|
+
flattened[key] = flatten(val)
|
21
|
+
end
|
22
|
+
flattened
|
23
|
+
when Array
|
24
|
+
obj.map { |v| flatten(v) }
|
25
|
+
when Query::Context::SharedMethods
|
26
|
+
if obj.invalid_null?
|
27
|
+
nil
|
28
|
+
elsif obj.skipped? && obj.value.empty?
|
29
|
+
nil
|
30
|
+
else
|
31
|
+
flatten(obj.value)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
obj
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|