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,242 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Language
|
4
|
+
# Depth-first traversal through the tree, calling hooks at each stop.
|
5
|
+
#
|
6
|
+
# @example Create a visitor counting certain field names
|
7
|
+
# class NameCounter < GraphQL::Language::Visitor
|
8
|
+
# def initialize(document, field_name)
|
9
|
+
# super(document)
|
10
|
+
# @field_name = field_name
|
11
|
+
# @count = 0
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# attr_reader :count
|
15
|
+
#
|
16
|
+
# def on_field(node, parent)
|
17
|
+
# # if this field matches our search, increment the counter
|
18
|
+
# if node.name == @field_name
|
19
|
+
# @count += 1
|
20
|
+
# end
|
21
|
+
# # Continue visiting subfields:
|
22
|
+
# super
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# # Initialize a visitor
|
27
|
+
# visitor = NameCounter.new(document, "name")
|
28
|
+
# # Run it
|
29
|
+
# visitor.visit
|
30
|
+
# # Check the result
|
31
|
+
# visitor.count
|
32
|
+
# # => 3
|
33
|
+
class Visitor
|
34
|
+
# If any hook returns this value, the {Visitor} stops visiting this
|
35
|
+
# node right away
|
36
|
+
# @deprecated Use `super` to continue the visit; or don't call it to halt.
|
37
|
+
SKIP = :_skip
|
38
|
+
|
39
|
+
class DeleteNode; end
|
40
|
+
|
41
|
+
# When this is returned from a visitor method,
|
42
|
+
# Then the `node` passed into the method is removed from `parent`'s children.
|
43
|
+
DELETE_NODE = DeleteNode.new
|
44
|
+
|
45
|
+
def initialize(document)
|
46
|
+
@document = document
|
47
|
+
@visitors = {}
|
48
|
+
@result = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [GraphQL::Language::Nodes::Document] The document with any modifications applied
|
52
|
+
attr_reader :result
|
53
|
+
|
54
|
+
# Get a {NodeVisitor} for `node_class`
|
55
|
+
# @param node_class [Class] The node class that you want to listen to
|
56
|
+
# @return [NodeVisitor]
|
57
|
+
#
|
58
|
+
# @example Run a hook whenever you enter a new Field
|
59
|
+
# visitor[GraphQL::Language::Nodes::Field] << ->(node, parent) { p "Here's a field" }
|
60
|
+
# @deprecated see `on_` methods, like {#on_field}
|
61
|
+
def [](node_class)
|
62
|
+
@visitors[node_class] ||= NodeVisitor.new
|
63
|
+
end
|
64
|
+
|
65
|
+
# Visit `document` and all children, applying hooks as you go
|
66
|
+
# @return [void]
|
67
|
+
def visit
|
68
|
+
result = on_node_with_modifications(@document, nil)
|
69
|
+
@result = if result.is_a?(Array)
|
70
|
+
result.first
|
71
|
+
else
|
72
|
+
# The node wasn't modified
|
73
|
+
@document
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Call the user-defined handler for `node`.
|
78
|
+
def visit_node(node, parent)
|
79
|
+
public_send(node.visit_method, node, parent)
|
80
|
+
end
|
81
|
+
|
82
|
+
# The default implementation for visiting an AST node.
|
83
|
+
# It doesn't _do_ anything, but it continues to visiting the node's children.
|
84
|
+
# To customize this hook, override one of its make_visit_methodes (or the base method?)
|
85
|
+
# in your subclasses.
|
86
|
+
#
|
87
|
+
# For compatibility, it calls hook procs, too.
|
88
|
+
# @param node [GraphQL::Language::Nodes::AbstractNode] the node being visited
|
89
|
+
# @param parent [GraphQL::Language::Nodes::AbstractNode, nil] the previously-visited node, or `nil` if this is the root node.
|
90
|
+
# @return [Array, nil] If there were modifications, it returns an array of new nodes, otherwise, it returns `nil`.
|
91
|
+
def on_abstract_node(node, parent)
|
92
|
+
if node.equal?(DELETE_NODE)
|
93
|
+
# This might be passed to `super(DELETE_NODE, ...)`
|
94
|
+
# by a user hook, don't want to keep visiting in that case.
|
95
|
+
nil
|
96
|
+
else
|
97
|
+
# Run hooks if there are any
|
98
|
+
new_node = node
|
99
|
+
no_hooks = !@visitors.key?(node.class)
|
100
|
+
if no_hooks || begin_visit(new_node, parent)
|
101
|
+
node.children.each do |child_node|
|
102
|
+
new_child_and_node = on_node_with_modifications(child_node, new_node)
|
103
|
+
# Reassign `node` in case the child hook makes a modification
|
104
|
+
if new_child_and_node.is_a?(Array)
|
105
|
+
new_node = new_child_and_node[1]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end_visit(new_node, parent) unless no_hooks
|
110
|
+
|
111
|
+
if new_node.equal?(node)
|
112
|
+
nil
|
113
|
+
else
|
114
|
+
[new_node, parent]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# We don't use `alias` here because it breaks `super`
|
120
|
+
def self.make_visit_method(node_method)
|
121
|
+
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
122
|
+
def #{node_method}(node, parent)
|
123
|
+
child_mod = on_abstract_node(node, parent)
|
124
|
+
# If visiting the children returned changes, continue passing those.
|
125
|
+
child_mod || [node, parent]
|
126
|
+
end
|
127
|
+
RUBY
|
128
|
+
end
|
129
|
+
|
130
|
+
make_visit_method :on_argument
|
131
|
+
make_visit_method :on_directive
|
132
|
+
make_visit_method :on_directive_definition
|
133
|
+
make_visit_method :on_directive_location
|
134
|
+
make_visit_method :on_document
|
135
|
+
make_visit_method :on_enum
|
136
|
+
make_visit_method :on_enum_type_definition
|
137
|
+
make_visit_method :on_enum_type_extension
|
138
|
+
make_visit_method :on_enum_value_definition
|
139
|
+
make_visit_method :on_field
|
140
|
+
make_visit_method :on_field_definition
|
141
|
+
make_visit_method :on_fragment_definition
|
142
|
+
make_visit_method :on_fragment_spread
|
143
|
+
make_visit_method :on_inline_fragment
|
144
|
+
make_visit_method :on_input_object
|
145
|
+
make_visit_method :on_input_object_type_definition
|
146
|
+
make_visit_method :on_input_object_type_extension
|
147
|
+
make_visit_method :on_input_value_definition
|
148
|
+
make_visit_method :on_interface_type_definition
|
149
|
+
make_visit_method :on_interface_type_extension
|
150
|
+
make_visit_method :on_list_type
|
151
|
+
make_visit_method :on_non_null_type
|
152
|
+
make_visit_method :on_null_value
|
153
|
+
make_visit_method :on_object_type_definition
|
154
|
+
make_visit_method :on_object_type_extension
|
155
|
+
make_visit_method :on_operation_definition
|
156
|
+
make_visit_method :on_scalar_type_definition
|
157
|
+
make_visit_method :on_scalar_type_extension
|
158
|
+
make_visit_method :on_schema_definition
|
159
|
+
make_visit_method :on_schema_extension
|
160
|
+
make_visit_method :on_type_name
|
161
|
+
make_visit_method :on_union_type_definition
|
162
|
+
make_visit_method :on_union_type_extension
|
163
|
+
make_visit_method :on_variable_definition
|
164
|
+
make_visit_method :on_variable_identifier
|
165
|
+
|
166
|
+
private
|
167
|
+
|
168
|
+
# Run the hooks for `node`, and if the hooks return a copy of `node`,
|
169
|
+
# copy `parent` so that it contains the copy of that node as a child,
|
170
|
+
# then return the copies
|
171
|
+
# If a non-array value is returned, consuming functions should ignore
|
172
|
+
# said value
|
173
|
+
def on_node_with_modifications(node, parent)
|
174
|
+
new_node_and_new_parent = visit_node(node, parent)
|
175
|
+
if new_node_and_new_parent.is_a?(Array)
|
176
|
+
new_node = new_node_and_new_parent[0]
|
177
|
+
new_parent = new_node_and_new_parent[1]
|
178
|
+
if new_node.is_a?(Nodes::AbstractNode) && !node.equal?(new_node)
|
179
|
+
# The user-provided hook returned a new node.
|
180
|
+
new_parent = new_parent && new_parent.replace_child(node, new_node)
|
181
|
+
return new_node, new_parent
|
182
|
+
elsif new_node.equal?(DELETE_NODE)
|
183
|
+
# The user-provided hook requested to remove this node
|
184
|
+
new_parent = new_parent && new_parent.delete_child(node)
|
185
|
+
return nil, new_parent
|
186
|
+
elsif new_node_and_new_parent.none? { |n| n == nil || n.class < Nodes::AbstractNode }
|
187
|
+
# The user-provided hook returned an array of who-knows-what
|
188
|
+
# return nil here to signify that no changes should be made
|
189
|
+
nil
|
190
|
+
else
|
191
|
+
new_node_and_new_parent
|
192
|
+
end
|
193
|
+
else
|
194
|
+
# The user-provided hook didn't make any modifications.
|
195
|
+
# In fact, the hook might have returned who-knows-what, so
|
196
|
+
# ignore the return value and use the original values.
|
197
|
+
new_node_and_new_parent
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def begin_visit(node, parent)
|
202
|
+
node_visitor = self[node.class]
|
203
|
+
self.class.apply_hooks(node_visitor.enter, node, parent)
|
204
|
+
end
|
205
|
+
|
206
|
+
# Should global `leave` visitors come first or last?
|
207
|
+
def end_visit(node, parent)
|
208
|
+
node_visitor = self[node.class]
|
209
|
+
self.class.apply_hooks(node_visitor.leave, node, parent)
|
210
|
+
end
|
211
|
+
|
212
|
+
# If one of the visitors returns SKIP, stop visiting this node
|
213
|
+
def self.apply_hooks(hooks, node, parent)
|
214
|
+
hooks.each do |proc|
|
215
|
+
return false if proc.call(node, parent) == SKIP
|
216
|
+
end
|
217
|
+
true
|
218
|
+
end
|
219
|
+
|
220
|
+
# Collect `enter` and `leave` hooks for classes in {GraphQL::Language::Nodes}
|
221
|
+
#
|
222
|
+
# Access {NodeVisitor}s via {GraphQL::Language::Visitor#[]}
|
223
|
+
class NodeVisitor
|
224
|
+
# @return [Array<Proc>] Hooks to call when entering a node of this type
|
225
|
+
attr_reader :enter
|
226
|
+
# @return [Array<Proc>] Hooks to call when leaving a node of this type
|
227
|
+
attr_reader :leave
|
228
|
+
|
229
|
+
def initialize
|
230
|
+
@enter = []
|
231
|
+
@leave = []
|
232
|
+
end
|
233
|
+
|
234
|
+
# Shorthand to add a hook to the {#enter} array
|
235
|
+
# @param hook [Proc] A hook to add
|
236
|
+
def <<(hook)
|
237
|
+
enter << hook
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/language/block_string"
|
3
|
+
require "graphql/language/printer"
|
4
|
+
require "graphql/language/sanitized_printer"
|
5
|
+
require "graphql/language/document_from_schema_definition"
|
6
|
+
require "graphql/language/generation"
|
7
|
+
require "graphql/language/lexer"
|
8
|
+
require "graphql/language/nodes"
|
9
|
+
require "graphql/language/cache"
|
10
|
+
require "graphql/language/parser"
|
11
|
+
require "graphql/language/token"
|
12
|
+
require "graphql/language/visitor"
|
13
|
+
require "graphql/language/definition_slice"
|
14
|
+
|
15
|
+
module GraphQL
|
16
|
+
module Language
|
17
|
+
# @api private
|
18
|
+
def self.serialize(value)
|
19
|
+
if value.is_a?(Hash)
|
20
|
+
serialized_hash = value.map do |k, v|
|
21
|
+
"#{k}:#{serialize v}"
|
22
|
+
end.join(",")
|
23
|
+
|
24
|
+
"{#{serialized_hash}}"
|
25
|
+
elsif value.is_a?(Array)
|
26
|
+
serialized_array = value.map do |v|
|
27
|
+
serialize v
|
28
|
+
end.join(",")
|
29
|
+
|
30
|
+
"[#{serialized_array}]"
|
31
|
+
else
|
32
|
+
JSON.generate(value, quirks_mode: true)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
# A list type modifies another type.
|
4
|
+
#
|
5
|
+
# List types can be created with the type helper (`types[InnerType]`)
|
6
|
+
# or {BaseType#to_list_type} (`InnerType.to_list_type`)
|
7
|
+
#
|
8
|
+
# For return types, it says that the returned value will be a list of the modified.
|
9
|
+
#
|
10
|
+
# @example A field which returns a list of items
|
11
|
+
# field :items, types[ItemType]
|
12
|
+
# # or
|
13
|
+
# field :items, ItemType.to_list_type
|
14
|
+
#
|
15
|
+
# For input types, it says that the incoming value will be a list of the modified type.
|
16
|
+
#
|
17
|
+
# @example A field which accepts a list of strings
|
18
|
+
# field :newNames do
|
19
|
+
# # ...
|
20
|
+
# argument :values, types[types.String]
|
21
|
+
# # or
|
22
|
+
# argument :values, types.String.to_list_type
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# Given a list type, you can always get the underlying type with {#unwrap}.
|
26
|
+
#
|
27
|
+
class ListType < GraphQL::BaseType
|
28
|
+
include GraphQL::BaseType::ModifiesAnotherType
|
29
|
+
attr_reader :of_type
|
30
|
+
def initialize(of_type:)
|
31
|
+
super()
|
32
|
+
@of_type = of_type
|
33
|
+
end
|
34
|
+
|
35
|
+
def kind
|
36
|
+
GraphQL::TypeKinds::LIST
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
"[#{of_type.to_s}]"
|
41
|
+
end
|
42
|
+
alias_method :inspect, :to_s
|
43
|
+
alias :to_type_signature :to_s
|
44
|
+
|
45
|
+
def coerce_result(value, ctx = nil)
|
46
|
+
if ctx.nil?
|
47
|
+
warn_deprecated_coerce("coerce_isolated_result")
|
48
|
+
ctx = GraphQL::Query::NullContext
|
49
|
+
end
|
50
|
+
ensure_array(value).map { |item| item.nil? ? nil : of_type.coerce_result(item, ctx) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def list?
|
54
|
+
true
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def coerce_non_null_input(value, ctx)
|
60
|
+
ensure_array(value).map { |item| of_type.coerce_input(item, ctx) }
|
61
|
+
end
|
62
|
+
|
63
|
+
def validate_non_null_input(value, ctx)
|
64
|
+
result = GraphQL::Query::InputValidationResult.new
|
65
|
+
|
66
|
+
ensure_array(value).each_with_index do |item, index|
|
67
|
+
item_result = of_type.validate_input(item, ctx)
|
68
|
+
if !item_result.valid?
|
69
|
+
result.merge_result!(index, item_result)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
result
|
74
|
+
end
|
75
|
+
|
76
|
+
def ensure_array(value)
|
77
|
+
value.is_a?(Array) ? value : [value]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
# Raised when a argument is configured with `loads:` and the client provides an `ID`,
|
5
|
+
# but no object is loaded for that ID.
|
6
|
+
#
|
7
|
+
# @see GraphQL::Schema::Member::HasArguments::ArgumentObjectLoader#load_application_object_failed, A hook which you can override in resolvers, mutations and input objects.
|
8
|
+
class LoadApplicationObjectFailedError < GraphQL::ExecutionError
|
9
|
+
# @return [GraphQL::Schema::Argument] the argument definition for the argument that was looked up
|
10
|
+
attr_reader :argument
|
11
|
+
# @return [String] The ID provided by the client
|
12
|
+
attr_reader :id
|
13
|
+
# @return [Object] The value found with this ID
|
14
|
+
attr_reader :object
|
15
|
+
def initialize(argument:, id:, object:)
|
16
|
+
@id = id
|
17
|
+
@argument = argument
|
18
|
+
@object = object
|
19
|
+
super("No object found for `#{argument.graphql_name}: #{id.inspect}`")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class NameValidator
|
4
|
+
VALID_NAME_REGEX = /^[_a-zA-Z][_a-zA-Z0-9]*$/
|
5
|
+
|
6
|
+
def self.validate!(name)
|
7
|
+
name = name.is_a?(String) ? name : name.to_s
|
8
|
+
raise GraphQL::InvalidNameError.new(name, VALID_NAME_REGEX) unless name.match?(VALID_NAME_REGEX)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
# A non-null type modifies another type.
|
4
|
+
#
|
5
|
+
# Non-null types can be created with `!` (`InnerType!`)
|
6
|
+
# or {BaseType#to_non_null_type} (`InnerType.to_non_null_type`)
|
7
|
+
#
|
8
|
+
# For return types, it says that the returned value will _always_ be present.
|
9
|
+
#
|
10
|
+
# @example A field which _always_ returns an error
|
11
|
+
# field :items, !ItemType
|
12
|
+
# # or
|
13
|
+
# field :items, ItemType.to_non_null_type
|
14
|
+
#
|
15
|
+
# (If the application fails to return a value, {InvalidNullError} will be passed to {Schema#type_error}.)
|
16
|
+
#
|
17
|
+
# For input types, it says that the incoming value _must_ be provided by the query.
|
18
|
+
#
|
19
|
+
# @example A field which _requires_ a string input
|
20
|
+
# field :newNames do
|
21
|
+
# # ...
|
22
|
+
# argument :values, !types.String
|
23
|
+
# # or
|
24
|
+
# argument :values, types.String.to_non_null_type
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# (If a value isn't provided, {Query::VariableValidationError} will be raised).
|
28
|
+
#
|
29
|
+
# Given a non-null type, you can always get the underlying type with {#unwrap}.
|
30
|
+
#
|
31
|
+
class NonNullType < GraphQL::BaseType
|
32
|
+
include GraphQL::BaseType::ModifiesAnotherType
|
33
|
+
extend Forwardable
|
34
|
+
|
35
|
+
attr_reader :of_type
|
36
|
+
def initialize(of_type:)
|
37
|
+
super()
|
38
|
+
@of_type = of_type
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid_input?(value, ctx)
|
42
|
+
validate_input(value, ctx).valid?
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate_input(value, ctx)
|
46
|
+
if value.nil?
|
47
|
+
result = GraphQL::Query::InputValidationResult.new
|
48
|
+
result.add_problem("Expected value to not be null")
|
49
|
+
result
|
50
|
+
else
|
51
|
+
of_type.validate_input(value, ctx)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def_delegators :@of_type, :coerce_input, :coerce_result, :list?
|
56
|
+
|
57
|
+
def kind
|
58
|
+
GraphQL::TypeKinds::NON_NULL
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_s
|
62
|
+
"#{of_type.to_s}!"
|
63
|
+
end
|
64
|
+
alias_method :inspect, :to_s
|
65
|
+
alias :to_type_signature :to_s
|
66
|
+
|
67
|
+
def non_null?
|
68
|
+
true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
# @api deprecated
|
4
|
+
class ObjectType < GraphQL::BaseType
|
5
|
+
extend Define::InstanceDefinable::DeprecatedDefine
|
6
|
+
|
7
|
+
accepts_definitions :interfaces, :fields, :mutation, :relay_node_type, field: GraphQL::Define::AssignObjectField
|
8
|
+
accepts_definitions implements: ->(type, *interfaces, inherit: false) { type.implements(interfaces, inherit: inherit) }
|
9
|
+
|
10
|
+
attr_accessor :fields, :mutation, :relay_node_type
|
11
|
+
ensure_defined(:fields, :mutation, :interfaces, :relay_node_type)
|
12
|
+
|
13
|
+
# @!attribute fields
|
14
|
+
# @return [Hash<String => GraphQL::Field>] Map String fieldnames to their {GraphQL::Field} implementations
|
15
|
+
|
16
|
+
# @!attribute mutation
|
17
|
+
# @return [GraphQL::Relay::Mutation, nil] The mutation this object type was derived from, if it is an auto-generated payload type.
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
super
|
21
|
+
@fields = {}
|
22
|
+
@clean_inherited_fields = nil
|
23
|
+
@structural_interface_type_memberships = []
|
24
|
+
@inherited_interface_type_memberships = []
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize_copy(other)
|
28
|
+
super
|
29
|
+
@structural_interface_type_memberships = other.structural_interface_type_memberships.dup
|
30
|
+
@inherited_interface_type_memberships = other.inherited_interface_type_memberships.dup
|
31
|
+
@fields = other.fields.dup
|
32
|
+
end
|
33
|
+
|
34
|
+
# This method declares interfaces for this type AND inherits any field definitions
|
35
|
+
# @param new_interfaces [Array<GraphQL::Interface>] interfaces that this type implements
|
36
|
+
# @deprecated Use `implements` instead of `interfaces`.
|
37
|
+
def interfaces=(new_interfaces)
|
38
|
+
@structural_interface_type_memberships = []
|
39
|
+
@inherited_interface_type_memberships = []
|
40
|
+
@clean_inherited_fields = nil
|
41
|
+
implements(new_interfaces, inherit: true)
|
42
|
+
end
|
43
|
+
|
44
|
+
def interfaces(ctx = GraphQL::Query::NullContext)
|
45
|
+
ensure_defined
|
46
|
+
visible_ifaces = []
|
47
|
+
unfiltered = ctx == GraphQL::Query::NullContext
|
48
|
+
[@structural_interface_type_memberships, @inherited_interface_type_memberships].each do |tms|
|
49
|
+
tms.each do |type_membership|
|
50
|
+
if unfiltered || type_membership.visible?(ctx)
|
51
|
+
# if this is derived from a class-based object, we have to
|
52
|
+
# get the `.graphql_definition` of the attached interface.
|
53
|
+
visible_ifaces << GraphQL::BaseType.resolve_related_type(type_membership.abstract_type)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
visible_ifaces
|
59
|
+
end
|
60
|
+
|
61
|
+
def kind
|
62
|
+
GraphQL::TypeKinds::OBJECT
|
63
|
+
end
|
64
|
+
|
65
|
+
# This fields doesnt have instrumenation applied
|
66
|
+
# @see [Schema#get_field] Get field with instrumentation
|
67
|
+
# @return [GraphQL::Field] The field definition for `field_name` (may be inherited from interfaces)
|
68
|
+
def get_field(field_name)
|
69
|
+
fields[field_name] || interface_fields[field_name]
|
70
|
+
end
|
71
|
+
|
72
|
+
# These fields don't have instrumenation applied
|
73
|
+
# @see [Schema#get_fields] Get fields with instrumentation
|
74
|
+
# @return [Array<GraphQL::Field>] All fields, including ones inherited from interfaces
|
75
|
+
def all_fields
|
76
|
+
interface_fields.merge(self.fields).values
|
77
|
+
end
|
78
|
+
|
79
|
+
# Declare that this object implements this interface.
|
80
|
+
# This declaration will be validated when the schema is defined.
|
81
|
+
# @param interfaces [Array<GraphQL::Interface>] add a new interface that this type implements
|
82
|
+
# @param inherits [Boolean] If true, copy the interfaces' field definitions to this type
|
83
|
+
def implements(interfaces, inherit: false, **options)
|
84
|
+
if !interfaces.is_a?(Array)
|
85
|
+
raise ArgumentError, "`implements(interfaces)` must be an array, not #{interfaces.class} (#{interfaces})"
|
86
|
+
end
|
87
|
+
@clean_inherited_fields = nil
|
88
|
+
|
89
|
+
type_memberships = inherit ? @inherited_interface_type_memberships : @structural_interface_type_memberships
|
90
|
+
interfaces.each do |iface|
|
91
|
+
iface = BaseType.resolve_related_type(iface)
|
92
|
+
if iface.is_a?(GraphQL::InterfaceType)
|
93
|
+
type_memberships << iface.type_membership_class.new(iface, self, **options)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def resolve_type_proc
|
99
|
+
nil
|
100
|
+
end
|
101
|
+
|
102
|
+
attr_writer :structural_interface_type_memberships
|
103
|
+
|
104
|
+
protected
|
105
|
+
|
106
|
+
attr_reader :structural_interface_type_memberships, :inherited_interface_type_memberships
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def normalize_interfaces(ifaces)
|
111
|
+
ifaces.map { |i_type| GraphQL::BaseType.resolve_related_type(i_type) }
|
112
|
+
end
|
113
|
+
|
114
|
+
def interface_fields
|
115
|
+
if @clean_inherited_fields
|
116
|
+
@clean_inherited_fields
|
117
|
+
else
|
118
|
+
ensure_defined
|
119
|
+
@clean_inherited_fields = {}
|
120
|
+
@inherited_interface_type_memberships.each do |type_membership|
|
121
|
+
iface = GraphQL::BaseType.resolve_related_type(type_membership.abstract_type)
|
122
|
+
if iface.is_a?(GraphQL::InterfaceType)
|
123
|
+
@clean_inherited_fields.merge!(iface.fields)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
@clean_inherited_fields
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/pagination/relation_connection"
|
3
|
+
|
4
|
+
module GraphQL
|
5
|
+
module Pagination
|
6
|
+
# Customizes `RelationConnection` to work with `ActiveRecord::Relation`s.
|
7
|
+
class ActiveRecordRelationConnection < Pagination::RelationConnection
|
8
|
+
private
|
9
|
+
|
10
|
+
def relation_larger_than(relation, size)
|
11
|
+
initial_offset = relation.offset_value || 0
|
12
|
+
relation.offset(initial_offset + size).exists?
|
13
|
+
end
|
14
|
+
|
15
|
+
def relation_count(relation)
|
16
|
+
int_or_hash = if relation.respond_to?(:unscope)
|
17
|
+
relation.unscope(:order).count(:all)
|
18
|
+
else
|
19
|
+
# Rails 3
|
20
|
+
relation.count
|
21
|
+
end
|
22
|
+
if int_or_hash.is_a?(Integer)
|
23
|
+
int_or_hash
|
24
|
+
else
|
25
|
+
# Grouped relations return count-by-group hashes
|
26
|
+
int_or_hash.length
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def relation_limit(relation)
|
31
|
+
relation.limit_value
|
32
|
+
end
|
33
|
+
|
34
|
+
def relation_offset(relation)
|
35
|
+
relation.offset_value
|
36
|
+
end
|
37
|
+
|
38
|
+
def null_relation(relation)
|
39
|
+
if relation.respond_to?(:none)
|
40
|
+
relation.none
|
41
|
+
else
|
42
|
+
# Rails 3
|
43
|
+
relation.where("1=2")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|