graphql_cody 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +5 -0
- data/MIT-LICENSE +20 -0
- data/lib/generators/graphql/core.rb +74 -0
- data/lib/generators/graphql/enum_generator.rb +33 -0
- data/lib/generators/graphql/install_generator.rb +190 -0
- data/lib/generators/graphql/interface_generator.rb +27 -0
- data/lib/generators/graphql/loader_generator.rb +21 -0
- data/lib/generators/graphql/mutation_generator.rb +55 -0
- data/lib/generators/graphql/object_generator.rb +79 -0
- data/lib/generators/graphql/relay.rb +63 -0
- data/lib/generators/graphql/relay_generator.rb +21 -0
- data/lib/generators/graphql/scalar_generator.rb +20 -0
- data/lib/generators/graphql/templates/base_argument.erb +6 -0
- data/lib/generators/graphql/templates/base_connection.erb +8 -0
- data/lib/generators/graphql/templates/base_edge.erb +8 -0
- data/lib/generators/graphql/templates/base_enum.erb +6 -0
- data/lib/generators/graphql/templates/base_field.erb +7 -0
- data/lib/generators/graphql/templates/base_input_object.erb +7 -0
- data/lib/generators/graphql/templates/base_interface.erb +9 -0
- data/lib/generators/graphql/templates/base_mutation.erb +10 -0
- data/lib/generators/graphql/templates/base_object.erb +7 -0
- data/lib/generators/graphql/templates/base_scalar.erb +6 -0
- data/lib/generators/graphql/templates/base_union.erb +6 -0
- data/lib/generators/graphql/templates/enum.erb +7 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +52 -0
- data/lib/generators/graphql/templates/interface.erb +8 -0
- data/lib/generators/graphql/templates/loader.erb +19 -0
- data/lib/generators/graphql/templates/mutation.erb +16 -0
- data/lib/generators/graphql/templates/mutation_type.erb +12 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +8 -0
- data/lib/generators/graphql/templates/query_type.erb +15 -0
- data/lib/generators/graphql/templates/scalar.erb +15 -0
- data/lib/generators/graphql/templates/schema.erb +27 -0
- data/lib/generators/graphql/templates/union.erb +7 -0
- data/lib/generators/graphql/type_generator.rb +98 -0
- data/lib/generators/graphql/union_generator.rb +33 -0
- data/lib/graphql/analysis/analyze_query.rb +98 -0
- data/lib/graphql/analysis/ast/analyzer.rb +84 -0
- data/lib/graphql/analysis/ast/field_usage.rb +51 -0
- data/lib/graphql/analysis/ast/max_query_complexity.rb +23 -0
- data/lib/graphql/analysis/ast/max_query_depth.rb +22 -0
- data/lib/graphql/analysis/ast/query_complexity.rb +230 -0
- data/lib/graphql/analysis/ast/query_depth.rb +56 -0
- data/lib/graphql/analysis/ast/visitor.rb +268 -0
- data/lib/graphql/analysis/ast.rb +91 -0
- data/lib/graphql/analysis/field_usage.rb +45 -0
- data/lib/graphql/analysis/max_query_complexity.rb +26 -0
- data/lib/graphql/analysis/max_query_depth.rb +26 -0
- data/lib/graphql/analysis/query_complexity.rb +88 -0
- data/lib/graphql/analysis/query_depth.rb +43 -0
- data/lib/graphql/analysis/reducer_state.rb +48 -0
- data/lib/graphql/analysis.rb +9 -0
- data/lib/graphql/analysis_error.rb +5 -0
- data/lib/graphql/argument.rb +131 -0
- data/lib/graphql/authorization.rb +82 -0
- data/lib/graphql/backtrace/inspect_result.rb +50 -0
- data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
- data/lib/graphql/backtrace/table.rb +159 -0
- data/lib/graphql/backtrace/traced_error.rb +54 -0
- data/lib/graphql/backtrace/tracer.rb +81 -0
- data/lib/graphql/backtrace.rb +64 -0
- data/lib/graphql/backwards_compatibility.rb +61 -0
- data/lib/graphql/base_type.rb +230 -0
- data/lib/graphql/boolean_type.rb +2 -0
- data/lib/graphql/coercion_error.rb +13 -0
- data/lib/graphql/compatibility/execution_specification/counter_schema.rb +53 -0
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +200 -0
- data/lib/graphql/compatibility/execution_specification.rb +436 -0
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +111 -0
- data/lib/graphql/compatibility/lazy_execution_specification.rb +215 -0
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +87 -0
- data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +79 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +266 -0
- data/lib/graphql/compatibility/schema_parser_specification.rb +682 -0
- data/lib/graphql/compatibility.rb +5 -0
- data/lib/graphql/dataloader/null_dataloader.rb +22 -0
- data/lib/graphql/dataloader/request.rb +19 -0
- data/lib/graphql/dataloader/request_all.rb +19 -0
- data/lib/graphql/dataloader/source.rb +155 -0
- data/lib/graphql/dataloader.rb +308 -0
- data/lib/graphql/define/assign_argument.rb +12 -0
- data/lib/graphql/define/assign_connection.rb +13 -0
- data/lib/graphql/define/assign_enum_value.rb +18 -0
- data/lib/graphql/define/assign_global_id_field.rb +11 -0
- data/lib/graphql/define/assign_mutation_function.rb +34 -0
- data/lib/graphql/define/assign_object_field.rb +42 -0
- data/lib/graphql/define/defined_object_proxy.rb +53 -0
- data/lib/graphql/define/instance_definable.rb +240 -0
- data/lib/graphql/define/no_definition_error.rb +7 -0
- data/lib/graphql/define/non_null_with_bang.rb +16 -0
- data/lib/graphql/define/type_definer.rb +31 -0
- data/lib/graphql/define.rb +31 -0
- data/lib/graphql/deprecated_dsl.rb +55 -0
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/dig.rb +19 -0
- data/lib/graphql/directive/deprecated_directive.rb +2 -0
- data/lib/graphql/directive/include_directive.rb +2 -0
- data/lib/graphql/directive/skip_directive.rb +2 -0
- data/lib/graphql/directive.rb +107 -0
- data/lib/graphql/enum_type.rb +133 -0
- data/lib/graphql/execution/directive_checks.rb +37 -0
- data/lib/graphql/execution/errors.rb +163 -0
- data/lib/graphql/execution/execute.rb +333 -0
- data/lib/graphql/execution/flatten.rb +40 -0
- data/lib/graphql/execution/instrumentation.rb +92 -0
- data/lib/graphql/execution/interpreter/argument_value.rb +28 -0
- data/lib/graphql/execution/interpreter/arguments.rb +88 -0
- data/lib/graphql/execution/interpreter/arguments_cache.rb +103 -0
- data/lib/graphql/execution/interpreter/execution_errors.rb +29 -0
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +18 -0
- data/lib/graphql/execution/interpreter/resolve.rb +70 -0
- data/lib/graphql/execution/interpreter/runtime.rb +949 -0
- data/lib/graphql/execution/interpreter.rb +122 -0
- data/lib/graphql/execution/lazy/lazy_method_map.rb +98 -0
- data/lib/graphql/execution/lazy/resolve.rb +91 -0
- data/lib/graphql/execution/lazy.rb +83 -0
- data/lib/graphql/execution/lookahead.rb +307 -0
- data/lib/graphql/execution/multiplex.rb +214 -0
- data/lib/graphql/execution/typecast.rb +50 -0
- data/lib/graphql/execution.rb +11 -0
- data/lib/graphql/execution_error.rb +58 -0
- data/lib/graphql/field/resolve.rb +59 -0
- data/lib/graphql/field.rb +226 -0
- data/lib/graphql/filter.rb +53 -0
- data/lib/graphql/float_type.rb +2 -0
- data/lib/graphql/function.rb +128 -0
- data/lib/graphql/id_type.rb +2 -0
- data/lib/graphql/input_object_type.rb +138 -0
- data/lib/graphql/int_type.rb +2 -0
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +36 -0
- data/lib/graphql/interface_type.rb +72 -0
- data/lib/graphql/internal_representation/document.rb +27 -0
- data/lib/graphql/internal_representation/node.rb +206 -0
- data/lib/graphql/internal_representation/print.rb +51 -0
- data/lib/graphql/internal_representation/rewrite.rb +184 -0
- data/lib/graphql/internal_representation/scope.rb +88 -0
- data/lib/graphql/internal_representation/visit.rb +36 -0
- data/lib/graphql/internal_representation.rb +7 -0
- data/lib/graphql/introspection/base_object.rb +13 -0
- data/lib/graphql/introspection/directive_location_enum.rb +15 -0
- data/lib/graphql/introspection/directive_type.rb +29 -0
- data/lib/graphql/introspection/dynamic_fields.rb +17 -0
- data/lib/graphql/introspection/entry_points.rb +35 -0
- data/lib/graphql/introspection/enum_value_type.rb +23 -0
- data/lib/graphql/introspection/field_type.rb +28 -0
- data/lib/graphql/introspection/input_value_type.rb +67 -0
- data/lib/graphql/introspection/introspection_query.rb +7 -0
- data/lib/graphql/introspection/schema_type.rb +44 -0
- data/lib/graphql/introspection/type_kind_enum.rb +13 -0
- data/lib/graphql/introspection/type_type.rb +95 -0
- data/lib/graphql/introspection.rb +114 -0
- data/lib/graphql/invalid_name_error.rb +11 -0
- data/lib/graphql/invalid_null_error.rb +50 -0
- data/lib/graphql/language/block_string.rb +99 -0
- data/lib/graphql/language/cache.rb +37 -0
- data/lib/graphql/language/definition_slice.rb +41 -0
- data/lib/graphql/language/document_from_schema_definition.rb +347 -0
- data/lib/graphql/language/generation.rb +24 -0
- data/lib/graphql/language/lexer.rb +1467 -0
- data/lib/graphql/language/lexer.rl +258 -0
- data/lib/graphql/language/nodes.rb +707 -0
- data/lib/graphql/language/parser.rb +1974 -0
- data/lib/graphql/language/parser.y +544 -0
- data/lib/graphql/language/printer.rb +366 -0
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/token.rb +34 -0
- data/lib/graphql/language/visitor.rb +242 -0
- data/lib/graphql/language.rb +36 -0
- data/lib/graphql/list_type.rb +80 -0
- data/lib/graphql/load_application_object_failed_error.rb +22 -0
- data/lib/graphql/name_validator.rb +11 -0
- data/lib/graphql/non_null_type.rb +71 -0
- data/lib/graphql/object_type.rb +130 -0
- data/lib/graphql/pagination/active_record_relation_connection.rb +48 -0
- data/lib/graphql/pagination/array_connection.rb +77 -0
- data/lib/graphql/pagination/connection.rb +226 -0
- data/lib/graphql/pagination/connections.rb +160 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +196 -0
- data/lib/graphql/pagination/sequel_dataset_connection.rb +28 -0
- data/lib/graphql/pagination.rb +6 -0
- data/lib/graphql/parse_error.rb +24 -0
- data/lib/graphql/query/arguments.rb +189 -0
- data/lib/graphql/query/arguments_cache.rb +24 -0
- data/lib/graphql/query/context.rb +371 -0
- data/lib/graphql/query/executor.rb +52 -0
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +43 -0
- data/lib/graphql/query/literal_input.rb +136 -0
- data/lib/graphql/query/null_context.rb +55 -0
- data/lib/graphql/query/result.rb +63 -0
- data/lib/graphql/query/serial_execution/field_resolution.rb +92 -0
- data/lib/graphql/query/serial_execution/operation_resolution.rb +19 -0
- data/lib/graphql/query/serial_execution/selection_resolution.rb +23 -0
- data/lib/graphql/query/serial_execution/value_resolution.rb +87 -0
- data/lib/graphql/query/serial_execution.rb +40 -0
- data/lib/graphql/query/validation_pipeline.rb +139 -0
- data/lib/graphql/query/variable_validation_error.rb +44 -0
- data/lib/graphql/query/variables.rb +78 -0
- data/lib/graphql/query.rb +454 -0
- data/lib/graphql/railtie.rb +117 -0
- data/lib/graphql/rake_task/validate.rb +63 -0
- data/lib/graphql/rake_task.rb +145 -0
- data/lib/graphql/relay/array_connection.rb +83 -0
- data/lib/graphql/relay/base_connection.rb +189 -0
- data/lib/graphql/relay/connection_instrumentation.rb +54 -0
- data/lib/graphql/relay/connection_resolve.rb +43 -0
- data/lib/graphql/relay/connection_type.rb +41 -0
- data/lib/graphql/relay/edge.rb +27 -0
- data/lib/graphql/relay/edge_type.rb +19 -0
- data/lib/graphql/relay/edges_instrumentation.rb +39 -0
- data/lib/graphql/relay/global_id_resolve.rb +18 -0
- data/lib/graphql/relay/mongo_relation_connection.rb +50 -0
- data/lib/graphql/relay/mutation/instrumentation.rb +23 -0
- data/lib/graphql/relay/mutation/resolve.rb +56 -0
- data/lib/graphql/relay/mutation/result.rb +38 -0
- data/lib/graphql/relay/mutation.rb +106 -0
- data/lib/graphql/relay/node.rb +39 -0
- data/lib/graphql/relay/page_info.rb +7 -0
- data/lib/graphql/relay/range_add.rb +59 -0
- data/lib/graphql/relay/relation_connection.rb +188 -0
- data/lib/graphql/relay/type_extensions.rb +32 -0
- data/lib/graphql/relay.rb +18 -0
- data/lib/graphql/rubocop/graphql/base_cop.rb +36 -0
- data/lib/graphql/rubocop/graphql/default_null_true.rb +43 -0
- data/lib/graphql/rubocop/graphql/default_required_true.rb +43 -0
- data/lib/graphql/rubocop.rb +4 -0
- data/lib/graphql/runtime_type_error.rb +5 -0
- data/lib/graphql/scalar_type.rb +91 -0
- data/lib/graphql/schema/addition.rb +247 -0
- data/lib/graphql/schema/argument.rb +383 -0
- data/lib/graphql/schema/base_64_bp.rb +26 -0
- data/lib/graphql/schema/base_64_encoder.rb +21 -0
- data/lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb +47 -0
- data/lib/graphql/schema/build_from_definition/resolve_map.rb +78 -0
- data/lib/graphql/schema/build_from_definition.rb +477 -0
- data/lib/graphql/schema/built_in_types.rb +12 -0
- data/lib/graphql/schema/catchall_middleware.rb +35 -0
- data/lib/graphql/schema/default_parse_error.rb +10 -0
- data/lib/graphql/schema/default_type_error.rb +17 -0
- data/lib/graphql/schema/directive/deprecated.rb +18 -0
- data/lib/graphql/schema/directive/feature.rb +66 -0
- data/lib/graphql/schema/directive/flagged.rb +57 -0
- data/lib/graphql/schema/directive/include.rb +25 -0
- data/lib/graphql/schema/directive/skip.rb +25 -0
- data/lib/graphql/schema/directive/transform.rb +60 -0
- data/lib/graphql/schema/directive.rb +210 -0
- data/lib/graphql/schema/enum.rb +193 -0
- data/lib/graphql/schema/enum_value.rb +97 -0
- data/lib/graphql/schema/field/connection_extension.rb +76 -0
- data/lib/graphql/schema/field/scope_extension.rb +22 -0
- data/lib/graphql/schema/field.rb +880 -0
- data/lib/graphql/schema/field_extension.rb +69 -0
- data/lib/graphql/schema/find_inherited_value.rb +36 -0
- data/lib/graphql/schema/finder.rb +155 -0
- data/lib/graphql/schema/input_object.rb +253 -0
- data/lib/graphql/schema/interface.rb +136 -0
- data/lib/graphql/schema/introspection_system.rb +169 -0
- data/lib/graphql/schema/invalid_type_error.rb +7 -0
- data/lib/graphql/schema/late_bound_type.rb +33 -0
- data/lib/graphql/schema/list.rb +75 -0
- data/lib/graphql/schema/loader.rb +226 -0
- data/lib/graphql/schema/member/accepts_definition.rb +159 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +129 -0
- data/lib/graphql/schema/member/build_type.rb +180 -0
- data/lib/graphql/schema/member/cached_graphql_definition.rb +31 -0
- data/lib/graphql/schema/member/graphql_type_names.rb +21 -0
- data/lib/graphql/schema/member/has_arguments.rb +332 -0
- data/lib/graphql/schema/member/has_ast_node.rb +20 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +25 -0
- data/lib/graphql/schema/member/has_directives.rb +98 -0
- data/lib/graphql/schema/member/has_fields.rb +163 -0
- data/lib/graphql/schema/member/has_interfaces.rb +90 -0
- data/lib/graphql/schema/member/has_path.rb +25 -0
- data/lib/graphql/schema/member/has_unresolved_type_error.rb +15 -0
- data/lib/graphql/schema/member/has_validators.rb +31 -0
- data/lib/graphql/schema/member/instrumentation.rb +131 -0
- data/lib/graphql/schema/member/relay_shortcuts.rb +47 -0
- data/lib/graphql/schema/member/scoped.rb +21 -0
- data/lib/graphql/schema/member/type_system_helpers.rb +38 -0
- data/lib/graphql/schema/member/validates_input.rb +33 -0
- data/lib/graphql/schema/member.rb +161 -0
- data/lib/graphql/schema/middleware_chain.rb +82 -0
- data/lib/graphql/schema/mutation.rb +94 -0
- data/lib/graphql/schema/non_null.rb +67 -0
- data/lib/graphql/schema/null_mask.rb +11 -0
- data/lib/graphql/schema/object.rb +150 -0
- data/lib/graphql/schema/possible_types.rb +44 -0
- data/lib/graphql/schema/printer.rb +100 -0
- data/lib/graphql/schema/relay_classic_mutation.rb +160 -0
- data/lib/graphql/schema/rescue_middleware.rb +60 -0
- data/lib/graphql/schema/resolver/has_payload_type.rb +96 -0
- data/lib/graphql/schema/resolver.rb +397 -0
- data/lib/graphql/schema/scalar.rb +69 -0
- data/lib/graphql/schema/subscription.rb +155 -0
- data/lib/graphql/schema/timeout.rb +123 -0
- data/lib/graphql/schema/timeout_middleware.rb +88 -0
- data/lib/graphql/schema/traversal.rb +228 -0
- data/lib/graphql/schema/type_expression.rb +43 -0
- data/lib/graphql/schema/type_membership.rb +48 -0
- data/lib/graphql/schema/union.rb +95 -0
- data/lib/graphql/schema/unique_within_type.rb +34 -0
- data/lib/graphql/schema/validation.rb +313 -0
- data/lib/graphql/schema/validator/allow_blank_validator.rb +29 -0
- data/lib/graphql/schema/validator/allow_null_validator.rb +26 -0
- data/lib/graphql/schema/validator/exclusion_validator.rb +33 -0
- data/lib/graphql/schema/validator/format_validator.rb +48 -0
- data/lib/graphql/schema/validator/inclusion_validator.rb +35 -0
- data/lib/graphql/schema/validator/length_validator.rb +59 -0
- data/lib/graphql/schema/validator/numericality_validator.rb +82 -0
- data/lib/graphql/schema/validator/required_validator.rb +68 -0
- data/lib/graphql/schema/validator.rb +174 -0
- data/lib/graphql/schema/warden.rb +409 -0
- data/lib/graphql/schema/wrapper.rb +29 -0
- data/lib/graphql/schema.rb +1945 -0
- data/lib/graphql/static_validation/all_rules.rb +40 -0
- data/lib/graphql/static_validation/base_visitor.rb +217 -0
- data/lib/graphql/static_validation/default_visitor.rb +15 -0
- data/lib/graphql/static_validation/definition_dependencies.rb +198 -0
- data/lib/graphql/static_validation/error.rb +46 -0
- data/lib/graphql/static_validation/interpreter_visitor.rb +14 -0
- data/lib/graphql/static_validation/literal_validator.rb +139 -0
- data/lib/graphql/static_validation/no_validate_visitor.rb +10 -0
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +66 -0
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +48 -0
- data/lib/graphql/static_validation/rules/argument_names_are_unique.rb +31 -0
- data/lib/graphql/static_validation/rules/argument_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +71 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +37 -0
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +23 -0
- data/lib/graphql/static_validation/rules/directives_are_defined_error.rb +29 -0
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +65 -0
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +30 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type_error.rb +32 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +73 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +418 -0
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +53 -0
- data/lib/graphql/static_validation/rules/fragment_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/fragment_names_are_unique_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +73 -0
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible_error.rb +35 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +39 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +21 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_named.rb +16 -0
- data/lib/graphql/static_validation/rules/fragments_are_named_error.rb +26 -0
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +37 -0
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types_error.rb +30 -0
- data/lib/graphql/static_validation/rules/fragments_are_used.rb +32 -0
- data/lib/graphql/static_validation/rules/fragments_are_used_error.rb +29 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique.rb +30 -0
- data/lib/graphql/static_validation/rules/input_object_names_are_unique_error.rb +30 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/no_definitions_are_present.rb +41 -0
- data/lib/graphql/static_validation/rules/no_definitions_are_present_error.rb +25 -0
- data/lib/graphql/static_validation/rules/operation_names_are_valid.rb +36 -0
- data/lib/graphql/static_validation/rules/operation_names_are_valid_error.rb +28 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +37 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present_error.rb +35 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +59 -0
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present_error.rb +35 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +50 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location_error.rb +29 -0
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +46 -0
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed_error.rb +39 -0
- data/lib/graphql/static_validation/rules/variable_names_are_unique.rb +24 -0
- data/lib/graphql/static_validation/rules/variable_names_are_unique_error.rb +29 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +153 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed_error.rb +38 -0
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +39 -0
- data/lib/graphql/static_validation/rules/variables_are_input_types_error.rb +32 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +155 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb +37 -0
- data/lib/graphql/static_validation/type_stack.rb +216 -0
- data/lib/graphql/static_validation/validation_context.rb +49 -0
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +96 -0
- data/lib/graphql/static_validation.rb +19 -0
- data/lib/graphql/string_encoding_error.rb +20 -0
- data/lib/graphql/string_type.rb +2 -0
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +245 -0
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +81 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +21 -0
- data/lib/graphql/subscriptions/event.rb +144 -0
- data/lib/graphql/subscriptions/instrumentation.rb +79 -0
- data/lib/graphql/subscriptions/serialize.rb +138 -0
- data/lib/graphql/subscriptions/subscription_root.rb +76 -0
- data/lib/graphql/subscriptions.rb +299 -0
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +35 -0
- data/lib/graphql/tracing/appoptics_tracing.rb +173 -0
- data/lib/graphql/tracing/appsignal_tracing.rb +51 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +76 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +51 -0
- data/lib/graphql/tracing/platform_tracing.rb +139 -0
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +32 -0
- data/lib/graphql/tracing/prometheus_tracing.rb +67 -0
- data/lib/graphql/tracing/scout_tracing.rb +54 -0
- data/lib/graphql/tracing/skylight_tracing.rb +70 -0
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +95 -0
- data/lib/graphql/type_kinds.rb +77 -0
- data/lib/graphql/types/big_int.rb +23 -0
- data/lib/graphql/types/boolean.rb +18 -0
- data/lib/graphql/types/float.rb +19 -0
- data/lib/graphql/types/id.rb +24 -0
- data/lib/graphql/types/int.rb +36 -0
- data/lib/graphql/types/iso_8601_date.rb +34 -0
- data/lib/graphql/types/iso_8601_date_time.rb +65 -0
- data/lib/graphql/types/json.rb +25 -0
- data/lib/graphql/types/relay/base_connection.rb +39 -0
- data/lib/graphql/types/relay/base_edge.rb +29 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +156 -0
- data/lib/graphql/types/relay/default_relay.rb +27 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +53 -0
- data/lib/graphql/types/relay/has_node_field.rb +41 -0
- data/lib/graphql/types/relay/has_nodes_field.rb +41 -0
- data/lib/graphql/types/relay/node.rb +15 -0
- data/lib/graphql/types/relay/node_behaviors.rb +15 -0
- data/lib/graphql/types/relay/node_field.rb +25 -0
- data/lib/graphql/types/relay/nodes_field.rb +27 -0
- data/lib/graphql/types/relay/page_info.rb +11 -0
- data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
- data/lib/graphql/types/relay.rb +41 -0
- data/lib/graphql/types/string.rb +29 -0
- data/lib/graphql/types.rb +11 -0
- data/lib/graphql/unauthorized_error.rb +29 -0
- data/lib/graphql/unauthorized_field_error.rb +23 -0
- data/lib/graphql/union_type.rb +115 -0
- data/lib/graphql/unresolved_type_error.rb +35 -0
- data/lib/graphql/upgrader/member.rb +937 -0
- data/lib/graphql/upgrader/schema.rb +38 -0
- data/lib/graphql/version.rb +4 -0
- data/lib/graphql.rb +168 -0
- data/readme.md +49 -0
- metadata +714 -0
@@ -0,0 +1,230 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Analysis
|
4
|
+
# Calculate the complexity of a query, using {Field#complexity} values.
|
5
|
+
module AST
|
6
|
+
class QueryComplexity < Analyzer
|
7
|
+
# State for the query complexity calculation:
|
8
|
+
# - `complexities_on_type` holds complexity scores for each type in an IRep node
|
9
|
+
def initialize(query)
|
10
|
+
super
|
11
|
+
@complexities_on_type_by_query = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
# Overide this method to use the complexity result
|
15
|
+
def result
|
16
|
+
max_possible_complexity
|
17
|
+
end
|
18
|
+
|
19
|
+
class ScopedTypeComplexity
|
20
|
+
# A single proc for {#scoped_children} hashes. Use this to avoid repeated allocations,
|
21
|
+
# since the lexical binding isn't important.
|
22
|
+
HASH_CHILDREN = ->(h, k) { h[k] = {} }
|
23
|
+
|
24
|
+
attr_reader :field_definition, :response_path, :query
|
25
|
+
|
26
|
+
# @param parent_type [Class] The owner of `field_definition`
|
27
|
+
# @param field_definition [GraphQL::Field, GraphQL::Schema::Field] Used for getting the `.complexity` configuration
|
28
|
+
# @param query [GraphQL::Query] Used for `query.possible_types`
|
29
|
+
# @param response_path [Array<String>] The path to the response key for the field
|
30
|
+
def initialize(parent_type, field_definition, query, response_path)
|
31
|
+
@parent_type = parent_type
|
32
|
+
@field_definition = field_definition
|
33
|
+
@query = query
|
34
|
+
@response_path = response_path
|
35
|
+
@scoped_children = nil
|
36
|
+
@nodes = []
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Array<GraphQL::Language::Nodes::Field>]
|
40
|
+
attr_reader :nodes
|
41
|
+
|
42
|
+
# Returns true if this field has no selections, ie, it's a scalar.
|
43
|
+
# We need a quick way to check whether we should continue traversing.
|
44
|
+
def terminal?
|
45
|
+
@scoped_children.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
# This value is only calculated when asked for to avoid needless hash allocations.
|
49
|
+
# Also, if it's never asked for, we determine that this scope complexity
|
50
|
+
# is a scalar field ({#terminal?}).
|
51
|
+
# @return [Hash<Hash<Class => ScopedTypeComplexity>]
|
52
|
+
def scoped_children
|
53
|
+
@scoped_children ||= Hash.new(&HASH_CHILDREN)
|
54
|
+
end
|
55
|
+
|
56
|
+
def own_complexity(child_complexity)
|
57
|
+
@field_definition.calculate_complexity(query: @query, nodes: @nodes, child_complexity: child_complexity)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def on_enter_field(node, parent, visitor)
|
62
|
+
# We don't want to visit fragment definitions,
|
63
|
+
# we'll visit them when we hit the spreads instead
|
64
|
+
return if visitor.visiting_fragment_definition?
|
65
|
+
return if visitor.skipping?
|
66
|
+
parent_type = visitor.parent_type_definition
|
67
|
+
field_key = node.alias || node.name
|
68
|
+
# Find the complexity calculation for this field --
|
69
|
+
# if we're re-entering a selection, we'll already have one.
|
70
|
+
# Otherwise, make a new one and store it.
|
71
|
+
#
|
72
|
+
# `node` and `visitor.field_definition` may appear from a cache,
|
73
|
+
# but I think that's ok. If the arguments _didn't_ match,
|
74
|
+
# then the query would have been rejected as invalid.
|
75
|
+
complexities_on_type = @complexities_on_type_by_query[visitor.query] ||= [ScopedTypeComplexity.new(nil, nil, query, visitor.response_path)]
|
76
|
+
|
77
|
+
complexity = complexities_on_type.last.scoped_children[parent_type][field_key] ||= ScopedTypeComplexity.new(parent_type, visitor.field_definition, visitor.query, visitor.response_path)
|
78
|
+
complexity.nodes.push(node)
|
79
|
+
# Push it on the stack.
|
80
|
+
complexities_on_type.push(complexity)
|
81
|
+
end
|
82
|
+
|
83
|
+
def on_leave_field(node, parent, visitor)
|
84
|
+
# We don't want to visit fragment definitions,
|
85
|
+
# we'll visit them when we hit the spreads instead
|
86
|
+
return if visitor.visiting_fragment_definition?
|
87
|
+
return if visitor.skipping?
|
88
|
+
complexities_on_type = @complexities_on_type_by_query[visitor.query]
|
89
|
+
complexities_on_type.pop
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
# @return [Integer]
|
95
|
+
def max_possible_complexity
|
96
|
+
@complexities_on_type_by_query.reduce(0) do |total, (query, complexities_on_type)|
|
97
|
+
root_complexity = complexities_on_type.last
|
98
|
+
# Use this entry point to calculate the total complexity
|
99
|
+
total_complexity_for_query = merged_max_complexity_for_scopes(query, [root_complexity.scoped_children])
|
100
|
+
total + total_complexity_for_query
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# @param query [GraphQL::Query] Used for `query.possible_types`
|
105
|
+
# @param scoped_children_hashes [Array<Hash>] Array of scoped children hashes
|
106
|
+
# @return [Integer]
|
107
|
+
def merged_max_complexity_for_scopes(query, scoped_children_hashes)
|
108
|
+
# Figure out what scopes are possible here.
|
109
|
+
# Use a hash, but ignore the values; it's just a fast way to work with the keys.
|
110
|
+
all_scopes = {}
|
111
|
+
scoped_children_hashes.each do |h|
|
112
|
+
all_scopes.merge!(h)
|
113
|
+
end
|
114
|
+
|
115
|
+
# If an abstract scope is present, but _all_ of its concrete types
|
116
|
+
# are also in the list, remove it from the list of scopes to check,
|
117
|
+
# because every possible type is covered by a concrete type.
|
118
|
+
# (That is, there are no remainder types to check.)
|
119
|
+
prev_keys = all_scopes.keys
|
120
|
+
prev_keys.each do |scope|
|
121
|
+
next unless scope.kind.abstract?
|
122
|
+
|
123
|
+
missing_concrete_types = query.possible_types(scope).select { |t| !all_scopes.key?(t) }
|
124
|
+
# This concrete type is possible _only_ as a member of the abstract type.
|
125
|
+
# So, attribute to it the complexity which belongs to the abstract type.
|
126
|
+
missing_concrete_types.each do |concrete_scope|
|
127
|
+
all_scopes[concrete_scope] = all_scopes[scope]
|
128
|
+
end
|
129
|
+
all_scopes.delete(scope)
|
130
|
+
end
|
131
|
+
|
132
|
+
# This will hold `{ type => int }` pairs, one for each possible branch
|
133
|
+
complexity_by_scope = {}
|
134
|
+
|
135
|
+
# For each scope,
|
136
|
+
# find the lexical selections that might apply to it,
|
137
|
+
# and gather them together into an array.
|
138
|
+
# Then, treat the set of selection hashes
|
139
|
+
# as a set and calculate the complexity for them as a unit
|
140
|
+
all_scopes.each do |scope, _|
|
141
|
+
# These will be the selections on `scope`
|
142
|
+
children_for_scope = []
|
143
|
+
scoped_children_hashes.each do |sc_h|
|
144
|
+
sc_h.each do |inner_scope, children_hash|
|
145
|
+
if applies_to?(query, scope, inner_scope)
|
146
|
+
children_for_scope << children_hash
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# Calculate the complexity for `scope`, merging all
|
152
|
+
# possible lexical branches.
|
153
|
+
complexity_value = merged_max_complexity(query, children_for_scope)
|
154
|
+
complexity_by_scope[scope] = complexity_value
|
155
|
+
end
|
156
|
+
|
157
|
+
# Return the max complexity among all scopes
|
158
|
+
complexity_by_scope.each_value.max
|
159
|
+
end
|
160
|
+
|
161
|
+
def applies_to?(query, left_scope, right_scope)
|
162
|
+
if left_scope == right_scope
|
163
|
+
# This can happen when several branches are being analyzed together
|
164
|
+
true
|
165
|
+
else
|
166
|
+
# Check if these two scopes have _any_ types in common.
|
167
|
+
possible_right_types = query.possible_types(right_scope)
|
168
|
+
possible_left_types = query.possible_types(left_scope)
|
169
|
+
!(possible_right_types & possible_left_types).empty?
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# A hook which is called whenever a field's max complexity is calculated.
|
174
|
+
# Override this method to capture individual field complexity details.
|
175
|
+
#
|
176
|
+
# @param scoped_type_complexity [ScopedTypeComplexity]
|
177
|
+
# @param max_complexity [Numeric] Field's maximum complexity including child complexity
|
178
|
+
# @param child_complexity [Numeric, nil] Field's child complexity
|
179
|
+
def field_complexity(scoped_type_complexity, max_complexity:, child_complexity: nil)
|
180
|
+
end
|
181
|
+
|
182
|
+
# @param children_for_scope [Array<Hash>] An array of `scoped_children[scope]` hashes
|
183
|
+
# (`{field_key => complexity}`)
|
184
|
+
# @return [Integer] Complexity value for all these selections in the current scope
|
185
|
+
def merged_max_complexity(query, children_for_scope)
|
186
|
+
all_keys = []
|
187
|
+
children_for_scope.each do |c|
|
188
|
+
all_keys.concat(c.keys)
|
189
|
+
end
|
190
|
+
all_keys.uniq!
|
191
|
+
complexity_for_keys = {}
|
192
|
+
|
193
|
+
all_keys.each do |child_key|
|
194
|
+
scoped_children_for_key = nil
|
195
|
+
complexity_for_key = nil
|
196
|
+
children_for_scope.each do |children_hash|
|
197
|
+
next unless children_hash.key?(child_key)
|
198
|
+
|
199
|
+
complexity_for_key = children_hash[child_key]
|
200
|
+
if complexity_for_key.terminal?
|
201
|
+
# Assume that all terminals would return the same complexity
|
202
|
+
# Since it's a terminal, its child complexity is zero.
|
203
|
+
complexity = complexity_for_key.own_complexity(0)
|
204
|
+
complexity_for_keys[child_key] = complexity
|
205
|
+
|
206
|
+
field_complexity(complexity_for_key, max_complexity: complexity, child_complexity: nil)
|
207
|
+
else
|
208
|
+
scoped_children_for_key ||= []
|
209
|
+
scoped_children_for_key << complexity_for_key.scoped_children
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
next unless scoped_children_for_key
|
214
|
+
|
215
|
+
child_complexity = merged_max_complexity_for_scopes(query, scoped_children_for_key)
|
216
|
+
# This is the _last_ one we visited; assume it's representative.
|
217
|
+
max_complexity = complexity_for_key.own_complexity(child_complexity)
|
218
|
+
|
219
|
+
field_complexity(complexity_for_key, max_complexity: max_complexity, child_complexity: child_complexity)
|
220
|
+
|
221
|
+
complexity_for_keys[child_key] = max_complexity
|
222
|
+
end
|
223
|
+
|
224
|
+
# Calculate the child complexity by summing the complexity of all selections
|
225
|
+
complexity_for_keys.each_value.inject(0, &:+)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Analysis
|
4
|
+
# A query reducer for measuring the depth of a given query.
|
5
|
+
#
|
6
|
+
# See https://graphql-ruby.org/queries/ast_analysis.html for more examples.
|
7
|
+
#
|
8
|
+
# @example Logging the depth of a query
|
9
|
+
# class LogQueryDepth < GraphQL::Analysis::QueryDepth
|
10
|
+
# def result
|
11
|
+
# log("GraphQL query depth: #{@max_depth}")
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # In your Schema file:
|
16
|
+
#
|
17
|
+
# class MySchema < GraphQL::Schema
|
18
|
+
# use GraphQL::Analysis::AST
|
19
|
+
# query_analyzer LogQueryDepth
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# # When you run the query, the depth will get logged:
|
23
|
+
#
|
24
|
+
# Schema.execute(query_str)
|
25
|
+
# # GraphQL query depth: 8
|
26
|
+
#
|
27
|
+
module AST
|
28
|
+
class QueryDepth < Analyzer
|
29
|
+
def initialize(query)
|
30
|
+
@max_depth = 0
|
31
|
+
@current_depth = 0
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def on_enter_field(node, parent, visitor)
|
36
|
+
return if visitor.skipping? || visitor.visiting_fragment_definition?
|
37
|
+
|
38
|
+
@current_depth += 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def on_leave_field(node, parent, visitor)
|
42
|
+
return if visitor.skipping? || visitor.visiting_fragment_definition?
|
43
|
+
|
44
|
+
if @max_depth < @current_depth
|
45
|
+
@max_depth = @current_depth
|
46
|
+
end
|
47
|
+
@current_depth -= 1
|
48
|
+
end
|
49
|
+
|
50
|
+
def result
|
51
|
+
@max_depth
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,268 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Analysis
|
4
|
+
module AST
|
5
|
+
# Depth first traversal through a query AST, calling AST analyzers
|
6
|
+
# along the way.
|
7
|
+
#
|
8
|
+
# The visitor is a special case of GraphQL::Language::Visitor, visiting
|
9
|
+
# only the selected operation, providing helpers for common use cases such
|
10
|
+
# as skipped fields and visiting fragment spreads.
|
11
|
+
#
|
12
|
+
# @see {GraphQL::Analysis::AST::Analyzer} AST Analyzers for queries
|
13
|
+
class Visitor < GraphQL::Language::Visitor
|
14
|
+
def initialize(query:, analyzers:)
|
15
|
+
@analyzers = analyzers
|
16
|
+
@path = []
|
17
|
+
@object_types = []
|
18
|
+
@directives = []
|
19
|
+
@field_definitions = []
|
20
|
+
@argument_definitions = []
|
21
|
+
@directive_definitions = []
|
22
|
+
@rescued_errors = []
|
23
|
+
@query = query
|
24
|
+
@schema = query.schema
|
25
|
+
@response_path = []
|
26
|
+
@skip_stack = [false]
|
27
|
+
super(query.selected_operation)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [GraphQL::Query] the query being visited
|
31
|
+
attr_reader :query
|
32
|
+
|
33
|
+
# @return [Array<GraphQL::ObjectType>] Types whose scope we've entered
|
34
|
+
attr_reader :object_types
|
35
|
+
|
36
|
+
# @return [Array<GraphQL::AnalysisError]
|
37
|
+
attr_reader :rescued_errors
|
38
|
+
|
39
|
+
def visit
|
40
|
+
return unless @document
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
# Visit Helpers
|
45
|
+
|
46
|
+
# @return [GraphQL::Query::Arguments] Arguments for this node, merging default values, literal values and query variables
|
47
|
+
# @see {GraphQL::Query#arguments_for}
|
48
|
+
def arguments_for(ast_node, field_definition)
|
49
|
+
@query.arguments_for(ast_node, field_definition)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Boolean] If the visitor is currently inside a fragment definition
|
53
|
+
def visiting_fragment_definition?
|
54
|
+
@in_fragment_def
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Boolean] If the current node should be skipped because of a skip or include directive
|
58
|
+
def skipping?
|
59
|
+
@skipping
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return [Array<String>] The path to the response key for the current field
|
63
|
+
def response_path
|
64
|
+
@response_path.dup
|
65
|
+
end
|
66
|
+
|
67
|
+
# Visitor Hooks
|
68
|
+
|
69
|
+
def on_operation_definition(node, parent)
|
70
|
+
object_type = @schema.root_type_for_operation(node.operation_type)
|
71
|
+
@object_types.push(object_type)
|
72
|
+
@path.push("#{node.operation_type}#{node.name ? " #{node.name}" : ""}")
|
73
|
+
call_analyzers(:on_enter_operation_definition, node, parent)
|
74
|
+
super
|
75
|
+
call_analyzers(:on_leave_operation_definition, node, parent)
|
76
|
+
@object_types.pop
|
77
|
+
@path.pop
|
78
|
+
end
|
79
|
+
|
80
|
+
def on_fragment_definition(node, parent)
|
81
|
+
on_fragment_with_type(node) do
|
82
|
+
@path.push("fragment #{node.name}")
|
83
|
+
@in_fragment_def = false
|
84
|
+
call_analyzers(:on_enter_fragment_definition, node, parent)
|
85
|
+
super
|
86
|
+
@in_fragment_def = false
|
87
|
+
call_analyzers(:on_leave_fragment_definition, node, parent)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def on_inline_fragment(node, parent)
|
92
|
+
on_fragment_with_type(node) do
|
93
|
+
@path.push("...#{node.type ? " on #{node.type.name}" : ""}")
|
94
|
+
call_analyzers(:on_enter_inline_fragment, node, parent)
|
95
|
+
super
|
96
|
+
call_analyzers(:on_leave_inline_fragment, node, parent)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def on_field(node, parent)
|
101
|
+
@response_path.push(node.alias || node.name)
|
102
|
+
parent_type = @object_types.last
|
103
|
+
field_definition = @schema.get_field(parent_type, node.name, @query.context)
|
104
|
+
@field_definitions.push(field_definition)
|
105
|
+
if !field_definition.nil?
|
106
|
+
next_object_type = field_definition.type.unwrap
|
107
|
+
@object_types.push(next_object_type)
|
108
|
+
else
|
109
|
+
@object_types.push(nil)
|
110
|
+
end
|
111
|
+
@path.push(node.alias || node.name)
|
112
|
+
|
113
|
+
@skipping = @skip_stack.last || skip?(node)
|
114
|
+
@skip_stack << @skipping
|
115
|
+
|
116
|
+
call_analyzers(:on_enter_field, node, parent)
|
117
|
+
super
|
118
|
+
|
119
|
+
@skipping = @skip_stack.pop
|
120
|
+
|
121
|
+
call_analyzers(:on_leave_field, node, parent)
|
122
|
+
@response_path.pop
|
123
|
+
@field_definitions.pop
|
124
|
+
@object_types.pop
|
125
|
+
@path.pop
|
126
|
+
end
|
127
|
+
|
128
|
+
def on_directive(node, parent)
|
129
|
+
directive_defn = @schema.directives[node.name]
|
130
|
+
@directive_definitions.push(directive_defn)
|
131
|
+
call_analyzers(:on_enter_directive, node, parent)
|
132
|
+
super
|
133
|
+
call_analyzers(:on_leave_directive, node, parent)
|
134
|
+
@directive_definitions.pop
|
135
|
+
end
|
136
|
+
|
137
|
+
def on_argument(node, parent)
|
138
|
+
argument_defn = if (arg = @argument_definitions.last)
|
139
|
+
arg_type = arg.type.unwrap
|
140
|
+
if arg_type.kind.input_object?
|
141
|
+
arg_type.get_argument(node.name, @query.context)
|
142
|
+
else
|
143
|
+
nil
|
144
|
+
end
|
145
|
+
elsif (directive_defn = @directive_definitions.last)
|
146
|
+
directive_defn.get_argument(node.name, @query.context)
|
147
|
+
elsif (field_defn = @field_definitions.last)
|
148
|
+
field_defn.get_argument(node.name, @query.context)
|
149
|
+
else
|
150
|
+
nil
|
151
|
+
end
|
152
|
+
|
153
|
+
@argument_definitions.push(argument_defn)
|
154
|
+
@path.push(node.name)
|
155
|
+
call_analyzers(:on_enter_argument, node, parent)
|
156
|
+
super
|
157
|
+
call_analyzers(:on_leave_argument, node, parent)
|
158
|
+
@argument_definitions.pop
|
159
|
+
@path.pop
|
160
|
+
end
|
161
|
+
|
162
|
+
def on_fragment_spread(node, parent)
|
163
|
+
@path.push("... #{node.name}")
|
164
|
+
call_analyzers(:on_enter_fragment_spread, node, parent)
|
165
|
+
enter_fragment_spread_inline(node)
|
166
|
+
super
|
167
|
+
leave_fragment_spread_inline(node)
|
168
|
+
call_analyzers(:on_leave_fragment_spread, node, parent)
|
169
|
+
@path.pop
|
170
|
+
end
|
171
|
+
|
172
|
+
def on_abstract_node(node, parent)
|
173
|
+
call_analyzers(:on_enter_abstract_node, node, parent)
|
174
|
+
super
|
175
|
+
call_analyzers(:on_leave_abstract_node, node, parent)
|
176
|
+
end
|
177
|
+
|
178
|
+
# @return [GraphQL::BaseType] The current object type
|
179
|
+
def type_definition
|
180
|
+
@object_types.last
|
181
|
+
end
|
182
|
+
|
183
|
+
# @return [GraphQL::BaseType] The type which the current type came from
|
184
|
+
def parent_type_definition
|
185
|
+
@object_types[-2]
|
186
|
+
end
|
187
|
+
|
188
|
+
# @return [GraphQL::Field, nil] The most-recently-entered GraphQL::Field, if currently inside one
|
189
|
+
def field_definition
|
190
|
+
@field_definitions.last
|
191
|
+
end
|
192
|
+
|
193
|
+
# @return [GraphQL::Field, nil] The GraphQL field which returned the object that the current field belongs to
|
194
|
+
def previous_field_definition
|
195
|
+
@field_definitions[-2]
|
196
|
+
end
|
197
|
+
|
198
|
+
# @return [GraphQL::Directive, nil] The most-recently-entered GraphQL::Directive, if currently inside one
|
199
|
+
def directive_definition
|
200
|
+
@directive_definitions.last
|
201
|
+
end
|
202
|
+
|
203
|
+
# @return [GraphQL::Argument, nil] The most-recently-entered GraphQL::Argument, if currently inside one
|
204
|
+
def argument_definition
|
205
|
+
@argument_definitions.last
|
206
|
+
end
|
207
|
+
|
208
|
+
# @return [GraphQL::Argument, nil] The previous GraphQL argument
|
209
|
+
def previous_argument_definition
|
210
|
+
@argument_definitions[-2]
|
211
|
+
end
|
212
|
+
|
213
|
+
private
|
214
|
+
|
215
|
+
# Visit a fragment spread inline instead of visiting the definition
|
216
|
+
# by itself.
|
217
|
+
def enter_fragment_spread_inline(fragment_spread)
|
218
|
+
fragment_def = query.fragments[fragment_spread.name]
|
219
|
+
|
220
|
+
object_type = if fragment_def.type
|
221
|
+
@query.warden.get_type(fragment_def.type.name)
|
222
|
+
else
|
223
|
+
object_types.last
|
224
|
+
end
|
225
|
+
|
226
|
+
object_types << object_type
|
227
|
+
|
228
|
+
fragment_def.selections.each do |selection|
|
229
|
+
visit_node(selection, fragment_def)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
# Visit a fragment spread inline instead of visiting the definition
|
234
|
+
# by itself.
|
235
|
+
def leave_fragment_spread_inline(_fragment_spread)
|
236
|
+
object_types.pop
|
237
|
+
end
|
238
|
+
|
239
|
+
def skip?(ast_node)
|
240
|
+
dir = ast_node.directives
|
241
|
+
dir.any? && !GraphQL::Execution::DirectiveChecks.include?(dir, query)
|
242
|
+
end
|
243
|
+
|
244
|
+
def call_analyzers(method, node, parent)
|
245
|
+
@analyzers.each do |analyzer|
|
246
|
+
begin
|
247
|
+
analyzer.public_send(method, node, parent, self)
|
248
|
+
rescue AnalysisError => err
|
249
|
+
@rescued_errors << err
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def on_fragment_with_type(node)
|
255
|
+
object_type = if node.type
|
256
|
+
@query.warden.get_type(node.type.name)
|
257
|
+
else
|
258
|
+
@object_types.last
|
259
|
+
end
|
260
|
+
@object_types.push(object_type)
|
261
|
+
yield(node)
|
262
|
+
@object_types.pop
|
263
|
+
@path.pop
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/analysis/ast/visitor"
|
3
|
+
require "graphql/analysis/ast/analyzer"
|
4
|
+
require "graphql/analysis/ast/field_usage"
|
5
|
+
require "graphql/analysis/ast/query_complexity"
|
6
|
+
require "graphql/analysis/ast/max_query_complexity"
|
7
|
+
require "graphql/analysis/ast/query_depth"
|
8
|
+
require "graphql/analysis/ast/max_query_depth"
|
9
|
+
|
10
|
+
module GraphQL
|
11
|
+
module Analysis
|
12
|
+
module AST
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def use(schema_class)
|
16
|
+
if schema_class.analysis_engine == self
|
17
|
+
definition_line = caller(2, 1).first
|
18
|
+
GraphQL::Deprecation.warn("GraphQL::Analysis::AST is now the default; remove `use GraphQL::Analysis::AST` from the schema definition (#{definition_line})")
|
19
|
+
else
|
20
|
+
schema_class.analysis_engine = self
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Analyze a multiplex, and all queries within.
|
25
|
+
# Multiplex analyzers are ran for all queries, keeping state.
|
26
|
+
# Query analyzers are ran per query, without carrying state between queries.
|
27
|
+
#
|
28
|
+
# @param multiplex [GraphQL::Execution::Multiplex]
|
29
|
+
# @param analyzers [Array<GraphQL::Analysis::AST::Analyzer>]
|
30
|
+
# @return [Array<Any>] Results from multiplex analyzers
|
31
|
+
def analyze_multiplex(multiplex, analyzers)
|
32
|
+
multiplex_analyzers = analyzers.map { |analyzer| analyzer.new(multiplex) }
|
33
|
+
|
34
|
+
multiplex.trace("analyze_multiplex", { multiplex: multiplex }) do
|
35
|
+
query_results = multiplex.queries.map do |query|
|
36
|
+
if query.valid?
|
37
|
+
analyze_query(
|
38
|
+
query,
|
39
|
+
query.analyzers,
|
40
|
+
multiplex_analyzers: multiplex_analyzers
|
41
|
+
)
|
42
|
+
else
|
43
|
+
[]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
multiplex_results = multiplex_analyzers.map(&:result)
|
48
|
+
multiplex_errors = analysis_errors(multiplex_results)
|
49
|
+
|
50
|
+
multiplex.queries.each_with_index do |query, idx|
|
51
|
+
query.analysis_errors = multiplex_errors + analysis_errors(query_results[idx])
|
52
|
+
end
|
53
|
+
multiplex_results
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param query [GraphQL::Query]
|
58
|
+
# @param analyzers [Array<GraphQL::Analysis::AST::Analyzer>]
|
59
|
+
# @return [Array<Any>] Results from those analyzers
|
60
|
+
def analyze_query(query, analyzers, multiplex_analyzers: [])
|
61
|
+
query.trace("analyze_query", { query: query }) do
|
62
|
+
query_analyzers = analyzers
|
63
|
+
.map { |analyzer| analyzer.new(query) }
|
64
|
+
.select { |analyzer| analyzer.analyze? }
|
65
|
+
|
66
|
+
analyzers_to_run = query_analyzers + multiplex_analyzers
|
67
|
+
if analyzers_to_run.any?
|
68
|
+
visitor = GraphQL::Analysis::AST::Visitor.new(
|
69
|
+
query: query,
|
70
|
+
analyzers: analyzers_to_run
|
71
|
+
)
|
72
|
+
|
73
|
+
visitor.visit
|
74
|
+
|
75
|
+
if visitor.rescued_errors.any?
|
76
|
+
visitor.rescued_errors
|
77
|
+
else
|
78
|
+
query_analyzers.map(&:result)
|
79
|
+
end
|
80
|
+
else
|
81
|
+
[]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def analysis_errors(results)
|
87
|
+
results.flatten.select { |r| r.is_a?(GraphQL::AnalysisError) }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Analysis
|
4
|
+
# A query reducer for tracking both field usage and deprecated field usage.
|
5
|
+
#
|
6
|
+
# @example Logging field usage and deprecated field usage
|
7
|
+
# Schema.query_analyzers << GraphQL::Analysis::FieldUsage.new { |query, used_fields, used_deprecated_fields|
|
8
|
+
# puts "Used GraphQL fields: #{used_fields.join(', ')}"
|
9
|
+
# puts "Used deprecated GraphQL fields: #{used_deprecated_fields.join(', ')}"
|
10
|
+
# }
|
11
|
+
# Schema.execute(query_str)
|
12
|
+
# # Used GraphQL fields: Cheese.id, Cheese.fatContent, Query.cheese
|
13
|
+
# # Used deprecated GraphQL fields: Cheese.fatContent
|
14
|
+
#
|
15
|
+
class FieldUsage
|
16
|
+
def initialize(&block)
|
17
|
+
@field_usage_handler = block
|
18
|
+
end
|
19
|
+
|
20
|
+
def initial_value(query)
|
21
|
+
{
|
22
|
+
query: query,
|
23
|
+
used_fields: Set.new,
|
24
|
+
used_deprecated_fields: Set.new
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def call(memo, visit_type, irep_node)
|
29
|
+
if irep_node.ast_node.is_a?(GraphQL::Language::Nodes::Field) && visit_type == :leave
|
30
|
+
field = "#{irep_node.owner_type.name}.#{irep_node.definition.name}"
|
31
|
+
memo[:used_fields] << field
|
32
|
+
if irep_node.definition.deprecation_reason
|
33
|
+
memo[:used_deprecated_fields] << field
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
memo
|
38
|
+
end
|
39
|
+
|
40
|
+
def final_value(memo)
|
41
|
+
@field_usage_handler.call(memo[:query], memo[:used_fields].to_a, memo[:used_deprecated_fields].to_a)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|