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,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'graphql/schema/member/base_dsl_methods'
|
3
|
+
require 'graphql/schema/member/graphql_type_names'
|
4
|
+
require 'graphql/schema/member/has_ast_node'
|
5
|
+
require 'graphql/schema/member/has_directives'
|
6
|
+
require 'graphql/schema/member/has_deprecation_reason'
|
7
|
+
require 'graphql/schema/member/has_interfaces'
|
8
|
+
require 'graphql/schema/member/has_path'
|
9
|
+
require 'graphql/schema/member/has_unresolved_type_error'
|
10
|
+
require 'graphql/schema/member/has_validators'
|
11
|
+
require 'graphql/schema/member/relay_shortcuts'
|
12
|
+
require 'graphql/schema/member/scoped'
|
13
|
+
require 'graphql/schema/member/type_system_helpers'
|
14
|
+
require 'graphql/schema/member/validates_input'
|
15
|
+
|
16
|
+
module GraphQL
|
17
|
+
class Schema
|
18
|
+
# The base class for things that make up the schema,
|
19
|
+
# eg objects, enums, scalars.
|
20
|
+
#
|
21
|
+
# @api private
|
22
|
+
class Member
|
23
|
+
include GraphQLTypeNames
|
24
|
+
extend BaseDSLMethods
|
25
|
+
extend BaseDSLMethods::ConfigurationExtension
|
26
|
+
introspection(false)
|
27
|
+
extend TypeSystemHelpers
|
28
|
+
extend Scoped
|
29
|
+
extend RelayShortcuts
|
30
|
+
extend HasPath
|
31
|
+
extend HasAstNode
|
32
|
+
extend HasDirectives
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
require 'graphql/schema/member/has_arguments'
|
38
|
+
require 'graphql/schema/member/has_fields'
|
39
|
+
require 'graphql/schema/member/build_type'
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
# This base class accepts configuration for a mutation root field,
|
6
|
+
# then it can be hooked up to your mutation root object type.
|
7
|
+
#
|
8
|
+
# If you want to customize how this class generates types, in your base class,
|
9
|
+
# override the various `generate_*` methods.
|
10
|
+
#
|
11
|
+
# @see {GraphQL::Schema::RelayClassicMutation} for an extension of this class with some conventions built-in.
|
12
|
+
#
|
13
|
+
# @example Creating a comment
|
14
|
+
# # Define the mutation:
|
15
|
+
# class Mutations::CreateComment < GraphQL::Schema::Mutation
|
16
|
+
# argument :body, String, required: true
|
17
|
+
# argument :post_id, ID, required: true
|
18
|
+
#
|
19
|
+
# field :comment, Types::Comment, null: true
|
20
|
+
# field :errors, [String], null: false
|
21
|
+
#
|
22
|
+
# def resolve(body:, post_id:)
|
23
|
+
# post = Post.find(post_id)
|
24
|
+
# comment = post.comments.build(body: body, author: context[:current_user])
|
25
|
+
# if comment.save
|
26
|
+
# # Successful creation, return the created object with no errors
|
27
|
+
# {
|
28
|
+
# comment: comment,
|
29
|
+
# errors: [],
|
30
|
+
# }
|
31
|
+
# else
|
32
|
+
# # Failed save, return the errors to the client
|
33
|
+
# {
|
34
|
+
# comment: nil,
|
35
|
+
# errors: comment.errors.full_messages
|
36
|
+
# }
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# # Hook it up to your mutation:
|
42
|
+
# class Types::Mutation < GraphQL::Schema::Object
|
43
|
+
# field :create_comment, mutation: Mutations::CreateComment
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# # Call it from GraphQL:
|
47
|
+
# result = MySchema.execute <<-GRAPHQL
|
48
|
+
# mutation {
|
49
|
+
# createComment(postId: "1", body: "Nice Post!") {
|
50
|
+
# errors
|
51
|
+
# comment {
|
52
|
+
# body
|
53
|
+
# author {
|
54
|
+
# login
|
55
|
+
# }
|
56
|
+
# }
|
57
|
+
# }
|
58
|
+
# }
|
59
|
+
# GRAPHQL
|
60
|
+
#
|
61
|
+
class Mutation < GraphQL::Schema::Resolver
|
62
|
+
extend GraphQL::Schema::Member::HasFields
|
63
|
+
extend GraphQL::Schema::Resolver::HasPayloadType
|
64
|
+
|
65
|
+
class << self
|
66
|
+
def visible?(context)
|
67
|
+
true
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def conflict_field_name_warning(field_defn)
|
73
|
+
"#{self.graphql_name}'s `field :#{field_defn.name}` conflicts with a built-in method, use `hash_key:` or `method:` to pick a different resolve behavior for this field (for example, `hash_key: :#{field_defn.resolver_method}_value`, and modify the return hash). Or use `method_conflict_warning: false` to suppress this warning."
|
74
|
+
end
|
75
|
+
|
76
|
+
# Override this to attach self as `mutation`
|
77
|
+
def generate_payload_type
|
78
|
+
payload_class = super
|
79
|
+
payload_class.mutation(self)
|
80
|
+
payload_class
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
class Schema
|
5
|
+
# Represents a non null type in the schema.
|
6
|
+
# Wraps a {Schema::Member} when it is required.
|
7
|
+
# @see {Schema::Member::TypeSystemHelpers#to_non_null_type}
|
8
|
+
class NonNull < GraphQL::Schema::Wrapper
|
9
|
+
include Schema::Member::ValidatesInput
|
10
|
+
|
11
|
+
# @return [GraphQL::TypeKinds::NON_NULL]
|
12
|
+
def kind
|
13
|
+
GraphQL::TypeKinds::NON_NULL
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [true]
|
17
|
+
def non_null?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [Boolean] True if this type wraps a list type
|
22
|
+
def list?
|
23
|
+
@of_type.list?
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_type_signature
|
27
|
+
"#{@of_type.to_type_signature}!"
|
28
|
+
end
|
29
|
+
|
30
|
+
def inspect
|
31
|
+
"#<#{self.class.name} @of_type=#{@of_type.inspect}>"
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_input(value, ctx, max_errors: nil)
|
35
|
+
if value.nil?
|
36
|
+
result = GraphQL::Query::InputValidationResult.new
|
37
|
+
result.add_problem("Expected value to not be null")
|
38
|
+
result
|
39
|
+
else
|
40
|
+
of_type.validate_input(value, ctx, max_errors: max_errors)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# This is for introspection, where it's expected the name will be `null`
|
45
|
+
def graphql_name
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def coerce_input(value, ctx)
|
50
|
+
# `.validate_input` above is used for variables, but this method is used for arguments
|
51
|
+
if value.nil?
|
52
|
+
raise GraphQL::ExecutionError, "`null` is not a valid input for `#{to_type_signature}`, please provide a value for this argument."
|
53
|
+
end
|
54
|
+
of_type.coerce_input(value, ctx)
|
55
|
+
end
|
56
|
+
|
57
|
+
def coerce_result(value, ctx)
|
58
|
+
of_type.coerce_result(value, ctx)
|
59
|
+
end
|
60
|
+
|
61
|
+
# This is for implementing introspection
|
62
|
+
def description
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "graphql/query/null_context"
|
4
|
+
|
5
|
+
module GraphQL
|
6
|
+
class Schema
|
7
|
+
class Object < GraphQL::Schema::Member
|
8
|
+
extend GraphQL::Schema::Member::HasFields
|
9
|
+
extend GraphQL::Schema::Member::HasInterfaces
|
10
|
+
|
11
|
+
# @return [Object] the application object this type is wrapping
|
12
|
+
attr_reader :object
|
13
|
+
|
14
|
+
# @return [GraphQL::Query::Context] the context instance for this query
|
15
|
+
attr_reader :context
|
16
|
+
|
17
|
+
# @return [GraphQL::Dataloader]
|
18
|
+
def dataloader
|
19
|
+
context.dataloader
|
20
|
+
end
|
21
|
+
|
22
|
+
# Call this in a field method to return a value that should be returned to the client
|
23
|
+
# without any further handling by GraphQL.
|
24
|
+
def raw_value(obj)
|
25
|
+
GraphQL::Execution::Interpreter::RawValue.new(obj)
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
# This is protected so that we can be sure callers use the public method, {.authorized_new}
|
30
|
+
# @see authorized_new to make instances
|
31
|
+
protected :new
|
32
|
+
|
33
|
+
# Make a new instance of this type _if_ the auth check passes,
|
34
|
+
# otherwise, raise an error.
|
35
|
+
#
|
36
|
+
# Probably only the framework should call this method.
|
37
|
+
#
|
38
|
+
# This might return a {GraphQL::Execution::Lazy} if the user-provided `.authorized?`
|
39
|
+
# hook returns some lazy value (like a Promise).
|
40
|
+
#
|
41
|
+
# The reason that the auth check is in this wrapper method instead of {.new} is because
|
42
|
+
# of how it might return a Promise. It would be weird if `.new` returned a promise;
|
43
|
+
# It would be a headache to try to maintain Promise-y state inside a {Schema::Object}
|
44
|
+
# instance. So, hopefully this wrapper method will do the job.
|
45
|
+
#
|
46
|
+
# @param object [Object] The thing wrapped by this object
|
47
|
+
# @param context [GraphQL::Query::Context]
|
48
|
+
# @return [GraphQL::Schema::Object, GraphQL::Execution::Lazy]
|
49
|
+
# @raise [GraphQL::UnauthorizedError] if the user-provided hook returns `false`
|
50
|
+
def authorized_new(object, context)
|
51
|
+
trace_payload = { context: context, type: self, object: object, path: context[:current_path] }
|
52
|
+
|
53
|
+
maybe_lazy_auth_val = context.query.trace("authorized", trace_payload) do
|
54
|
+
begin
|
55
|
+
authorized?(object, context)
|
56
|
+
rescue GraphQL::UnauthorizedError => err
|
57
|
+
context.schema.unauthorized_object(err)
|
58
|
+
rescue StandardError => err
|
59
|
+
context.query.handle_or_reraise(err)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
auth_val = if context.schema.lazy?(maybe_lazy_auth_val)
|
64
|
+
GraphQL::Execution::Lazy.new do
|
65
|
+
context.query.trace("authorized_lazy", trace_payload) do
|
66
|
+
context.schema.sync_lazy(maybe_lazy_auth_val)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
else
|
70
|
+
maybe_lazy_auth_val
|
71
|
+
end
|
72
|
+
|
73
|
+
context.schema.after_lazy(auth_val) do |is_authorized|
|
74
|
+
if is_authorized
|
75
|
+
self.new(object, context)
|
76
|
+
else
|
77
|
+
# It failed the authorization check, so go to the schema's authorized object hook
|
78
|
+
err = GraphQL::UnauthorizedError.new(object: object, type: self, context: context)
|
79
|
+
# If a new value was returned, wrap that instead of the original value
|
80
|
+
begin
|
81
|
+
new_obj = context.schema.unauthorized_object(err)
|
82
|
+
if new_obj
|
83
|
+
self.new(new_obj, context)
|
84
|
+
else
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def initialize(object, context)
|
94
|
+
@object = object
|
95
|
+
@context = context
|
96
|
+
end
|
97
|
+
|
98
|
+
class << self
|
99
|
+
# Set up a type-specific invalid null error to use when this object's non-null fields wrongly return `nil`.
|
100
|
+
# It should help with debugging and bug tracker integrations.
|
101
|
+
def const_missing(name)
|
102
|
+
if name == :InvalidNullError
|
103
|
+
custom_err_class = GraphQL::InvalidNullError.subclass_for(self)
|
104
|
+
const_set(:InvalidNullError, custom_err_class)
|
105
|
+
custom_err_class
|
106
|
+
else
|
107
|
+
super
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def kind
|
112
|
+
GraphQL::TypeKinds::OBJECT
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -1,156 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
class Schema
|
3
4
|
# Used to convert your {GraphQL::Schema} to a GraphQL schema string
|
4
5
|
#
|
6
|
+
# @example print your schema to standard output (via helper)
|
7
|
+
# puts GraphQL::Schema::Printer.print_schema(MySchema)
|
8
|
+
#
|
5
9
|
# @example print your schema to standard output
|
6
|
-
#
|
7
|
-
#
|
10
|
+
# puts GraphQL::Schema::Printer.new(MySchema).print_schema
|
11
|
+
#
|
12
|
+
# @example print a single type to standard output
|
13
|
+
# class Types::Query < GraphQL::Schema::Object
|
14
|
+
# description "The query root of this schema"
|
15
|
+
#
|
16
|
+
# field :post, Types::Post, null: true
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# class Types::Post < GraphQL::Schema::Object
|
20
|
+
# description "A blog post"
|
8
21
|
#
|
9
|
-
|
10
|
-
|
22
|
+
# field :id, ID, null: false
|
23
|
+
# field :title, String, null: false
|
24
|
+
# field :body, String, null: false
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# class MySchema < GraphQL::Schema
|
28
|
+
# query(Types::Query)
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# printer = GraphQL::Schema::Printer.new(MySchema)
|
32
|
+
# puts printer.print_type(Types::Post)
|
33
|
+
#
|
34
|
+
class Printer < GraphQL::Language::Printer
|
35
|
+
attr_reader :schema, :warden
|
11
36
|
|
12
|
-
# Return a GraphQL schema string for the defined types in the schema
|
13
37
|
# @param schema [GraphQL::Schema]
|
14
|
-
|
15
|
-
|
38
|
+
# @param context [Hash]
|
39
|
+
# @param only [<#call(member, ctx)>]
|
40
|
+
# @param except [<#call(member, ctx)>]
|
41
|
+
# @param introspection [Boolean] Should include the introspection types in the string?
|
42
|
+
def initialize(schema, context: nil, only: nil, except: nil, introspection: false)
|
43
|
+
@document_from_schema = GraphQL::Language::DocumentFromSchemaDefinition.new(
|
44
|
+
schema,
|
45
|
+
context: context,
|
46
|
+
only: only,
|
47
|
+
except: except,
|
48
|
+
include_introspection_types: introspection,
|
49
|
+
)
|
50
|
+
|
51
|
+
@document = @document_from_schema.document
|
52
|
+
@schema = schema
|
16
53
|
end
|
17
54
|
|
18
55
|
# Return the GraphQL schema string for the introspection type system
|
19
|
-
def print_introspection_schema
|
20
|
-
query_root =
|
21
|
-
|
56
|
+
def self.print_introspection_schema
|
57
|
+
query_root = Class.new(GraphQL::Schema::Object) do
|
58
|
+
graphql_name "Root"
|
59
|
+
field :throwaway_field, String
|
22
60
|
end
|
23
|
-
schema =
|
24
|
-
print_filtered_schema(schema, method(:is_introspection_type))
|
25
|
-
end
|
61
|
+
schema = Class.new(GraphQL::Schema) { query(query_root) }
|
26
62
|
|
27
|
-
|
63
|
+
introspection_schema_ast = GraphQL::Language::DocumentFromSchemaDefinition.new(
|
64
|
+
schema,
|
65
|
+
except: ->(member, _) { member.graphql_name == "Root" },
|
66
|
+
include_introspection_types: true,
|
67
|
+
include_built_in_directives: true,
|
68
|
+
).document
|
28
69
|
|
29
|
-
|
30
|
-
types = schema.types.values.select{ |type| type_filter.call(type) }.sort_by(&:name)
|
31
|
-
types.map{ |type| print_type(type) }.join("\n\n")
|
70
|
+
introspection_schema_ast.to_query_string(printer: IntrospectionPrinter.new)
|
32
71
|
end
|
33
72
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
73
|
+
# Return a GraphQL schema string for the defined types in the schema
|
74
|
+
# @param schema [GraphQL::Schema]
|
75
|
+
# @param context [Hash]
|
76
|
+
# @param only [<#call(member, ctx)>]
|
77
|
+
# @param except [<#call(member, ctx)>]
|
78
|
+
def self.print_schema(schema, **args)
|
79
|
+
printer = new(schema, **args)
|
80
|
+
printer.print_schema
|
39
81
|
end
|
40
82
|
|
41
|
-
|
42
|
-
|
83
|
+
# Return a GraphQL schema string for the defined types in the schema
|
84
|
+
def print_schema
|
85
|
+
print(@document) + "\n"
|
43
86
|
end
|
44
87
|
|
45
88
|
def print_type(type)
|
46
|
-
|
89
|
+
node = @document_from_schema.build_type_definition_node(type)
|
90
|
+
print(node)
|
47
91
|
end
|
48
92
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
type.all_fields.map{ |field| " #{field.name}#{print_args(field)}: #{field.type}" }.join("\n")
|
53
|
-
end
|
54
|
-
|
55
|
-
def print_args(field)
|
56
|
-
return if field.arguments.empty?
|
57
|
-
"(#{field.arguments.values.map{ |arg| print_input_value(arg) }.join(", ")})"
|
58
|
-
end
|
59
|
-
|
60
|
-
def print_input_value(arg)
|
61
|
-
if arg.default_value.nil?
|
62
|
-
default_string = nil
|
63
|
-
else
|
64
|
-
default_string = " = #{print_value(arg.default_value, arg.type)}"
|
65
|
-
end
|
66
|
-
|
67
|
-
"#{arg.name}: #{arg.type.to_s}#{default_string}"
|
68
|
-
end
|
69
|
-
|
70
|
-
def print_value(value, type)
|
71
|
-
case type
|
72
|
-
when FLOAT_TYPE
|
73
|
-
value.to_f.inspect
|
74
|
-
when INT_TYPE
|
75
|
-
value.to_i.inspect
|
76
|
-
when BOOLEAN_TYPE
|
77
|
-
(!!value).inspect
|
78
|
-
when ScalarType, ID_TYPE, STRING_TYPE
|
79
|
-
value.to_s.inspect
|
80
|
-
when EnumType
|
81
|
-
value.to_s
|
82
|
-
when InputObjectType
|
83
|
-
fields = value.to_h.map{ |field_name, field_value|
|
84
|
-
field_type = type.input_fields.fetch(field_name.to_s).type
|
85
|
-
"#{field_name}: #{print_value(field_value, field_type)}"
|
86
|
-
}.join(", ")
|
87
|
-
"{ #{fields} }"
|
88
|
-
when NonNullType
|
89
|
-
print_value(value, type.of_type)
|
90
|
-
when ListType
|
91
|
-
"[#{value.to_a.map{ |v| print_value(v, type.of_type) }.join(", ")}]"
|
92
|
-
else
|
93
|
-
raise NotImplementedError, "Unexpected value type #{type.inspect}"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class ScalarPrinter
|
99
|
-
def self.print(type)
|
100
|
-
"scalar #{type.name}"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
class ObjectPrinter
|
105
|
-
extend FieldPrinter
|
106
|
-
def self.print(type)
|
107
|
-
if type.interfaces.any?
|
108
|
-
implementations = " implements #{type.interfaces.map(&:to_s).join(", ")}"
|
109
|
-
else
|
110
|
-
implementations = nil
|
111
|
-
end
|
112
|
-
"type #{type.name}#{implementations} {\n#{print_fields(type)}\n}"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
class InterfacePrinter
|
117
|
-
extend FieldPrinter
|
118
|
-
def self.print(type)
|
119
|
-
"interface #{type.name} {\n#{print_fields(type)}\n}"
|
120
|
-
end
|
93
|
+
class IntrospectionPrinter < GraphQL::Language::Printer
|
94
|
+
def print_schema_definition(schema)
|
95
|
+
"schema {\n query: Root\n}"
|
121
96
|
end
|
122
|
-
|
123
|
-
class UnionPrinter
|
124
|
-
def self.print(type)
|
125
|
-
"union #{type.name} = #{type.possible_types.map(&:to_s).join(" | ")}\n}"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
class EnumPrinter
|
130
|
-
def self.print(type)
|
131
|
-
values = type.values.values.map{ |v| " #{v.name}" }.join("\n")
|
132
|
-
"enum #{type.name} {\n#{values}\n}"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
class InputObjectPrinter
|
137
|
-
extend FieldPrinter
|
138
|
-
def self.print(type)
|
139
|
-
fields = type.input_fields.values.map{ |field| " #{print_input_value(field)}" }.join("\n")
|
140
|
-
"input #{type.name} {\n#{fields}\n}"
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
STRATEGIES = {
|
145
|
-
GraphQL::TypeKinds::SCALAR => ScalarPrinter,
|
146
|
-
GraphQL::TypeKinds::OBJECT => ObjectPrinter,
|
147
|
-
GraphQL::TypeKinds::INTERFACE => InterfacePrinter,
|
148
|
-
GraphQL::TypeKinds::UNION => UnionPrinter,
|
149
|
-
GraphQL::TypeKinds::ENUM => EnumPrinter,
|
150
|
-
GraphQL::TypeKinds::INPUT_OBJECT => InputObjectPrinter,
|
151
|
-
}
|
152
97
|
end
|
153
|
-
private_constant :TypeKindPrinters
|
154
98
|
end
|
155
99
|
end
|
156
100
|
end
|