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,53 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::StaticValidation::VariablesAreUsedAndDefined do
|
4
|
-
let(:query_string) {'
|
5
|
-
query getCheese(
|
6
|
-
$usedVar: Int,
|
7
|
-
$usedInnerVar: String,
|
8
|
-
$usedInlineFragmentVar: Boolean,
|
9
|
-
$usedFragmentVar: Int,
|
10
|
-
$notUsedVar: Float,
|
11
|
-
) {
|
12
|
-
cheese(id: $usedVar) {
|
13
|
-
source(str: $usedInnerVar)
|
14
|
-
whatever(undefined: $undefinedVar)
|
15
|
-
... on Cheese {
|
16
|
-
something(bool: $usedInlineFragmentVar)
|
17
|
-
}
|
18
|
-
... outerCheeseFields
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
fragment outerCheeseFields on Cheese {
|
23
|
-
... innerCheeseFields
|
24
|
-
}
|
25
|
-
|
26
|
-
fragment innerCheeseFields on Cheese {
|
27
|
-
source(notDefined: $undefinedFragmentVar)
|
28
|
-
someField(someArg: $usedFragmentVar)
|
29
|
-
}
|
30
|
-
'}
|
31
|
-
|
32
|
-
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::VariablesAreUsedAndDefined]) }
|
33
|
-
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
34
|
-
let(:errors) { validator.validate(query)[:errors] }
|
35
|
-
|
36
|
-
it "finds variables which are used-but-not-defined or defined-but-not-used" do
|
37
|
-
expected = [
|
38
|
-
{
|
39
|
-
"message"=>"Variable $notUsedVar is declared by getCheese but not used",
|
40
|
-
"locations"=>[{"line"=>2, "column"=>5}]
|
41
|
-
},
|
42
|
-
{
|
43
|
-
"message"=>"Variable $undefinedVar is used by getCheese but not declared",
|
44
|
-
"locations"=>[{"line"=>11, "column"=>29}]
|
45
|
-
},
|
46
|
-
{
|
47
|
-
"message"=>"Variable $undefinedFragmentVar is used by innerCheeseFields but not declared",
|
48
|
-
"locations"=>[{"line"=>24, "column"=>26}]
|
49
|
-
},
|
50
|
-
]
|
51
|
-
assert_equal(expected, errors)
|
52
|
-
end
|
53
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
class TypeCheckValidator
|
4
|
-
def self.checks
|
5
|
-
@checks ||= []
|
6
|
-
end
|
7
|
-
|
8
|
-
def validate(context)
|
9
|
-
self.class.checks.clear
|
10
|
-
context.visitor[GraphQL::Language::Nodes::Field] << -> (node, parent) {
|
11
|
-
self.class.checks << context.object_types.map(&:name)
|
12
|
-
}
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe GraphQL::StaticValidation::TypeStack do
|
17
|
-
let(:query_string) {%|
|
18
|
-
query getCheese {
|
19
|
-
cheese(id: 1) { id, ... edibleFields }
|
20
|
-
}
|
21
|
-
fragment edibleFields on Edible { fatContent @skip(if: false)}
|
22
|
-
|}
|
23
|
-
|
24
|
-
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [TypeCheckValidator]) }
|
25
|
-
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
26
|
-
|
27
|
-
|
28
|
-
it "stores up types" do
|
29
|
-
validator.validate(query)
|
30
|
-
expected = [
|
31
|
-
["Query", "Cheese"],
|
32
|
-
["Query", "Cheese", "Non-Null"],
|
33
|
-
["Edible", "Non-Null"]
|
34
|
-
]
|
35
|
-
assert_equal(expected, TypeCheckValidator.checks)
|
36
|
-
end
|
37
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::StaticValidation::Validator do
|
4
|
-
let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema) }
|
5
|
-
let(:query) { GraphQL::Query.new(DummySchema, query_string) }
|
6
|
-
let(:errors) { validator.validate(query)[:errors] }
|
7
|
-
|
8
|
-
|
9
|
-
describe "validation order" do
|
10
|
-
let(:document) { GraphQL.parse(query_string)}
|
11
|
-
|
12
|
-
describe "fields & arguments" do
|
13
|
-
let(:query_string) { %|
|
14
|
-
query getCheese($id: Int!) {
|
15
|
-
cheese(id: $undefinedVar, bogusArg: true) {
|
16
|
-
source,
|
17
|
-
nonsenseField,
|
18
|
-
id(nonsenseArg: 1)
|
19
|
-
bogusField(bogusArg: true)
|
20
|
-
}
|
21
|
-
|
22
|
-
otherCheese: cheese(id: $id) {
|
23
|
-
source,
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|}
|
27
|
-
|
28
|
-
it "handles args on invalid fields" do
|
29
|
-
# nonsenseField, nonsenseArg, bogusField, bogusArg, undefinedVar
|
30
|
-
assert_equal(5, errors.length)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "infinite fragments" do
|
35
|
-
let(:query_string) { %|
|
36
|
-
query getCheese {
|
37
|
-
cheese(id: 1) {
|
38
|
-
... cheeseFields
|
39
|
-
}
|
40
|
-
}
|
41
|
-
fragment cheeseFields on Cheese {
|
42
|
-
id, ... cheeseFields
|
43
|
-
}
|
44
|
-
|}
|
45
|
-
|
46
|
-
it "handles infinite fragment spreads" do
|
47
|
-
assert_equal(1, errors.length)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "fragment spreads with no selections" do
|
52
|
-
let(:query_string) {%|
|
53
|
-
query SimpleQuery {
|
54
|
-
cheese(id: 1) {
|
55
|
-
# OK:
|
56
|
-
... {
|
57
|
-
id
|
58
|
-
}
|
59
|
-
# NOT OK:
|
60
|
-
...cheeseFields
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|}
|
64
|
-
it "marks an error" do
|
65
|
-
assert_equal(1, errors.length)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::STRING_TYPE do
|
4
|
-
describe "coerce_input" do
|
5
|
-
it "accepts strings" do
|
6
|
-
assert_equal "str", GraphQL::STRING_TYPE.coerce_input("str")
|
7
|
-
end
|
8
|
-
|
9
|
-
it "doesn't accept other types" do
|
10
|
-
assert_equal nil, GraphQL::STRING_TYPE.coerce_input(100)
|
11
|
-
assert_equal nil, GraphQL::STRING_TYPE.coerce_input(true)
|
12
|
-
assert_equal nil, GraphQL::STRING_TYPE.coerce_input(0.999)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe GraphQL::UnionType do
|
4
|
-
let(:type_1) { OpenStruct.new(kind: GraphQL::TypeKinds::OBJECT)}
|
5
|
-
let(:type_2) { OpenStruct.new(kind: GraphQL::TypeKinds::OBJECT)}
|
6
|
-
let(:type_3) { OpenStruct.new(kind: GraphQL::TypeKinds::SCALAR)}
|
7
|
-
let(:union) {
|
8
|
-
types = [type_1, type_2]
|
9
|
-
GraphQL::UnionType.define {
|
10
|
-
name("MyUnion")
|
11
|
-
description("Some items")
|
12
|
-
possible_types(types)
|
13
|
-
}
|
14
|
-
}
|
15
|
-
it "has a name" do
|
16
|
-
assert_equal("MyUnion", union.name)
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
it "infers type from an object" do
|
21
|
-
assert_equal(CheeseType, DairyProductUnion.resolve_type(CHEESES[1], OpenStruct.new(schema: DummySchema)))
|
22
|
-
end
|
23
|
-
|
24
|
-
it '#include? returns true if type in in possible_types' do
|
25
|
-
assert union.include?(type_1)
|
26
|
-
end
|
27
|
-
|
28
|
-
it '#include? returns false if type is not in possible_types' do
|
29
|
-
assert_equal(false, union.include?(type_3))
|
30
|
-
end
|
31
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require "codeclimate-test-reporter"
|
2
|
-
CodeClimate::TestReporter.start
|
3
|
-
require "graphql"
|
4
|
-
require "benchmark"
|
5
|
-
require "minitest/autorun"
|
6
|
-
require "minitest/focus"
|
7
|
-
require "minitest/reporters"
|
8
|
-
require "pry"
|
9
|
-
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
10
|
-
|
11
|
-
Minitest::Spec.make_my_diffs_pretty!
|
12
|
-
|
13
|
-
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
14
|
-
# to be shown.
|
15
|
-
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
16
|
-
|
17
|
-
# # Load support files
|
18
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
data/spec/support/dairy_app.rb
DELETED
@@ -1,309 +0,0 @@
|
|
1
|
-
require_relative "./dairy_data"
|
2
|
-
|
3
|
-
class NoSuchDairyError < StandardError; end
|
4
|
-
|
5
|
-
EdibleInterface = GraphQL::InterfaceType.define do
|
6
|
-
name "Edible"
|
7
|
-
description "Something you can eat, yum"
|
8
|
-
field :fatContent, !types.Float, "Percentage which is fat"
|
9
|
-
field :origin, !types.String, "Place the edible comes from"
|
10
|
-
end
|
11
|
-
|
12
|
-
AnimalProductInterface = GraphQL::InterfaceType.define do
|
13
|
-
name "AnimalProduct"
|
14
|
-
description "Comes from an animal, no joke"
|
15
|
-
field :source, !types.String, "Animal which produced this product"
|
16
|
-
end
|
17
|
-
|
18
|
-
DairyAnimalEnum = GraphQL::EnumType.define do
|
19
|
-
name "DairyAnimal"
|
20
|
-
description "An animal which can yield milk"
|
21
|
-
value("COW", "Animal with black and white spots", value: 1)
|
22
|
-
value("GOAT", "Animal with horns")
|
23
|
-
value("SHEEP", "Animal with wool")
|
24
|
-
value("YAK", "Animal with long hair", deprecation_reason: "Out of fashion")
|
25
|
-
end
|
26
|
-
|
27
|
-
CheeseType = GraphQL::ObjectType.define do
|
28
|
-
name "Cheese"
|
29
|
-
description "Cultured dairy product"
|
30
|
-
interfaces ["EdibleInterface", -> { AnimalProductInterface }]
|
31
|
-
|
32
|
-
# Can have (name, type, desc)
|
33
|
-
field :id, !types.Int, "Unique identifier"
|
34
|
-
field :flavor, !types.String, "Kind of Cheese"
|
35
|
-
field :origin, !types.String, "Place the cheese comes from"
|
36
|
-
|
37
|
-
field :source, !DairyAnimalEnum,
|
38
|
-
"Animal which produced the milk for this cheese"
|
39
|
-
|
40
|
-
# Or can define by block:
|
41
|
-
field :similarCheese, -> { CheeseType }, "Cheeses like this one" do
|
42
|
-
argument :source, !types[!DairyAnimalEnum]
|
43
|
-
resolve -> (t, a, c) {
|
44
|
-
# get the strings out:
|
45
|
-
sources = a["source"]
|
46
|
-
if sources.include?("YAK")
|
47
|
-
raise NoSuchDairyError.new("No cheeses are made from Yak milk!")
|
48
|
-
else
|
49
|
-
CHEESES.values.find { |c| sources.include?(c.source) }
|
50
|
-
end
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
field :nullableCheese, -> { CheeseType }, "Cheeses like this one" do
|
55
|
-
argument :source, types[!DairyAnimalEnum]
|
56
|
-
resolve -> (t, a, c) { raise("NotImplemented") }
|
57
|
-
end
|
58
|
-
|
59
|
-
field :deeplyNullableCheese, -> { CheeseType }, "Cheeses like this one" do
|
60
|
-
argument :source, types[types[DairyAnimalEnum]]
|
61
|
-
resolve -> (t, a, c) { raise("NotImplemented") }
|
62
|
-
end
|
63
|
-
|
64
|
-
field :fatContent, property: :fat_content do
|
65
|
-
type(!GraphQL::FLOAT_TYPE)
|
66
|
-
description("Percentage which is milkfat")
|
67
|
-
deprecation_reason("Diet fashion has changed")
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
MilkType = GraphQL::ObjectType.define do
|
72
|
-
name "Milk"
|
73
|
-
description "Dairy beverage"
|
74
|
-
interfaces [EdibleInterface, AnimalProductInterface]
|
75
|
-
field :id, !types.ID
|
76
|
-
field :source, DairyAnimalEnum, "Animal which produced this milk"
|
77
|
-
field :origin, !types.String, "Place the milk comes from"
|
78
|
-
field :flavors, types[types.String], "Chocolate, Strawberry, etc" do
|
79
|
-
argument :limit, types.Int
|
80
|
-
resolve -> (milk, args, ctx) {
|
81
|
-
args[:limit] ? milk.flavors.first(args[:limit]) : milk.flavors
|
82
|
-
}
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
SweetenerInterface = GraphQL::InterfaceType.define do
|
87
|
-
name "Sweetener"
|
88
|
-
field :sweetness, types.Int
|
89
|
-
end
|
90
|
-
|
91
|
-
# No actual data; This type is an "orphan", only accessible through Interfaces
|
92
|
-
HoneyType = GraphQL::ObjectType.define do
|
93
|
-
name "Honey"
|
94
|
-
description "Sweet, dehydrated bee barf"
|
95
|
-
field :flowerType, types.String, "What flower this honey came from"
|
96
|
-
interfaces [EdibleInterface, AnimalProductInterface, SweetenerInterface]
|
97
|
-
end
|
98
|
-
|
99
|
-
DairyType = GraphQL::ObjectType.define do
|
100
|
-
name "Dairy"
|
101
|
-
description "A farm where milk is harvested and cheese is produced"
|
102
|
-
field :id, !types.ID
|
103
|
-
field :cheese, CheeseType
|
104
|
-
field :milks, types[MilkType]
|
105
|
-
end
|
106
|
-
|
107
|
-
MaybeNullType = GraphQL::ObjectType.define do
|
108
|
-
name "MaybeNull"
|
109
|
-
description "An object whose fields return nil"
|
110
|
-
field :cheese, CheeseType
|
111
|
-
end
|
112
|
-
|
113
|
-
DairyProductUnion = GraphQL::UnionType.define do
|
114
|
-
name "DairyProduct"
|
115
|
-
description "Kinds of food made from milk"
|
116
|
-
possible_types ["MilkType", -> { CheeseType }]
|
117
|
-
end
|
118
|
-
|
119
|
-
CowType = GraphQL::ObjectType.define do
|
120
|
-
name "Cow"
|
121
|
-
description "A farm where milk is harvested and cheese is produced"
|
122
|
-
field :id, !types.ID
|
123
|
-
field :name, types.String
|
124
|
-
field :last_produced_dairy, DairyProductUnion
|
125
|
-
|
126
|
-
field :cantBeNullButIs do
|
127
|
-
type !GraphQL::STRING_TYPE
|
128
|
-
resolve -> (t, a, c) { nil }
|
129
|
-
end
|
130
|
-
|
131
|
-
field :cantBeNullButRaisesExecutionError do
|
132
|
-
type !GraphQL::STRING_TYPE
|
133
|
-
resolve -> (t, a, c) { raise GraphQL::ExecutionError, "BOOM" }
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
DairyProductInputType = GraphQL::InputObjectType.define {
|
138
|
-
name "DairyProductInput"
|
139
|
-
description "Properties for finding a dairy product"
|
140
|
-
input_field :source, !DairyAnimalEnum do
|
141
|
-
# ensure we can define description in block
|
142
|
-
description "Where it came from"
|
143
|
-
end
|
144
|
-
|
145
|
-
input_field :originDairy, types.String, "Dairy which produced it", default_value: "Sugar Hollow Dairy" do
|
146
|
-
description "Ignored because arg takes precedence"
|
147
|
-
default_value "Ignored because keyword arg takes precedence"
|
148
|
-
end
|
149
|
-
|
150
|
-
input_field :fatContent, types.Float, "How much fat it has" do
|
151
|
-
# ensure we can define default in block
|
152
|
-
default_value 0.3
|
153
|
-
end
|
154
|
-
|
155
|
-
# ensure default can be false
|
156
|
-
input_field :organic, types.Boolean, default_value: false
|
157
|
-
}
|
158
|
-
|
159
|
-
DeepNonNullType = GraphQL::ObjectType.define do
|
160
|
-
name "DeepNonNull"
|
161
|
-
field :nonNullInt, !types.Int do
|
162
|
-
argument :returning, types.Int
|
163
|
-
resolve -> (obj, args, ctx) { args[:returning] }
|
164
|
-
end
|
165
|
-
|
166
|
-
field :deepNonNull, -> { DeepNonNullType.to_non_null_type } do
|
167
|
-
resolve -> (obj, args, ctx) { :deepNonNull }
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
class FetchField
|
172
|
-
def self.create(type:, data:, id_type: !GraphQL::INT_TYPE)
|
173
|
-
desc = "Find a #{type.name} by id"
|
174
|
-
return_type = type
|
175
|
-
GraphQL::Field.define do
|
176
|
-
type(return_type)
|
177
|
-
description(desc)
|
178
|
-
argument :id, id_type
|
179
|
-
|
180
|
-
resolve -> (t, a, c) {
|
181
|
-
id_string = a["id"].to_s # Cheese has Int type, Milk has ID type :(
|
182
|
-
id, item = data.find { |id, item| id.to_s == id_string }
|
183
|
-
item
|
184
|
-
}
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
class SingletonField
|
190
|
-
def self.create(type:, data:)
|
191
|
-
desc = "Find the only #{type.name}"
|
192
|
-
return_type = type
|
193
|
-
GraphQL::Field.define do
|
194
|
-
type(return_type)
|
195
|
-
description(desc)
|
196
|
-
|
197
|
-
resolve -> (t, a, c) {data}
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
SourceFieldDefn = Proc.new {
|
203
|
-
type GraphQL::ListType.new(of_type: CheeseType)
|
204
|
-
description "Cheese from source"
|
205
|
-
argument :source, DairyAnimalEnum, default_value: "COW"
|
206
|
-
resolve -> (target, arguments, context) {
|
207
|
-
CHEESES.values.select{ |c| c.source == arguments["source"] }
|
208
|
-
}
|
209
|
-
}
|
210
|
-
|
211
|
-
FavoriteFieldDefn = Proc.new {
|
212
|
-
description "My favorite food"
|
213
|
-
type EdibleInterface
|
214
|
-
resolve -> (t, a, c) { MILKS[1] }
|
215
|
-
}
|
216
|
-
|
217
|
-
QueryType = GraphQL::ObjectType.define do
|
218
|
-
name "Query"
|
219
|
-
description "Query root of the system"
|
220
|
-
field :root, types.String do
|
221
|
-
resolve ->(root_value, args, c) { root_value }
|
222
|
-
end
|
223
|
-
field :cheese, field: FetchField.create(type: CheeseType, data: CHEESES)
|
224
|
-
field :milk, field: FetchField.create(type: MilkType, data: MILKS, id_type: !types.ID)
|
225
|
-
field :dairy, field: SingletonField.create(type: DairyType, data: DAIRY)
|
226
|
-
field :fromSource, &SourceFieldDefn
|
227
|
-
field :favoriteEdible, &FavoriteFieldDefn
|
228
|
-
field :cow, field: SingletonField.create(type: CowType, data: COW)
|
229
|
-
field :searchDairy do
|
230
|
-
description "Find dairy products matching a description"
|
231
|
-
type !DairyProductUnion
|
232
|
-
# This is a list just for testing 😬
|
233
|
-
argument :product, types[DairyProductInputType], default_value: [{"source" => "SHEEP"}]
|
234
|
-
resolve -> (t, args, c) {
|
235
|
-
source = args["product"][0][:source] # String or Sym is ok
|
236
|
-
products = CHEESES.values + MILKS.values
|
237
|
-
if !source.nil?
|
238
|
-
products = products.select { |pr| pr.source == source }
|
239
|
-
end
|
240
|
-
products.first
|
241
|
-
}
|
242
|
-
end
|
243
|
-
|
244
|
-
field :error do
|
245
|
-
description "Raise an error"
|
246
|
-
type GraphQL::STRING_TYPE
|
247
|
-
resolve -> (t, a, c) { raise("This error was raised on purpose") }
|
248
|
-
end
|
249
|
-
|
250
|
-
field :executionError do
|
251
|
-
type GraphQL::STRING_TYPE
|
252
|
-
resolve -> (t, a, c) { raise(GraphQL::ExecutionError, "There was an execution error") }
|
253
|
-
end
|
254
|
-
|
255
|
-
# To test possibly-null fields
|
256
|
-
field :maybeNull, MaybeNullType do
|
257
|
-
resolve -> (t, a, c) { OpenStruct.new(cheese: nil) }
|
258
|
-
end
|
259
|
-
|
260
|
-
field :deepNonNull, !DeepNonNullType do
|
261
|
-
resolve -> (o, a, c) { :deepNonNull }
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
GLOBAL_VALUES = []
|
266
|
-
|
267
|
-
ReplaceValuesInputType = GraphQL::InputObjectType.define do
|
268
|
-
name "ReplaceValuesInput"
|
269
|
-
input_field :values, !types[!types.Int]
|
270
|
-
end
|
271
|
-
|
272
|
-
MutationType = GraphQL::ObjectType.define do
|
273
|
-
name "Mutation"
|
274
|
-
description "The root for mutations in this schema"
|
275
|
-
field :pushValue, !types[!types.Int] do
|
276
|
-
description("Push a value onto a global array :D")
|
277
|
-
argument :value, !types.Int
|
278
|
-
resolve -> (o, args, ctx) {
|
279
|
-
GLOBAL_VALUES << args[:value]
|
280
|
-
GLOBAL_VALUES
|
281
|
-
}
|
282
|
-
end
|
283
|
-
|
284
|
-
field :replaceValues, !types[!types.Int] do
|
285
|
-
description("Replace the global array with new values")
|
286
|
-
argument :input, !ReplaceValuesInputType
|
287
|
-
resolve -> (o, args, ctx) {
|
288
|
-
GLOBAL_VALUES.clear
|
289
|
-
GLOBAL_VALUES.push(*args[:input][:values])
|
290
|
-
GLOBAL_VALUES
|
291
|
-
}
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
SubscriptionType = GraphQL::ObjectType.define do
|
296
|
-
name "Subscription"
|
297
|
-
field :test, types.String do
|
298
|
-
resolve -> (o, a, c) { "Test" }
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
DummySchema = GraphQL::Schema.new(
|
303
|
-
query: QueryType,
|
304
|
-
mutation: MutationType,
|
305
|
-
subscription: SubscriptionType,
|
306
|
-
max_depth: 5,
|
307
|
-
types: [HoneyType],
|
308
|
-
)
|
309
|
-
DummySchema.rescue_from(NoSuchDairyError) { |err| err.message }
|
data/spec/support/dairy_data.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
Cheese = Struct.new(:id, :flavor, :origin, :fat_content, :source)
|
2
|
-
CHEESES = {
|
3
|
-
1 => Cheese.new(1, "Brie", "France", 0.19, 1),
|
4
|
-
2 => Cheese.new(2, "Gouda", "Netherlands", 0.3, 1),
|
5
|
-
3 => Cheese.new(3, "Manchego", "Spain", 0.065, "SHEEP")
|
6
|
-
}
|
7
|
-
|
8
|
-
Milk = Struct.new(:id, :fatContent, :origin, :source, :flavors)
|
9
|
-
MILKS = {
|
10
|
-
1 => Milk.new(1, 0.04, "Antiquity", 1, ["Natural", "Chocolate", "Strawberry"]),
|
11
|
-
}
|
12
|
-
|
13
|
-
DAIRY = OpenStruct.new(
|
14
|
-
id: 1,
|
15
|
-
cheese: CHEESES[1],
|
16
|
-
milks: [MILKS[1]]
|
17
|
-
)
|
18
|
-
|
19
|
-
COW = OpenStruct.new(
|
20
|
-
id: 1,
|
21
|
-
name: "Billy",
|
22
|
-
last_produced_dairy: MILKS[1]
|
23
|
-
)
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# This is the minimum required interface for an input object
|
2
|
-
class MinimumInputObject
|
3
|
-
include Enumerable
|
4
|
-
|
5
|
-
def initialize(values)
|
6
|
-
@values = values
|
7
|
-
end
|
8
|
-
|
9
|
-
def each(&block)
|
10
|
-
@values.each(&block)
|
11
|
-
end
|
12
|
-
|
13
|
-
def [](key)
|
14
|
-
@values[key]
|
15
|
-
end
|
16
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
luke = OpenStruct.new({
|
2
|
-
id: "1000",
|
3
|
-
name: "Luke Skywalker",
|
4
|
-
friends: ["1002", "1003", "2000", "2001"],
|
5
|
-
appearsIn: [4, 5, 6],
|
6
|
-
homePlanet: "Tatooine",
|
7
|
-
})
|
8
|
-
|
9
|
-
vader = OpenStruct.new({
|
10
|
-
id: "1001",
|
11
|
-
name: "Darth Vader",
|
12
|
-
friends: ["1004"],
|
13
|
-
appearsIn: [4, 5, 6],
|
14
|
-
homePlanet: "Tatooine",
|
15
|
-
})
|
16
|
-
|
17
|
-
han = OpenStruct.new({
|
18
|
-
id: "1002",
|
19
|
-
name: "Han Solo",
|
20
|
-
friends: ["1000", "1003", "2001"],
|
21
|
-
appearsIn: [4, 5, 6],
|
22
|
-
})
|
23
|
-
|
24
|
-
leia = OpenStruct.new({
|
25
|
-
id: "1003",
|
26
|
-
name: "Leia Organa",
|
27
|
-
friends: ["1000", "1002", "2000", "2001"],
|
28
|
-
appearsIn: [4, 5, 6],
|
29
|
-
homePlanet: "Alderaan",
|
30
|
-
})
|
31
|
-
|
32
|
-
tarkin = OpenStruct.new({
|
33
|
-
id: "1004",
|
34
|
-
name: "Wilhuff Tarkin",
|
35
|
-
friends: ["1001"],
|
36
|
-
appearsIn: [4],
|
37
|
-
})
|
38
|
-
|
39
|
-
HUMAN_DATA = {
|
40
|
-
"1000" => luke,
|
41
|
-
"1001" => vader,
|
42
|
-
"1002" => han,
|
43
|
-
"1003" => leia,
|
44
|
-
"1004" => tarkin,
|
45
|
-
}
|
46
|
-
|
47
|
-
threepio = OpenStruct.new({
|
48
|
-
id: "2000",
|
49
|
-
name: "C-3PO",
|
50
|
-
friends: ["1000", "1002", "1003", "2001"],
|
51
|
-
appearsIn: [4, 5, 6],
|
52
|
-
primaryFunction: "Protocol",
|
53
|
-
})
|
54
|
-
|
55
|
-
artoo = OpenStruct.new({
|
56
|
-
id: "2001",
|
57
|
-
name: "R2-D2",
|
58
|
-
friends: ["1000", "1002", "1003"],
|
59
|
-
appearsIn: [4, 5, 6],
|
60
|
-
primaryFunction: "Astromech",
|
61
|
-
})
|
62
|
-
|
63
|
-
DROID_DATA = {
|
64
|
-
"2000" => threepio,
|
65
|
-
"2001" => artoo,
|
66
|
-
}
|
67
|
-
|
68
|
-
# Get friends from IDs
|
69
|
-
GET_FRIENDS = -> (obj, args, ctx) do
|
70
|
-
obj.friends.map { |id| HUMAN_DATA[id] || DROID_DATA[id]}
|
71
|
-
end
|