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,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "graphql/schema/find_inherited_value"
|
4
|
+
|
5
|
+
module GraphQL
|
6
|
+
class Schema
|
7
|
+
class Member
|
8
|
+
# DSL methods shared by lots of things in the GraphQL Schema.
|
9
|
+
# @api private
|
10
|
+
# @see Classes that extend this, eg {GraphQL::Schema::Object}
|
11
|
+
module BaseDSLMethods
|
12
|
+
include GraphQL::Schema::FindInheritedValue
|
13
|
+
|
14
|
+
# Call this with a new name to override the default name for this schema member; OR
|
15
|
+
# call it without an argument to get the name of this schema member
|
16
|
+
#
|
17
|
+
# The default name is implemented in default_graphql_name
|
18
|
+
# @param new_name [String]
|
19
|
+
# @return [String]
|
20
|
+
def graphql_name(new_name = nil)
|
21
|
+
if new_name
|
22
|
+
GraphQL::NameValidator.validate!(new_name)
|
23
|
+
@graphql_name = new_name
|
24
|
+
else
|
25
|
+
overridden_graphql_name || default_graphql_name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def overridden_graphql_name
|
30
|
+
defined?(@graphql_name) ? @graphql_name : nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# Just a convenience method to point out that people should use graphql_name instead
|
34
|
+
def name(new_name = nil)
|
35
|
+
return super() if new_name.nil?
|
36
|
+
|
37
|
+
fail(
|
38
|
+
"The new name override method is `graphql_name`, not `name`. Usage: "\
|
39
|
+
"graphql_name \"#{new_name}\""
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Call this method to provide a new description; OR
|
44
|
+
# call it without an argument to get the description
|
45
|
+
# @param new_description [String]
|
46
|
+
# @return [String]
|
47
|
+
def description(new_description = nil)
|
48
|
+
if new_description
|
49
|
+
@description = new_description
|
50
|
+
elsif defined?(@description)
|
51
|
+
@description
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# This pushes some configurations _down_ the inheritance tree,
|
58
|
+
# in order to prevent repetitive lookups at runtime.
|
59
|
+
module ConfigurationExtension
|
60
|
+
def inherited(child_class)
|
61
|
+
child_class.introspection(introspection)
|
62
|
+
child_class.description(description)
|
63
|
+
if overridden_graphql_name
|
64
|
+
child_class.graphql_name(overridden_graphql_name)
|
65
|
+
end
|
66
|
+
super
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [Boolean] If true, this object is part of the introspection system
|
71
|
+
def introspection(new_introspection = nil)
|
72
|
+
if !new_introspection.nil?
|
73
|
+
@introspection = new_introspection
|
74
|
+
elsif defined?(@introspection)
|
75
|
+
@introspection
|
76
|
+
else
|
77
|
+
false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def introspection?
|
82
|
+
introspection
|
83
|
+
end
|
84
|
+
|
85
|
+
# The mutation this type was derived from, if it was derived from a mutation
|
86
|
+
# @return [Class]
|
87
|
+
def mutation(mutation_class = nil)
|
88
|
+
if mutation_class
|
89
|
+
@mutation = mutation_class
|
90
|
+
elsif defined?(@mutation)
|
91
|
+
@mutation
|
92
|
+
else
|
93
|
+
nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# @return [GraphQL::BaseType] Convert this type to a legacy-style object.
|
98
|
+
def to_graphql
|
99
|
+
raise GraphQL::RequiredImplementationMissingError
|
100
|
+
end
|
101
|
+
|
102
|
+
alias :unwrap :itself
|
103
|
+
|
104
|
+
# Creates the default name for a schema member.
|
105
|
+
# The default name is the Ruby constant name,
|
106
|
+
# without any namespaces and with any `-Type` suffix removed
|
107
|
+
def default_graphql_name
|
108
|
+
@default_graphql_name ||= begin
|
109
|
+
raise GraphQL::RequiredImplementationMissingError, 'Anonymous class should declare a `graphql_name`' if name.nil?
|
110
|
+
|
111
|
+
name.split("::").last.sub(/Type\Z/, "")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def visible?(context)
|
116
|
+
true
|
117
|
+
end
|
118
|
+
|
119
|
+
def accessible?(context)
|
120
|
+
true
|
121
|
+
end
|
122
|
+
|
123
|
+
def authorized?(object, context)
|
124
|
+
true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
class Member
|
5
|
+
# @api private
|
6
|
+
module BuildType
|
7
|
+
LIST_TYPE_ERROR = "Use an array of [T] or [T, null: true] for list types; other arrays are not supported"
|
8
|
+
|
9
|
+
module_function
|
10
|
+
# @param type_expr [String, Class, GraphQL::BaseType]
|
11
|
+
# @return [GraphQL::BaseType]
|
12
|
+
def parse_type(type_expr, null:)
|
13
|
+
list_type = false
|
14
|
+
|
15
|
+
return_type = case type_expr
|
16
|
+
when String
|
17
|
+
case type_expr
|
18
|
+
when "String"
|
19
|
+
GraphQL::Types::String
|
20
|
+
when "Int", "Integer"
|
21
|
+
GraphQL::Types::Int
|
22
|
+
when "Float"
|
23
|
+
GraphQL::Types::Float
|
24
|
+
when "Boolean"
|
25
|
+
GraphQL::Types::Boolean
|
26
|
+
when "ID"
|
27
|
+
GraphQL::Types::ID
|
28
|
+
when /\A\[.*\]\Z/
|
29
|
+
list_type = true
|
30
|
+
# List members are required by default
|
31
|
+
parse_type(type_expr[1..-2], null: false)
|
32
|
+
when /.*!\Z/
|
33
|
+
null = false
|
34
|
+
parse_type(type_expr[0..-2], null: true)
|
35
|
+
else
|
36
|
+
maybe_type = constantize(type_expr)
|
37
|
+
case maybe_type
|
38
|
+
when GraphQL::BaseType
|
39
|
+
maybe_type
|
40
|
+
when Module
|
41
|
+
# This is a way to check that it's the right kind of module:
|
42
|
+
if maybe_type.respond_to?(:graphql_definition)
|
43
|
+
maybe_type
|
44
|
+
else
|
45
|
+
raise ArgumentError, "Unexpected class/module found for GraphQL type: #{type_expr} (must be type definition class/module)"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
when GraphQL::BaseType, GraphQL::Schema::LateBoundType
|
50
|
+
type_expr
|
51
|
+
when Array
|
52
|
+
case type_expr.length
|
53
|
+
when 1
|
54
|
+
list_type = true
|
55
|
+
# List members are required by default
|
56
|
+
parse_type(type_expr.first, null: false)
|
57
|
+
when 2
|
58
|
+
inner_type, nullable_option = type_expr
|
59
|
+
if nullable_option.keys != [:null] || (nullable_option[:null] != true && nullable_option[:null] != false)
|
60
|
+
raise ArgumentError, LIST_TYPE_ERROR
|
61
|
+
end
|
62
|
+
list_type = true
|
63
|
+
parse_type(inner_type, null: nullable_option[:null])
|
64
|
+
else
|
65
|
+
raise ArgumentError, LIST_TYPE_ERROR
|
66
|
+
end
|
67
|
+
when GraphQL::Schema::NonNull, GraphQL::Schema::List
|
68
|
+
type_expr
|
69
|
+
when Module
|
70
|
+
# This is a way to check that it's the right kind of module:
|
71
|
+
if type_expr.respond_to?(:graphql_definition)
|
72
|
+
type_expr
|
73
|
+
else
|
74
|
+
# Eg `String` => GraphQL::Types::String
|
75
|
+
parse_type(type_expr.name, null: true)
|
76
|
+
end
|
77
|
+
when Proc
|
78
|
+
parse_type(type_expr.call, null: true)
|
79
|
+
when false
|
80
|
+
raise ArgumentError, "Received `false` instead of a type, maybe a `!` should be replaced with `null: true` (for fields) or `required: true` (for arguments)"
|
81
|
+
end
|
82
|
+
|
83
|
+
if return_type.nil?
|
84
|
+
raise "Unexpected type input: #{type_expr.inspect} (#{type_expr.class})"
|
85
|
+
end
|
86
|
+
|
87
|
+
# Apply list_type first, that way the
|
88
|
+
# .to_non_null_type applies to the list type, not the inner type
|
89
|
+
if list_type
|
90
|
+
return_type = return_type.to_list_type
|
91
|
+
end
|
92
|
+
|
93
|
+
if !null
|
94
|
+
return_type = return_type.to_non_null_type
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
return_type
|
99
|
+
end
|
100
|
+
|
101
|
+
def to_type_name(something)
|
102
|
+
case something
|
103
|
+
when GraphQL::BaseType, GraphQL::Schema::LateBoundType
|
104
|
+
something.unwrap.name
|
105
|
+
when Array
|
106
|
+
to_type_name(something.first)
|
107
|
+
when Module
|
108
|
+
if something.respond_to?(:graphql_name)
|
109
|
+
something.graphql_name
|
110
|
+
else
|
111
|
+
to_type_name(something.name)
|
112
|
+
end
|
113
|
+
when String
|
114
|
+
something.gsub(/\]\[\!/, "").split("::").last
|
115
|
+
when GraphQL::Schema::NonNull, GraphQL::Schema::List
|
116
|
+
to_type_name(something.unwrap)
|
117
|
+
else
|
118
|
+
raise "Unhandled to_type_name input: #{something} (#{something.class})"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def camelize(string)
|
123
|
+
return string if string == '_'
|
124
|
+
return string unless string.include?("_")
|
125
|
+
camelized = string.split('_').map(&:capitalize).join
|
126
|
+
camelized[0] = camelized[0].downcase
|
127
|
+
if (match_data = string.match(/\A(_+)/))
|
128
|
+
camelized = "#{match_data[0]}#{camelized}"
|
129
|
+
end
|
130
|
+
camelized
|
131
|
+
end
|
132
|
+
|
133
|
+
# Resolves constant from string (based on Rails `ActiveSupport::Inflector.constantize`)
|
134
|
+
def constantize(string)
|
135
|
+
names = string.split('::')
|
136
|
+
|
137
|
+
# Trigger a built-in NameError exception including the ill-formed constant in the message.
|
138
|
+
Object.const_get(string) if names.empty?
|
139
|
+
|
140
|
+
# Remove the first blank element in case of '::ClassName' notation.
|
141
|
+
names.shift if names.size > 1 && names.first.empty?
|
142
|
+
|
143
|
+
names.inject(Object) do |constant, name|
|
144
|
+
if constant == Object
|
145
|
+
constant.const_get(name)
|
146
|
+
else
|
147
|
+
candidate = constant.const_get(name)
|
148
|
+
next candidate if constant.const_defined?(name, false)
|
149
|
+
next candidate unless Object.const_defined?(name)
|
150
|
+
|
151
|
+
# Go down the ancestors to check if it is owned directly. The check
|
152
|
+
# stops when we reach Object or the end of ancestors tree.
|
153
|
+
constant = constant.ancestors.inject do |const, ancestor|
|
154
|
+
break const if ancestor == Object
|
155
|
+
break ancestor if ancestor.const_defined?(name, false)
|
156
|
+
const
|
157
|
+
end
|
158
|
+
|
159
|
+
# Owner is in Object, so raise.
|
160
|
+
constant.const_get(name, false)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def underscore(string)
|
166
|
+
if string.match?(/\A[a-z_]+\Z/)
|
167
|
+
return string
|
168
|
+
end
|
169
|
+
string2 = string.dup
|
170
|
+
|
171
|
+
string2.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') # URLDecoder -> URL_Decoder
|
172
|
+
string2.gsub!(/([a-z\d])([A-Z])/,'\1_\2') # someThing -> some_Thing
|
173
|
+
string2.downcase!
|
174
|
+
|
175
|
+
string2
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
class Member
|
6
|
+
# Adds a layer of caching over user-supplied `.to_graphql` methods.
|
7
|
+
# Users override `.to_graphql`, but all runtime code should use `.graphql_definition`.
|
8
|
+
# @api private
|
9
|
+
# @see concrete classes that extend this, eg {Schema::Object}
|
10
|
+
module CachedGraphQLDefinition
|
11
|
+
# A cached result of {.to_graphql}.
|
12
|
+
# It's cached here so that user-overridden {.to_graphql} implementations
|
13
|
+
# are also cached
|
14
|
+
def graphql_definition
|
15
|
+
@graphql_definition ||= to_graphql
|
16
|
+
end
|
17
|
+
|
18
|
+
# This is for a common interface with .define-based types
|
19
|
+
def type_class
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
# Wipe out the cached graphql_definition so that `.to_graphql` will be called again.
|
24
|
+
def initialize_copy(original)
|
25
|
+
super
|
26
|
+
@graphql_definition = nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
class Member
|
6
|
+
# These constants are interpreted as GraphQL types when defining fields or arguments
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# field :is_draft, Boolean, null: false
|
10
|
+
# field :id, ID, null: false
|
11
|
+
# field :score, Int, null: false
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
module GraphQLTypeNames
|
15
|
+
Boolean = "Boolean"
|
16
|
+
ID = "ID"
|
17
|
+
Int = "Int"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,332 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Schema
|
4
|
+
class Member
|
5
|
+
module HasArguments
|
6
|
+
def self.included(cls)
|
7
|
+
cls.extend(ArgumentClassAccessor)
|
8
|
+
cls.include(ArgumentObjectLoader)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.extended(cls)
|
12
|
+
cls.extend(ArgumentClassAccessor)
|
13
|
+
cls.include(ArgumentObjectLoader)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @see {GraphQL::Schema::Argument#initialize} for parameters
|
17
|
+
# @return [GraphQL::Schema::Argument] An instance of {arguments_class}, created from `*args`
|
18
|
+
def argument(*args, **kwargs, &block)
|
19
|
+
kwargs[:owner] = self
|
20
|
+
loads = kwargs[:loads]
|
21
|
+
if loads
|
22
|
+
name = args[0]
|
23
|
+
name_as_string = name.to_s
|
24
|
+
|
25
|
+
inferred_arg_name = case name_as_string
|
26
|
+
when /_id$/
|
27
|
+
name_as_string.sub(/_id$/, "").to_sym
|
28
|
+
when /_ids$/
|
29
|
+
name_as_string.sub(/_ids$/, "")
|
30
|
+
.sub(/([^s])$/, "\\1s")
|
31
|
+
.to_sym
|
32
|
+
else
|
33
|
+
name
|
34
|
+
end
|
35
|
+
|
36
|
+
kwargs[:as] ||= inferred_arg_name
|
37
|
+
end
|
38
|
+
arg_defn = self.argument_class.new(*args, **kwargs, &block)
|
39
|
+
add_argument(arg_defn)
|
40
|
+
|
41
|
+
if self.is_a?(Class) && !method_defined?(:"load_#{arg_defn.keyword}")
|
42
|
+
method_owner = if self < GraphQL::Schema::InputObject || self < GraphQL::Schema::Directive
|
43
|
+
"self."
|
44
|
+
elsif self < GraphQL::Schema::Resolver
|
45
|
+
""
|
46
|
+
else
|
47
|
+
raise "Unexpected argument owner: #{self}"
|
48
|
+
end
|
49
|
+
if loads && arg_defn.type.list?
|
50
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
51
|
+
def #{method_owner}load_#{arg_defn.keyword}(values, context = nil)
|
52
|
+
argument = get_argument("#{arg_defn.graphql_name}")
|
53
|
+
(context || self.context).schema.after_lazy(values) do |values2|
|
54
|
+
GraphQL::Execution::Lazy.all(values2.map { |value| load_application_object(argument, value, context || self.context) })
|
55
|
+
end
|
56
|
+
end
|
57
|
+
RUBY
|
58
|
+
elsif loads
|
59
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
60
|
+
def #{method_owner}load_#{arg_defn.keyword}(value, context = nil)
|
61
|
+
argument = get_argument("#{arg_defn.graphql_name}")
|
62
|
+
load_application_object(argument, value, context || self.context)
|
63
|
+
end
|
64
|
+
RUBY
|
65
|
+
else
|
66
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
67
|
+
def #{method_owner}load_#{arg_defn.keyword}(value, _context = nil)
|
68
|
+
value
|
69
|
+
end
|
70
|
+
RUBY
|
71
|
+
end
|
72
|
+
end
|
73
|
+
arg_defn
|
74
|
+
end
|
75
|
+
|
76
|
+
# Register this argument with the class.
|
77
|
+
# @param arg_defn [GraphQL::Schema::Argument]
|
78
|
+
# @return [GraphQL::Schema::Argument]
|
79
|
+
def add_argument(arg_defn)
|
80
|
+
@own_arguments ||= {}
|
81
|
+
prev_defn = own_arguments[arg_defn.name]
|
82
|
+
case prev_defn
|
83
|
+
when nil
|
84
|
+
own_arguments[arg_defn.name] = arg_defn
|
85
|
+
when Array
|
86
|
+
prev_defn << arg_defn
|
87
|
+
when GraphQL::Schema::Argument
|
88
|
+
own_arguments[arg_defn.name] = [prev_defn, arg_defn]
|
89
|
+
else
|
90
|
+
raise "Invariant: unexpected `@own_arguments[#{arg_defn.name.inspect}]`: #{prev_defn.inspect}"
|
91
|
+
end
|
92
|
+
arg_defn
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return [Hash<String => GraphQL::Schema::Argument] Arguments defined on this thing, keyed by name. Includes inherited definitions
|
96
|
+
def arguments(context = GraphQL::Query::NullContext)
|
97
|
+
inherited_arguments = ((self.is_a?(Class) && superclass.respond_to?(:arguments)) ? superclass.arguments(context) : nil)
|
98
|
+
# Local definitions override inherited ones
|
99
|
+
if own_arguments.any?
|
100
|
+
own_arguments_that_apply = {}
|
101
|
+
own_arguments.each do |name, args_entry|
|
102
|
+
if (visible_defn = Warden.visible_entry?(:visible_argument?, args_entry, context))
|
103
|
+
own_arguments_that_apply[visible_defn.graphql_name] = visible_defn
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if inherited_arguments
|
109
|
+
if own_arguments_that_apply
|
110
|
+
inherited_arguments.merge(own_arguments_that_apply)
|
111
|
+
else
|
112
|
+
inherited_arguments
|
113
|
+
end
|
114
|
+
else
|
115
|
+
# might be nil if there are actually no arguments
|
116
|
+
own_arguments_that_apply || own_arguments
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def all_argument_definitions
|
121
|
+
if self.is_a?(Class)
|
122
|
+
all_defns = {}
|
123
|
+
ancestors.reverse_each do |ancestor|
|
124
|
+
if ancestor.respond_to?(:own_arguments)
|
125
|
+
all_defns.merge!(ancestor.own_arguments)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
else
|
129
|
+
all_defns = own_arguments
|
130
|
+
end
|
131
|
+
all_defns = all_defns.values
|
132
|
+
all_defns.flatten!
|
133
|
+
all_defns
|
134
|
+
end
|
135
|
+
|
136
|
+
# @return [GraphQL::Schema::Argument, nil] Argument defined on this thing, fetched by name.
|
137
|
+
def get_argument(argument_name, context = GraphQL::Query::NullContext)
|
138
|
+
warden = Warden.from_context(context)
|
139
|
+
if !self.is_a?(Class)
|
140
|
+
a = own_arguments[argument_name]
|
141
|
+
a && Warden.visible_entry?(:visible_argument?, a, context, warden)
|
142
|
+
else
|
143
|
+
for ancestor in ancestors
|
144
|
+
if ancestor.respond_to?(:own_arguments) &&
|
145
|
+
(a = ancestor.own_arguments[argument_name]) &&
|
146
|
+
(a = Warden.visible_entry?(:visible_argument?, a, context, warden))
|
147
|
+
return a
|
148
|
+
end
|
149
|
+
end
|
150
|
+
nil
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# @param new_arg_class [Class] A class to use for building argument definitions
|
155
|
+
def argument_class(new_arg_class = nil)
|
156
|
+
self.class.argument_class(new_arg_class)
|
157
|
+
end
|
158
|
+
|
159
|
+
# @api private
|
160
|
+
# If given a block, it will eventually yield the loaded args to the block.
|
161
|
+
#
|
162
|
+
# If no block is given, it will immediately dataload (but might return a Lazy).
|
163
|
+
#
|
164
|
+
# @param values [Hash<String, Object>]
|
165
|
+
# @param context [GraphQL::Query::Context]
|
166
|
+
# @yield [Interpreter::Arguments, Execution::Lazy<Interpeter::Arguments>]
|
167
|
+
# @return [Interpreter::Arguments, Execution::Lazy<Interpeter::Arguments>]
|
168
|
+
def coerce_arguments(parent_object, values, context, &block)
|
169
|
+
# Cache this hash to avoid re-merging it
|
170
|
+
arg_defns = self.arguments(context)
|
171
|
+
total_args_count = arg_defns.size
|
172
|
+
|
173
|
+
finished_args = nil
|
174
|
+
prepare_finished_args = -> {
|
175
|
+
if total_args_count == 0
|
176
|
+
finished_args = GraphQL::Execution::Interpreter::Arguments::EMPTY
|
177
|
+
if block_given?
|
178
|
+
block.call(finished_args)
|
179
|
+
end
|
180
|
+
else
|
181
|
+
argument_values = {}
|
182
|
+
resolved_args_count = 0
|
183
|
+
raised_error = false
|
184
|
+
arg_defns.each do |arg_name, arg_defn|
|
185
|
+
context.dataloader.append_job do
|
186
|
+
begin
|
187
|
+
arg_defn.coerce_into_values(parent_object, values, context, argument_values)
|
188
|
+
rescue GraphQL::ExecutionError, GraphQL::UnauthorizedError => err
|
189
|
+
raised_error = true
|
190
|
+
finished_args = err
|
191
|
+
if block_given?
|
192
|
+
block.call(finished_args)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
resolved_args_count += 1
|
197
|
+
if resolved_args_count == total_args_count && !raised_error
|
198
|
+
finished_args = context.schema.after_any_lazies(argument_values.values) {
|
199
|
+
GraphQL::Execution::Interpreter::Arguments.new(
|
200
|
+
argument_values: argument_values,
|
201
|
+
)
|
202
|
+
}
|
203
|
+
if block_given?
|
204
|
+
block.call(finished_args)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
}
|
211
|
+
|
212
|
+
if block_given?
|
213
|
+
prepare_finished_args.call
|
214
|
+
nil
|
215
|
+
else
|
216
|
+
# This API returns eagerly, gotta run it now
|
217
|
+
context.dataloader.run_isolated(&prepare_finished_args)
|
218
|
+
finished_args
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Usually, this is validated statically by RequiredArgumentsArePresent,
|
223
|
+
# but not for directives.
|
224
|
+
# TODO apply static validations on schema definitions?
|
225
|
+
def validate_directive_argument(arg_defn, value)
|
226
|
+
if arg_defn.owner.is_a?(Class) && arg_defn.owner < GraphQL::Schema::Directive
|
227
|
+
if value.nil? && arg_defn.type.non_null?
|
228
|
+
raise ArgumentError, "#{arg_defn.path} is required, but no value was given"
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def arguments_statically_coercible?
|
234
|
+
return @arguments_statically_coercible if defined?(@arguments_statically_coercible)
|
235
|
+
|
236
|
+
@arguments_statically_coercible = all_argument_definitions.all?(&:statically_coercible?)
|
237
|
+
end
|
238
|
+
|
239
|
+
module ArgumentClassAccessor
|
240
|
+
def argument_class(new_arg_class = nil)
|
241
|
+
if new_arg_class
|
242
|
+
@argument_class = new_arg_class
|
243
|
+
elsif defined?(@argument_class) && @argument_class
|
244
|
+
@argument_class
|
245
|
+
else
|
246
|
+
superclass.respond_to?(:argument_class) ? superclass.argument_class : GraphQL::Schema::Argument
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
module ArgumentObjectLoader
|
252
|
+
# Look up the corresponding object for a provided ID.
|
253
|
+
# By default, it uses Relay-style {Schema.object_from_id},
|
254
|
+
# override this to find objects another way.
|
255
|
+
#
|
256
|
+
# @param type [Class, Module] A GraphQL type definition
|
257
|
+
# @param id [String] A client-provided to look up
|
258
|
+
# @param context [GraphQL::Query::Context] the current context
|
259
|
+
def object_from_id(type, id, context)
|
260
|
+
context.schema.object_from_id(id, context)
|
261
|
+
end
|
262
|
+
|
263
|
+
def load_application_object(argument, id, context)
|
264
|
+
# See if any object can be found for this ID
|
265
|
+
if id.nil?
|
266
|
+
return nil
|
267
|
+
end
|
268
|
+
object_from_id(argument.loads, id, context)
|
269
|
+
end
|
270
|
+
|
271
|
+
def load_and_authorize_application_object(argument, id, context)
|
272
|
+
loaded_application_object = load_application_object(argument, id, context)
|
273
|
+
authorize_application_object(argument, id, context, loaded_application_object)
|
274
|
+
end
|
275
|
+
|
276
|
+
def authorize_application_object(argument, id, context, loaded_application_object)
|
277
|
+
context.schema.after_lazy(loaded_application_object) do |application_object|
|
278
|
+
if application_object.nil?
|
279
|
+
err = GraphQL::LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object)
|
280
|
+
load_application_object_failed(err)
|
281
|
+
end
|
282
|
+
# Double-check that the located object is actually of this type
|
283
|
+
# (Don't want to allow arbitrary access to objects this way)
|
284
|
+
resolved_application_object_type = context.schema.resolve_type(argument.loads, application_object, context)
|
285
|
+
context.schema.after_lazy(resolved_application_object_type) do |application_object_type|
|
286
|
+
possible_object_types = context.warden.possible_types(argument.loads)
|
287
|
+
if !possible_object_types.include?(application_object_type)
|
288
|
+
err = GraphQL::LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object)
|
289
|
+
load_application_object_failed(err)
|
290
|
+
else
|
291
|
+
# This object was loaded successfully
|
292
|
+
# and resolved to the right type,
|
293
|
+
# now apply the `.authorized?` class method if there is one
|
294
|
+
if (class_based_type = application_object_type.type_class)
|
295
|
+
context.schema.after_lazy(class_based_type.authorized?(application_object, context)) do |authed|
|
296
|
+
if authed
|
297
|
+
application_object
|
298
|
+
else
|
299
|
+
err = GraphQL::UnauthorizedError.new(
|
300
|
+
object: application_object,
|
301
|
+
type: class_based_type,
|
302
|
+
context: context,
|
303
|
+
)
|
304
|
+
if self.respond_to?(:unauthorized_object)
|
305
|
+
err.set_backtrace(caller)
|
306
|
+
unauthorized_object(err)
|
307
|
+
else
|
308
|
+
raise err
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
else
|
313
|
+
application_object
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
def load_application_object_failed(err)
|
321
|
+
raise err
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
NO_ARGUMENTS = {}.freeze
|
326
|
+
def own_arguments
|
327
|
+
@own_arguments || NO_ARGUMENTS
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|