graphql 0.16.0 → 2.0.15
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.
Potentially problematic release.
This version of graphql might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.yardopts +5 -0
- data/lib/generators/graphql/core.rb +69 -0
- data/lib/generators/graphql/enum_generator.rb +27 -0
- data/lib/generators/graphql/field_extractor.rb +31 -0
- data/lib/generators/graphql/input_generator.rb +50 -0
- data/lib/generators/graphql/install/mutation_root_generator.rb +34 -0
- data/lib/generators/graphql/install/templates/base_mutation.erb +10 -0
- data/lib/generators/graphql/install/templates/mutation_type.erb +12 -0
- data/lib/generators/graphql/install_generator.rb +197 -0
- data/lib/generators/graphql/interface_generator.rb +27 -0
- data/lib/generators/graphql/loader_generator.rb +21 -0
- data/lib/generators/graphql/mutation_create_generator.rb +22 -0
- data/lib/generators/graphql/mutation_delete_generator.rb +22 -0
- data/lib/generators/graphql/mutation_generator.rb +30 -0
- data/lib/generators/graphql/mutation_update_generator.rb +22 -0
- data/lib/generators/graphql/object_generator.rb +50 -0
- data/lib/generators/graphql/orm_mutations_base.rb +40 -0
- data/lib/generators/graphql/relay.rb +49 -0
- data/lib/generators/graphql/relay_generator.rb +21 -0
- data/lib/generators/graphql/scalar_generator.rb +22 -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_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 +11 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +52 -0
- data/lib/generators/graphql/templates/input.erb +9 -0
- data/lib/generators/graphql/templates/interface.erb +10 -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_create.erb +20 -0
- data/lib/generators/graphql/templates/mutation_delete.erb +20 -0
- data/lib/generators/graphql/templates/mutation_update.erb +21 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +10 -0
- data/lib/generators/graphql/templates/query_type.erb +15 -0
- data/lib/generators/graphql/templates/scalar.erb +17 -0
- data/lib/generators/graphql/templates/schema.erb +30 -0
- data/lib/generators/graphql/templates/union.erb +9 -0
- data/lib/generators/graphql/type_generator.rb +135 -0
- data/lib/generators/graphql/union_generator.rb +33 -0
- data/lib/graphql/analysis/ast/analyzer.rb +84 -0
- data/lib/graphql/analysis/ast/field_usage.rb +57 -0
- data/lib/graphql/analysis/ast/max_query_complexity.rb +22 -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 +55 -0
- data/lib/graphql/analysis/ast/visitor.rb +269 -0
- data/lib/graphql/analysis/ast.rb +81 -0
- data/lib/graphql/analysis.rb +2 -5
- data/lib/graphql/analysis_error.rb +1 -0
- data/lib/graphql/backtrace/inspect_result.rb +50 -0
- data/lib/graphql/backtrace/table.rb +141 -0
- data/lib/graphql/backtrace/traced_error.rb +54 -0
- data/lib/graphql/backtrace/tracer.rb +80 -0
- data/lib/graphql/backtrace.rb +58 -0
- data/lib/graphql/coercion_error.rb +13 -0
- data/lib/graphql/dataloader/null_dataloader.rb +24 -0
- data/lib/graphql/dataloader/request.rb +19 -0
- data/lib/graphql/dataloader/request_all.rb +19 -0
- data/lib/graphql/dataloader/source.rb +164 -0
- data/lib/graphql/dataloader.rb +311 -0
- data/lib/graphql/date_encoding_error.rb +16 -0
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/dig.rb +19 -0
- data/lib/graphql/execution/directive_checks.rb +37 -0
- data/lib/graphql/execution/errors.rb +93 -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 +105 -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 +77 -0
- data/lib/graphql/execution/interpreter/runtime.rb +994 -0
- data/lib/graphql/execution/interpreter.rb +226 -0
- data/lib/graphql/execution/lazy/lazy_method_map.rb +98 -0
- data/lib/graphql/execution/lazy.rb +75 -0
- data/lib/graphql/execution/lookahead.rb +311 -0
- data/lib/graphql/execution/multiplex.rb +45 -0
- data/lib/graphql/execution.rb +18 -0
- data/lib/graphql/execution_error.rb +34 -1
- data/lib/graphql/filter.rb +53 -0
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +36 -0
- data/lib/graphql/introspection/base_object.rb +13 -0
- data/lib/graphql/introspection/directive_location_enum.rb +12 -5
- data/lib/graphql/introspection/directive_type.rb +30 -10
- data/lib/graphql/introspection/dynamic_fields.rb +12 -0
- data/lib/graphql/introspection/entry_points.rb +22 -0
- data/lib/graphql/introspection/enum_value_type.rb +21 -8
- data/lib/graphql/introspection/field_type.rb +26 -10
- data/lib/graphql/introspection/input_value_type.rb +64 -14
- data/lib/graphql/introspection/introspection_query.rb +7 -76
- data/lib/graphql/introspection/schema_type.rb +42 -17
- data/lib/graphql/introspection/type_kind_enum.rb +11 -5
- data/lib/graphql/introspection/type_type.rb +104 -16
- data/lib/graphql/introspection.rb +104 -13
- data/lib/graphql/invalid_name_error.rb +11 -0
- data/lib/graphql/invalid_null_error.rb +36 -8
- 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 +335 -0
- data/lib/graphql/language/generation.rb +16 -86
- data/lib/graphql/language/lexer.rb +1436 -705
- data/lib/graphql/language/lexer.rl +172 -64
- data/lib/graphql/language/nodes.rb +617 -105
- data/lib/graphql/language/parser.rb +1524 -430
- data/lib/graphql/language/parser.y +348 -73
- data/lib/graphql/language/printer.rb +386 -0
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/token.rb +16 -3
- data/lib/graphql/language/visitor.rb +169 -25
- data/lib/graphql/language.rb +30 -0
- data/lib/graphql/load_application_object_failed_error.rb +22 -0
- data/lib/graphql/name_validator.rb +11 -0
- data/lib/graphql/pagination/active_record_relation_connection.rb +85 -0
- data/lib/graphql/pagination/array_connection.rb +79 -0
- data/lib/graphql/pagination/connection.rb +253 -0
- data/lib/graphql/pagination/connections.rb +135 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +228 -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/context.rb +266 -12
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +34 -7
- data/lib/graphql/query/null_context.rb +52 -0
- data/lib/graphql/query/result.rb +63 -0
- data/lib/graphql/query/validation_pipeline.rb +114 -0
- data/lib/graphql/query/variable_validation_error.rb +27 -3
- data/lib/graphql/query/variables.rb +75 -24
- data/lib/graphql/query.rb +359 -92
- data/lib/graphql/railtie.rb +13 -0
- data/lib/graphql/rake_task/validate.rb +63 -0
- data/lib/graphql/rake_task.rb +146 -0
- data/lib/graphql/relay/range_add.rb +52 -0
- data/lib/graphql/relay.rb +3 -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/schema/addition.rb +245 -0
- data/lib/graphql/schema/argument.rb +395 -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 +492 -0
- data/lib/graphql/schema/built_in_types.rb +12 -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/one_of.rb +12 -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 +212 -0
- data/lib/graphql/schema/enum.rb +176 -0
- data/lib/graphql/schema/enum_value.rb +77 -0
- data/lib/graphql/schema/field/connection_extension.rb +80 -0
- data/lib/graphql/schema/field/scope_extension.rb +22 -0
- data/lib/graphql/schema/field.rb +862 -0
- data/lib/graphql/schema/field_extension.rb +156 -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 +258 -0
- data/lib/graphql/schema/interface.rb +113 -0
- data/lib/graphql/schema/introspection_system.rb +164 -0
- data/lib/graphql/schema/invalid_type_error.rb +1 -0
- data/lib/graphql/schema/late_bound_type.rb +37 -0
- data/lib/graphql/schema/list.rb +86 -0
- data/lib/graphql/schema/loader.rb +228 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +124 -0
- data/lib/graphql/schema/member/build_type.rb +178 -0
- data/lib/graphql/schema/member/graphql_type_names.rb +21 -0
- data/lib/graphql/schema/member/has_arguments.rb +376 -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 +113 -0
- data/lib/graphql/schema/member/has_fields.rb +163 -0
- data/lib/graphql/schema/member/has_interfaces.rb +88 -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/relay_shortcuts.rb +73 -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 +39 -0
- data/lib/graphql/schema/mutation.rb +85 -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 +117 -0
- data/lib/graphql/schema/printer.rb +72 -128
- data/lib/graphql/schema/relay_classic_mutation.rb +179 -0
- data/lib/graphql/schema/resolver/has_payload_type.rb +106 -0
- data/lib/graphql/schema/resolver.rb +402 -0
- data/lib/graphql/schema/scalar.rb +68 -0
- data/lib/graphql/schema/subscription.rb +148 -0
- data/lib/graphql/schema/timeout.rb +123 -0
- data/lib/graphql/schema/type_expression.rb +29 -5
- data/lib/graphql/schema/type_membership.rb +51 -0
- data/lib/graphql/schema/union.rb +81 -0
- data/lib/graphql/schema/unique_within_type.rb +34 -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 +82 -0
- data/lib/graphql/schema/validator.rb +171 -0
- data/lib/graphql/schema/warden.rb +413 -0
- data/lib/graphql/schema/wrapper.rb +24 -0
- data/lib/graphql/schema.rb +1179 -104
- data/lib/graphql/static_validation/all_rules.rb +14 -0
- data/lib/graphql/static_validation/base_visitor.rb +200 -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 +113 -22
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +59 -11
- 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 +62 -8
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +37 -0
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +20 -13
- 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 +32 -26
- 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 +21 -23
- 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 +55 -18
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +390 -70
- 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 +54 -37
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible_error.rb +35 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +26 -16
- data/lib/graphql/static_validation/rules/fragment_types_exist_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +13 -19
- 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 +25 -20
- 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 +22 -33
- 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/one_of_input_objects_are_valid.rb +66 -0
- data/lib/graphql/static_validation/rules/one_of_input_objects_are_valid_error.rb +29 -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/query_root_exists.rb +17 -0
- data/lib/graphql/static_validation/rules/query_root_exists_error.rb +26 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +22 -21
- 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 +56 -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 +36 -18
- 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 +103 -39
- 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 +22 -14
- 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 +92 -70
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb +37 -0
- data/lib/graphql/static_validation/type_stack.rb +85 -24
- data/lib/graphql/static_validation/validation_context.rb +25 -46
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +46 -15
- data/lib/graphql/static_validation.rb +6 -3
- data/lib/graphql/string_encoding_error.rb +20 -0
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +247 -0
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +81 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +58 -0
- data/lib/graphql/subscriptions/event.rb +144 -0
- data/lib/graphql/subscriptions/instrumentation.rb +28 -0
- data/lib/graphql/subscriptions/serialize.rb +158 -0
- data/lib/graphql/subscriptions.rb +306 -0
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +21 -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 +100 -0
- data/lib/graphql/tracing/instrumentation_tracing.rb +83 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +51 -0
- data/lib/graphql/tracing/notifications_tracing.rb +59 -0
- data/lib/graphql/tracing/platform_tracing.rb +122 -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/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +94 -0
- data/lib/graphql/type_kinds.rb +50 -22
- 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 +45 -0
- data/lib/graphql/types/iso_8601_date_time.rb +76 -0
- data/lib/graphql/types/json.rb +25 -0
- data/lib/graphql/types/relay/base_connection.rb +49 -0
- data/lib/graphql/types/relay/base_edge.rb +29 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +154 -0
- data/lib/graphql/types/relay/default_relay.rb +21 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +64 -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 +19 -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 +39 -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/unresolved_type_error.rb +35 -0
- data/lib/graphql/version.rb +2 -1
- data/lib/graphql.rb +86 -41
- data/readme.md +15 -101
- metadata +394 -279
- data/lib/graphql/analysis/analyze_query.rb +0 -73
- data/lib/graphql/analysis/max_query_complexity.rb +0 -25
- data/lib/graphql/analysis/max_query_depth.rb +0 -25
- data/lib/graphql/analysis/query_complexity.rb +0 -122
- data/lib/graphql/analysis/query_depth.rb +0 -54
- data/lib/graphql/argument.rb +0 -25
- data/lib/graphql/base_type.rb +0 -115
- data/lib/graphql/boolean_type.rb +0 -9
- data/lib/graphql/define/assign_argument.rb +0 -20
- data/lib/graphql/define/assign_enum_value.rb +0 -16
- data/lib/graphql/define/assign_object_field.rb +0 -21
- data/lib/graphql/define/assignment_dictionary.rb +0 -26
- data/lib/graphql/define/defined_object_proxy.rb +0 -32
- data/lib/graphql/define/instance_definable.rb +0 -79
- data/lib/graphql/define/non_null_with_bang.rb +0 -15
- data/lib/graphql/define/type_definer.rb +0 -30
- data/lib/graphql/define.rb +0 -8
- data/lib/graphql/directive/include_directive.rb +0 -10
- data/lib/graphql/directive/skip_directive.rb +0 -11
- data/lib/graphql/directive.rb +0 -49
- data/lib/graphql/enum_type.rb +0 -95
- data/lib/graphql/field.rb +0 -131
- data/lib/graphql/float_type.rb +0 -5
- data/lib/graphql/id_type.rb +0 -12
- data/lib/graphql/input_object_type.rb +0 -71
- data/lib/graphql/int_type.rb +0 -5
- data/lib/graphql/interface_type.rb +0 -38
- data/lib/graphql/internal_representation/node.rb +0 -81
- data/lib/graphql/internal_representation/rewrite.rb +0 -177
- data/lib/graphql/internal_representation.rb +0 -2
- data/lib/graphql/introspection/arguments_field.rb +0 -5
- data/lib/graphql/introspection/enum_values_field.rb +0 -13
- data/lib/graphql/introspection/fields_field.rb +0 -13
- data/lib/graphql/introspection/input_fields_field.rb +0 -12
- data/lib/graphql/introspection/interfaces_field.rb +0 -5
- data/lib/graphql/introspection/of_type_field.rb +0 -6
- data/lib/graphql/introspection/possible_types_field.rb +0 -11
- data/lib/graphql/introspection/schema_field.rb +0 -15
- data/lib/graphql/introspection/type_by_name_field.rb +0 -16
- data/lib/graphql/introspection/typename_field.rb +0 -15
- data/lib/graphql/list_type.rb +0 -46
- data/lib/graphql/non_null_type.rb +0 -43
- data/lib/graphql/object_type.rb +0 -93
- data/lib/graphql/query/arguments.rb +0 -76
- data/lib/graphql/query/directive_resolution.rb +0 -16
- data/lib/graphql/query/executor.rb +0 -45
- data/lib/graphql/query/literal_input.rb +0 -90
- data/lib/graphql/query/serial_execution/execution_context.rb +0 -31
- data/lib/graphql/query/serial_execution/field_resolution.rb +0 -82
- data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -27
- data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -42
- data/lib/graphql/query/serial_execution/value_resolution.rb +0 -107
- data/lib/graphql/query/serial_execution.rb +0 -41
- data/lib/graphql/query/type_resolver.rb +0 -25
- data/lib/graphql/scalar_type.rb +0 -53
- data/lib/graphql/schema/catchall_middleware.rb +0 -34
- data/lib/graphql/schema/middleware_chain.rb +0 -28
- data/lib/graphql/schema/possible_types.rb +0 -34
- data/lib/graphql/schema/reduce_types.rb +0 -68
- data/lib/graphql/schema/rescue_middleware.rb +0 -53
- data/lib/graphql/schema/timeout_middleware.rb +0 -67
- data/lib/graphql/schema/type_map.rb +0 -30
- data/lib/graphql/schema/validation.rb +0 -164
- data/lib/graphql/static_validation/arguments_validator.rb +0 -48
- data/lib/graphql/static_validation/message.rb +0 -36
- data/lib/graphql/string_type.rb +0 -5
- data/lib/graphql/union_type.rb +0 -38
- data/spec/graphql/analysis/analyze_query_spec.rb +0 -50
- data/spec/graphql/analysis/max_query_complexity_spec.rb +0 -62
- data/spec/graphql/analysis/max_query_depth_spec.rb +0 -100
- data/spec/graphql/analysis/query_complexity_spec.rb +0 -235
- data/spec/graphql/analysis/query_depth_spec.rb +0 -80
- data/spec/graphql/argument_spec.rb +0 -20
- data/spec/graphql/base_type_spec.rb +0 -24
- data/spec/graphql/boolean_type_spec.rb +0 -20
- data/spec/graphql/define/instance_definable_spec.rb +0 -55
- data/spec/graphql/directive_spec.rb +0 -77
- data/spec/graphql/enum_type_spec.rb +0 -31
- data/spec/graphql/execution_error_spec.rb +0 -61
- data/spec/graphql/field_spec.rb +0 -92
- data/spec/graphql/float_type_spec.rb +0 -15
- data/spec/graphql/id_type_spec.rb +0 -32
- data/spec/graphql/input_object_type_spec.rb +0 -162
- data/spec/graphql/int_type_spec.rb +0 -15
- data/spec/graphql/interface_type_spec.rb +0 -56
- data/spec/graphql/internal_representation/rewrite_spec.rb +0 -120
- data/spec/graphql/introspection/directive_type_spec.rb +0 -50
- data/spec/graphql/introspection/input_value_type_spec.rb +0 -42
- data/spec/graphql/introspection/introspection_query_spec.rb +0 -10
- data/spec/graphql/introspection/schema_type_spec.rb +0 -45
- data/spec/graphql/introspection/type_type_spec.rb +0 -122
- data/spec/graphql/language/generation_spec.rb +0 -42
- data/spec/graphql/language/parser_spec.rb +0 -442
- data/spec/graphql/language/visitor_spec.rb +0 -49
- data/spec/graphql/list_type_spec.rb +0 -32
- data/spec/graphql/non_null_type_spec.rb +0 -31
- data/spec/graphql/object_type_spec.rb +0 -42
- data/spec/graphql/query/arguments_spec.rb +0 -25
- data/spec/graphql/query/context_spec.rb +0 -83
- data/spec/graphql/query/executor_spec.rb +0 -273
- data/spec/graphql/query/serial_execution/execution_context_spec.rb +0 -53
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +0 -66
- data/spec/graphql/query/type_resolver_spec.rb +0 -8
- data/spec/graphql/query/variables_spec.rb +0 -28
- data/spec/graphql/query_spec.rb +0 -363
- data/spec/graphql/scalar_type_spec.rb +0 -61
- data/spec/graphql/schema/catchall_middleware_spec.rb +0 -32
- data/spec/graphql/schema/middleware_chain_spec.rb +0 -42
- data/spec/graphql/schema/printer_spec.rb +0 -190
- data/spec/graphql/schema/reduce_types_spec.rb +0 -102
- data/spec/graphql/schema/rescue_middleware_spec.rb +0 -33
- data/spec/graphql/schema/timeout_middleware_spec.rb +0 -180
- data/spec/graphql/schema/type_expression_spec.rb +0 -38
- data/spec/graphql/schema/validation_spec.rb +0 -219
- data/spec/graphql/schema_spec.rb +0 -23
- data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +0 -63
- data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +0 -48
- data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +0 -34
- data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +0 -39
- data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +0 -60
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +0 -31
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +0 -48
- data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +0 -47
- data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +0 -39
- data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +0 -44
- data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +0 -49
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +0 -25
- data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +0 -42
- data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +0 -44
- data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +0 -63
- data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +0 -37
- data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +0 -53
- data/spec/graphql/static_validation/type_stack_spec.rb +0 -37
- data/spec/graphql/static_validation/validator_spec.rb +0 -69
- data/spec/graphql/string_type_spec.rb +0 -15
- data/spec/graphql/union_type_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -18
- data/spec/support/dairy_app.rb +0 -309
- data/spec/support/dairy_data.rb +0 -23
- data/spec/support/minimum_input_object.rb +0 -16
- data/spec/support/star_wars_data.rb +0 -71
- data/spec/support/star_wars_schema.rb +0 -76
@@ -1,204 +1,716 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
module Language
|
3
4
|
module Nodes
|
4
|
-
# AbstractNode
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# {AbstractNode} is the base class for all nodes in a GraphQL AST.
|
6
|
+
#
|
7
|
+
# It provides some APIs for working with ASTs:
|
8
|
+
# - `children` returns all AST nodes attached to this one. Used for tree traversal.
|
9
|
+
# - `scalars` returns all scalar (Ruby) values attached to this one. Used for comparing nodes.
|
10
|
+
# - `to_query_string` turns an AST node into a GraphQL string
|
7
11
|
class AbstractNode
|
8
|
-
|
12
|
+
module DefinitionNode
|
13
|
+
# This AST node's {#line} returns the first line, which may be the description.
|
14
|
+
# @return [Integer] The first line of the definition (not the description)
|
15
|
+
attr_reader :definition_line
|
16
|
+
|
17
|
+
def initialize(options = {})
|
18
|
+
@definition_line = options.delete(:definition_line)
|
19
|
+
super(options)
|
20
|
+
end
|
21
|
+
end
|
9
22
|
|
10
|
-
|
11
|
-
|
23
|
+
attr_reader :line, :col, :filename
|
24
|
+
|
25
|
+
# Initialize a node by extracting its position,
|
26
|
+
# then calling the class's `initialize_node` method.
|
27
|
+
# @param options [Hash] Initial attributes for this node
|
28
|
+
def initialize(options = {})
|
12
29
|
if options.key?(:position_source)
|
13
30
|
position_source = options.delete(:position_source)
|
14
|
-
@line
|
15
|
-
|
16
|
-
@line = options.delete(:line)
|
17
|
-
@col = options.delete(:col)
|
31
|
+
@line = position_source.line
|
32
|
+
@col = position_source.col
|
18
33
|
end
|
19
34
|
|
20
|
-
|
35
|
+
@filename = options.delete(:filename)
|
36
|
+
|
37
|
+
initialize_node(**options)
|
21
38
|
end
|
22
39
|
|
23
|
-
#
|
24
|
-
|
25
|
-
|
40
|
+
# Value equality
|
41
|
+
# @return [Boolean] True if `self` is equivalent to `other`
|
42
|
+
def ==(other)
|
43
|
+
return true if equal?(other)
|
44
|
+
other.kind_of?(self.class) &&
|
45
|
+
other.scalars == self.scalars &&
|
46
|
+
other.children == self.children
|
26
47
|
end
|
27
48
|
|
28
|
-
|
49
|
+
NO_CHILDREN = [].freeze
|
50
|
+
|
51
|
+
# @return [Array<GraphQL::Language::Nodes::AbstractNode>] all nodes in the tree below this one
|
29
52
|
def children
|
30
|
-
|
31
|
-
.map { |attr_name| public_send(attr_name) }
|
32
|
-
.flatten
|
53
|
+
NO_CHILDREN
|
33
54
|
end
|
34
55
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
56
|
+
# @return [Array<Integer, Float, String, Boolean, Array>] Scalar values attached to this node
|
57
|
+
def scalars
|
58
|
+
NO_CHILDREN
|
59
|
+
end
|
60
|
+
|
61
|
+
# This might be unnecessary, but its easiest to add it here.
|
62
|
+
def initialize_copy(other)
|
63
|
+
@children = nil
|
64
|
+
@scalars = nil
|
65
|
+
@query_string = nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def children_method_name
|
69
|
+
self.class.children_method_name
|
40
70
|
end
|
41
71
|
|
42
72
|
def position
|
43
73
|
[line, col]
|
44
74
|
end
|
45
75
|
|
46
|
-
def to_query_string
|
47
|
-
|
76
|
+
def to_query_string(printer: GraphQL::Language::Printer.new)
|
77
|
+
if printer.is_a?(GraphQL::Language::Printer)
|
78
|
+
@query_string ||= printer.print(self)
|
79
|
+
else
|
80
|
+
printer.print(self)
|
81
|
+
end
|
48
82
|
end
|
49
|
-
end
|
50
83
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
84
|
+
# This creates a copy of `self`, with `new_options` applied.
|
85
|
+
# @param new_options [Hash]
|
86
|
+
# @return [AbstractNode] a shallow copy of `self`
|
87
|
+
def merge(new_options)
|
88
|
+
dup.merge!(new_options)
|
55
89
|
end
|
56
90
|
|
57
|
-
|
58
|
-
|
91
|
+
# Copy `self`, but modify the copy so that `previous_child` is replaced by `new_child`
|
92
|
+
def replace_child(previous_child, new_child)
|
93
|
+
# Figure out which list `previous_child` may be found in
|
94
|
+
method_name = previous_child.children_method_name
|
95
|
+
# Get the value from this (original) node
|
96
|
+
prev_children = public_send(method_name)
|
97
|
+
if prev_children.is_a?(Array)
|
98
|
+
# Copy that list, and replace `previous_child` with `new_child`
|
99
|
+
# in the list.
|
100
|
+
new_children = prev_children.dup
|
101
|
+
prev_idx = new_children.index(previous_child)
|
102
|
+
new_children[prev_idx] = new_child
|
103
|
+
else
|
104
|
+
# Use the new value for the given attribute
|
105
|
+
new_children = new_child
|
106
|
+
end
|
107
|
+
# Copy this node, but with the new child value
|
108
|
+
copy_of_self = merge(method_name => new_children)
|
109
|
+
# Return the copy:
|
110
|
+
copy_of_self
|
59
111
|
end
|
60
|
-
end
|
61
112
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
113
|
+
# TODO DRY with `replace_child`
|
114
|
+
def delete_child(previous_child)
|
115
|
+
# Figure out which list `previous_child` may be found in
|
116
|
+
method_name = previous_child.children_method_name
|
117
|
+
# Copy that list, and delete previous_child
|
118
|
+
new_children = public_send(method_name).dup
|
119
|
+
new_children.delete(previous_child)
|
120
|
+
# Copy this node, but with the new list of children:
|
121
|
+
copy_of_self = merge(method_name => new_children)
|
122
|
+
# Return the copy:
|
123
|
+
copy_of_self
|
66
124
|
end
|
67
125
|
|
68
|
-
|
69
|
-
|
126
|
+
protected
|
127
|
+
|
128
|
+
def merge!(new_options)
|
129
|
+
new_options.each do |key, value|
|
130
|
+
instance_variable_set(:"@#{key}", value)
|
131
|
+
end
|
132
|
+
self
|
70
133
|
end
|
134
|
+
|
135
|
+
class << self
|
136
|
+
# Add a default `#visit_method` and `#children_method_name` using the class name
|
137
|
+
def inherited(child_class)
|
138
|
+
super
|
139
|
+
name_underscored = child_class.name
|
140
|
+
.split("::").last
|
141
|
+
.gsub(/([a-z])([A-Z])/,'\1_\2') # insert underscores
|
142
|
+
.downcase # remove caps
|
143
|
+
|
144
|
+
child_class.module_eval <<-RUBY
|
145
|
+
def visit_method
|
146
|
+
:on_#{name_underscored}
|
147
|
+
end
|
148
|
+
|
149
|
+
class << self
|
150
|
+
attr_accessor :children_method_name
|
151
|
+
end
|
152
|
+
self.children_method_name = :#{name_underscored}s
|
153
|
+
RUBY
|
154
|
+
end
|
155
|
+
|
156
|
+
private
|
157
|
+
|
158
|
+
# Name accessors which return lists of nodes,
|
159
|
+
# along with the kind of node they return, if possible.
|
160
|
+
# - Add a reader for these children
|
161
|
+
# - Add a persistent update method to add a child
|
162
|
+
# - Generate a `#children` method
|
163
|
+
def children_methods(children_of_type)
|
164
|
+
if defined?(@children_methods)
|
165
|
+
raise "Can't re-call .children_methods for #{self} (already have: #{@children_methods})"
|
166
|
+
else
|
167
|
+
@children_methods = children_of_type
|
168
|
+
end
|
169
|
+
|
170
|
+
if children_of_type == false
|
171
|
+
@children_methods = {}
|
172
|
+
# skip
|
173
|
+
else
|
174
|
+
|
175
|
+
children_of_type.each do |method_name, node_type|
|
176
|
+
module_eval <<-RUBY, __FILE__, __LINE__
|
177
|
+
# A reader for these children
|
178
|
+
attr_reader :#{method_name}
|
179
|
+
RUBY
|
180
|
+
|
181
|
+
if node_type
|
182
|
+
# Only generate a method if we know what kind of node to make
|
183
|
+
module_eval <<-RUBY, __FILE__, __LINE__
|
184
|
+
# Singular method: create a node with these options
|
185
|
+
# and return a new `self` which includes that node in this list.
|
186
|
+
def merge_#{method_name.to_s.sub(/s$/, "")}(node_opts)
|
187
|
+
merge(#{method_name}: #{method_name} + [#{node_type.name}.new(node_opts)])
|
188
|
+
end
|
189
|
+
RUBY
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
if children_of_type.size == 1
|
194
|
+
module_eval <<-RUBY, __FILE__, __LINE__
|
195
|
+
alias :children #{children_of_type.keys.first}
|
196
|
+
RUBY
|
197
|
+
else
|
198
|
+
module_eval <<-RUBY, __FILE__, __LINE__
|
199
|
+
def children
|
200
|
+
@children ||= begin
|
201
|
+
if #{children_of_type.keys.map { |k| "@#{k}.any?" }.join(" || ")}
|
202
|
+
new_children = []
|
203
|
+
#{children_of_type.keys.map { |k| "new_children.concat(@#{k})" }.join("; ")}
|
204
|
+
new_children.freeze
|
205
|
+
new_children
|
206
|
+
else
|
207
|
+
NO_CHILDREN
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
RUBY
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
if defined?(@scalar_methods)
|
216
|
+
if !method_defined?(:initialize_node)
|
217
|
+
generate_initialize_node
|
218
|
+
else
|
219
|
+
# This method was defined manually
|
220
|
+
end
|
221
|
+
else
|
222
|
+
raise "Can't generate_initialize_node because scalar_methods wasn't called; call it before children_methods"
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# These methods return a plain Ruby value, not another node
|
227
|
+
# - Add reader methods
|
228
|
+
# - Add a `#scalars` method
|
229
|
+
def scalar_methods(*method_names)
|
230
|
+
if defined?(@scalar_methods)
|
231
|
+
raise "Can't re-call .scalar_methods for #{self} (already have: #{@scalar_methods})"
|
232
|
+
else
|
233
|
+
@scalar_methods = method_names
|
234
|
+
end
|
235
|
+
|
236
|
+
if method_names == [false]
|
237
|
+
@scalar_methods = []
|
238
|
+
# skip it
|
239
|
+
else
|
240
|
+
module_eval <<-RUBY, __FILE__, __LINE__
|
241
|
+
# add readers for each scalar
|
242
|
+
attr_reader #{method_names.map { |m| ":#{m}"}.join(", ")}
|
243
|
+
|
244
|
+
def scalars
|
245
|
+
@scalars ||= [#{method_names.map { |k| "@#{k}" }.join(", ")}].freeze
|
246
|
+
end
|
247
|
+
RUBY
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def generate_initialize_node
|
252
|
+
scalar_method_names = @scalar_methods
|
253
|
+
# TODO: These probably should be scalar methods, but `types` returns an array
|
254
|
+
[:types, :description].each do |extra_method|
|
255
|
+
if method_defined?(extra_method)
|
256
|
+
scalar_method_names += [extra_method]
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
all_method_names = scalar_method_names + @children_methods.keys
|
261
|
+
if all_method_names.include?(:alias)
|
262
|
+
# Rather than complicating this special case,
|
263
|
+
# let it be overridden (in field)
|
264
|
+
return
|
265
|
+
else
|
266
|
+
arguments = scalar_method_names.map { |m| "#{m}: nil"} +
|
267
|
+
@children_methods.keys.map { |m| "#{m}: NO_CHILDREN" }
|
268
|
+
|
269
|
+
assignments = scalar_method_names.map { |m| "@#{m} = #{m}"} +
|
270
|
+
@children_methods.keys.map { |m| "@#{m} = #{m}.freeze" }
|
271
|
+
|
272
|
+
module_eval <<-RUBY, __FILE__, __LINE__
|
273
|
+
def initialize_node #{arguments.join(", ")}
|
274
|
+
#{assignments.join("\n")}
|
275
|
+
end
|
276
|
+
RUBY
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
# Base class for non-null type names and list type names
|
283
|
+
class WrapperType < AbstractNode
|
284
|
+
scalar_methods :of_type
|
285
|
+
children_methods(false)
|
71
286
|
end
|
72
287
|
|
288
|
+
# Base class for nodes whose only value is a name (no child nodes or other scalars)
|
289
|
+
class NameOnlyNode < AbstractNode
|
290
|
+
scalar_methods :name
|
291
|
+
children_methods(false)
|
292
|
+
end
|
73
293
|
|
294
|
+
# A key-value pair for a field's inputs
|
74
295
|
class Argument < AbstractNode
|
75
|
-
|
296
|
+
scalar_methods :name, :value
|
297
|
+
children_methods(false)
|
76
298
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
299
|
+
# @!attribute name
|
300
|
+
# @return [String] the key for this argument
|
301
|
+
|
302
|
+
# @!attribute value
|
303
|
+
# @return [String, Float, Integer, Boolean, Array, InputObject] The value passed for this key
|
81
304
|
|
82
305
|
def children
|
83
|
-
|
306
|
+
@children ||= Array(value).flatten.select { |v| v.is_a?(AbstractNode) }
|
84
307
|
end
|
85
308
|
end
|
86
309
|
|
87
310
|
class Directive < AbstractNode
|
88
|
-
|
89
|
-
|
311
|
+
scalar_methods :name
|
312
|
+
children_methods(arguments: GraphQL::Language::Nodes::Argument)
|
313
|
+
end
|
90
314
|
|
91
|
-
|
92
|
-
@name = name
|
93
|
-
@arguments = arguments
|
94
|
-
end
|
315
|
+
class DirectiveLocation < NameOnlyNode
|
95
316
|
end
|
96
317
|
|
318
|
+
class DirectiveDefinition < AbstractNode
|
319
|
+
include DefinitionNode
|
320
|
+
attr_reader :description
|
321
|
+
scalar_methods :name, :repeatable
|
322
|
+
children_methods(
|
323
|
+
locations: Nodes::DirectiveLocation,
|
324
|
+
arguments: Nodes::Argument,
|
325
|
+
)
|
326
|
+
end
|
327
|
+
|
328
|
+
# This is the AST root for normal queries
|
329
|
+
#
|
330
|
+
# @example Deriving a document by parsing a string
|
331
|
+
# document = GraphQL.parse(query_string)
|
332
|
+
#
|
333
|
+
# @example Creating a string from a document
|
334
|
+
# document.to_query_string
|
335
|
+
# # { ... }
|
336
|
+
#
|
337
|
+
# @example Creating a custom string from a document
|
338
|
+
# class VariableScrubber < GraphQL::Language::Printer
|
339
|
+
# def print_argument(arg)
|
340
|
+
# "#{arg.name}: <HIDDEN>"
|
341
|
+
# end
|
342
|
+
# end
|
343
|
+
#
|
344
|
+
# document.to_query_string(printer: VariableScrubber.new)
|
345
|
+
#
|
97
346
|
class Document < AbstractNode
|
98
|
-
|
99
|
-
|
347
|
+
scalar_methods false
|
348
|
+
children_methods(definitions: nil)
|
349
|
+
# @!attribute definitions
|
350
|
+
# @return [Array<OperationDefinition, FragmentDefinition>] top-level GraphQL units: operations or fragments
|
100
351
|
|
101
|
-
def
|
102
|
-
|
352
|
+
def slice_definition(name)
|
353
|
+
GraphQL::Language::DefinitionSlice.slice(self, name)
|
103
354
|
end
|
104
355
|
end
|
105
356
|
|
106
|
-
|
357
|
+
# An enum value. The string is available as {#name}.
|
358
|
+
class Enum < NameOnlyNode
|
359
|
+
end
|
360
|
+
|
361
|
+
# A null value literal.
|
362
|
+
class NullValue < NameOnlyNode
|
363
|
+
end
|
107
364
|
|
365
|
+
# A single selection in a GraphQL query.
|
108
366
|
class Field < AbstractNode
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
367
|
+
NONE = [].freeze
|
368
|
+
|
369
|
+
scalar_methods :name, :alias
|
370
|
+
children_methods({
|
371
|
+
arguments: GraphQL::Language::Nodes::Argument,
|
372
|
+
selections: GraphQL::Language::Nodes::Field,
|
373
|
+
directives: GraphQL::Language::Nodes::Directive,
|
374
|
+
})
|
375
|
+
|
376
|
+
# @!attribute selections
|
377
|
+
# @return [Array<Nodes::Field>] Selections on this object (or empty array if this is a scalar field)
|
378
|
+
|
379
|
+
def initialize_node(attributes)
|
380
|
+
@name = attributes[:name]
|
381
|
+
@arguments = attributes[:arguments] || NONE
|
382
|
+
@directives = attributes[:directives] || NONE
|
383
|
+
@selections = attributes[:selections] || NONE
|
114
384
|
# oops, alias is a keyword:
|
115
|
-
@alias =
|
116
|
-
@arguments = arguments
|
117
|
-
@directives = directives
|
118
|
-
@selections = selections
|
385
|
+
@alias = attributes[:alias]
|
119
386
|
end
|
387
|
+
|
388
|
+
# Override this because default is `:fields`
|
389
|
+
self.children_method_name = :selections
|
120
390
|
end
|
121
391
|
|
392
|
+
# A reusable fragment, defined at document-level.
|
122
393
|
class FragmentDefinition < AbstractNode
|
123
|
-
|
124
|
-
|
394
|
+
# @!attribute name
|
395
|
+
# @return [String] the identifier for this fragment, which may be applied with `...#{name}`
|
125
396
|
|
397
|
+
# @!attribute type
|
398
|
+
# @return [String] the type condition for this fragment (name of type which it may apply to)
|
126
399
|
def initialize_node(name: nil, type: nil, directives: [], selections: [])
|
127
400
|
@name = name
|
128
401
|
@type = type
|
129
402
|
@directives = directives
|
130
403
|
@selections = selections
|
131
404
|
end
|
405
|
+
|
406
|
+
scalar_methods :name, :type
|
407
|
+
children_methods({
|
408
|
+
selections: GraphQL::Language::Nodes::Field,
|
409
|
+
directives: GraphQL::Language::Nodes::Directive,
|
410
|
+
})
|
411
|
+
|
412
|
+
self.children_method_name = :definitions
|
132
413
|
end
|
133
414
|
|
415
|
+
# Application of a named fragment in a selection
|
134
416
|
class FragmentSpread < AbstractNode
|
135
|
-
|
136
|
-
|
417
|
+
scalar_methods :name
|
418
|
+
children_methods(directives: GraphQL::Language::Nodes::Directive)
|
137
419
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
420
|
+
self.children_method_name = :selections
|
421
|
+
|
422
|
+
# @!attribute name
|
423
|
+
# @return [String] The identifier of the fragment to apply, corresponds with {FragmentDefinition#name}
|
142
424
|
end
|
143
425
|
|
426
|
+
# An unnamed fragment, defined directly in the query with `... { }`
|
144
427
|
class InlineFragment < AbstractNode
|
145
|
-
|
146
|
-
|
428
|
+
scalar_methods :type
|
429
|
+
children_methods({
|
430
|
+
selections: GraphQL::Language::Nodes::Field,
|
431
|
+
directives: GraphQL::Language::Nodes::Directive,
|
432
|
+
})
|
147
433
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
434
|
+
self.children_method_name = :selections
|
435
|
+
|
436
|
+
# @!attribute type
|
437
|
+
# @return [String, nil] Name of the type this fragment applies to, or `nil` if this fragment applies to any type
|
153
438
|
end
|
154
439
|
|
440
|
+
# A collection of key-value inputs which may be a field argument
|
155
441
|
class InputObject < AbstractNode
|
156
|
-
|
157
|
-
|
442
|
+
scalar_methods(false)
|
443
|
+
children_methods(arguments: GraphQL::Language::Nodes::Argument)
|
158
444
|
|
159
|
-
|
160
|
-
|
161
|
-
end
|
445
|
+
# @!attribute arguments
|
446
|
+
# @return [Array<Nodes::Argument>] A list of key-value pairs inside this input object
|
162
447
|
|
448
|
+
# @return [Hash<String, Any>] Recursively turn this input object into a Ruby Hash
|
163
449
|
def to_h(options={})
|
164
450
|
arguments.inject({}) do |memo, pair|
|
165
451
|
v = pair.value
|
166
|
-
memo[pair.name] =
|
452
|
+
memo[pair.name] = serialize_value_for_hash v
|
167
453
|
memo
|
168
454
|
end
|
169
455
|
end
|
456
|
+
|
457
|
+
self.children_method_name = :value
|
458
|
+
|
459
|
+
private
|
460
|
+
|
461
|
+
def serialize_value_for_hash(value)
|
462
|
+
case value
|
463
|
+
when InputObject
|
464
|
+
value.to_h
|
465
|
+
when Array
|
466
|
+
value.map do |v|
|
467
|
+
serialize_value_for_hash v
|
468
|
+
end
|
469
|
+
when Enum
|
470
|
+
value.name
|
471
|
+
when NullValue
|
472
|
+
nil
|
473
|
+
else
|
474
|
+
value
|
475
|
+
end
|
476
|
+
end
|
170
477
|
end
|
171
478
|
|
479
|
+
# A list type definition, denoted with `[...]` (used for variable type definitions)
|
480
|
+
class ListType < WrapperType
|
481
|
+
end
|
172
482
|
|
483
|
+
# A non-null type definition, denoted with `...!` (used for variable type definitions)
|
484
|
+
class NonNullType < WrapperType
|
485
|
+
end
|
486
|
+
|
487
|
+
# An operation-level query variable
|
488
|
+
class VariableDefinition < AbstractNode
|
489
|
+
scalar_methods :name, :type, :default_value
|
490
|
+
children_methods false
|
491
|
+
# @!attribute default_value
|
492
|
+
# @return [String, Integer, Float, Boolean, Array, NullValue] A Ruby value to use if no other value is provided
|
493
|
+
|
494
|
+
# @!attribute type
|
495
|
+
# @return [TypeName, NonNullType, ListType] The expected type of this value
|
173
496
|
|
174
|
-
|
175
|
-
|
497
|
+
# @!attribute name
|
498
|
+
# @return [String] The identifier for this variable, _without_ `$`
|
176
499
|
|
500
|
+
self.children_method_name = :variables
|
501
|
+
end
|
502
|
+
|
503
|
+
# A query, mutation or subscription.
|
504
|
+
# May be anonymous or named.
|
505
|
+
# May be explicitly typed (eg `mutation { ... }`) or implicitly a query (eg `{ ... }`).
|
177
506
|
class OperationDefinition < AbstractNode
|
178
|
-
|
179
|
-
|
507
|
+
scalar_methods :operation_type, :name
|
508
|
+
children_methods({
|
509
|
+
variables: GraphQL::Language::Nodes::VariableDefinition,
|
510
|
+
selections: GraphQL::Language::Nodes::Field,
|
511
|
+
directives: GraphQL::Language::Nodes::Directive,
|
512
|
+
})
|
180
513
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
514
|
+
# @!attribute variables
|
515
|
+
# @return [Array<VariableDefinition>] Variable $definitions for this operation
|
516
|
+
|
517
|
+
# @!attribute selections
|
518
|
+
# @return [Array<Field>] Root-level fields on this operation
|
519
|
+
|
520
|
+
# @!attribute operation_type
|
521
|
+
# @return [String, nil] The root type for this operation, or `nil` for implicit `"query"`
|
522
|
+
|
523
|
+
# @!attribute name
|
524
|
+
# @return [String, nil] The name for this operation, or `nil` if unnamed
|
525
|
+
|
526
|
+
self.children_method_name = :definitions
|
188
527
|
end
|
189
528
|
|
190
|
-
|
529
|
+
# A type name, used for variable definitions
|
530
|
+
class TypeName < NameOnlyNode
|
531
|
+
end
|
191
532
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
533
|
+
# Usage of a variable in a query. Name does _not_ include `$`.
|
534
|
+
class VariableIdentifier < NameOnlyNode
|
535
|
+
self.children_method_name = :value
|
536
|
+
end
|
537
|
+
|
538
|
+
class SchemaDefinition < AbstractNode
|
539
|
+
include DefinitionNode
|
540
|
+
scalar_methods :query, :mutation, :subscription
|
541
|
+
children_methods({
|
542
|
+
directives: GraphQL::Language::Nodes::Directive,
|
543
|
+
})
|
544
|
+
self.children_method_name = :definitions
|
545
|
+
end
|
546
|
+
|
547
|
+
class SchemaExtension < AbstractNode
|
548
|
+
scalar_methods :query, :mutation, :subscription
|
549
|
+
children_methods({
|
550
|
+
directives: GraphQL::Language::Nodes::Directive,
|
551
|
+
})
|
552
|
+
self.children_method_name = :definitions
|
553
|
+
end
|
554
|
+
|
555
|
+
class ScalarTypeDefinition < AbstractNode
|
556
|
+
include DefinitionNode
|
557
|
+
attr_reader :description
|
558
|
+
scalar_methods :name
|
559
|
+
children_methods({
|
560
|
+
directives: GraphQL::Language::Nodes::Directive,
|
561
|
+
})
|
562
|
+
self.children_method_name = :definitions
|
563
|
+
end
|
564
|
+
|
565
|
+
class ScalarTypeExtension < AbstractNode
|
566
|
+
scalar_methods :name
|
567
|
+
children_methods({
|
568
|
+
directives: GraphQL::Language::Nodes::Directive,
|
569
|
+
})
|
570
|
+
self.children_method_name = :definitions
|
571
|
+
end
|
572
|
+
|
573
|
+
class InputValueDefinition < AbstractNode
|
574
|
+
include DefinitionNode
|
575
|
+
attr_reader :description
|
576
|
+
scalar_methods :name, :type, :default_value
|
577
|
+
children_methods({
|
578
|
+
directives: GraphQL::Language::Nodes::Directive,
|
579
|
+
})
|
580
|
+
self.children_method_name = :fields
|
581
|
+
end
|
582
|
+
|
583
|
+
class FieldDefinition < AbstractNode
|
584
|
+
include DefinitionNode
|
585
|
+
attr_reader :description
|
586
|
+
scalar_methods :name, :type
|
587
|
+
children_methods({
|
588
|
+
directives: GraphQL::Language::Nodes::Directive,
|
589
|
+
arguments: GraphQL::Language::Nodes::InputValueDefinition,
|
590
|
+
})
|
591
|
+
self.children_method_name = :fields
|
592
|
+
|
593
|
+
# this is so that `children_method_name` of `InputValueDefinition` works properly
|
594
|
+
# with `#replace_child`
|
595
|
+
alias :fields :arguments
|
596
|
+
def merge(new_options)
|
597
|
+
if (f = new_options.delete(:fields))
|
598
|
+
new_options[:arguments] = f
|
599
|
+
end
|
600
|
+
super
|
198
601
|
end
|
199
602
|
end
|
200
603
|
|
201
|
-
class
|
604
|
+
class ObjectTypeDefinition < AbstractNode
|
605
|
+
include DefinitionNode
|
606
|
+
attr_reader :description
|
607
|
+
scalar_methods :name, :interfaces
|
608
|
+
children_methods({
|
609
|
+
directives: GraphQL::Language::Nodes::Directive,
|
610
|
+
fields: GraphQL::Language::Nodes::FieldDefinition,
|
611
|
+
})
|
612
|
+
self.children_method_name = :definitions
|
613
|
+
end
|
614
|
+
|
615
|
+
class ObjectTypeExtension < AbstractNode
|
616
|
+
scalar_methods :name, :interfaces
|
617
|
+
children_methods({
|
618
|
+
directives: GraphQL::Language::Nodes::Directive,
|
619
|
+
fields: GraphQL::Language::Nodes::FieldDefinition,
|
620
|
+
})
|
621
|
+
self.children_method_name = :definitions
|
622
|
+
end
|
623
|
+
|
624
|
+
class InterfaceTypeDefinition < AbstractNode
|
625
|
+
include DefinitionNode
|
626
|
+
attr_reader :description
|
627
|
+
scalar_methods :name
|
628
|
+
children_methods({
|
629
|
+
interfaces: GraphQL::Language::Nodes::TypeName,
|
630
|
+
directives: GraphQL::Language::Nodes::Directive,
|
631
|
+
fields: GraphQL::Language::Nodes::FieldDefinition,
|
632
|
+
})
|
633
|
+
self.children_method_name = :definitions
|
634
|
+
end
|
635
|
+
|
636
|
+
class InterfaceTypeExtension < AbstractNode
|
637
|
+
scalar_methods :name
|
638
|
+
children_methods({
|
639
|
+
interfaces: GraphQL::Language::Nodes::TypeName,
|
640
|
+
directives: GraphQL::Language::Nodes::Directive,
|
641
|
+
fields: GraphQL::Language::Nodes::FieldDefinition,
|
642
|
+
})
|
643
|
+
self.children_method_name = :definitions
|
644
|
+
end
|
645
|
+
|
646
|
+
class UnionTypeDefinition < AbstractNode
|
647
|
+
include DefinitionNode
|
648
|
+
attr_reader :description, :types
|
649
|
+
scalar_methods :name
|
650
|
+
children_methods({
|
651
|
+
directives: GraphQL::Language::Nodes::Directive,
|
652
|
+
})
|
653
|
+
self.children_method_name = :definitions
|
654
|
+
end
|
655
|
+
|
656
|
+
class UnionTypeExtension < AbstractNode
|
657
|
+
attr_reader :types
|
658
|
+
scalar_methods :name
|
659
|
+
children_methods({
|
660
|
+
directives: GraphQL::Language::Nodes::Directive,
|
661
|
+
})
|
662
|
+
self.children_method_name = :definitions
|
663
|
+
end
|
664
|
+
|
665
|
+
class EnumValueDefinition < AbstractNode
|
666
|
+
include DefinitionNode
|
667
|
+
attr_reader :description
|
668
|
+
scalar_methods :name
|
669
|
+
children_methods({
|
670
|
+
directives: GraphQL::Language::Nodes::Directive,
|
671
|
+
})
|
672
|
+
self.children_method_name = :values
|
673
|
+
end
|
674
|
+
|
675
|
+
class EnumTypeDefinition < AbstractNode
|
676
|
+
include DefinitionNode
|
677
|
+
attr_reader :description
|
678
|
+
scalar_methods :name
|
679
|
+
children_methods({
|
680
|
+
directives: GraphQL::Language::Nodes::Directive,
|
681
|
+
values: GraphQL::Language::Nodes::EnumValueDefinition,
|
682
|
+
})
|
683
|
+
self.children_method_name = :definitions
|
684
|
+
end
|
685
|
+
|
686
|
+
class EnumTypeExtension < AbstractNode
|
687
|
+
scalar_methods :name
|
688
|
+
children_methods({
|
689
|
+
directives: GraphQL::Language::Nodes::Directive,
|
690
|
+
values: GraphQL::Language::Nodes::EnumValueDefinition,
|
691
|
+
})
|
692
|
+
self.children_method_name = :definitions
|
693
|
+
end
|
694
|
+
|
695
|
+
class InputObjectTypeDefinition < AbstractNode
|
696
|
+
include DefinitionNode
|
697
|
+
attr_reader :description
|
698
|
+
scalar_methods :name
|
699
|
+
children_methods({
|
700
|
+
directives: GraphQL::Language::Nodes::Directive,
|
701
|
+
fields: GraphQL::Language::Nodes::InputValueDefinition,
|
702
|
+
})
|
703
|
+
self.children_method_name = :definitions
|
704
|
+
end
|
705
|
+
|
706
|
+
class InputObjectTypeExtension < AbstractNode
|
707
|
+
scalar_methods :name
|
708
|
+
children_methods({
|
709
|
+
directives: GraphQL::Language::Nodes::Directive,
|
710
|
+
fields: GraphQL::Language::Nodes::InputValueDefinition,
|
711
|
+
})
|
712
|
+
self.children_method_name = :definitions
|
713
|
+
end
|
202
714
|
end
|
203
715
|
end
|
204
716
|
end
|