graphql_cody 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +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,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/pagination/relation_connection"
|
3
|
+
|
4
|
+
module GraphQL
|
5
|
+
module Pagination
|
6
|
+
# Customizes `RelationConnection` to work with `Sequel::Dataset`s.
|
7
|
+
class SequelDatasetConnection < Pagination::RelationConnection
|
8
|
+
private
|
9
|
+
|
10
|
+
def relation_offset(relation)
|
11
|
+
relation.opts[:offset]
|
12
|
+
end
|
13
|
+
|
14
|
+
def relation_limit(relation)
|
15
|
+
relation.opts[:limit]
|
16
|
+
end
|
17
|
+
|
18
|
+
def relation_count(relation)
|
19
|
+
# Remove order to make it faster
|
20
|
+
relation.order(nil).count
|
21
|
+
end
|
22
|
+
|
23
|
+
def null_relation(relation)
|
24
|
+
relation.where(false)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/pagination/array_connection"
|
3
|
+
require "graphql/pagination/active_record_relation_connection"
|
4
|
+
require "graphql/pagination/connections"
|
5
|
+
require "graphql/pagination/mongoid_relation_connection"
|
6
|
+
require "graphql/pagination/sequel_dataset_connection"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class ParseError < GraphQL::Error
|
4
|
+
attr_reader :line, :col, :query
|
5
|
+
def initialize(message, line, col, query, filename: nil)
|
6
|
+
if filename
|
7
|
+
message += " (#{filename})"
|
8
|
+
end
|
9
|
+
|
10
|
+
super(message)
|
11
|
+
@line = line
|
12
|
+
@col = col
|
13
|
+
@query = query
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_h
|
17
|
+
locations = line ? [{ "line" => line, "column" => col }] : []
|
18
|
+
{
|
19
|
+
"message" => message,
|
20
|
+
"locations" => locations,
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Query
|
4
|
+
# Read-only access to values, normalizing all keys to strings
|
5
|
+
#
|
6
|
+
# {Arguments} recursively wraps the input in {Arguments} instances.
|
7
|
+
class Arguments
|
8
|
+
extend Forwardable
|
9
|
+
include GraphQL::Dig
|
10
|
+
|
11
|
+
def self.construct_arguments_class(argument_owner)
|
12
|
+
argument_definitions = argument_owner.arguments # rubocop:disable Development/ContextIsPassedCop -- legacy-related
|
13
|
+
argument_owner.arguments_class = Class.new(self) do
|
14
|
+
self.argument_owner = argument_owner
|
15
|
+
self.argument_definitions = argument_definitions
|
16
|
+
|
17
|
+
argument_definitions.each do |_arg_name, arg_definition|
|
18
|
+
if arg_definition.method_access?
|
19
|
+
expose_as = arg_definition.expose_as.to_s.freeze
|
20
|
+
expose_as_underscored = GraphQL::Schema::Member::BuildType.underscore(expose_as).freeze
|
21
|
+
method_names = [expose_as, expose_as_underscored].uniq
|
22
|
+
method_names.each do |method_name|
|
23
|
+
# Don't define a helper method if it would override something.
|
24
|
+
if method_defined?(method_name)
|
25
|
+
GraphQL::Deprecation.warn(
|
26
|
+
"Unable to define a helper for argument with name '#{method_name}' "\
|
27
|
+
"as this is a reserved name. Add `method_access: false` to stop this warning."
|
28
|
+
)
|
29
|
+
else
|
30
|
+
define_method(method_name) do
|
31
|
+
# Always use `expose_as` here, since #[] doesn't accept underscored names
|
32
|
+
self[expose_as]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_reader :argument_values
|
42
|
+
|
43
|
+
def initialize(values, context:, defaults_used:)
|
44
|
+
@argument_values = values.inject({}) do |memo, (inner_key, inner_value)|
|
45
|
+
arg_name = inner_key.to_s
|
46
|
+
arg_defn = self.class.argument_definitions[arg_name] || raise("Not found #{arg_name} among #{self.class.argument_definitions.keys}")
|
47
|
+
arg_default_used = defaults_used.include?(arg_name)
|
48
|
+
arg_value = wrap_value(inner_value, arg_defn.type, context)
|
49
|
+
string_key = arg_defn.expose_as
|
50
|
+
memo[string_key] = ArgumentValue.new(string_key, arg_value, arg_defn, arg_default_used)
|
51
|
+
memo
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# @param key [String, Symbol] name or index of value to access
|
56
|
+
# @return [Object] the argument at that key
|
57
|
+
def [](key)
|
58
|
+
key_s = key.is_a?(String) ? key : key.to_s
|
59
|
+
@argument_values.fetch(key_s, NULL_ARGUMENT_VALUE).value
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param key [String, Symbol] name of value to access
|
63
|
+
# @return [Boolean] true if the argument was present in this field
|
64
|
+
def key?(key)
|
65
|
+
key_s = key.is_a?(String) ? key : key.to_s
|
66
|
+
@argument_values.key?(key_s)
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param key [String, Symbol] name of value to access
|
70
|
+
# @return [Boolean] true if the argument default was passed as the argument value to the resolver
|
71
|
+
def default_used?(key)
|
72
|
+
key_s = key.is_a?(String) ? key : key.to_s
|
73
|
+
@argument_values.fetch(key_s, NULL_ARGUMENT_VALUE).default_used?
|
74
|
+
end
|
75
|
+
|
76
|
+
# Get the hash of all values, with stringified keys
|
77
|
+
# @return [Hash] the stringified hash
|
78
|
+
def to_h
|
79
|
+
@to_h ||= begin
|
80
|
+
h = {}
|
81
|
+
each_value do |arg_value|
|
82
|
+
arg_key = arg_value.definition.expose_as
|
83
|
+
h[arg_key] = unwrap_value(arg_value.value)
|
84
|
+
end
|
85
|
+
h
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def_delegators :to_h, :keys, :values, :each
|
90
|
+
def_delegators :@argument_values, :any?
|
91
|
+
|
92
|
+
def prepare
|
93
|
+
self
|
94
|
+
end
|
95
|
+
|
96
|
+
# Access each key, value and type for the arguments in this set.
|
97
|
+
# @yield [argument_value] The {ArgumentValue} for each argument
|
98
|
+
# @yieldparam argument_value [ArgumentValue]
|
99
|
+
def each_value
|
100
|
+
@argument_values.each_value do |argument_value|
|
101
|
+
yield(argument_value)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class << self
|
106
|
+
attr_accessor :argument_definitions, :argument_owner
|
107
|
+
end
|
108
|
+
|
109
|
+
NoArguments = Class.new(self) do
|
110
|
+
self.argument_definitions = []
|
111
|
+
end
|
112
|
+
|
113
|
+
NO_ARGS = NoArguments.new({}, context: nil, defaults_used: Set.new)
|
114
|
+
|
115
|
+
# Convert this instance into valid Ruby keyword arguments
|
116
|
+
# @return [{Symbol=>Object}]
|
117
|
+
def to_kwargs
|
118
|
+
ruby_kwargs = {}
|
119
|
+
|
120
|
+
keys.each do |key|
|
121
|
+
ruby_kwargs[Schema::Member::BuildType.underscore(key).to_sym] = self[key]
|
122
|
+
end
|
123
|
+
|
124
|
+
ruby_kwargs
|
125
|
+
end
|
126
|
+
|
127
|
+
alias :to_hash :to_kwargs
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
class ArgumentValue
|
132
|
+
attr_reader :key, :value, :definition
|
133
|
+
attr_writer :default_used
|
134
|
+
|
135
|
+
def initialize(key, value, definition, default_used)
|
136
|
+
@key = key
|
137
|
+
@value = value
|
138
|
+
@definition = definition
|
139
|
+
@default_used = default_used
|
140
|
+
end
|
141
|
+
|
142
|
+
# @return [Boolean] true if the argument default was passed as the argument value to the resolver
|
143
|
+
def default_used?
|
144
|
+
@default_used
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
NULL_ARGUMENT_VALUE = ArgumentValue.new(nil, nil, nil, nil)
|
149
|
+
|
150
|
+
def wrap_value(value, arg_defn_type, context)
|
151
|
+
if value.nil?
|
152
|
+
nil
|
153
|
+
else
|
154
|
+
case arg_defn_type
|
155
|
+
when GraphQL::ListType
|
156
|
+
value.map { |item| wrap_value(item, arg_defn_type.of_type, context) }
|
157
|
+
when GraphQL::NonNullType
|
158
|
+
wrap_value(value, arg_defn_type.of_type, context)
|
159
|
+
when GraphQL::InputObjectType
|
160
|
+
if value.is_a?(Hash)
|
161
|
+
result = arg_defn_type.arguments_class.new(value, context: context, defaults_used: Set.new)
|
162
|
+
result.prepare
|
163
|
+
else
|
164
|
+
value
|
165
|
+
end
|
166
|
+
else
|
167
|
+
value
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def unwrap_value(value)
|
173
|
+
case value
|
174
|
+
when Array
|
175
|
+
value.map { |item| unwrap_value(item) }
|
176
|
+
when Hash
|
177
|
+
value.inject({}) do |memo, (key, value)|
|
178
|
+
memo[key] = unwrap_value(value)
|
179
|
+
memo
|
180
|
+
end
|
181
|
+
when GraphQL::Query::Arguments, GraphQL::Schema::InputObject
|
182
|
+
value.to_h
|
183
|
+
else
|
184
|
+
value
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Query
|
4
|
+
module ArgumentsCache
|
5
|
+
# @return [Hash<InternalRepresentation::Node, GraphQL::Language::NodesDirectiveNode => Hash<GraphQL::Field, GraphQL::Directive => GraphQL::Query::Arguments>>]
|
6
|
+
def self.build(query)
|
7
|
+
Hash.new do |h1, irep_or_ast_node|
|
8
|
+
h1[irep_or_ast_node] = Hash.new do |h2, definition|
|
9
|
+
ast_node = irep_or_ast_node.is_a?(GraphQL::InternalRepresentation::Node) ? irep_or_ast_node.ast_node : irep_or_ast_node
|
10
|
+
h2[definition] = if definition.arguments(query.context).empty?
|
11
|
+
GraphQL::Query::Arguments::NO_ARGS
|
12
|
+
else
|
13
|
+
GraphQL::Query::LiteralInput.from_arguments(
|
14
|
+
ast_node.arguments,
|
15
|
+
definition,
|
16
|
+
query.variables,
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,371 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Query
|
4
|
+
# Expose some query-specific info to field resolve functions.
|
5
|
+
# It delegates `[]` to the hash that's passed to `GraphQL::Query#initialize`.
|
6
|
+
class Context
|
7
|
+
module SharedMethods
|
8
|
+
# @return [Object] The target for field resolution
|
9
|
+
attr_accessor :object
|
10
|
+
|
11
|
+
# @return [Hash, Array, String, Integer, Float, Boolean, nil] The resolved value for this field
|
12
|
+
attr_reader :value
|
13
|
+
|
14
|
+
# @return [Boolean] were any fields of this selection skipped?
|
15
|
+
attr_reader :skipped
|
16
|
+
alias :skipped? :skipped
|
17
|
+
|
18
|
+
# @api private
|
19
|
+
attr_writer :skipped
|
20
|
+
|
21
|
+
# Return this value to tell the runtime
|
22
|
+
# to exclude this field from the response altogether
|
23
|
+
def skip
|
24
|
+
GraphQL::Execution::Execute::SKIP
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Boolean] True if this selection has been nullified by a null child
|
28
|
+
def invalid_null?
|
29
|
+
@invalid_null
|
30
|
+
end
|
31
|
+
|
32
|
+
# Remove this child from the result value
|
33
|
+
# (used for null propagation and skip)
|
34
|
+
# @api private
|
35
|
+
def delete_child(child_ctx)
|
36
|
+
@value.delete(child_ctx.key)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create a child context to use for `key`
|
40
|
+
# @param key [String, Integer] The key in the response (name or index)
|
41
|
+
# @param irep_node [InternalRepresentation::Node] The node being evaluated
|
42
|
+
# @api private
|
43
|
+
def spawn_child(key:, irep_node:, object:)
|
44
|
+
FieldResolutionContext.new(
|
45
|
+
@context,
|
46
|
+
key,
|
47
|
+
irep_node,
|
48
|
+
self,
|
49
|
+
object
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Add error at query-level.
|
54
|
+
# @param error [GraphQL::ExecutionError] an execution error
|
55
|
+
# @return [void]
|
56
|
+
def add_error(error)
|
57
|
+
if !error.is_a?(ExecutionError)
|
58
|
+
raise TypeError, "expected error to be a ExecutionError, but was #{error.class}"
|
59
|
+
end
|
60
|
+
errors << error
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
|
64
|
+
# @example Print the GraphQL backtrace during field resolution
|
65
|
+
# puts ctx.backtrace
|
66
|
+
#
|
67
|
+
# @return [GraphQL::Backtrace] The backtrace for this point in query execution
|
68
|
+
def backtrace
|
69
|
+
GraphQL::Backtrace.new(self)
|
70
|
+
end
|
71
|
+
|
72
|
+
def execution_errors
|
73
|
+
@execution_errors ||= ExecutionErrors.new(self)
|
74
|
+
end
|
75
|
+
|
76
|
+
def lookahead
|
77
|
+
ast_nodes = irep_node.ast_nodes
|
78
|
+
field = irep_node.definition.metadata[:type_class] || raise("Lookahead is only compatible with class-based schemas")
|
79
|
+
Execution::Lookahead.new(query: query, ast_nodes: ast_nodes, field: field)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class ExecutionErrors
|
84
|
+
def initialize(ctx)
|
85
|
+
@context = ctx
|
86
|
+
end
|
87
|
+
|
88
|
+
def add(err_or_msg)
|
89
|
+
err = case err_or_msg
|
90
|
+
when String
|
91
|
+
GraphQL::ExecutionError.new(err_or_msg)
|
92
|
+
when GraphQL::ExecutionError
|
93
|
+
err_or_msg
|
94
|
+
else
|
95
|
+
raise ArgumentError, "expected String or GraphQL::ExecutionError, not #{err_or_msg.class} (#{err_or_msg.inspect})"
|
96
|
+
end
|
97
|
+
# This will assign ast_node and path
|
98
|
+
@context.add_error(err)
|
99
|
+
end
|
100
|
+
|
101
|
+
alias :>> :add
|
102
|
+
alias :push :add
|
103
|
+
end
|
104
|
+
|
105
|
+
include SharedMethods
|
106
|
+
extend Forwardable
|
107
|
+
|
108
|
+
attr_reader :execution_strategy
|
109
|
+
# `strategy` is required by GraphQL::Batch
|
110
|
+
alias_method :strategy, :execution_strategy
|
111
|
+
|
112
|
+
def execution_strategy=(new_strategy)
|
113
|
+
# GraphQL::Batch re-assigns this value but it was previously not used
|
114
|
+
# (ExecutionContext#strategy was used instead)
|
115
|
+
# now it _is_ used, but it breaks GraphQL::Batch tests
|
116
|
+
@execution_strategy ||= new_strategy
|
117
|
+
end
|
118
|
+
|
119
|
+
# @return [GraphQL::InternalRepresentation::Node] The internal representation for this query node
|
120
|
+
def irep_node
|
121
|
+
@irep_node ||= query.irep_selection
|
122
|
+
end
|
123
|
+
|
124
|
+
# @return [GraphQL::Language::Nodes::Field] The AST node for the currently-executing field
|
125
|
+
def ast_node
|
126
|
+
@irep_node.ast_node
|
127
|
+
end
|
128
|
+
|
129
|
+
# @return [Array<GraphQL::ExecutionError>] errors returned during execution
|
130
|
+
attr_reader :errors
|
131
|
+
|
132
|
+
# @return [GraphQL::Query] The query whose context this is
|
133
|
+
attr_reader :query
|
134
|
+
|
135
|
+
# @return [GraphQL::Schema]
|
136
|
+
attr_reader :schema
|
137
|
+
|
138
|
+
# @return [Array<String, Integer>] The current position in the result
|
139
|
+
attr_reader :path
|
140
|
+
|
141
|
+
# Make a new context which delegates key lookup to `values`
|
142
|
+
# @param query [GraphQL::Query] the query who owns this context
|
143
|
+
# @param values [Hash] A hash of arbitrary values which will be accessible at query-time
|
144
|
+
def initialize(query:, schema: query.schema, values:, object:)
|
145
|
+
@query = query
|
146
|
+
@schema = schema
|
147
|
+
@provided_values = values || {}
|
148
|
+
@object = object
|
149
|
+
# Namespaced storage, where user-provided values are in `nil` namespace:
|
150
|
+
@storage = Hash.new { |h, k| h[k] = {} }
|
151
|
+
@storage[nil] = @provided_values
|
152
|
+
@errors = []
|
153
|
+
@path = []
|
154
|
+
@value = nil
|
155
|
+
@context = self # for SharedMethods
|
156
|
+
@scoped_context = {}
|
157
|
+
end
|
158
|
+
|
159
|
+
def dataloader
|
160
|
+
@dataloader ||= self[:dataloader] || (query.multiplex ? query.multiplex.dataloader : schema.dataloader_class.new)
|
161
|
+
end
|
162
|
+
|
163
|
+
# @api private
|
164
|
+
attr_writer :interpreter
|
165
|
+
|
166
|
+
# @api private
|
167
|
+
attr_writer :value
|
168
|
+
|
169
|
+
# @api private
|
170
|
+
attr_accessor :scoped_context
|
171
|
+
|
172
|
+
def []=(key, value)
|
173
|
+
@provided_values[key] = value
|
174
|
+
end
|
175
|
+
|
176
|
+
def_delegators :@query, :trace, :interpreter?
|
177
|
+
|
178
|
+
# @!method []=(key, value)
|
179
|
+
# Reassign `key` to the hash passed to {Schema#execute} as `context:`
|
180
|
+
|
181
|
+
# Lookup `key` from the hash passed to {Schema#execute} as `context:`
|
182
|
+
def [](key)
|
183
|
+
return @scoped_context[key] if @scoped_context.key?(key)
|
184
|
+
@provided_values[key]
|
185
|
+
end
|
186
|
+
|
187
|
+
def delete(key)
|
188
|
+
if @scoped_context.key?(key)
|
189
|
+
@scoped_context.delete(key)
|
190
|
+
else
|
191
|
+
@provided_values.delete(key)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
UNSPECIFIED_FETCH_DEFAULT = Object.new
|
196
|
+
|
197
|
+
def fetch(key, default = UNSPECIFIED_FETCH_DEFAULT)
|
198
|
+
if @scoped_context.key?(key)
|
199
|
+
@scoped_context[key]
|
200
|
+
elsif @provided_values.key?(key)
|
201
|
+
@provided_values[key]
|
202
|
+
elsif default != UNSPECIFIED_FETCH_DEFAULT
|
203
|
+
default
|
204
|
+
elsif block_given?
|
205
|
+
yield(self, key)
|
206
|
+
else
|
207
|
+
raise KeyError.new(key: key)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def dig(key, *other_keys)
|
212
|
+
@scoped_context.key?(key) ? @scoped_context.dig(key, *other_keys) : @provided_values.dig(key, *other_keys)
|
213
|
+
end
|
214
|
+
|
215
|
+
def to_h
|
216
|
+
@provided_values.merge(@scoped_context)
|
217
|
+
end
|
218
|
+
alias :to_hash :to_h
|
219
|
+
|
220
|
+
def key?(key)
|
221
|
+
@scoped_context.key?(key) || @provided_values.key?(key)
|
222
|
+
end
|
223
|
+
|
224
|
+
# @return [GraphQL::Schema::Warden]
|
225
|
+
def warden
|
226
|
+
@warden ||= (@query && @query.warden)
|
227
|
+
end
|
228
|
+
|
229
|
+
# @api private
|
230
|
+
attr_writer :warden
|
231
|
+
|
232
|
+
# Get an isolated hash for `ns`. Doesn't affect user-provided storage.
|
233
|
+
# @param ns [Object] a usage-specific namespace identifier
|
234
|
+
# @return [Hash] namespaced storage
|
235
|
+
def namespace(ns)
|
236
|
+
@storage[ns]
|
237
|
+
end
|
238
|
+
|
239
|
+
def inspect
|
240
|
+
"#<Query::Context ...>"
|
241
|
+
end
|
242
|
+
|
243
|
+
# @api private
|
244
|
+
def received_null_child
|
245
|
+
@invalid_null = true
|
246
|
+
@value = nil
|
247
|
+
end
|
248
|
+
|
249
|
+
def scoped_merge!(hash)
|
250
|
+
@scoped_context = @scoped_context.merge(hash)
|
251
|
+
end
|
252
|
+
|
253
|
+
def scoped_set!(key, value)
|
254
|
+
scoped_merge!(key => value)
|
255
|
+
nil
|
256
|
+
end
|
257
|
+
|
258
|
+
class FieldResolutionContext
|
259
|
+
include SharedMethods
|
260
|
+
include Tracing::Traceable
|
261
|
+
extend Forwardable
|
262
|
+
|
263
|
+
attr_reader :irep_node, :field, :parent_type, :query, :schema, :parent, :key, :type
|
264
|
+
alias :selection :irep_node
|
265
|
+
|
266
|
+
def initialize(context, key, irep_node, parent, object)
|
267
|
+
@context = context
|
268
|
+
@key = key
|
269
|
+
@parent = parent
|
270
|
+
@object = object
|
271
|
+
@irep_node = irep_node
|
272
|
+
@field = irep_node.definition
|
273
|
+
@parent_type = irep_node.owner_type
|
274
|
+
@type = field.type
|
275
|
+
# This is needed constantly, so set it ahead of time:
|
276
|
+
@query = context.query
|
277
|
+
@schema = context.schema
|
278
|
+
@tracers = @query.tracers
|
279
|
+
# This hack flag is required by ConnectionResolve
|
280
|
+
@wrapped_connection = false
|
281
|
+
@wrapped_object = false
|
282
|
+
end
|
283
|
+
|
284
|
+
# @api private
|
285
|
+
attr_accessor :wrapped_connection, :wrapped_object
|
286
|
+
|
287
|
+
def path
|
288
|
+
@path ||= @parent.path.dup << @key
|
289
|
+
end
|
290
|
+
|
291
|
+
def_delegators :@context,
|
292
|
+
:[], :[]=, :key?, :fetch, :to_h, :namespace, :dig,
|
293
|
+
:spawn, :warden, :errors,
|
294
|
+
:execution_strategy, :strategy, :interpreter?
|
295
|
+
|
296
|
+
# @return [GraphQL::Language::Nodes::Field] The AST node for the currently-executing field
|
297
|
+
def ast_node
|
298
|
+
@irep_node.ast_node
|
299
|
+
end
|
300
|
+
|
301
|
+
# Add error to current field resolution.
|
302
|
+
# @param error [GraphQL::ExecutionError] an execution error
|
303
|
+
# @return [void]
|
304
|
+
def add_error(error)
|
305
|
+
super
|
306
|
+
error.ast_node ||= irep_node.ast_node
|
307
|
+
error.path ||= path
|
308
|
+
nil
|
309
|
+
end
|
310
|
+
|
311
|
+
def inspect
|
312
|
+
"#<GraphQL Context @ #{irep_node.owner_type.name}.#{field.name}>"
|
313
|
+
end
|
314
|
+
|
315
|
+
# Set a new value for this field in the response.
|
316
|
+
# It may be updated after resolving a {Lazy}.
|
317
|
+
# If it is {Execute::PROPAGATE_NULL}, tell the owner to propagate null.
|
318
|
+
# If it's {Execute::Execution::SKIP}, remove this field result from its parent
|
319
|
+
# @param new_value [Any] The GraphQL-ready value
|
320
|
+
# @api private
|
321
|
+
def value=(new_value)
|
322
|
+
case new_value
|
323
|
+
when GraphQL::Execution::Execute::PROPAGATE_NULL, nil
|
324
|
+
@invalid_null = true
|
325
|
+
@value = nil
|
326
|
+
if @type.kind.non_null?
|
327
|
+
@parent.received_null_child
|
328
|
+
end
|
329
|
+
when GraphQL::Execution::Execute::SKIP
|
330
|
+
@parent.skipped = true
|
331
|
+
@parent.delete_child(self)
|
332
|
+
else
|
333
|
+
@value = new_value
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
protected
|
338
|
+
|
339
|
+
def received_null_child
|
340
|
+
case @value
|
341
|
+
when Hash
|
342
|
+
self.value = GraphQL::Execution::Execute::PROPAGATE_NULL
|
343
|
+
when Array
|
344
|
+
if list_of_non_null_items?(@type)
|
345
|
+
self.value = GraphQL::Execution::Execute::PROPAGATE_NULL
|
346
|
+
end
|
347
|
+
when nil
|
348
|
+
# TODO This is a hack
|
349
|
+
# It was already nulled out but it's getting reassigned
|
350
|
+
else
|
351
|
+
raise "Unexpected value for received_null_child (#{self.value.class}): #{value}"
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
private
|
356
|
+
|
357
|
+
def list_of_non_null_items?(type)
|
358
|
+
case type
|
359
|
+
when GraphQL::NonNullType
|
360
|
+
# Unwrap [T]!
|
361
|
+
list_of_non_null_items?(type.of_type)
|
362
|
+
when GraphQL::ListType
|
363
|
+
type.of_type.is_a?(GraphQL::NonNullType)
|
364
|
+
else
|
365
|
+
raise "Unexpected list_of_non_null_items check: #{type}"
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Query
|
4
|
+
class Executor
|
5
|
+
class PropagateNull < StandardError; end
|
6
|
+
|
7
|
+
# @return [GraphQL::Query] the query being executed
|
8
|
+
attr_reader :query
|
9
|
+
|
10
|
+
def initialize(query)
|
11
|
+
@query = query
|
12
|
+
end
|
13
|
+
|
14
|
+
# Evaluate {operation_name} on {query}.
|
15
|
+
# Handle {GraphQL::ExecutionError}s by putting them in the "errors" key.
|
16
|
+
# @return [Hash] A GraphQL response, with either a "data" key or an "errors" key
|
17
|
+
def result
|
18
|
+
execute
|
19
|
+
rescue GraphQL::ExecutionError => err
|
20
|
+
query.context.errors << err
|
21
|
+
{"errors" => [err.to_h]}
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def execute
|
27
|
+
operation = query.selected_operation
|
28
|
+
return {} if operation.nil?
|
29
|
+
|
30
|
+
op_type = operation.operation_type
|
31
|
+
root_type = query.root_type_for_operation(op_type)
|
32
|
+
execution_strategy_class = query.schema.execution_strategy_for_operation(op_type)
|
33
|
+
execution_strategy = execution_strategy_class.new
|
34
|
+
|
35
|
+
query.context.execution_strategy = execution_strategy
|
36
|
+
data_result = begin
|
37
|
+
execution_strategy.execute(operation, root_type, query)
|
38
|
+
rescue PropagateNull
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
result = { "data" => data_result }
|
42
|
+
error_result = query.context.errors.map(&:to_h)
|
43
|
+
|
44
|
+
if error_result.any?
|
45
|
+
result["errors"] = error_result
|
46
|
+
end
|
47
|
+
|
48
|
+
result
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|