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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 46b43157a331eae41dd54897d24dbc3adac190910237c7c1c158fc2bc32b6616
|
4
|
+
data.tar.gz: 118ac97b740ba1340d3e6b9aee5fa2f81ca25dc8769a98ec0d8e25d63e839711
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be38356ecdff7f8a9627bb021e83d13ea92e951b287386e76fd6e42ff05ef0a5a37ce9c98e6e4bf1834459989558f6c8b512c98e7642bef2c624578c1db24932
|
7
|
+
data.tar.gz: b0b75f342dca7a731b1b59e6399d364184152ceb0c5deb9fb4338a3582b3b6e38bf789a53839f6def9eb4b9c079c45e74675fb608a184dff4e6aeaf0ce052dfd
|
data/.yardopts
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/generators/base'
|
3
|
+
|
4
|
+
module Graphql
|
5
|
+
module Generators
|
6
|
+
module Core
|
7
|
+
def self.included(base)
|
8
|
+
base.send(
|
9
|
+
:class_option,
|
10
|
+
:directory,
|
11
|
+
type: :string,
|
12
|
+
default: "app/graphql",
|
13
|
+
desc: "Directory where generated files should be saved"
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def insert_root_type(type, name)
|
18
|
+
log :add_root_type, type
|
19
|
+
sentinel = /< GraphQL::Schema\s*\n/m
|
20
|
+
|
21
|
+
in_root do
|
22
|
+
if File.exist?(schema_file_path)
|
23
|
+
inject_into_file schema_file_path, " #{type}(Types::#{name})\n", after: sentinel, verbose: false, force: false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def schema_file_path
|
29
|
+
"#{options[:directory]}/#{schema_name.underscore}.rb"
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_dir(dir)
|
33
|
+
empty_directory(dir)
|
34
|
+
if !options[:skip_keeps]
|
35
|
+
create_file("#{dir}/.keep")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def module_namespacing_when_supported
|
40
|
+
if defined?(module_namespacing)
|
41
|
+
module_namespacing { yield }
|
42
|
+
else
|
43
|
+
yield
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def schema_name
|
50
|
+
@schema_name ||= begin
|
51
|
+
if options[:schema]
|
52
|
+
options[:schema]
|
53
|
+
else
|
54
|
+
"#{parent_name}Schema"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def parent_name
|
60
|
+
require File.expand_path("config/application", destination_root)
|
61
|
+
if Rails.application.class.respond_to?(:module_parent_name)
|
62
|
+
Rails.application.class.module_parent_name
|
63
|
+
else
|
64
|
+
Rails.application.class.parent_name
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'generators/graphql/type_generator'
|
3
|
+
|
4
|
+
module Graphql
|
5
|
+
module Generators
|
6
|
+
# Generate an enum type by name, with the given values.
|
7
|
+
# To add a `value:` option, add another value after a `:`.
|
8
|
+
#
|
9
|
+
# ```
|
10
|
+
# rails g graphql:enum ProgrammingLanguage RUBY PYTHON PERL PERL6:"PERL"
|
11
|
+
# ```
|
12
|
+
class EnumGenerator < TypeGeneratorBase
|
13
|
+
desc "Create a GraphQL::EnumType with the given name and values"
|
14
|
+
source_root File.expand_path('../templates', __FILE__)
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def graphql_type
|
19
|
+
"enum"
|
20
|
+
end
|
21
|
+
|
22
|
+
def prepared_values
|
23
|
+
custom_fields.map { |v| v.split(":", 2) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/generators/base'
|
3
|
+
|
4
|
+
module Graphql
|
5
|
+
module Generators
|
6
|
+
module FieldExtractor
|
7
|
+
def fields
|
8
|
+
columns = []
|
9
|
+
columns += (klass&.columns&.map { |c| generate_column_string(c) } || [])
|
10
|
+
columns + custom_fields
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_column_string(column)
|
14
|
+
name = column.name
|
15
|
+
required = column.null ? "" : "!"
|
16
|
+
type = column_type_string(column)
|
17
|
+
"#{name}:#{required}#{type}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def column_type_string(column)
|
21
|
+
column.name == "id" ? "ID" : column.type.to_s.camelize
|
22
|
+
end
|
23
|
+
|
24
|
+
def klass
|
25
|
+
@klass ||= Module.const_get(name.camelize)
|
26
|
+
rescue NameError
|
27
|
+
@klass = nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'generators/graphql/type_generator'
|
3
|
+
require 'generators/graphql/field_extractor'
|
4
|
+
|
5
|
+
module Graphql
|
6
|
+
module Generators
|
7
|
+
# Generate an input type by name,
|
8
|
+
# with the specified fields.
|
9
|
+
#
|
10
|
+
# ```
|
11
|
+
# rails g graphql:object PostType name:string!
|
12
|
+
# ```
|
13
|
+
class InputGenerator < TypeGeneratorBase
|
14
|
+
desc "Create a GraphQL::InputObjectType with the given name and fields"
|
15
|
+
source_root File.expand_path('../templates', __FILE__)
|
16
|
+
include FieldExtractor
|
17
|
+
|
18
|
+
def self.normalize_type_expression(type_expression, mode:, null: true)
|
19
|
+
case type_expression.camelize
|
20
|
+
when "Text", "Citext"
|
21
|
+
["String", null]
|
22
|
+
when "Decimal"
|
23
|
+
["Float", null]
|
24
|
+
when "DateTime", "Datetime"
|
25
|
+
["GraphQL::Types::ISO8601DateTime", null]
|
26
|
+
when "Date"
|
27
|
+
["GraphQL::Types::ISO8601Date", null]
|
28
|
+
when "Json", "Jsonb", "Hstore"
|
29
|
+
["GraphQL::Types::JSON", null]
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def graphql_type
|
38
|
+
"input"
|
39
|
+
end
|
40
|
+
|
41
|
+
def type_ruby_name
|
42
|
+
super.gsub(/Type\z/, "InputType")
|
43
|
+
end
|
44
|
+
|
45
|
+
def type_file_name
|
46
|
+
super.gsub(/_type\z/, "_input_type")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators/base"
|
4
|
+
require_relative "../core"
|
5
|
+
|
6
|
+
module Graphql
|
7
|
+
module Generators
|
8
|
+
module Install
|
9
|
+
class MutationRootGenerator < Rails::Generators::Base
|
10
|
+
include Core
|
11
|
+
|
12
|
+
desc "Create mutation base type, mutation root tipe, and adds the latter to the schema"
|
13
|
+
source_root File.expand_path('../templates', __FILE__)
|
14
|
+
|
15
|
+
class_option :schema,
|
16
|
+
type: :string,
|
17
|
+
default: nil,
|
18
|
+
desc: "Name for the schema constant (default: {app_name}Schema)"
|
19
|
+
|
20
|
+
class_option :skip_keeps,
|
21
|
+
type: :boolean,
|
22
|
+
default: false,
|
23
|
+
desc: "Skip .keep files for source control"
|
24
|
+
|
25
|
+
def generate
|
26
|
+
create_dir("#{options[:directory]}/mutations")
|
27
|
+
template("base_mutation.erb", "#{options[:directory]}/mutations/base_mutation.rb", { skip: true })
|
28
|
+
template("mutation_type.erb", "#{options[:directory]}/types/mutation_type.rb", { skip: true })
|
29
|
+
insert_root_type('mutation', 'MutationType')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% module_namespacing_when_supported do -%>
|
2
|
+
module Mutations
|
3
|
+
class BaseMutation < GraphQL::Schema::RelayClassicMutation
|
4
|
+
argument_class Types::BaseArgument
|
5
|
+
field_class Types::BaseField
|
6
|
+
input_object_class Types::BaseInputObject
|
7
|
+
object_class Types::BaseObject
|
8
|
+
end
|
9
|
+
end
|
10
|
+
<% end -%>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<% module_namespacing_when_supported do -%>
|
2
|
+
module Types
|
3
|
+
class MutationType < Types::BaseObject
|
4
|
+
# TODO: remove me
|
5
|
+
field :test_field, String, null: false,
|
6
|
+
description: "An example field added by the generator"
|
7
|
+
def test_field
|
8
|
+
"Hello World"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
<% end -%>
|
@@ -0,0 +1,197 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'rails/generators/base'
|
4
|
+
require_relative 'core'
|
5
|
+
require_relative 'relay'
|
6
|
+
|
7
|
+
module Graphql
|
8
|
+
module Generators
|
9
|
+
# Add GraphQL to a Rails app with `rails g graphql:install`.
|
10
|
+
#
|
11
|
+
# Setup a folder structure for GraphQL:
|
12
|
+
#
|
13
|
+
# ```
|
14
|
+
# - app/
|
15
|
+
# - graphql/
|
16
|
+
# - resolvers/
|
17
|
+
# - types/
|
18
|
+
# - base_argument.rb
|
19
|
+
# - base_field.rb
|
20
|
+
# - base_enum.rb
|
21
|
+
# - base_input_object.rb
|
22
|
+
# - base_interface.rb
|
23
|
+
# - base_object.rb
|
24
|
+
# - base_scalar.rb
|
25
|
+
# - base_union.rb
|
26
|
+
# - query_type.rb
|
27
|
+
# - loaders/
|
28
|
+
# - mutations/
|
29
|
+
# - base_mutation.rb
|
30
|
+
# - {app_name}_schema.rb
|
31
|
+
# ```
|
32
|
+
#
|
33
|
+
# (Add `.gitkeep`s by default, support `--skip-keeps`)
|
34
|
+
#
|
35
|
+
# Add a controller for serving GraphQL queries:
|
36
|
+
#
|
37
|
+
# ```
|
38
|
+
# app/controllers/graphql_controller.rb
|
39
|
+
# ```
|
40
|
+
#
|
41
|
+
# Add a route for that controller:
|
42
|
+
#
|
43
|
+
# ```ruby
|
44
|
+
# # config/routes.rb
|
45
|
+
# post "/graphql", to: "graphql#execute"
|
46
|
+
# ```
|
47
|
+
#
|
48
|
+
# Accept a `--batch` option which adds `GraphQL::Batch` setup.
|
49
|
+
#
|
50
|
+
# Use `--skip-graphiql` to skip `graphiql-rails` installation.
|
51
|
+
#
|
52
|
+
# TODO: also add base classes
|
53
|
+
class InstallGenerator < Rails::Generators::Base
|
54
|
+
include Core
|
55
|
+
include Relay
|
56
|
+
|
57
|
+
desc "Install GraphQL folder structure and boilerplate code"
|
58
|
+
source_root File.expand_path('../templates', __FILE__)
|
59
|
+
|
60
|
+
class_option :schema,
|
61
|
+
type: :string,
|
62
|
+
default: nil,
|
63
|
+
desc: "Name for the schema constant (default: {app_name}Schema)"
|
64
|
+
|
65
|
+
class_option :skip_keeps,
|
66
|
+
type: :boolean,
|
67
|
+
default: false,
|
68
|
+
desc: "Skip .keep files for source control"
|
69
|
+
|
70
|
+
class_option :skip_graphiql,
|
71
|
+
type: :boolean,
|
72
|
+
default: false,
|
73
|
+
desc: "Skip graphiql-rails installation"
|
74
|
+
|
75
|
+
class_option :skip_mutation_root_type,
|
76
|
+
type: :boolean,
|
77
|
+
default: false,
|
78
|
+
desc: "Skip creation of the mutation root type"
|
79
|
+
|
80
|
+
class_option :relay,
|
81
|
+
type: :boolean,
|
82
|
+
default: true,
|
83
|
+
desc: "Include installation of Relay conventions (nodes, connections, edges)"
|
84
|
+
|
85
|
+
class_option :batch,
|
86
|
+
type: :boolean,
|
87
|
+
default: false,
|
88
|
+
desc: "Include GraphQL::Batch installation"
|
89
|
+
|
90
|
+
class_option :playground,
|
91
|
+
type: :boolean,
|
92
|
+
default: false,
|
93
|
+
desc: "Use GraphQL Playground over Graphiql as IDE"
|
94
|
+
|
95
|
+
# These two options are taken from Rails' own generators'
|
96
|
+
class_option :api,
|
97
|
+
type: :boolean,
|
98
|
+
desc: "Preconfigure smaller stack for API only apps"
|
99
|
+
|
100
|
+
def create_folder_structure
|
101
|
+
create_dir("#{options[:directory]}/types")
|
102
|
+
template("schema.erb", schema_file_path)
|
103
|
+
|
104
|
+
["base_object", "base_argument", "base_field", "base_enum", "base_input_object", "base_interface", "base_scalar", "base_union"].each do |base_type|
|
105
|
+
template("#{base_type}.erb", "#{options[:directory]}/types/#{base_type}.rb")
|
106
|
+
end
|
107
|
+
|
108
|
+
# Note: You can't have a schema without the query type, otherwise introspection breaks
|
109
|
+
template("query_type.erb", "#{options[:directory]}/types/query_type.rb")
|
110
|
+
insert_root_type('query', 'QueryType')
|
111
|
+
|
112
|
+
invoke "graphql:install:mutation_root" unless options.skip_mutation_root_type?
|
113
|
+
|
114
|
+
template("graphql_controller.erb", "app/controllers/graphql_controller.rb")
|
115
|
+
route('post "/graphql", to: "graphql#execute"')
|
116
|
+
|
117
|
+
if options[:batch]
|
118
|
+
gem("graphql-batch")
|
119
|
+
create_dir("#{options[:directory]}/loaders")
|
120
|
+
end
|
121
|
+
|
122
|
+
if options.api?
|
123
|
+
say("Skipped graphiql, as this rails project is API only")
|
124
|
+
say(" You may wish to use GraphiQL.app for development: https://github.com/skevy/graphiql-app")
|
125
|
+
elsif !options[:skip_graphiql]
|
126
|
+
# `gem(...)` uses `gsub_file(...)` under the hood, which is a no-op for `rails destroy...` (when `behavior == :revoke`).
|
127
|
+
# So handle that case by calling `gsub_file` with `force: true`.
|
128
|
+
if behavior == :invoke && !File.read(Rails.root.join("Gemfile")).include?("graphiql-rails")
|
129
|
+
gem("graphiql-rails", group: :development)
|
130
|
+
elsif behavior == :revoke
|
131
|
+
gemfile_pattern = /\n\s*gem ('|")graphiql-rails('|"), :?group(:| =>) :development/
|
132
|
+
gsub_file Rails.root.join("Gemfile"), gemfile_pattern, "", { force: true }
|
133
|
+
end
|
134
|
+
|
135
|
+
# This is a little cheat just to get cleaner shell output:
|
136
|
+
log :route, 'graphiql-rails'
|
137
|
+
shell.mute do
|
138
|
+
# Rails 5.2 has better support for `route`?
|
139
|
+
if Rails::VERSION::STRING > "5.2"
|
140
|
+
route <<-RUBY
|
141
|
+
if Rails.env.development?
|
142
|
+
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
|
143
|
+
end
|
144
|
+
RUBY
|
145
|
+
else
|
146
|
+
route <<-RUBY
|
147
|
+
if Rails.env.development?
|
148
|
+
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
|
149
|
+
end
|
150
|
+
RUBY
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
if options[:playground]
|
156
|
+
gem("graphql_playground-rails", group: :development)
|
157
|
+
|
158
|
+
log :route, 'graphql_playground-rails'
|
159
|
+
shell.mute do
|
160
|
+
if Rails::VERSION::STRING > "5.2"
|
161
|
+
route <<-RUBY
|
162
|
+
if Rails.env.development?
|
163
|
+
mount GraphqlPlayground::Rails::Engine, at: "/playground", graphql_path: "/graphql"
|
164
|
+
end
|
165
|
+
RUBY
|
166
|
+
else
|
167
|
+
route <<-RUBY
|
168
|
+
if Rails.env.development?
|
169
|
+
mount GraphqlPlayground::Rails::Engine, at: "/playground", graphql_path: "/graphql"
|
170
|
+
end
|
171
|
+
RUBY
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
if options[:relay]
|
177
|
+
install_relay
|
178
|
+
end
|
179
|
+
|
180
|
+
if gemfile_modified?
|
181
|
+
say "Gemfile has been modified, make sure you `bundle install`"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
private
|
186
|
+
|
187
|
+
def gemfile_modified?
|
188
|
+
@gemfile_modified
|
189
|
+
end
|
190
|
+
|
191
|
+
def gem(*args)
|
192
|
+
@gemfile_modified = true
|
193
|
+
super(*args)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'generators/graphql/type_generator'
|
3
|
+
|
4
|
+
module Graphql
|
5
|
+
module Generators
|
6
|
+
# Generate an interface type by name,
|
7
|
+
# with the specified fields.
|
8
|
+
#
|
9
|
+
# ```
|
10
|
+
# rails g graphql:interface NamedEntityType name:String!
|
11
|
+
# ```
|
12
|
+
class InterfaceGenerator < TypeGeneratorBase
|
13
|
+
desc "Create a GraphQL::InterfaceType with the given name and fields"
|
14
|
+
source_root File.expand_path('../templates', __FILE__)
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def graphql_type
|
19
|
+
"interface"
|
20
|
+
end
|
21
|
+
|
22
|
+
def fields
|
23
|
+
custom_fields
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/generators'
|
3
|
+
require "rails/generators/named_base"
|
4
|
+
require_relative "core"
|
5
|
+
|
6
|
+
module Graphql
|
7
|
+
module Generators
|
8
|
+
# @example Generate a `GraphQL::Batch` loader by name.
|
9
|
+
# rails g graphql:loader RecordLoader
|
10
|
+
class LoaderGenerator < Rails::Generators::NamedBase
|
11
|
+
include Core
|
12
|
+
|
13
|
+
desc "Create a GraphQL::Batch::Loader by name"
|
14
|
+
source_root File.expand_path('../templates', __FILE__)
|
15
|
+
|
16
|
+
def create_loader_file
|
17
|
+
template "loader.erb", "#{options[:directory]}/loaders/#{file_path}.rb"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'orm_mutations_base'
|
3
|
+
|
4
|
+
module Graphql
|
5
|
+
module Generators
|
6
|
+
# TODO: What other options should be supported?
|
7
|
+
#
|
8
|
+
# @example Generate a `GraphQL::Schema::RelayClassicMutation` by name
|
9
|
+
# rails g graphql:mutation CreatePostMutation
|
10
|
+
class MutationCreateGenerator < OrmMutationsBase
|
11
|
+
|
12
|
+
desc "Scaffold a Relay Classic ORM create mutation for the given model class"
|
13
|
+
source_root File.expand_path('../templates', __FILE__)
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def operation_type
|
18
|
+
"create"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'orm_mutations_base'
|
3
|
+
|
4
|
+
module Graphql
|
5
|
+
module Generators
|
6
|
+
# TODO: What other options should be supported?
|
7
|
+
#
|
8
|
+
# @example Generate a `GraphQL::Schema::RelayClassicMutation` by name
|
9
|
+
# rails g graphql:mutation CreatePostMutation
|
10
|
+
class MutationDeleteGenerator < OrmMutationsBase
|
11
|
+
|
12
|
+
desc "Scaffold a Relay Classic ORM delete mutation for the given model class"
|
13
|
+
source_root File.expand_path('../templates', __FILE__)
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def operation_type
|
18
|
+
"delete"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'rails/generators/named_base'
|
4
|
+
require_relative 'core'
|
5
|
+
|
6
|
+
module Graphql
|
7
|
+
module Generators
|
8
|
+
# TODO: What other options should be supported?
|
9
|
+
#
|
10
|
+
# @example Generate a `GraphQL::Schema::RelayClassicMutation` by name
|
11
|
+
# rails g graphql:mutation CreatePostMutation
|
12
|
+
class MutationGenerator < Rails::Generators::NamedBase
|
13
|
+
include Core
|
14
|
+
|
15
|
+
desc "Create a Relay Classic mutation by name"
|
16
|
+
source_root File.expand_path('../templates', __FILE__)
|
17
|
+
|
18
|
+
def create_mutation_file
|
19
|
+
template "mutation.erb", File.join(options[:directory], "/mutations/", class_path, "#{file_name}.rb")
|
20
|
+
|
21
|
+
sentinel = /class .*MutationType\s*<\s*[^\s]+?\n/m
|
22
|
+
in_root do
|
23
|
+
path = "#{options[:directory]}/types/mutation_type.rb"
|
24
|
+
invoke "graphql:install:mutation_root" unless File.exist?(path)
|
25
|
+
inject_into_file "#{options[:directory]}/types/mutation_type.rb", " field :#{file_name}, mutation: Mutations::#{class_name}\n", after: sentinel, verbose: false, force: false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'orm_mutations_base'
|
3
|
+
|
4
|
+
module Graphql
|
5
|
+
module Generators
|
6
|
+
# TODO: What other options should be supported?
|
7
|
+
#
|
8
|
+
# @example Generate a `GraphQL::Schema::RelayClassicMutation` by name
|
9
|
+
# rails g graphql:mutation CreatePostMutation
|
10
|
+
class MutationUpdateGenerator < OrmMutationsBase
|
11
|
+
|
12
|
+
desc "Scaffold a Relay Classic ORM update mutation for the given model class"
|
13
|
+
source_root File.expand_path('../templates', __FILE__)
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def operation_type
|
18
|
+
"update"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'generators/graphql/type_generator'
|
3
|
+
require 'generators/graphql/field_extractor'
|
4
|
+
|
5
|
+
module Graphql
|
6
|
+
module Generators
|
7
|
+
# Generate an object type by name,
|
8
|
+
# with the specified fields.
|
9
|
+
#
|
10
|
+
# ```
|
11
|
+
# rails g graphql:object PostType name:String!
|
12
|
+
# ```
|
13
|
+
#
|
14
|
+
# Add the Node interface with `--node`.
|
15
|
+
class ObjectGenerator < TypeGeneratorBase
|
16
|
+
desc "Create a GraphQL::ObjectType with the given name and fields." \
|
17
|
+
"If the given type name matches an existing ActiveRecord model, the generated type will automatically include fields for the models database columns."
|
18
|
+
source_root File.expand_path('../templates', __FILE__)
|
19
|
+
include FieldExtractor
|
20
|
+
|
21
|
+
class_option :node,
|
22
|
+
type: :boolean,
|
23
|
+
default: false,
|
24
|
+
desc: "Include the Relay Node interface"
|
25
|
+
|
26
|
+
def self.normalize_type_expression(type_expression, mode:, null: true)
|
27
|
+
case type_expression.camelize
|
28
|
+
when "Text", "Citext"
|
29
|
+
["String", null]
|
30
|
+
when "Decimal"
|
31
|
+
["Float", null]
|
32
|
+
when "DateTime", "Datetime"
|
33
|
+
["GraphQL::Types::ISO8601DateTime", null]
|
34
|
+
when "Date"
|
35
|
+
["GraphQL::Types::ISO8601Date", null]
|
36
|
+
when "Json", "Jsonb", "Hstore"
|
37
|
+
["GraphQL::Types::JSON", null]
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def graphql_type
|
46
|
+
"object"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|