graphql 0.16.0 → 2.0.15
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "graphql/tracing/active_support_notifications_tracing"
|
3
|
+
require "graphql/tracing/platform_tracing"
|
4
|
+
require "graphql/tracing/appoptics_tracing"
|
5
|
+
require "graphql/tracing/appsignal_tracing"
|
6
|
+
require "graphql/tracing/data_dog_tracing"
|
7
|
+
require "graphql/tracing/new_relic_tracing"
|
8
|
+
require "graphql/tracing/scout_tracing"
|
9
|
+
require "graphql/tracing/statsd_tracing"
|
10
|
+
require "graphql/tracing/prometheus_tracing"
|
11
|
+
|
12
|
+
if defined?(PrometheusExporter::Server)
|
13
|
+
require "graphql/tracing/prometheus_tracing/graphql_collector"
|
14
|
+
end
|
15
|
+
|
16
|
+
module GraphQL
|
17
|
+
# Library entry point for performance metric reporting.
|
18
|
+
#
|
19
|
+
# @example Sending custom events
|
20
|
+
# query.trace("my_custom_event", { ... }) do
|
21
|
+
# # do stuff ...
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# @example Adding a tracer to a schema
|
25
|
+
# class MySchema < GraphQL::Schema
|
26
|
+
# tracer MyTracer # <= responds to .trace(key, data, &block)
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# @example Adding a tracer to a single query
|
30
|
+
# MySchema.execute(query_str, context: { backtrace: true })
|
31
|
+
#
|
32
|
+
# Events:
|
33
|
+
#
|
34
|
+
# Key | Metadata
|
35
|
+
# ----|---------
|
36
|
+
# lex | `{ query_string: String }`
|
37
|
+
# parse | `{ query_string: String }`
|
38
|
+
# validate | `{ query: GraphQL::Query, validate: Boolean }`
|
39
|
+
# analyze_multiplex | `{ multiplex: GraphQL::Execution::Multiplex }`
|
40
|
+
# analyze_query | `{ query: GraphQL::Query }`
|
41
|
+
# execute_multiplex | `{ multiplex: GraphQL::Execution::Multiplex }`
|
42
|
+
# execute_query | `{ query: GraphQL::Query }`
|
43
|
+
# execute_query_lazy | `{ query: GraphQL::Query?, multiplex: GraphQL::Execution::Multiplex? }`
|
44
|
+
# execute_field | `{ owner: Class, field: GraphQL::Schema::Field, query: GraphQL::Query, path: Array<String, Integer>, ast_node: GraphQL::Language::Nodes::Field}`
|
45
|
+
# execute_field_lazy | `{ owner: Class, field: GraphQL::Schema::Field, query: GraphQL::Query, path: Array<String, Integer>, ast_node: GraphQL::Language::Nodes::Field}`
|
46
|
+
# authorized | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
|
47
|
+
# authorized_lazy | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
|
48
|
+
# resolve_type | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
|
49
|
+
# resolve_type_lazy | `{ context: GraphQL::Query::Context, type: Class, object: Object, path: Array<String, Integer> }`
|
50
|
+
#
|
51
|
+
# Note that `execute_field` and `execute_field_lazy` receive different data in different settings:
|
52
|
+
#
|
53
|
+
# - When using {GraphQL::Execution::Interpreter}, they receive `{field:, path:, query:}`
|
54
|
+
# - Otherwise, they receive `{context: ...}`
|
55
|
+
#
|
56
|
+
module Tracing
|
57
|
+
# Objects may include traceable to gain a `.trace(...)` method.
|
58
|
+
# The object must have a `@tracers` ivar of type `Array<<#trace(k, d, &b)>>`.
|
59
|
+
# @api private
|
60
|
+
module Traceable
|
61
|
+
# @param key [String] The name of the event in GraphQL internals
|
62
|
+
# @param metadata [Hash] Event-related metadata (can be anything)
|
63
|
+
# @return [Object] Must return the value of the block
|
64
|
+
def trace(key, metadata, &block)
|
65
|
+
return yield if @tracers.empty?
|
66
|
+
call_tracers(0, key, metadata, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# If there's a tracer at `idx`, call it and then increment `idx`.
|
72
|
+
# Otherwise, yield.
|
73
|
+
#
|
74
|
+
# @param idx [Integer] Which tracer to call
|
75
|
+
# @param key [String] The current event name
|
76
|
+
# @param metadata [Object] The current event object
|
77
|
+
# @return Whatever the block returns
|
78
|
+
def call_tracers(idx, key, metadata, &block)
|
79
|
+
if idx == @tracers.length
|
80
|
+
yield
|
81
|
+
else
|
82
|
+
@tracers[idx].trace(key, metadata) { call_tracers(idx + 1, key, metadata, &block) }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
module NullTracer
|
88
|
+
module_function
|
89
|
+
def trace(k, v)
|
90
|
+
yield
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/graphql/type_kinds.rb
CHANGED
@@ -1,20 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
# Type kinds are the basic categories which a type may belong to (`Object`, `Scalar`, `Union`...)
|
3
4
|
module TypeKinds
|
4
5
|
# These objects are singletons, eg `GraphQL::TypeKinds::UNION`, `GraphQL::TypeKinds::SCALAR`.
|
5
6
|
class TypeKind
|
6
|
-
attr_reader :name
|
7
|
-
def initialize(name,
|
7
|
+
attr_reader :name, :description
|
8
|
+
def initialize(name, abstract: false, fields: false, wraps: false, input: false, description: nil)
|
8
9
|
@name = name
|
9
|
-
@
|
10
|
+
@abstract = abstract
|
10
11
|
@fields = fields
|
11
12
|
@wraps = wraps
|
12
13
|
@input = input
|
13
|
-
@composite = fields? ||
|
14
|
+
@composite = fields? || abstract?
|
15
|
+
@description = description
|
14
16
|
end
|
15
17
|
|
16
18
|
# Does this TypeKind have multiple possible implementors?
|
17
|
-
|
19
|
+
# @deprecated Use `abstract?` instead of `resolves?`.
|
20
|
+
def resolves?; @abstract; end
|
21
|
+
# Is this TypeKind abstract?
|
22
|
+
def abstract?; @abstract; end
|
18
23
|
# Does this TypeKind have queryable fields?
|
19
24
|
def fields?; @fields; end
|
20
25
|
# Does this TypeKind modify another type?
|
@@ -24,26 +29,49 @@ module GraphQL
|
|
24
29
|
def to_s; @name; end
|
25
30
|
# Is this TypeKind composed of many values?
|
26
31
|
def composite?; @composite; end
|
27
|
-
end
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
INTERFACE = TypeKind.new("INTERFACE", resolves: true, fields: true),
|
33
|
-
UNION = TypeKind.new("UNION", resolves: true),
|
34
|
-
ENUM = TypeKind.new("ENUM", input: true),
|
35
|
-
INPUT_OBJECT = TypeKind.new("INPUT_OBJECT", input: true),
|
36
|
-
LIST = TypeKind.new("LIST", wraps: true),
|
37
|
-
NON_NULL = TypeKind.new("NON_NULL", wraps: true),
|
38
|
-
]
|
33
|
+
def scalar?
|
34
|
+
self == TypeKinds::SCALAR
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
def object?
|
38
|
+
self == TypeKinds::OBJECT
|
39
|
+
end
|
40
|
+
|
41
|
+
def interface?
|
42
|
+
self == TypeKinds::INTERFACE
|
43
|
+
end
|
44
|
+
|
45
|
+
def union?
|
46
|
+
self == TypeKinds::UNION
|
47
|
+
end
|
48
|
+
|
49
|
+
def enum?
|
50
|
+
self == TypeKinds::ENUM
|
51
|
+
end
|
52
|
+
|
53
|
+
def input_object?
|
54
|
+
self == TypeKinds::INPUT_OBJECT
|
55
|
+
end
|
56
|
+
|
57
|
+
def list?
|
58
|
+
self == TypeKinds::LIST
|
59
|
+
end
|
60
|
+
|
61
|
+
def non_null?
|
62
|
+
self == TypeKinds::NON_NULL
|
46
63
|
end
|
47
64
|
end
|
65
|
+
|
66
|
+
TYPE_KINDS = [
|
67
|
+
SCALAR = TypeKind.new("SCALAR", input: true, description: 'Indicates this type is a scalar.'),
|
68
|
+
OBJECT = TypeKind.new("OBJECT", fields: true, description: 'Indicates this type is an object. `fields` and `interfaces` are valid fields.'),
|
69
|
+
INTERFACE = TypeKind.new("INTERFACE", abstract: true, fields: true, description: 'Indicates this type is an interface. `fields` and `possibleTypes` are valid fields.'),
|
70
|
+
UNION = TypeKind.new("UNION", abstract: true, description: 'Indicates this type is a union. `possibleTypes` is a valid field.'),
|
71
|
+
ENUM = TypeKind.new("ENUM", input: true, description: 'Indicates this type is an enum. `enumValues` is a valid field.'),
|
72
|
+
INPUT_OBJECT = TypeKind.new("INPUT_OBJECT", input: true, description: 'Indicates this type is an input object. `inputFields` is a valid field.'),
|
73
|
+
LIST = TypeKind.new("LIST", wraps: true, description: 'Indicates this type is a list. `ofType` is a valid field.'),
|
74
|
+
NON_NULL = TypeKind.new("NON_NULL", wraps: true, description: 'Indicates this type is a non-null. `ofType` is a valid field.'),
|
75
|
+
]
|
48
76
|
end
|
49
77
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Types
|
5
|
+
class BigInt < GraphQL::Schema::Scalar
|
6
|
+
description "Represents non-fractional signed whole numeric values. Since the value may exceed the size of a 32-bit integer, it's encoded as a string."
|
7
|
+
|
8
|
+
def self.coerce_input(value, _ctx)
|
9
|
+
value && parse_int(value)
|
10
|
+
rescue ArgumentError
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.coerce_result(value, _ctx)
|
15
|
+
value.to_i.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.parse_int(value)
|
19
|
+
value.is_a?(Numeric) ? value : Integer(value, 10)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Types
|
4
|
+
class Boolean < GraphQL::Schema::Scalar
|
5
|
+
description "Represents `true` or `false` values."
|
6
|
+
|
7
|
+
def self.coerce_input(value, _ctx)
|
8
|
+
(value == true || value == false) ? value : nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.coerce_result(value, _ctx)
|
12
|
+
!!value
|
13
|
+
end
|
14
|
+
|
15
|
+
default_scalar true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Types
|
5
|
+
class Float < GraphQL::Schema::Scalar
|
6
|
+
description "Represents signed double-precision fractional values as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point)."
|
7
|
+
|
8
|
+
def self.coerce_input(value, _ctx)
|
9
|
+
value.is_a?(Numeric) ? value.to_f : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.coerce_result(value, _ctx)
|
13
|
+
value.to_f
|
14
|
+
end
|
15
|
+
|
16
|
+
default_scalar true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Types
|
4
|
+
class ID < GraphQL::Schema::Scalar
|
5
|
+
graphql_name "ID"
|
6
|
+
description "Represents a unique identifier that is Base64 obfuscated. It is often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"VXNlci0xMA==\"`) or integer (such as `4`) input value will be accepted as an ID."
|
7
|
+
default_scalar true
|
8
|
+
def self.coerce_result(value, _ctx)
|
9
|
+
value.is_a?(::String) ? value : value.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.coerce_input(value, _ctx)
|
13
|
+
case value
|
14
|
+
when ::String
|
15
|
+
value
|
16
|
+
when Integer
|
17
|
+
value.to_s
|
18
|
+
else
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Types
|
5
|
+
# @see {Types::BigInt} for handling integers outside 32-bit range.
|
6
|
+
class Int < GraphQL::Schema::Scalar
|
7
|
+
description "Represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1."
|
8
|
+
|
9
|
+
MIN = -(2**31)
|
10
|
+
MAX = (2**31) - 1
|
11
|
+
|
12
|
+
def self.coerce_input(value, ctx)
|
13
|
+
return if !value.is_a?(Integer)
|
14
|
+
|
15
|
+
if value >= MIN && value <= MAX
|
16
|
+
value
|
17
|
+
else
|
18
|
+
err = GraphQL::IntegerDecodingError.new(value)
|
19
|
+
ctx.schema.type_error(err, ctx)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.coerce_result(value, ctx)
|
24
|
+
value = value.to_i
|
25
|
+
if value >= MIN && value <= MAX
|
26
|
+
value
|
27
|
+
else
|
28
|
+
err = GraphQL::IntegerEncodingError.new(value, context: ctx)
|
29
|
+
ctx.schema.type_error(err, ctx)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
default_scalar true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Types
|
4
|
+
# This scalar takes `Date`s and transmits them as strings,
|
5
|
+
# using ISO 8601 format.
|
6
|
+
#
|
7
|
+
# Use it for fields or arguments as follows:
|
8
|
+
#
|
9
|
+
# field :published_at, GraphQL::Types::ISO8601Date, null: false
|
10
|
+
#
|
11
|
+
# argument :deliver_at, GraphQL::Types::ISO8601Date, null: false
|
12
|
+
#
|
13
|
+
# Alternatively, use this built-in scalar as inspiration for your
|
14
|
+
# own Date type.
|
15
|
+
class ISO8601Date < GraphQL::Schema::Scalar
|
16
|
+
description "An ISO 8601-encoded date"
|
17
|
+
specified_by_url "https://tools.ietf.org/html/rfc3339"
|
18
|
+
|
19
|
+
# @param value [Date,Time,DateTime,String]
|
20
|
+
# @return [String]
|
21
|
+
def self.coerce_result(value, _ctx)
|
22
|
+
Date.parse(value.to_s).iso8601
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param str_value [String, Date, DateTime, Time]
|
26
|
+
# @return [Date, nil]
|
27
|
+
def self.coerce_input(value, ctx)
|
28
|
+
if value.is_a?(::Date)
|
29
|
+
value
|
30
|
+
elsif value.is_a?(::DateTime)
|
31
|
+
value.to_date
|
32
|
+
elsif value.is_a?(::Time)
|
33
|
+
value.to_date
|
34
|
+
elsif value.nil?
|
35
|
+
nil
|
36
|
+
else
|
37
|
+
Date.iso8601(value)
|
38
|
+
end
|
39
|
+
rescue ArgumentError, TypeError
|
40
|
+
err = GraphQL::DateEncodingError.new(value)
|
41
|
+
ctx.schema.type_error(err, ctx)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module GraphQL
|
6
|
+
module Types
|
7
|
+
# This scalar takes `Time`s and transmits them as strings,
|
8
|
+
# using ISO 8601 format.
|
9
|
+
#
|
10
|
+
# Use it for fields or arguments as follows:
|
11
|
+
#
|
12
|
+
# field :created_at, GraphQL::Types::ISO8601DateTime, null: false
|
13
|
+
#
|
14
|
+
# argument :deliver_at, GraphQL::Types::ISO8601DateTime, null: false
|
15
|
+
#
|
16
|
+
# Alternatively, use this built-in scalar as inspiration for your
|
17
|
+
# own DateTime type.
|
18
|
+
class ISO8601DateTime < GraphQL::Schema::Scalar
|
19
|
+
description "An ISO 8601-encoded datetime"
|
20
|
+
specified_by_url "https://tools.ietf.org/html/rfc3339"
|
21
|
+
|
22
|
+
# It's not compatible with Rails' default,
|
23
|
+
# i.e. ActiveSupport::JSON::Encoder.time_precision (3 by default)
|
24
|
+
DEFAULT_TIME_PRECISION = 0
|
25
|
+
|
26
|
+
# @return [Integer]
|
27
|
+
def self.time_precision
|
28
|
+
@time_precision || DEFAULT_TIME_PRECISION
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param [Integer] value
|
32
|
+
def self.time_precision=(value)
|
33
|
+
@time_precision = value
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param value [Time,Date,DateTime,String]
|
37
|
+
# @return [String]
|
38
|
+
def self.coerce_result(value, _ctx)
|
39
|
+
case value
|
40
|
+
when Date
|
41
|
+
return value.to_time.iso8601(time_precision)
|
42
|
+
when ::String
|
43
|
+
return Time.parse(value).iso8601(time_precision)
|
44
|
+
else
|
45
|
+
# Time, DateTime or compatible is given:
|
46
|
+
return value.iso8601(time_precision)
|
47
|
+
end
|
48
|
+
rescue StandardError => error
|
49
|
+
raise GraphQL::Error, "An incompatible object (#{value.class}) was given to #{self}. Make sure that only Times, Dates, DateTimes, and well-formatted Strings are used with this type. (#{error.message})"
|
50
|
+
end
|
51
|
+
|
52
|
+
# @param str_value [String]
|
53
|
+
# @return [Time]
|
54
|
+
def self.coerce_input(str_value, _ctx)
|
55
|
+
Time.iso8601(str_value)
|
56
|
+
rescue ArgumentError, TypeError
|
57
|
+
begin
|
58
|
+
dt = Date.iso8601(str_value).to_time
|
59
|
+
# For compatibility, continue accepting dates given without times
|
60
|
+
# But without this, it would zero out given any time part of `str_value` (hours and/or minutes)
|
61
|
+
if dt.iso8601.start_with?(str_value)
|
62
|
+
dt
|
63
|
+
elsif str_value.length == 8 && str_value.match?(/\A\d{8}\Z/)
|
64
|
+
# Allow dates that are missing the "-". eg. "20220404"
|
65
|
+
dt
|
66
|
+
else
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
rescue ArgumentError, TypeError
|
70
|
+
# Invalid input
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Types
|
4
|
+
# An untyped JSON scalar that maps to Ruby hashes, arrays, strings, integers, floats, booleans and nils.
|
5
|
+
# This should be used judiciously because it subverts the GraphQL type system.
|
6
|
+
#
|
7
|
+
# Use it for fields or arguments as follows:
|
8
|
+
#
|
9
|
+
# field :template_parameters, GraphQL::Types::JSON, null: false
|
10
|
+
#
|
11
|
+
# argument :template_parameters, GraphQL::Types::JSON, null: false
|
12
|
+
#
|
13
|
+
class JSON < GraphQL::Schema::Scalar
|
14
|
+
description "Represents untyped JSON"
|
15
|
+
|
16
|
+
def self.coerce_input(value, _context)
|
17
|
+
value
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.coerce_result(value, _context)
|
21
|
+
value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Types
|
5
|
+
module Relay
|
6
|
+
# Use this to implement Relay connections, or take it as inspiration
|
7
|
+
# for Relay classes in your own app.
|
8
|
+
#
|
9
|
+
# You may wish to copy this code into your own base class,
|
10
|
+
# so you can extend your own `BaseObject` instead of `GraphQL::Schema::Object`.
|
11
|
+
#
|
12
|
+
# @example Implementation a connection and edge
|
13
|
+
# class BaseObject < GraphQL::Schema::Object; end
|
14
|
+
#
|
15
|
+
# # Given some object in your app ...
|
16
|
+
# class Types::Post < BaseObject
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# # Make a couple of base classes:
|
20
|
+
# class Types::BaseEdge < GraphQL::Types::Relay::BaseEdge; end
|
21
|
+
# class Types::BaseConnection < GraphQL::Types::Relay::BaseConnection; end
|
22
|
+
#
|
23
|
+
# # Then extend them for the object in your app
|
24
|
+
# class Types::PostEdge < Types::BaseEdge
|
25
|
+
# node_type Types::Post
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# class Types::PostConnection < Types::BaseConnection
|
29
|
+
# edge_type Types::PostEdge,
|
30
|
+
# edges_nullable: true,
|
31
|
+
# edge_nullable: true,
|
32
|
+
# node_nullable: true,
|
33
|
+
# nodes_field: true
|
34
|
+
#
|
35
|
+
# # Alternatively, you can call the class methods followed by your edge type
|
36
|
+
# # edges_nullable true
|
37
|
+
# # edge_nullable true
|
38
|
+
# # nodes_nullable true
|
39
|
+
# # has_nodes_field true
|
40
|
+
# # edge_type Types::PostEdge
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# @see Relay::BaseEdge for edge types
|
44
|
+
class BaseConnection < Schema::Object
|
45
|
+
include ConnectionBehaviors
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module Types
|
4
|
+
module Relay
|
5
|
+
# A class-based definition for Relay edges.
|
6
|
+
#
|
7
|
+
# Use this as a parent class in your app, or use it as inspiration for your
|
8
|
+
# own base `Edge` class.
|
9
|
+
#
|
10
|
+
# For example, you may want to extend your own `BaseObject` instead of the
|
11
|
+
# built-in `GraphQL::Schema::Object`.
|
12
|
+
#
|
13
|
+
# @example Making a UserEdge type
|
14
|
+
# # Make a base class for your app
|
15
|
+
# class Types::BaseEdge < GraphQL::Types::Relay::BaseEdge
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# # Then extend your own base class
|
19
|
+
# class Types::UserEdge < Types::BaseEdge
|
20
|
+
# node_type(Types::User)
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# @see {Relay::BaseConnection} for connection types
|
24
|
+
class BaseEdge < GraphQL::Schema::Object
|
25
|
+
include Types::Relay::EdgeBehaviors
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|