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,214 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Execution
|
4
|
+
# Execute multiple queries under the same multiplex "umbrella".
|
5
|
+
# They can share a batching context and reduce redundant database hits.
|
6
|
+
#
|
7
|
+
# The flow is:
|
8
|
+
#
|
9
|
+
# - Multiplex instrumentation setup
|
10
|
+
# - Query instrumentation setup
|
11
|
+
# - Analyze the multiplex + each query
|
12
|
+
# - Begin each query
|
13
|
+
# - Resolve lazy values, breadth-first across all queries
|
14
|
+
# - Finish each query (eg, get errors)
|
15
|
+
# - Query instrumentation teardown
|
16
|
+
# - Multiplex instrumentation teardown
|
17
|
+
#
|
18
|
+
# If one query raises an application error, all queries will be in undefined states.
|
19
|
+
#
|
20
|
+
# Validation errors and {GraphQL::ExecutionError}s are handled in isolation:
|
21
|
+
# one of these errors in one query will not affect the other queries.
|
22
|
+
#
|
23
|
+
# @see {Schema#multiplex} for public API
|
24
|
+
# @api private
|
25
|
+
class Multiplex
|
26
|
+
# Used internally to signal that the query shouldn't be executed
|
27
|
+
# @api private
|
28
|
+
NO_OPERATION = {}.freeze
|
29
|
+
|
30
|
+
include Tracing::Traceable
|
31
|
+
|
32
|
+
attr_reader :context, :queries, :schema, :max_complexity, :dataloader
|
33
|
+
def initialize(schema:, queries:, context:, max_complexity:)
|
34
|
+
@schema = schema
|
35
|
+
@queries = queries
|
36
|
+
@queries.each { |q| q.multiplex = self }
|
37
|
+
@context = context
|
38
|
+
@dataloader = @context[:dataloader] ||= @schema.dataloader_class.new
|
39
|
+
@tracers = schema.tracers + (context[:tracers] || [])
|
40
|
+
# Support `context: {backtrace: true}`
|
41
|
+
if context[:backtrace] && !@tracers.include?(GraphQL::Backtrace::Tracer)
|
42
|
+
@tracers << GraphQL::Backtrace::Tracer
|
43
|
+
end
|
44
|
+
@max_complexity = max_complexity
|
45
|
+
end
|
46
|
+
|
47
|
+
class << self
|
48
|
+
def run_all(schema, query_options, **kwargs)
|
49
|
+
queries = query_options.map { |opts| GraphQL::Query.new(schema, nil, **opts) }
|
50
|
+
run_queries(schema, queries, **kwargs)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @param schema [GraphQL::Schema]
|
54
|
+
# @param queries [Array<GraphQL::Query>]
|
55
|
+
# @param context [Hash]
|
56
|
+
# @param max_complexity [Integer, nil]
|
57
|
+
# @return [Array<Hash>] One result per query
|
58
|
+
def run_queries(schema, queries, context: {}, max_complexity: schema.max_complexity)
|
59
|
+
multiplex = self.new(schema: schema, queries: queries, context: context, max_complexity: max_complexity)
|
60
|
+
multiplex.trace("execute_multiplex", { multiplex: multiplex }) do
|
61
|
+
if supports_multiplexing?(schema)
|
62
|
+
instrument_and_analyze(multiplex) do
|
63
|
+
run_as_multiplex(multiplex)
|
64
|
+
end
|
65
|
+
else
|
66
|
+
if queries.length != 1
|
67
|
+
raise ArgumentError, "Multiplexing doesn't support custom execution strategies, run one query at a time instead"
|
68
|
+
else
|
69
|
+
instrument_and_analyze(multiplex) do
|
70
|
+
[run_one_legacy(schema, queries.first)]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# @param query [GraphQL::Query]
|
78
|
+
def begin_query(results, idx, query, multiplex)
|
79
|
+
operation = query.selected_operation
|
80
|
+
result = if operation.nil? || !query.valid? || query.context.errors.any?
|
81
|
+
NO_OPERATION
|
82
|
+
else
|
83
|
+
begin
|
84
|
+
# These were checked to be the same in `#supports_multiplexing?`
|
85
|
+
query.schema.query_execution_strategy.begin_query(query, multiplex)
|
86
|
+
rescue GraphQL::ExecutionError => err
|
87
|
+
query.context.errors << err
|
88
|
+
NO_OPERATION
|
89
|
+
end
|
90
|
+
end
|
91
|
+
results[idx] = result
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def run_as_multiplex(multiplex)
|
98
|
+
|
99
|
+
multiplex.schema.query_execution_strategy.begin_multiplex(multiplex)
|
100
|
+
queries = multiplex.queries
|
101
|
+
# Do as much eager evaluation of the query as possible
|
102
|
+
results = []
|
103
|
+
queries.each_with_index do |query, idx|
|
104
|
+
multiplex.dataloader.append_job { begin_query(results, idx, query, multiplex) }
|
105
|
+
end
|
106
|
+
|
107
|
+
multiplex.dataloader.run
|
108
|
+
|
109
|
+
# Then, work through lazy results in a breadth-first way
|
110
|
+
multiplex.dataloader.append_job {
|
111
|
+
multiplex.schema.query_execution_strategy.finish_multiplex(results, multiplex)
|
112
|
+
}
|
113
|
+
multiplex.dataloader.run
|
114
|
+
|
115
|
+
# Then, find all errors and assign the result to the query object
|
116
|
+
results.each_with_index do |data_result, idx|
|
117
|
+
query = queries[idx]
|
118
|
+
finish_query(data_result, query, multiplex)
|
119
|
+
# Get the Query::Result, not the Hash
|
120
|
+
results[idx] = query.result
|
121
|
+
end
|
122
|
+
|
123
|
+
results
|
124
|
+
rescue Exception
|
125
|
+
# TODO rescue at a higher level so it will catch errors in analysis, too
|
126
|
+
# Assign values here so that the query's `@executed` becomes true
|
127
|
+
queries.map { |q| q.result_values ||= {} }
|
128
|
+
raise
|
129
|
+
end
|
130
|
+
|
131
|
+
# @param data_result [Hash] The result for the "data" key, if any
|
132
|
+
# @param query [GraphQL::Query] The query which was run
|
133
|
+
# @return [Hash] final result of this query, including all values and errors
|
134
|
+
def finish_query(data_result, query, multiplex)
|
135
|
+
# Assign the result so that it can be accessed in instrumentation
|
136
|
+
query.result_values = if data_result.equal?(NO_OPERATION)
|
137
|
+
if !query.valid? || query.context.errors.any?
|
138
|
+
# A bit weird, but `Query#static_errors` _includes_ `query.context.errors`
|
139
|
+
{ "errors" => query.static_errors.map(&:to_h) }
|
140
|
+
else
|
141
|
+
data_result
|
142
|
+
end
|
143
|
+
else
|
144
|
+
# Use `context.value` which was assigned during execution
|
145
|
+
result = query.schema.query_execution_strategy.finish_query(query, multiplex)
|
146
|
+
|
147
|
+
if query.context.errors.any?
|
148
|
+
error_result = query.context.errors.map(&:to_h)
|
149
|
+
result["errors"] = error_result
|
150
|
+
end
|
151
|
+
|
152
|
+
result
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# use the old `query_execution_strategy` etc to run this query
|
157
|
+
def run_one_legacy(schema, query)
|
158
|
+
GraphQL::Deprecation.warn "Multiplex.run_one_legacy will be removed from GraphQL-Ruby 2.0, upgrade to the Interpreter to avoid this deprecated codepath: https://graphql-ruby.org/queries/interpreter.html"
|
159
|
+
|
160
|
+
query.result_values = if !query.valid?
|
161
|
+
all_errors = query.validation_errors + query.analysis_errors + query.context.errors
|
162
|
+
if all_errors.any?
|
163
|
+
{ "errors" => all_errors.map(&:to_h) }
|
164
|
+
else
|
165
|
+
nil
|
166
|
+
end
|
167
|
+
else
|
168
|
+
GraphQL::Query::Executor.new(query).result
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
DEFAULT_STRATEGIES = [
|
173
|
+
GraphQL::Execution::Execute,
|
174
|
+
GraphQL::Execution::Interpreter
|
175
|
+
]
|
176
|
+
# @return [Boolean] True if the schema is only using one strategy, and it's one that supports multiplexing.
|
177
|
+
def supports_multiplexing?(schema)
|
178
|
+
schema_strategies = [schema.query_execution_strategy, schema.mutation_execution_strategy, schema.subscription_execution_strategy]
|
179
|
+
schema_strategies.uniq!
|
180
|
+
schema_strategies.size == 1 && DEFAULT_STRATEGIES.include?(schema_strategies.first)
|
181
|
+
end
|
182
|
+
|
183
|
+
# Apply multiplex & query instrumentation to `queries`.
|
184
|
+
#
|
185
|
+
# It yields when the queries should be executed, then runs teardown.
|
186
|
+
def instrument_and_analyze(multiplex)
|
187
|
+
GraphQL::Execution::Instrumentation.apply_instrumenters(multiplex) do
|
188
|
+
schema = multiplex.schema
|
189
|
+
if schema.interpreter? && schema.analysis_engine != GraphQL::Analysis::AST
|
190
|
+
raise <<-ERR
|
191
|
+
Can't use `GraphQL::Execution::Interpreter` without `GraphQL::Analysis::AST`, please add this plugin to your schema:
|
192
|
+
|
193
|
+
use GraphQL::Analysis::AST
|
194
|
+
|
195
|
+
For information about the new analysis engine: https://graphql-ruby.org/queries/ast_analysis.html
|
196
|
+
ERR
|
197
|
+
end
|
198
|
+
multiplex_analyzers = schema.multiplex_analyzers
|
199
|
+
if multiplex.max_complexity
|
200
|
+
multiplex_analyzers += if schema.using_ast_analysis?
|
201
|
+
[GraphQL::Analysis::AST::MaxQueryComplexity]
|
202
|
+
else
|
203
|
+
[GraphQL::Analysis::MaxQueryComplexity.new(multiplex.max_complexity)]
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
schema.analysis_engine.analyze_multiplex(multiplex, multiplex_analyzers)
|
208
|
+
yield
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Execution
|
4
|
+
# @api private
|
5
|
+
module Typecast
|
6
|
+
# @return [Boolean]
|
7
|
+
def self.subtype?(parent_type, child_type)
|
8
|
+
if parent_type == child_type
|
9
|
+
# Equivalent types are subtypes
|
10
|
+
true
|
11
|
+
elsif child_type.is_a?(GraphQL::NonNullType)
|
12
|
+
# A non-null type is a subtype of a nullable type
|
13
|
+
# if its inner type is a subtype of that type
|
14
|
+
if parent_type.is_a?(GraphQL::NonNullType)
|
15
|
+
subtype?(parent_type.of_type, child_type.of_type)
|
16
|
+
else
|
17
|
+
subtype?(parent_type, child_type.of_type)
|
18
|
+
end
|
19
|
+
else
|
20
|
+
case parent_type
|
21
|
+
when GraphQL::InterfaceType
|
22
|
+
# A type is a subtype of an interface
|
23
|
+
# if it implements that interface
|
24
|
+
case child_type
|
25
|
+
when GraphQL::ObjectType
|
26
|
+
child_type.interfaces.include?(parent_type)
|
27
|
+
else
|
28
|
+
false
|
29
|
+
end
|
30
|
+
when GraphQL::UnionType
|
31
|
+
# A type is a subtype of that union
|
32
|
+
# if the union includes that type
|
33
|
+
parent_type.possible_types.include?(child_type)
|
34
|
+
when GraphQL::ListType
|
35
|
+
# A list type is a subtype of another list type
|
36
|
+
# if its inner type is a subtype of the other inner type
|
37
|
+
case child_type
|
38
|
+
when GraphQL::ListType
|
39
|
+
subtype?(parent_type.of_type, child_type.of_type)
|
40
|
+
else
|
41
|
+
false
|
42
|
+
end
|
43
|
+
else
|
44
|
+
false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/execution/directive_checks"
|
3
|
+
require "graphql/execution/execute"
|
4
|
+
require "graphql/execution/flatten"
|
5
|
+
require "graphql/execution/instrumentation"
|
6
|
+
require "graphql/execution/interpreter"
|
7
|
+
require "graphql/execution/lazy"
|
8
|
+
require "graphql/execution/lookahead"
|
9
|
+
require "graphql/execution/multiplex"
|
10
|
+
require "graphql/execution/typecast"
|
11
|
+
require "graphql/execution/errors"
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
# If a field's resolve function returns a {ExecutionError},
|
4
|
+
# the error will be inserted into the response's `"errors"` key
|
5
|
+
# and the field will resolve to `nil`.
|
6
|
+
class ExecutionError < GraphQL::Error
|
7
|
+
# @return [GraphQL::Language::Nodes::Field] the field where the error occurred
|
8
|
+
attr_accessor :ast_node
|
9
|
+
|
10
|
+
# @return [String] an array describing the JSON-path into the execution
|
11
|
+
# response which corresponds to this error.
|
12
|
+
attr_accessor :path
|
13
|
+
|
14
|
+
# @return [Hash] Optional data for error objects
|
15
|
+
# @deprecated Use `extensions` instead of `options`. The GraphQL spec
|
16
|
+
# recommends that any custom entries in an error be under the
|
17
|
+
# `extensions` key.
|
18
|
+
attr_accessor :options
|
19
|
+
|
20
|
+
# @return [Hash] Optional custom data for error objects which will be added
|
21
|
+
# under the `extensions` key.
|
22
|
+
attr_accessor :extensions
|
23
|
+
|
24
|
+
def initialize(message, ast_node: nil, options: nil, extensions: nil)
|
25
|
+
@ast_node = ast_node
|
26
|
+
@options = options
|
27
|
+
@extensions = extensions
|
28
|
+
super(message)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Hash] An entry for the response's "errors" key
|
32
|
+
def to_h
|
33
|
+
hash = {
|
34
|
+
"message" => message,
|
35
|
+
}
|
36
|
+
if ast_node
|
37
|
+
hash["locations"] = [
|
38
|
+
{
|
39
|
+
"line" => ast_node.line,
|
40
|
+
"column" => ast_node.col,
|
41
|
+
}
|
42
|
+
]
|
43
|
+
end
|
44
|
+
if path
|
45
|
+
hash["path"] = path
|
46
|
+
end
|
47
|
+
if options
|
48
|
+
hash.merge!(options)
|
49
|
+
end
|
50
|
+
if extensions
|
51
|
+
hash["extensions"] = extensions.each_with_object({}) { |(key, value), ext|
|
52
|
+
ext[key.to_s] = value
|
53
|
+
}
|
54
|
+
end
|
55
|
+
hash
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Field
|
4
|
+
# Create resolve procs ahead of time based on a {GraphQL::Field}'s `name`, `property`, and `hash_key` configuration.
|
5
|
+
module Resolve
|
6
|
+
module_function
|
7
|
+
|
8
|
+
# @param field [GraphQL::Field] A field that needs a resolve proc
|
9
|
+
# @return [Proc] A resolver for this field, based on its config
|
10
|
+
def create_proc(field)
|
11
|
+
if field.property
|
12
|
+
MethodResolve.new(field)
|
13
|
+
elsif !field.hash_key.nil?
|
14
|
+
HashKeyResolve.new(field.hash_key)
|
15
|
+
else
|
16
|
+
NameResolve.new(field)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# These only require `obj` as input
|
21
|
+
class BuiltInResolve
|
22
|
+
end
|
23
|
+
|
24
|
+
# Resolve the field by `public_send`ing `@method_name`
|
25
|
+
class MethodResolve < BuiltInResolve
|
26
|
+
def initialize(field)
|
27
|
+
@method_name = field.property.to_sym
|
28
|
+
end
|
29
|
+
|
30
|
+
def call(obj, args, ctx)
|
31
|
+
obj.public_send(@method_name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Resolve the field by looking up `@hash_key` with `#[]`
|
36
|
+
class HashKeyResolve < BuiltInResolve
|
37
|
+
def initialize(hash_key)
|
38
|
+
@hash_key = hash_key
|
39
|
+
end
|
40
|
+
|
41
|
+
def call(obj, args, ctx)
|
42
|
+
obj[@hash_key]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Call the field's name at query-time since
|
47
|
+
# it might have changed
|
48
|
+
class NameResolve < BuiltInResolve
|
49
|
+
def initialize(field)
|
50
|
+
@field = field
|
51
|
+
end
|
52
|
+
|
53
|
+
def call(obj, args, ctx)
|
54
|
+
obj.public_send(@field.name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/field/resolve"
|
3
|
+
|
4
|
+
module GraphQL
|
5
|
+
# @api deprecated
|
6
|
+
class Field
|
7
|
+
include GraphQL::Define::InstanceDefinable
|
8
|
+
accepts_definitions :name, :description, :deprecation_reason,
|
9
|
+
:resolve, :lazy_resolve,
|
10
|
+
:type, :arguments,
|
11
|
+
:property, :hash_key, :complexity,
|
12
|
+
:mutation, :function,
|
13
|
+
:edge_class,
|
14
|
+
:relay_node_field,
|
15
|
+
:relay_nodes_field,
|
16
|
+
:subscription_scope,
|
17
|
+
:trace,
|
18
|
+
:introspection,
|
19
|
+
argument: GraphQL::Define::AssignArgument
|
20
|
+
|
21
|
+
ensure_defined(
|
22
|
+
:name, :deprecation_reason, :description, :description=, :property, :hash_key,
|
23
|
+
:mutation, :arguments, :complexity, :function,
|
24
|
+
:resolve, :resolve=, :lazy_resolve, :lazy_resolve=, :lazy_resolve_proc, :resolve_proc,
|
25
|
+
:type, :type=, :name=, :property=, :hash_key=,
|
26
|
+
:relay_node_field, :relay_nodes_field, :edges?, :edge_class, :subscription_scope,
|
27
|
+
:introspection?
|
28
|
+
)
|
29
|
+
|
30
|
+
# @return [Boolean] True if this is the Relay find-by-id field
|
31
|
+
attr_accessor :relay_node_field
|
32
|
+
|
33
|
+
# @return [Boolean] True if this is the Relay find-by-ids field
|
34
|
+
attr_accessor :relay_nodes_field
|
35
|
+
|
36
|
+
# @return [<#call(obj, args, ctx)>] A proc-like object which can be called to return the field's value
|
37
|
+
attr_reader :resolve_proc
|
38
|
+
|
39
|
+
# @return [<#call(obj, args, ctx)>] A proc-like object which can be called trigger a lazy resolution
|
40
|
+
attr_reader :lazy_resolve_proc
|
41
|
+
|
42
|
+
# @return [String] The name of this field on its {GraphQL::ObjectType} (or {GraphQL::InterfaceType})
|
43
|
+
attr_reader :name
|
44
|
+
alias :graphql_name :name
|
45
|
+
|
46
|
+
# @return [String, nil] The client-facing description of this field
|
47
|
+
attr_accessor :description
|
48
|
+
|
49
|
+
# @return [String, nil] The client-facing reason why this field is deprecated (if present, the field is deprecated)
|
50
|
+
attr_accessor :deprecation_reason
|
51
|
+
|
52
|
+
# @return [Hash<String => GraphQL::Argument>] Map String argument names to their {GraphQL::Argument} implementations
|
53
|
+
attr_accessor :arguments
|
54
|
+
|
55
|
+
# @return [GraphQL::Relay::Mutation, nil] The mutation this field was derived from, if it was derived from a mutation
|
56
|
+
attr_accessor :mutation
|
57
|
+
|
58
|
+
# @return [Numeric, Proc] The complexity for this field (default: 1), as a constant or a proc like `->(query_ctx, args, child_complexity) { } # Numeric`
|
59
|
+
attr_accessor :complexity
|
60
|
+
|
61
|
+
# @return [Symbol, nil] The method to call on `obj` to return this field (overrides {#name} if present)
|
62
|
+
attr_reader :property
|
63
|
+
|
64
|
+
# @return [Object, nil] The key to access with `obj.[]` to resolve this field (overrides {#name} if present)
|
65
|
+
attr_reader :hash_key
|
66
|
+
|
67
|
+
# @return [Object, GraphQL::Function] The function used to derive this field
|
68
|
+
attr_accessor :function
|
69
|
+
|
70
|
+
attr_accessor :arguments_class
|
71
|
+
|
72
|
+
attr_writer :connection
|
73
|
+
attr_writer :introspection
|
74
|
+
|
75
|
+
# @return [nil, String] Prefix for subscription names from this field
|
76
|
+
attr_accessor :subscription_scope
|
77
|
+
|
78
|
+
# @return [Boolean] True if this field should be traced. By default, fields are only traced if they are not a ScalarType or EnumType.
|
79
|
+
attr_accessor :trace
|
80
|
+
|
81
|
+
attr_accessor :ast_node
|
82
|
+
|
83
|
+
# Future-compatible alias
|
84
|
+
# @see {GraphQL::SchemaMember}
|
85
|
+
alias :graphql_definition :itself
|
86
|
+
|
87
|
+
# @return [Boolean]
|
88
|
+
def connection?
|
89
|
+
@connection
|
90
|
+
end
|
91
|
+
|
92
|
+
# @return [nil, Class]
|
93
|
+
# @api private
|
94
|
+
attr_accessor :edge_class
|
95
|
+
|
96
|
+
# @return [Boolean]
|
97
|
+
def edges?
|
98
|
+
!!@edge_class
|
99
|
+
end
|
100
|
+
|
101
|
+
# @return [nil, Integer]
|
102
|
+
attr_accessor :connection_max_page_size
|
103
|
+
|
104
|
+
def initialize
|
105
|
+
@complexity = 1
|
106
|
+
@arguments = {}
|
107
|
+
@resolve_proc = build_default_resolver
|
108
|
+
@lazy_resolve_proc = DefaultLazyResolve
|
109
|
+
@relay_node_field = false
|
110
|
+
@connection = false
|
111
|
+
@connection_max_page_size = nil
|
112
|
+
@edge_class = nil
|
113
|
+
@trace = nil
|
114
|
+
@introspection = false
|
115
|
+
end
|
116
|
+
|
117
|
+
def initialize_copy(other)
|
118
|
+
ensure_defined
|
119
|
+
super
|
120
|
+
@arguments = other.arguments.dup
|
121
|
+
end
|
122
|
+
|
123
|
+
# @return [Boolean] Is this field a predefined introspection field?
|
124
|
+
def introspection?
|
125
|
+
@introspection
|
126
|
+
end
|
127
|
+
|
128
|
+
# Get a value for this field
|
129
|
+
# @example resolving a field value
|
130
|
+
# field.resolve(obj, args, ctx)
|
131
|
+
#
|
132
|
+
# @param object [Object] The object this field belongs to
|
133
|
+
# @param arguments [Hash] Arguments declared in the query
|
134
|
+
# @param context [GraphQL::Query::Context]
|
135
|
+
def resolve(object, arguments, context)
|
136
|
+
resolve_proc.call(object, arguments, context)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Provide a new callable for this field's resolve function. If `nil`,
|
140
|
+
# a new resolve proc will be build based on its {#name}, {#property} or {#hash_key}.
|
141
|
+
# @param new_resolve_proc [<#call(obj, args, ctx)>, nil]
|
142
|
+
def resolve=(new_resolve_proc)
|
143
|
+
@resolve_proc = new_resolve_proc || build_default_resolver
|
144
|
+
end
|
145
|
+
|
146
|
+
def type=(new_return_type)
|
147
|
+
@clean_type = nil
|
148
|
+
@dirty_type = new_return_type
|
149
|
+
end
|
150
|
+
|
151
|
+
# Get the return type for this field.
|
152
|
+
def type
|
153
|
+
@clean_type ||= GraphQL::BaseType.resolve_related_type(@dirty_type)
|
154
|
+
end
|
155
|
+
|
156
|
+
def name=(new_name)
|
157
|
+
old_name = defined?(@name) ? @name : nil
|
158
|
+
@name = new_name
|
159
|
+
|
160
|
+
if old_name != new_name && @resolve_proc.is_a?(Field::Resolve::NameResolve)
|
161
|
+
# Since the NameResolve would use the old field name,
|
162
|
+
# reset resolve proc when the name has changed
|
163
|
+
self.resolve = nil
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# @param new_property [Symbol] A method to call to resolve this field. Overrides the existing resolve proc.
|
168
|
+
def property=(new_property)
|
169
|
+
@property = new_property
|
170
|
+
self.resolve = nil # reset resolve proc
|
171
|
+
end
|
172
|
+
|
173
|
+
# @param new_hash_key [Symbol] A key to access with `#[key]` to resolve this field. Overrides the existing resolve proc.
|
174
|
+
def hash_key=(new_hash_key)
|
175
|
+
@hash_key = new_hash_key
|
176
|
+
self.resolve = nil # reset resolve proc
|
177
|
+
end
|
178
|
+
|
179
|
+
def to_s
|
180
|
+
"<Field name:#{name || "not-named"} desc:#{description} resolve:#{resolve_proc}>"
|
181
|
+
end
|
182
|
+
|
183
|
+
# If {#resolve} returned an object which should be handled lazily,
|
184
|
+
# this method will be called later to force the object to return its value.
|
185
|
+
# @param obj [Object] The {#resolve}-provided object, registered with {Schema#lazy_resolve}
|
186
|
+
# @param args [GraphQL::Query::Arguments] Arguments to this field
|
187
|
+
# @param ctx [GraphQL::Query::Context] Context for this field
|
188
|
+
# @return [Object] The result of calling the registered method on `obj`
|
189
|
+
def lazy_resolve(obj, args, ctx)
|
190
|
+
@lazy_resolve_proc.call(obj, args, ctx)
|
191
|
+
end
|
192
|
+
|
193
|
+
# Assign a new resolve proc to this field. Used for {#lazy_resolve}
|
194
|
+
def lazy_resolve=(new_lazy_resolve_proc)
|
195
|
+
@lazy_resolve_proc = new_lazy_resolve_proc
|
196
|
+
end
|
197
|
+
|
198
|
+
# Prepare a lazy value for this field. It may be `then`-ed and resolved later.
|
199
|
+
# @return [GraphQL::Execution::Lazy] A lazy wrapper around `obj` and its registered method name
|
200
|
+
def prepare_lazy(obj, args, ctx)
|
201
|
+
GraphQL::Execution::Lazy.new {
|
202
|
+
lazy_resolve(obj, args, ctx)
|
203
|
+
}
|
204
|
+
end
|
205
|
+
|
206
|
+
def type_class
|
207
|
+
metadata[:type_class]
|
208
|
+
end
|
209
|
+
|
210
|
+
def get_argument(argument_name)
|
211
|
+
arguments[argument_name]
|
212
|
+
end
|
213
|
+
|
214
|
+
private
|
215
|
+
|
216
|
+
def build_default_resolver
|
217
|
+
GraphQL::Field::Resolve.create_proc(self)
|
218
|
+
end
|
219
|
+
|
220
|
+
module DefaultLazyResolve
|
221
|
+
def self.call(obj, args, ctx)
|
222
|
+
ctx.schema.sync_lazy(obj)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
# @api private
|
4
|
+
class Filter
|
5
|
+
def initialize(only: nil, except: nil)
|
6
|
+
@only = only
|
7
|
+
@except = except
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns true if `member, ctx` passes this filter
|
11
|
+
def call(member, ctx)
|
12
|
+
(@only ? @only.call(member, ctx) : true) &&
|
13
|
+
(@except ? !@except.call(member, ctx) : true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def merge(only: nil, except: nil)
|
17
|
+
onlies = [self].concat(Array(only))
|
18
|
+
merged_only = MergedOnly.build(onlies)
|
19
|
+
merged_except = MergedExcept.build(Array(except))
|
20
|
+
self.class.new(only: merged_only, except: merged_except)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
class MergedOnly
|
26
|
+
def initialize(first, second)
|
27
|
+
@first = first
|
28
|
+
@second = second
|
29
|
+
end
|
30
|
+
|
31
|
+
def call(member, ctx)
|
32
|
+
@first.call(member, ctx) && @second.call(member, ctx)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.build(onlies)
|
36
|
+
case onlies.size
|
37
|
+
when 0
|
38
|
+
nil
|
39
|
+
when 1
|
40
|
+
onlies[0]
|
41
|
+
else
|
42
|
+
onlies.reduce { |memo, only| self.new(memo, only) }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class MergedExcept < MergedOnly
|
48
|
+
def call(member, ctx)
|
49
|
+
@first.call(member, ctx) || @second.call(member, ctx)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|