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,454 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/query/arguments"
|
3
|
+
require "graphql/query/arguments_cache"
|
4
|
+
require "graphql/query/context"
|
5
|
+
require "graphql/query/executor"
|
6
|
+
require "graphql/query/fingerprint"
|
7
|
+
require "graphql/query/literal_input"
|
8
|
+
require "graphql/query/null_context"
|
9
|
+
require "graphql/query/result"
|
10
|
+
require "graphql/query/serial_execution"
|
11
|
+
require "graphql/query/variables"
|
12
|
+
require "graphql/query/input_validation_result"
|
13
|
+
require "graphql/query/variable_validation_error"
|
14
|
+
require "graphql/query/validation_pipeline"
|
15
|
+
|
16
|
+
module GraphQL
|
17
|
+
# A combination of query string and {Schema} instance which can be reduced to a {#result}.
|
18
|
+
class Query
|
19
|
+
include Tracing::Traceable
|
20
|
+
extend Forwardable
|
21
|
+
|
22
|
+
class OperationNameMissingError < GraphQL::ExecutionError
|
23
|
+
def initialize(name)
|
24
|
+
msg = if name.nil?
|
25
|
+
%|An operation name is required|
|
26
|
+
else
|
27
|
+
%|No operation named "#{name}"|
|
28
|
+
end
|
29
|
+
super(msg)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_reader :schema, :context, :provided_variables
|
34
|
+
|
35
|
+
# The value for root types
|
36
|
+
attr_accessor :root_value
|
37
|
+
|
38
|
+
# @return [nil, String] The operation name provided by client or the one inferred from the document. Used to determine which operation to run.
|
39
|
+
attr_accessor :operation_name
|
40
|
+
|
41
|
+
# @return [Boolean] if false, static validation is skipped (execution behavior for invalid queries is undefined)
|
42
|
+
attr_accessor :validate
|
43
|
+
|
44
|
+
attr_writer :query_string
|
45
|
+
|
46
|
+
# @return [GraphQL::Language::Nodes::Document]
|
47
|
+
def document
|
48
|
+
# It's ok if this hasn't been assigned yet
|
49
|
+
if @query_string || @document
|
50
|
+
with_prepared_ast { @document }
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def inspect
|
57
|
+
"query ..."
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [String, nil] The name of the operation to run (may be inferred)
|
61
|
+
def selected_operation_name
|
62
|
+
return nil unless selected_operation
|
63
|
+
selected_operation.name
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [String, nil] the triggered event, if this query is a subscription update
|
67
|
+
attr_reader :subscription_topic
|
68
|
+
|
69
|
+
attr_reader :tracers
|
70
|
+
|
71
|
+
# Prepare query `query_string` on `schema`
|
72
|
+
# @param schema [GraphQL::Schema]
|
73
|
+
# @param query_string [String]
|
74
|
+
# @param context [#[]] an arbitrary hash of values which you can access in {GraphQL::Field#resolve}
|
75
|
+
# @param variables [Hash] values for `$variables` in the query
|
76
|
+
# @param operation_name [String] if the query string contains many operations, this is the one which should be executed
|
77
|
+
# @param root_value [Object] the object used to resolve fields on the root type
|
78
|
+
# @param max_depth [Numeric] the maximum number of nested selections allowed for this query (falls back to schema-level value)
|
79
|
+
# @param max_complexity [Numeric] the maximum field complexity for this query (falls back to schema-level value)
|
80
|
+
# @param except [<#call(schema_member, context)>] If provided, objects will be hidden from the schema when `.call(schema_member, context)` returns truthy
|
81
|
+
# @param only [<#call(schema_member, context)>] If provided, objects will be hidden from the schema when `.call(schema_member, context)` returns false
|
82
|
+
def initialize(schema, query_string = nil, query: nil, document: nil, context: nil, variables: nil, validate: true, subscription_topic: nil, operation_name: nil, root_value: nil, max_depth: schema.max_depth, max_complexity: schema.max_complexity, except: nil, only: nil, warden: nil)
|
83
|
+
# Even if `variables: nil` is passed, use an empty hash for simpler logic
|
84
|
+
variables ||= {}
|
85
|
+
|
86
|
+
# Use the `.graphql_definition` here which will return legacy types instead of classes
|
87
|
+
if schema.is_a?(Class) && !schema.interpreter?
|
88
|
+
schema = schema.graphql_definition
|
89
|
+
end
|
90
|
+
@schema = schema
|
91
|
+
@interpreter = @schema.interpreter?
|
92
|
+
@filter = schema.default_filter.merge(except: except, only: only)
|
93
|
+
@context = schema.context_class.new(query: self, object: root_value, values: context)
|
94
|
+
@warden = warden
|
95
|
+
@subscription_topic = subscription_topic
|
96
|
+
@root_value = root_value
|
97
|
+
@fragments = nil
|
98
|
+
@operations = nil
|
99
|
+
@validate = validate
|
100
|
+
@tracers = schema.tracers + (context ? context.fetch(:tracers, []) : [])
|
101
|
+
# Support `ctx[:backtrace] = true` for wrapping backtraces
|
102
|
+
if context && context[:backtrace] && !@tracers.include?(GraphQL::Backtrace::Tracer)
|
103
|
+
@tracers << GraphQL::Backtrace::Tracer
|
104
|
+
end
|
105
|
+
|
106
|
+
@analysis_errors = []
|
107
|
+
if variables.is_a?(String)
|
108
|
+
raise ArgumentError, "Query variables should be a Hash, not a String. Try JSON.parse to prepare variables."
|
109
|
+
else
|
110
|
+
@provided_variables = variables || {}
|
111
|
+
end
|
112
|
+
|
113
|
+
@query_string = query_string || query
|
114
|
+
@document = document
|
115
|
+
|
116
|
+
if @query_string && @document
|
117
|
+
raise ArgumentError, "Query should only be provided a query string or a document, not both."
|
118
|
+
end
|
119
|
+
|
120
|
+
if @query_string && !@query_string.is_a?(String)
|
121
|
+
raise ArgumentError, "Query string argument should be a String, got #{@query_string.class.name} instead."
|
122
|
+
end
|
123
|
+
|
124
|
+
# A two-layer cache of type resolution:
|
125
|
+
# { abstract_type => { value => resolved_type } }
|
126
|
+
@resolved_types_cache = Hash.new do |h1, k1|
|
127
|
+
h1[k1] = Hash.new do |h2, k2|
|
128
|
+
h2[k2] = @schema.resolve_type(k1, k2, @context)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Trying to execute a document
|
133
|
+
# with no operations returns an empty hash
|
134
|
+
@ast_variables = []
|
135
|
+
@mutation = false
|
136
|
+
@operation_name = operation_name
|
137
|
+
@prepared_ast = false
|
138
|
+
@validation_pipeline = nil
|
139
|
+
@max_depth = max_depth
|
140
|
+
@max_complexity = max_complexity
|
141
|
+
|
142
|
+
@result_values = nil
|
143
|
+
@executed = false
|
144
|
+
|
145
|
+
# TODO add a general way to define schema-level filters
|
146
|
+
if @schema.respond_to?(:visible?)
|
147
|
+
merge_filters(only: @schema.method(:visible?))
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# If a document was provided to `GraphQL::Schema#execute` instead of the raw query string, we will need to get it from the document
|
152
|
+
def query_string
|
153
|
+
@query_string ||= (document ? document.to_query_string : nil)
|
154
|
+
end
|
155
|
+
|
156
|
+
def interpreter?
|
157
|
+
@interpreter
|
158
|
+
end
|
159
|
+
|
160
|
+
attr_accessor :multiplex
|
161
|
+
|
162
|
+
def subscription_update?
|
163
|
+
@subscription_topic && subscription?
|
164
|
+
end
|
165
|
+
|
166
|
+
# A lookahead for the root selections of this query
|
167
|
+
# @return [GraphQL::Execution::Lookahead]
|
168
|
+
def lookahead
|
169
|
+
@lookahead ||= begin
|
170
|
+
ast_node = selected_operation
|
171
|
+
root_type = warden.root_type_for_operation(ast_node.operation_type || "query")
|
172
|
+
root_type = root_type.type_class || raise("Invariant: `lookahead` only works with class-based types")
|
173
|
+
GraphQL::Execution::Lookahead.new(query: self, root_type: root_type, ast_nodes: [ast_node])
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# @api private
|
178
|
+
def result_values=(result_hash)
|
179
|
+
if @executed
|
180
|
+
raise "Invariant: Can't reassign result"
|
181
|
+
else
|
182
|
+
@executed = true
|
183
|
+
@result_values = result_hash
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# @api private
|
188
|
+
attr_reader :result_values
|
189
|
+
|
190
|
+
def fragments
|
191
|
+
with_prepared_ast { @fragments }
|
192
|
+
end
|
193
|
+
|
194
|
+
def operations
|
195
|
+
with_prepared_ast { @operations }
|
196
|
+
end
|
197
|
+
|
198
|
+
# Get the result for this query, executing it once
|
199
|
+
# @return [Hash] A GraphQL response, with `"data"` and/or `"errors"` keys
|
200
|
+
def result
|
201
|
+
if !@executed
|
202
|
+
Execution::Multiplex.run_queries(@schema, [self], context: @context)
|
203
|
+
end
|
204
|
+
@result ||= Query::Result.new(query: self, values: @result_values)
|
205
|
+
end
|
206
|
+
|
207
|
+
def executed?
|
208
|
+
@executed
|
209
|
+
end
|
210
|
+
|
211
|
+
def static_errors
|
212
|
+
validation_errors + analysis_errors + context.errors
|
213
|
+
end
|
214
|
+
|
215
|
+
# This is the operation to run for this query.
|
216
|
+
# If more than one operation is present, it must be named at runtime.
|
217
|
+
# @return [GraphQL::Language::Nodes::OperationDefinition, nil]
|
218
|
+
def selected_operation
|
219
|
+
with_prepared_ast { @selected_operation }
|
220
|
+
end
|
221
|
+
|
222
|
+
# Determine the values for variables of this query, using default values
|
223
|
+
# if a value isn't provided at runtime.
|
224
|
+
#
|
225
|
+
# If some variable is invalid, errors are added to {#validation_errors}.
|
226
|
+
#
|
227
|
+
# @return [GraphQL::Query::Variables] Variables to apply to this query
|
228
|
+
def variables
|
229
|
+
@variables ||= begin
|
230
|
+
with_prepared_ast {
|
231
|
+
GraphQL::Query::Variables.new(
|
232
|
+
@context,
|
233
|
+
@ast_variables,
|
234
|
+
@provided_variables,
|
235
|
+
)
|
236
|
+
}
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def irep_selection
|
241
|
+
@selection ||= begin
|
242
|
+
if selected_operation && internal_representation
|
243
|
+
internal_representation.operation_definitions[selected_operation.name]
|
244
|
+
else
|
245
|
+
nil
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# Node-level cache for calculating arguments. Used during execution and query analysis.
|
251
|
+
# @param ast_node [GraphQL::Language::Nodes::AbstractNode]
|
252
|
+
# @param definition [GraphQL::Schema::Field]
|
253
|
+
# @param parent_object [GraphQL::Schema::Object]
|
254
|
+
# @return Hash{Symbol => Object}
|
255
|
+
def arguments_for(ast_node, definition, parent_object: nil)
|
256
|
+
if interpreter?
|
257
|
+
arguments_cache.fetch(ast_node, definition, parent_object)
|
258
|
+
else
|
259
|
+
arguments_cache[ast_node][definition]
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def arguments_cache
|
264
|
+
if interpreter?
|
265
|
+
@arguments_cache ||= Execution::Interpreter::ArgumentsCache.new(self)
|
266
|
+
else
|
267
|
+
@arguments_cache ||= ArgumentsCache.build(self)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
# A version of the given query string, with:
|
272
|
+
# - Variables inlined to the query
|
273
|
+
# - Strings replaced with `<REDACTED>`
|
274
|
+
# @return [String, nil] Returns nil if the query is invalid.
|
275
|
+
def sanitized_query_string(inline_variables: true)
|
276
|
+
with_prepared_ast {
|
277
|
+
schema.sanitized_printer.new(self, inline_variables: inline_variables).sanitized_query_string
|
278
|
+
}
|
279
|
+
end
|
280
|
+
|
281
|
+
# This contains a few components:
|
282
|
+
#
|
283
|
+
# - The selected operation name (or `anonymous`)
|
284
|
+
# - The fingerprint of the query string
|
285
|
+
# - The number of given variables (for readability)
|
286
|
+
# - The fingerprint of the given variables
|
287
|
+
#
|
288
|
+
# This fingerprint can be used to track runs of the same operation-variables combination over time.
|
289
|
+
#
|
290
|
+
# @see operation_fingerprint
|
291
|
+
# @see variables_fingerprint
|
292
|
+
# @return [String] An opaque hash identifying this operation-variables combination
|
293
|
+
def fingerprint
|
294
|
+
@fingerprint ||= "#{operation_fingerprint}/#{variables_fingerprint}"
|
295
|
+
end
|
296
|
+
|
297
|
+
# @return [String] An opaque hash for identifying this query's given query string and selected operation
|
298
|
+
def operation_fingerprint
|
299
|
+
@operation_fingerprint ||= "#{selected_operation_name || "anonymous"}/#{Fingerprint.generate(query_string)}"
|
300
|
+
end
|
301
|
+
|
302
|
+
# @return [String] An opaque hash for identifying this query's given a variable values (not including defaults)
|
303
|
+
def variables_fingerprint
|
304
|
+
@variables_fingerprint ||= "#{provided_variables.size}/#{Fingerprint.generate(provided_variables.to_json)}"
|
305
|
+
end
|
306
|
+
|
307
|
+
def validation_pipeline
|
308
|
+
with_prepared_ast { @validation_pipeline }
|
309
|
+
end
|
310
|
+
|
311
|
+
def_delegators :validation_pipeline, :validation_errors, :internal_representation,
|
312
|
+
:analyzers, :ast_analyzers, :max_depth, :max_complexity
|
313
|
+
|
314
|
+
attr_accessor :analysis_errors
|
315
|
+
def valid?
|
316
|
+
validation_pipeline.valid? && analysis_errors.empty?
|
317
|
+
end
|
318
|
+
|
319
|
+
def warden
|
320
|
+
with_prepared_ast { @warden }
|
321
|
+
end
|
322
|
+
|
323
|
+
def_delegators :warden, :get_type, :get_field, :possible_types, :root_type_for_operation
|
324
|
+
|
325
|
+
# @param abstract_type [GraphQL::UnionType, GraphQL::InterfaceType]
|
326
|
+
# @param value [Object] Any runtime value
|
327
|
+
# @return [GraphQL::ObjectType, nil] The runtime type of `value` from {Schema#resolve_type}
|
328
|
+
# @see {#possible_types} to apply filtering from `only` / `except`
|
329
|
+
def resolve_type(abstract_type, value = :__undefined__)
|
330
|
+
if value.is_a?(Symbol) && value == :__undefined__
|
331
|
+
# Old method signature
|
332
|
+
value = abstract_type
|
333
|
+
abstract_type = nil
|
334
|
+
end
|
335
|
+
if value.is_a?(GraphQL::Schema::Object)
|
336
|
+
value = value.object
|
337
|
+
end
|
338
|
+
@resolved_types_cache[abstract_type][value]
|
339
|
+
end
|
340
|
+
|
341
|
+
def mutation?
|
342
|
+
with_prepared_ast { @mutation }
|
343
|
+
end
|
344
|
+
|
345
|
+
def query?
|
346
|
+
with_prepared_ast { @query }
|
347
|
+
end
|
348
|
+
|
349
|
+
# @return [void]
|
350
|
+
def merge_filters(only: nil, except: nil)
|
351
|
+
if @prepared_ast
|
352
|
+
raise "Can't add filters after preparing the query"
|
353
|
+
else
|
354
|
+
@filter = @filter.merge(only: only, except: except)
|
355
|
+
end
|
356
|
+
nil
|
357
|
+
end
|
358
|
+
|
359
|
+
def subscription?
|
360
|
+
with_prepared_ast { @subscription }
|
361
|
+
end
|
362
|
+
|
363
|
+
# @api private
|
364
|
+
def with_error_handling
|
365
|
+
schema.error_handler.with_error_handling(context) do
|
366
|
+
yield
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
private
|
371
|
+
|
372
|
+
def find_operation(operations, operation_name)
|
373
|
+
if operation_name.nil? && operations.length == 1
|
374
|
+
operations.values.first
|
375
|
+
elsif !operations.key?(operation_name)
|
376
|
+
nil
|
377
|
+
else
|
378
|
+
operations.fetch(operation_name)
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
def prepare_ast
|
383
|
+
@prepared_ast = true
|
384
|
+
@warden ||= GraphQL::Schema::Warden.new(@filter, schema: @schema, context: @context)
|
385
|
+
parse_error = nil
|
386
|
+
@document ||= begin
|
387
|
+
if query_string
|
388
|
+
GraphQL.parse(query_string, tracer: self)
|
389
|
+
end
|
390
|
+
rescue GraphQL::ParseError => err
|
391
|
+
parse_error = err
|
392
|
+
@schema.parse_error(err, @context)
|
393
|
+
nil
|
394
|
+
end
|
395
|
+
|
396
|
+
@fragments = {}
|
397
|
+
@operations = {}
|
398
|
+
if @document
|
399
|
+
@document.definitions.each do |part|
|
400
|
+
case part
|
401
|
+
when GraphQL::Language::Nodes::FragmentDefinition
|
402
|
+
@fragments[part.name] = part
|
403
|
+
when GraphQL::Language::Nodes::OperationDefinition
|
404
|
+
@operations[part.name] = part
|
405
|
+
end
|
406
|
+
end
|
407
|
+
elsif parse_error
|
408
|
+
# This will be handled later
|
409
|
+
else
|
410
|
+
parse_error = GraphQL::ExecutionError.new("No query string was present")
|
411
|
+
@context.add_error(parse_error)
|
412
|
+
end
|
413
|
+
|
414
|
+
# Trying to execute a document
|
415
|
+
# with no operations returns an empty hash
|
416
|
+
@ast_variables = []
|
417
|
+
@mutation = false
|
418
|
+
@subscription = false
|
419
|
+
operation_name_error = nil
|
420
|
+
if @operations.any?
|
421
|
+
@selected_operation = find_operation(@operations, @operation_name)
|
422
|
+
if @selected_operation.nil?
|
423
|
+
operation_name_error = GraphQL::Query::OperationNameMissingError.new(@operation_name)
|
424
|
+
else
|
425
|
+
if @operation_name.nil?
|
426
|
+
@operation_name = @selected_operation.name
|
427
|
+
end
|
428
|
+
@ast_variables = @selected_operation.variables
|
429
|
+
@mutation = @selected_operation.operation_type == "mutation"
|
430
|
+
@query = @selected_operation.operation_type == "query"
|
431
|
+
@subscription = @selected_operation.operation_type == "subscription"
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
@validation_pipeline = GraphQL::Query::ValidationPipeline.new(
|
436
|
+
query: self,
|
437
|
+
validate: @validate,
|
438
|
+
parse_error: parse_error,
|
439
|
+
operation_name_error: operation_name_error,
|
440
|
+
max_depth: @max_depth,
|
441
|
+
max_complexity: @max_complexity
|
442
|
+
)
|
443
|
+
end
|
444
|
+
|
445
|
+
# Since the query string is processed at the last possible moment,
|
446
|
+
# any internal values which depend on it should be accessed within this wrapper.
|
447
|
+
def with_prepared_ast
|
448
|
+
if !@prepared_ast
|
449
|
+
prepare_ast
|
450
|
+
end
|
451
|
+
yield
|
452
|
+
end
|
453
|
+
end
|
454
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
config.before_configuration do
|
6
|
+
# Bootsnap compile cache has similar expiration properties,
|
7
|
+
# so we assume that if the user has bootsnap setup it's ok
|
8
|
+
# to piggy back on it.
|
9
|
+
if ::Object.const_defined?("Bootsnap::CompileCache::ISeq") && Bootsnap::CompileCache::ISeq.cache_dir
|
10
|
+
Language::Parser.cache ||= Language::Cache.new(Pathname.new(Bootsnap::CompileCache::ISeq.cache_dir).join('graphql'))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
rake_tasks do
|
15
|
+
# Defer this so that you only need the `parser` gem when you _run_ the upgrader
|
16
|
+
def load_upgraders
|
17
|
+
require_relative './upgrader/member'
|
18
|
+
require_relative './upgrader/schema'
|
19
|
+
end
|
20
|
+
|
21
|
+
namespace :graphql do
|
22
|
+
task :upgrade, [:dir] do |t, args|
|
23
|
+
unless (dir = args[:dir])
|
24
|
+
fail 'You have to give me a directory where your GraphQL schema and types live. ' \
|
25
|
+
'For example: `bin/rake graphql:upgrade[app/graphql/**/*]`'
|
26
|
+
end
|
27
|
+
|
28
|
+
Dir[dir].each do |file|
|
29
|
+
# Members (types, interfaces, etc.)
|
30
|
+
if file =~ /.*_(type|interface|enum|union|)\.rb$/
|
31
|
+
Rake::Task["graphql:upgrade:member"].execute(Struct.new(:member_file).new(file))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
puts "Upgrade complete! Note that this is a best-effort approach, and may very well contain some bugs."
|
36
|
+
puts "Don't forget to create the base objects. For example, you could run:"
|
37
|
+
puts "\tbin/rake graphql:upgrade:create_base_objects[app/graphql]"
|
38
|
+
end
|
39
|
+
|
40
|
+
namespace :upgrade do
|
41
|
+
task :create_base_objects, [:base_dir] do |t, args|
|
42
|
+
unless (base_dir = args[:base_dir])
|
43
|
+
fail 'You have to give me a directory where your GraphQL types live. ' \
|
44
|
+
'For example: `bin/rake graphql:upgrade:create_base_objects[app/graphql]`'
|
45
|
+
end
|
46
|
+
|
47
|
+
destination_file = File.join(base_dir, "types", "base_scalar.rb")
|
48
|
+
unless File.exists?(destination_file)
|
49
|
+
FileUtils.mkdir_p(File.dirname(destination_file))
|
50
|
+
File.open(destination_file, 'w') do |f|
|
51
|
+
f.puts "class Types::BaseScalar < GraphQL::Schema::Scalar\nend"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
destination_file = File.join(base_dir, "types", "base_input_object.rb")
|
56
|
+
unless File.exists?(destination_file)
|
57
|
+
FileUtils.mkdir_p(File.dirname(destination_file))
|
58
|
+
File.open(destination_file, 'w') do |f|
|
59
|
+
f.puts "class Types::BaseInputObject < GraphQL::Schema::InputObject\nend"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
destination_file = File.join(base_dir, "types", "base_enum.rb")
|
64
|
+
unless File.exists?(destination_file)
|
65
|
+
FileUtils.mkdir_p(File.dirname(destination_file))
|
66
|
+
File.open(destination_file, 'w') do |f|
|
67
|
+
f.puts "class Types::BaseEnum < GraphQL::Schema::Enum\nend"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
destination_file = File.join(base_dir, "types", "base_union.rb")
|
72
|
+
unless File.exists?(destination_file)
|
73
|
+
FileUtils.mkdir_p(File.dirname(destination_file))
|
74
|
+
File.open(destination_file, 'w') do |f|
|
75
|
+
f.puts "class Types::BaseUnion < GraphQL::Schema::Union\nend"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
destination_file = File.join(base_dir, "types", "base_interface.rb")
|
80
|
+
unless File.exists?(destination_file)
|
81
|
+
FileUtils.mkdir_p(File.dirname(destination_file))
|
82
|
+
File.open(destination_file, 'w') do |f|
|
83
|
+
f.puts "module Types::BaseInterface\n include GraphQL::Schema::Interface\nend"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
destination_file = File.join(base_dir, "types", "base_object.rb")
|
88
|
+
unless File.exists?(destination_file)
|
89
|
+
File.open(destination_file, 'w') do |f|
|
90
|
+
f.puts "class Types::BaseObject < GraphQL::Schema::Object\nend"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
task :schema, [:schema_file] do |t, args|
|
96
|
+
schema_file = args.schema_file
|
97
|
+
load_upgraders
|
98
|
+
upgrader = GraphQL::Upgrader::Schema.new File.read(schema_file)
|
99
|
+
|
100
|
+
puts "- Transforming schema #{schema_file}"
|
101
|
+
File.open(schema_file, 'w') { |f| f.write upgrader.upgrade }
|
102
|
+
end
|
103
|
+
|
104
|
+
task :member, [:member_file] do |t, args|
|
105
|
+
member_file = args.member_file
|
106
|
+
load_upgraders
|
107
|
+
upgrader = GraphQL::Upgrader::Member.new File.read(member_file)
|
108
|
+
next unless upgrader.upgradeable?
|
109
|
+
|
110
|
+
puts "- Transforming member #{member_file}"
|
111
|
+
File.open(member_file, 'w') { |f| f.write upgrader.upgrade }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class RakeTask
|
5
|
+
extend Rake::DSL
|
6
|
+
|
7
|
+
desc "Get the checksum of a graphql-pro version and compare it to published versions on GitHub and graphql-ruby.org"
|
8
|
+
task "graphql:pro:validate", [:gem_version] do |t, args|
|
9
|
+
version = args[:gem_version]
|
10
|
+
if version.nil?
|
11
|
+
raise ArgumentError, "A specific version is required, eg `rake graphql:pro:validate[1.12.0]`"
|
12
|
+
end
|
13
|
+
check = "\e[32m✓\e[0m"
|
14
|
+
ex = "\e[31m✘\e[0m"
|
15
|
+
puts "Validating graphql-pro v#{version}"
|
16
|
+
puts " - Checking for graphql-pro credentials..."
|
17
|
+
|
18
|
+
creds = `bundle config gems.graphql.pro`[/[a-z0-9]{11}:[a-z0-9]{11}/]
|
19
|
+
if creds.nil?
|
20
|
+
puts " #{ex} failed, please set with `bundle config gems.graphql.pro $MY_CREDENTIALS`"
|
21
|
+
exit(1)
|
22
|
+
else
|
23
|
+
puts " #{check} found"
|
24
|
+
end
|
25
|
+
|
26
|
+
puts " - Fetching the gem..."
|
27
|
+
fetch_result = `gem fetch graphql-pro -v #{version} --source https://#{creds}@gems.graphql.pro`
|
28
|
+
if fetch_result.empty?
|
29
|
+
puts " #{ex} failed to fetch v#{version}"
|
30
|
+
exit(1)
|
31
|
+
else
|
32
|
+
puts " #{check} fetched"
|
33
|
+
end
|
34
|
+
|
35
|
+
puts " - Validating digest..."
|
36
|
+
require "digest/sha2"
|
37
|
+
gem_digest = Digest::SHA512.new.hexdigest(File.read("graphql-pro-#{version}.gem"))
|
38
|
+
require "net/http"
|
39
|
+
github_uri = URI("https://raw.githubusercontent.com/rmosolgo/graphql-ruby/master/guides/pro/checksums/graphql-pro-#{version}.txt")
|
40
|
+
# Remove final newline from .txt file
|
41
|
+
github_digest = Net::HTTP.get(github_uri).chomp
|
42
|
+
|
43
|
+
docs_uri = URI("https://graphql-ruby.org/pro/checksums/graphql-pro-#{version}.txt")
|
44
|
+
docs_digest = Net::HTTP.get(docs_uri).chomp
|
45
|
+
|
46
|
+
if docs_digest == gem_digest && github_digest == gem_digest
|
47
|
+
puts " #{check} validated from GitHub"
|
48
|
+
puts " #{check} validated from graphql-ruby.org"
|
49
|
+
else
|
50
|
+
puts " #{ex} SHA mismatch:"
|
51
|
+
puts " Downloaded: #{gem_digest}"
|
52
|
+
puts " GitHub: #{github_digest}"
|
53
|
+
puts " graphql-ruby.org: #{docs_digest}"
|
54
|
+
puts ""
|
55
|
+
puts " This download of graphql-pro is invalid, please open an issue:"
|
56
|
+
puts " https://github.com/rmosolgo/graphql-ruby/issues/new?title=graphql-pro%20digest%20mismatch%20(#{version})"
|
57
|
+
exit(1)
|
58
|
+
end
|
59
|
+
|
60
|
+
puts "\e[32m✔\e[0m graphql-pro #{version} validated successfully!"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|