graphql_cody 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +5 -0
- data/MIT-LICENSE +20 -0
- data/lib/generators/graphql/core.rb +74 -0
- data/lib/generators/graphql/enum_generator.rb +33 -0
- data/lib/generators/graphql/install_generator.rb +190 -0
- data/lib/generators/graphql/interface_generator.rb +27 -0
- data/lib/generators/graphql/loader_generator.rb +21 -0
- data/lib/generators/graphql/mutation_generator.rb +55 -0
- data/lib/generators/graphql/object_generator.rb +79 -0
- data/lib/generators/graphql/relay.rb +63 -0
- data/lib/generators/graphql/relay_generator.rb +21 -0
- data/lib/generators/graphql/scalar_generator.rb +20 -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_mutation.erb +10 -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 +7 -0
- data/lib/generators/graphql/templates/graphql_controller.erb +52 -0
- data/lib/generators/graphql/templates/interface.erb +8 -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_type.erb +12 -0
- data/lib/generators/graphql/templates/node_type.erb +9 -0
- data/lib/generators/graphql/templates/object.erb +8 -0
- data/lib/generators/graphql/templates/query_type.erb +15 -0
- data/lib/generators/graphql/templates/scalar.erb +15 -0
- data/lib/generators/graphql/templates/schema.erb +27 -0
- data/lib/generators/graphql/templates/union.erb +7 -0
- data/lib/generators/graphql/type_generator.rb +98 -0
- data/lib/generators/graphql/union_generator.rb +33 -0
- data/lib/graphql/analysis/analyze_query.rb +98 -0
- data/lib/graphql/analysis/ast/analyzer.rb +84 -0
- data/lib/graphql/analysis/ast/field_usage.rb +51 -0
- data/lib/graphql/analysis/ast/max_query_complexity.rb +23 -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 +56 -0
- data/lib/graphql/analysis/ast/visitor.rb +268 -0
- data/lib/graphql/analysis/ast.rb +91 -0
- data/lib/graphql/analysis/field_usage.rb +45 -0
- data/lib/graphql/analysis/max_query_complexity.rb +26 -0
- data/lib/graphql/analysis/max_query_depth.rb +26 -0
- data/lib/graphql/analysis/query_complexity.rb +88 -0
- data/lib/graphql/analysis/query_depth.rb +43 -0
- data/lib/graphql/analysis/reducer_state.rb +48 -0
- data/lib/graphql/analysis.rb +9 -0
- data/lib/graphql/analysis_error.rb +5 -0
- data/lib/graphql/argument.rb +131 -0
- data/lib/graphql/authorization.rb +82 -0
- data/lib/graphql/backtrace/inspect_result.rb +50 -0
- data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
- data/lib/graphql/backtrace/table.rb +159 -0
- data/lib/graphql/backtrace/traced_error.rb +54 -0
- data/lib/graphql/backtrace/tracer.rb +81 -0
- data/lib/graphql/backtrace.rb +64 -0
- data/lib/graphql/backwards_compatibility.rb +61 -0
- data/lib/graphql/base_type.rb +230 -0
- data/lib/graphql/boolean_type.rb +2 -0
- data/lib/graphql/coercion_error.rb +13 -0
- data/lib/graphql/compatibility/execution_specification/counter_schema.rb +53 -0
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +200 -0
- data/lib/graphql/compatibility/execution_specification.rb +436 -0
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +111 -0
- data/lib/graphql/compatibility/lazy_execution_specification.rb +215 -0
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +87 -0
- data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +79 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +266 -0
- data/lib/graphql/compatibility/schema_parser_specification.rb +682 -0
- data/lib/graphql/compatibility.rb +5 -0
- data/lib/graphql/dataloader/null_dataloader.rb +22 -0
- data/lib/graphql/dataloader/request.rb +19 -0
- data/lib/graphql/dataloader/request_all.rb +19 -0
- data/lib/graphql/dataloader/source.rb +155 -0
- data/lib/graphql/dataloader.rb +308 -0
- data/lib/graphql/define/assign_argument.rb +12 -0
- data/lib/graphql/define/assign_connection.rb +13 -0
- data/lib/graphql/define/assign_enum_value.rb +18 -0
- data/lib/graphql/define/assign_global_id_field.rb +11 -0
- data/lib/graphql/define/assign_mutation_function.rb +34 -0
- data/lib/graphql/define/assign_object_field.rb +42 -0
- data/lib/graphql/define/defined_object_proxy.rb +53 -0
- data/lib/graphql/define/instance_definable.rb +240 -0
- data/lib/graphql/define/no_definition_error.rb +7 -0
- data/lib/graphql/define/non_null_with_bang.rb +16 -0
- data/lib/graphql/define/type_definer.rb +31 -0
- data/lib/graphql/define.rb +31 -0
- data/lib/graphql/deprecated_dsl.rb +55 -0
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/dig.rb +19 -0
- data/lib/graphql/directive/deprecated_directive.rb +2 -0
- data/lib/graphql/directive/include_directive.rb +2 -0
- data/lib/graphql/directive/skip_directive.rb +2 -0
- data/lib/graphql/directive.rb +107 -0
- data/lib/graphql/enum_type.rb +133 -0
- data/lib/graphql/execution/directive_checks.rb +37 -0
- data/lib/graphql/execution/errors.rb +163 -0
- data/lib/graphql/execution/execute.rb +333 -0
- data/lib/graphql/execution/flatten.rb +40 -0
- data/lib/graphql/execution/instrumentation.rb +92 -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 +103 -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 +70 -0
- data/lib/graphql/execution/interpreter/runtime.rb +949 -0
- data/lib/graphql/execution/interpreter.rb +122 -0
- data/lib/graphql/execution/lazy/lazy_method_map.rb +98 -0
- data/lib/graphql/execution/lazy/resolve.rb +91 -0
- data/lib/graphql/execution/lazy.rb +83 -0
- data/lib/graphql/execution/lookahead.rb +307 -0
- data/lib/graphql/execution/multiplex.rb +214 -0
- data/lib/graphql/execution/typecast.rb +50 -0
- data/lib/graphql/execution.rb +11 -0
- data/lib/graphql/execution_error.rb +58 -0
- data/lib/graphql/field/resolve.rb +59 -0
- data/lib/graphql/field.rb +226 -0
- data/lib/graphql/filter.rb +53 -0
- data/lib/graphql/float_type.rb +2 -0
- data/lib/graphql/function.rb +128 -0
- data/lib/graphql/id_type.rb +2 -0
- data/lib/graphql/input_object_type.rb +138 -0
- data/lib/graphql/int_type.rb +2 -0
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +36 -0
- data/lib/graphql/interface_type.rb +72 -0
- data/lib/graphql/internal_representation/document.rb +27 -0
- data/lib/graphql/internal_representation/node.rb +206 -0
- data/lib/graphql/internal_representation/print.rb +51 -0
- data/lib/graphql/internal_representation/rewrite.rb +184 -0
- data/lib/graphql/internal_representation/scope.rb +88 -0
- data/lib/graphql/internal_representation/visit.rb +36 -0
- data/lib/graphql/internal_representation.rb +7 -0
- data/lib/graphql/introspection/base_object.rb +13 -0
- data/lib/graphql/introspection/directive_location_enum.rb +15 -0
- data/lib/graphql/introspection/directive_type.rb +29 -0
- data/lib/graphql/introspection/dynamic_fields.rb +17 -0
- data/lib/graphql/introspection/entry_points.rb +35 -0
- data/lib/graphql/introspection/enum_value_type.rb +23 -0
- data/lib/graphql/introspection/field_type.rb +28 -0
- data/lib/graphql/introspection/input_value_type.rb +67 -0
- data/lib/graphql/introspection/introspection_query.rb +7 -0
- data/lib/graphql/introspection/schema_type.rb +44 -0
- data/lib/graphql/introspection/type_kind_enum.rb +13 -0
- data/lib/graphql/introspection/type_type.rb +95 -0
- data/lib/graphql/introspection.rb +114 -0
- data/lib/graphql/invalid_name_error.rb +11 -0
- data/lib/graphql/invalid_null_error.rb +50 -0
- 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 +347 -0
- data/lib/graphql/language/generation.rb +24 -0
- data/lib/graphql/language/lexer.rb +1467 -0
- data/lib/graphql/language/lexer.rl +258 -0
- data/lib/graphql/language/nodes.rb +707 -0
- data/lib/graphql/language/parser.rb +1974 -0
- data/lib/graphql/language/parser.y +544 -0
- data/lib/graphql/language/printer.rb +366 -0
- data/lib/graphql/language/sanitized_printer.rb +222 -0
- data/lib/graphql/language/token.rb +34 -0
- data/lib/graphql/language/visitor.rb +242 -0
- data/lib/graphql/language.rb +36 -0
- data/lib/graphql/list_type.rb +80 -0
- data/lib/graphql/load_application_object_failed_error.rb +22 -0
- data/lib/graphql/name_validator.rb +11 -0
- data/lib/graphql/non_null_type.rb +71 -0
- data/lib/graphql/object_type.rb +130 -0
- data/lib/graphql/pagination/active_record_relation_connection.rb +48 -0
- data/lib/graphql/pagination/array_connection.rb +77 -0
- data/lib/graphql/pagination/connection.rb +226 -0
- data/lib/graphql/pagination/connections.rb +160 -0
- data/lib/graphql/pagination/mongoid_relation_connection.rb +25 -0
- data/lib/graphql/pagination/relation_connection.rb +196 -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/arguments.rb +189 -0
- data/lib/graphql/query/arguments_cache.rb +24 -0
- data/lib/graphql/query/context.rb +371 -0
- data/lib/graphql/query/executor.rb +52 -0
- data/lib/graphql/query/fingerprint.rb +26 -0
- data/lib/graphql/query/input_validation_result.rb +43 -0
- data/lib/graphql/query/literal_input.rb +136 -0
- data/lib/graphql/query/null_context.rb +55 -0
- data/lib/graphql/query/result.rb +63 -0
- data/lib/graphql/query/serial_execution/field_resolution.rb +92 -0
- data/lib/graphql/query/serial_execution/operation_resolution.rb +19 -0
- data/lib/graphql/query/serial_execution/selection_resolution.rb +23 -0
- data/lib/graphql/query/serial_execution/value_resolution.rb +87 -0
- data/lib/graphql/query/serial_execution.rb +40 -0
- data/lib/graphql/query/validation_pipeline.rb +139 -0
- data/lib/graphql/query/variable_validation_error.rb +44 -0
- data/lib/graphql/query/variables.rb +78 -0
- data/lib/graphql/query.rb +454 -0
- data/lib/graphql/railtie.rb +117 -0
- data/lib/graphql/rake_task/validate.rb +63 -0
- data/lib/graphql/rake_task.rb +145 -0
- data/lib/graphql/relay/array_connection.rb +83 -0
- data/lib/graphql/relay/base_connection.rb +189 -0
- data/lib/graphql/relay/connection_instrumentation.rb +54 -0
- data/lib/graphql/relay/connection_resolve.rb +43 -0
- data/lib/graphql/relay/connection_type.rb +41 -0
- data/lib/graphql/relay/edge.rb +27 -0
- data/lib/graphql/relay/edge_type.rb +19 -0
- data/lib/graphql/relay/edges_instrumentation.rb +39 -0
- data/lib/graphql/relay/global_id_resolve.rb +18 -0
- data/lib/graphql/relay/mongo_relation_connection.rb +50 -0
- data/lib/graphql/relay/mutation/instrumentation.rb +23 -0
- data/lib/graphql/relay/mutation/resolve.rb +56 -0
- data/lib/graphql/relay/mutation/result.rb +38 -0
- data/lib/graphql/relay/mutation.rb +106 -0
- data/lib/graphql/relay/node.rb +39 -0
- data/lib/graphql/relay/page_info.rb +7 -0
- data/lib/graphql/relay/range_add.rb +59 -0
- data/lib/graphql/relay/relation_connection.rb +188 -0
- data/lib/graphql/relay/type_extensions.rb +32 -0
- data/lib/graphql/relay.rb +18 -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/scalar_type.rb +91 -0
- data/lib/graphql/schema/addition.rb +247 -0
- data/lib/graphql/schema/argument.rb +383 -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 +477 -0
- data/lib/graphql/schema/built_in_types.rb +12 -0
- data/lib/graphql/schema/catchall_middleware.rb +35 -0
- data/lib/graphql/schema/default_parse_error.rb +10 -0
- data/lib/graphql/schema/default_type_error.rb +17 -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/skip.rb +25 -0
- data/lib/graphql/schema/directive/transform.rb +60 -0
- data/lib/graphql/schema/directive.rb +210 -0
- data/lib/graphql/schema/enum.rb +193 -0
- data/lib/graphql/schema/enum_value.rb +97 -0
- data/lib/graphql/schema/field/connection_extension.rb +76 -0
- data/lib/graphql/schema/field/scope_extension.rb +22 -0
- data/lib/graphql/schema/field.rb +880 -0
- data/lib/graphql/schema/field_extension.rb +69 -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 +253 -0
- data/lib/graphql/schema/interface.rb +136 -0
- data/lib/graphql/schema/introspection_system.rb +169 -0
- data/lib/graphql/schema/invalid_type_error.rb +7 -0
- data/lib/graphql/schema/late_bound_type.rb +33 -0
- data/lib/graphql/schema/list.rb +75 -0
- data/lib/graphql/schema/loader.rb +226 -0
- data/lib/graphql/schema/member/accepts_definition.rb +159 -0
- data/lib/graphql/schema/member/base_dsl_methods.rb +129 -0
- data/lib/graphql/schema/member/build_type.rb +180 -0
- data/lib/graphql/schema/member/cached_graphql_definition.rb +31 -0
- data/lib/graphql/schema/member/graphql_type_names.rb +21 -0
- data/lib/graphql/schema/member/has_arguments.rb +332 -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 +98 -0
- data/lib/graphql/schema/member/has_fields.rb +163 -0
- data/lib/graphql/schema/member/has_interfaces.rb +90 -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/instrumentation.rb +131 -0
- data/lib/graphql/schema/member/relay_shortcuts.rb +47 -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 +161 -0
- data/lib/graphql/schema/middleware_chain.rb +82 -0
- data/lib/graphql/schema/mutation.rb +94 -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 +150 -0
- data/lib/graphql/schema/possible_types.rb +44 -0
- data/lib/graphql/schema/printer.rb +100 -0
- data/lib/graphql/schema/relay_classic_mutation.rb +160 -0
- data/lib/graphql/schema/rescue_middleware.rb +60 -0
- data/lib/graphql/schema/resolver/has_payload_type.rb +96 -0
- data/lib/graphql/schema/resolver.rb +397 -0
- data/lib/graphql/schema/scalar.rb +69 -0
- data/lib/graphql/schema/subscription.rb +155 -0
- data/lib/graphql/schema/timeout.rb +123 -0
- data/lib/graphql/schema/timeout_middleware.rb +88 -0
- data/lib/graphql/schema/traversal.rb +228 -0
- data/lib/graphql/schema/type_expression.rb +43 -0
- data/lib/graphql/schema/type_membership.rb +48 -0
- data/lib/graphql/schema/union.rb +95 -0
- data/lib/graphql/schema/unique_within_type.rb +34 -0
- data/lib/graphql/schema/validation.rb +313 -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 +68 -0
- data/lib/graphql/schema/validator.rb +174 -0
- data/lib/graphql/schema/warden.rb +409 -0
- data/lib/graphql/schema/wrapper.rb +29 -0
- data/lib/graphql/schema.rb +1945 -0
- data/lib/graphql/static_validation/all_rules.rb +40 -0
- data/lib/graphql/static_validation/base_visitor.rb +217 -0
- data/lib/graphql/static_validation/default_visitor.rb +15 -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 +139 -0
- data/lib/graphql/static_validation/no_validate_visitor.rb +10 -0
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +66 -0
- 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 +71 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +37 -0
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +23 -0
- 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 +65 -0
- 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 +30 -0
- 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 +73 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections_error.rb +31 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +418 -0
- 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 +73 -0
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible_error.rb +35 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +39 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist_error.rb +29 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +21 -0
- 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 +37 -0
- 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 +32 -0
- 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/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/required_arguments_are_present.rb +37 -0
- 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 +50 -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 +46 -0
- 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 +153 -0
- 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 +39 -0
- 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 +155 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined_error.rb +37 -0
- data/lib/graphql/static_validation/type_stack.rb +216 -0
- data/lib/graphql/static_validation/validation_context.rb +49 -0
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +96 -0
- data/lib/graphql/static_validation.rb +19 -0
- data/lib/graphql/string_encoding_error.rb +20 -0
- data/lib/graphql/string_type.rb +2 -0
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +245 -0
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +81 -0
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +21 -0
- data/lib/graphql/subscriptions/event.rb +144 -0
- data/lib/graphql/subscriptions/instrumentation.rb +79 -0
- data/lib/graphql/subscriptions/serialize.rb +138 -0
- data/lib/graphql/subscriptions/subscription_root.rb +76 -0
- data/lib/graphql/subscriptions.rb +299 -0
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +35 -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 +76 -0
- data/lib/graphql/tracing/new_relic_tracing.rb +51 -0
- data/lib/graphql/tracing/platform_tracing.rb +139 -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/skylight_tracing.rb +70 -0
- data/lib/graphql/tracing/statsd_tracing.rb +42 -0
- data/lib/graphql/tracing.rb +95 -0
- data/lib/graphql/type_kinds.rb +77 -0
- 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 +34 -0
- data/lib/graphql/types/iso_8601_date_time.rb +65 -0
- data/lib/graphql/types/json.rb +25 -0
- data/lib/graphql/types/relay/base_connection.rb +39 -0
- data/lib/graphql/types/relay/base_edge.rb +29 -0
- data/lib/graphql/types/relay/connection_behaviors.rb +156 -0
- data/lib/graphql/types/relay/default_relay.rb +27 -0
- data/lib/graphql/types/relay/edge_behaviors.rb +53 -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 +15 -0
- data/lib/graphql/types/relay/node_field.rb +25 -0
- data/lib/graphql/types/relay/nodes_field.rb +27 -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 +41 -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/union_type.rb +115 -0
- data/lib/graphql/unresolved_type_error.rb +35 -0
- data/lib/graphql/upgrader/member.rb +937 -0
- data/lib/graphql/upgrader/schema.rb +38 -0
- data/lib/graphql/version.rb +4 -0
- data/lib/graphql.rb +168 -0
- data/readme.md +49 -0
- metadata +714 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d2aa5d3dcabeb1333411679bdf9bb39506665cd3e08a8115856f83a55def484f
|
4
|
+
data.tar.gz: b8f31dcb5e5f39c657d39b7089517b3accd8dc2577f94f66f909f30fb66a399f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12afaf75f16856716e196a2757978fcf5cb8fe3c1d82eadcdb3ef07ec8c3a9d38cee262cf8c70c8f9a612867a61ad25713278abce0319e71991567785a0a42ea
|
7
|
+
data.tar.gz: 7774a98a8c9bfbd317a2db13cd3413504ab02102e83f4e1424fa03200426ecd82c8e00e182c2c5f1f493c41bab484fe4031b8ff138356e2a4db462b8b0fa8b0c
|
data/.yardopts
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Robert Mosolgo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,74 @@
|
|
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
|
+
inject_into_file schema_file_path, " #{type}(Types::#{name})\n", after: sentinel, verbose: false, force: false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_mutation_root_type
|
27
|
+
create_dir("#{options[:directory]}/mutations")
|
28
|
+
template("base_mutation.erb", "#{options[:directory]}/mutations/base_mutation.rb", { skip: true })
|
29
|
+
template("mutation_type.erb", "#{options[:directory]}/types/mutation_type.rb", { skip: true })
|
30
|
+
insert_root_type('mutation', 'MutationType')
|
31
|
+
end
|
32
|
+
|
33
|
+
def schema_file_path
|
34
|
+
"#{options[:directory]}/#{schema_name.underscore}.rb"
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_dir(dir)
|
38
|
+
empty_directory(dir)
|
39
|
+
if !options[:skip_keeps]
|
40
|
+
create_file("#{dir}/.keep")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def module_namespacing_when_supported
|
45
|
+
if defined?(module_namespacing)
|
46
|
+
module_namespacing { yield }
|
47
|
+
else
|
48
|
+
yield
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def schema_name
|
55
|
+
@schema_name ||= begin
|
56
|
+
if options[:schema]
|
57
|
+
options[:schema]
|
58
|
+
else
|
59
|
+
"#{parent_name}Schema"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def parent_name
|
65
|
+
require File.expand_path("config/application", destination_root)
|
66
|
+
if Rails.application.class.respond_to?(:module_parent_name)
|
67
|
+
Rails.application.class.module_parent_name
|
68
|
+
else
|
69
|
+
Rails.application.class.parent_name
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
argument :values,
|
17
|
+
type: :array,
|
18
|
+
default: [],
|
19
|
+
banner: "value{:ruby_value} value{:ruby_value} ...",
|
20
|
+
desc: "Values for this enum (if present, ruby_value will be inserted verbatim)"
|
21
|
+
|
22
|
+
def create_type_file
|
23
|
+
template "enum.erb", "#{options[:directory]}/types/#{type_file_name}.rb"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def prepared_values
|
29
|
+
values.map { |v| v.split(":", 2) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,190 @@
|
|
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 `--no-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
|
+
create_mutation_root_type 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] && !File.read(Rails.root.join("Gemfile")).include?("graphiql-rails")
|
126
|
+
gem("graphiql-rails", group: :development)
|
127
|
+
|
128
|
+
# This is a little cheat just to get cleaner shell output:
|
129
|
+
log :route, 'graphiql-rails'
|
130
|
+
shell.mute do
|
131
|
+
# Rails 5.2 has better support for `route`?
|
132
|
+
if Rails::VERSION::STRING > "5.2"
|
133
|
+
route <<-RUBY
|
134
|
+
if Rails.env.development?
|
135
|
+
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
|
136
|
+
end
|
137
|
+
RUBY
|
138
|
+
else
|
139
|
+
route <<-RUBY
|
140
|
+
if Rails.env.development?
|
141
|
+
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
|
142
|
+
end
|
143
|
+
RUBY
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
if options[:playground]
|
149
|
+
gem("graphql_playground-rails", group: :development)
|
150
|
+
|
151
|
+
log :route, 'graphql_playground-rails'
|
152
|
+
shell.mute do
|
153
|
+
if Rails::VERSION::STRING > "5.2"
|
154
|
+
route <<-RUBY
|
155
|
+
if Rails.env.development?
|
156
|
+
mount GraphqlPlayground::Rails::Engine, at: "/playground", graphql_path: "/graphql"
|
157
|
+
end
|
158
|
+
RUBY
|
159
|
+
else
|
160
|
+
route <<-RUBY
|
161
|
+
if Rails.env.development?
|
162
|
+
mount GraphqlPlayground::Rails::Engine, at: "/playground", graphql_path: "/graphql"
|
163
|
+
end
|
164
|
+
RUBY
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
if options[:relay]
|
170
|
+
install_relay
|
171
|
+
end
|
172
|
+
|
173
|
+
if gemfile_modified?
|
174
|
+
say "Gemfile has been modified, make sure you `bundle install`"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
private
|
179
|
+
|
180
|
+
def gemfile_modified?
|
181
|
+
@gemfile_modified
|
182
|
+
end
|
183
|
+
|
184
|
+
def gem(*args)
|
185
|
+
@gemfile_modified = true
|
186
|
+
super(*args)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
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
|
+
argument :fields,
|
17
|
+
type: :array,
|
18
|
+
default: [],
|
19
|
+
banner: "name:type name:type ...",
|
20
|
+
desc: "Fields for this interface (type may be expressed as Ruby or GraphQL)"
|
21
|
+
|
22
|
+
def create_type_file
|
23
|
+
template "interface.erb", "#{options[:directory]}/types/#{type_file_name}.rb"
|
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,55 @@
|
|
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::Base
|
13
|
+
include Core
|
14
|
+
|
15
|
+
desc "Create a Relay Classic mutation by name"
|
16
|
+
source_root File.expand_path('../templates', __FILE__)
|
17
|
+
|
18
|
+
argument :name, type: :string
|
19
|
+
|
20
|
+
def initialize(args, *options) # :nodoc:
|
21
|
+
# Unfreeze name in case it's given as a frozen string
|
22
|
+
args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen?
|
23
|
+
super
|
24
|
+
|
25
|
+
assign_names!(name)
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_reader :file_name, :mutation_name, :field_name
|
29
|
+
|
30
|
+
def create_mutation_file
|
31
|
+
unless @behavior == :revoke
|
32
|
+
create_mutation_root_type
|
33
|
+
else
|
34
|
+
log :gsub, "#{options[:directory]}/types/mutation_type.rb"
|
35
|
+
end
|
36
|
+
|
37
|
+
template "mutation.erb", "#{options[:directory]}/mutations/#{file_name}.rb"
|
38
|
+
|
39
|
+
sentinel = /class .*MutationType\s*<\s*[^\s]+?\n/m
|
40
|
+
in_root do
|
41
|
+
gsub_file "#{options[:directory]}/types/mutation_type.rb", / \# TODO\: Add Mutations as fields\s*\n/m, ""
|
42
|
+
inject_into_file "#{options[:directory]}/types/mutation_type.rb", " field :#{field_name}, mutation: Mutations::#{mutation_name}\n", after: sentinel, verbose: false, force: false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def assign_names!(name)
|
49
|
+
@field_name = name.camelize.underscore
|
50
|
+
@mutation_name = name.camelize(:upper)
|
51
|
+
@file_name = name.camelize.underscore
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'generators/graphql/type_generator'
|
3
|
+
|
4
|
+
module Graphql
|
5
|
+
module Generators
|
6
|
+
# Generate an object type by name,
|
7
|
+
# with the specified fields.
|
8
|
+
#
|
9
|
+
# ```
|
10
|
+
# rails g graphql:object PostType name:String!
|
11
|
+
# ```
|
12
|
+
#
|
13
|
+
# Add the Node interface with `--node`.
|
14
|
+
class ObjectGenerator < TypeGeneratorBase
|
15
|
+
desc "Create a GraphQL::ObjectType with the given name and fields." \
|
16
|
+
"If the given type name matches an existing ActiveRecord model, the generated type will automatically include fields for the models database columns."
|
17
|
+
source_root File.expand_path('../templates', __FILE__)
|
18
|
+
|
19
|
+
argument :custom_fields,
|
20
|
+
type: :array,
|
21
|
+
default: [],
|
22
|
+
banner: "name:type name:type ...",
|
23
|
+
desc: "Fields for this object (type may be expressed as Ruby or GraphQL)"
|
24
|
+
|
25
|
+
class_option :node,
|
26
|
+
type: :boolean,
|
27
|
+
default: false,
|
28
|
+
desc: "Include the Relay Node interface"
|
29
|
+
|
30
|
+
def create_type_file
|
31
|
+
template "object.erb", "#{options[:directory]}/types/#{type_file_name}.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
def fields
|
35
|
+
columns = []
|
36
|
+
columns += klass.columns.map { |c| generate_column_string(c) } if class_exists?
|
37
|
+
columns + custom_fields
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.normalize_type_expression(type_expression, mode:, null: true)
|
41
|
+
case type_expression
|
42
|
+
when "Text"
|
43
|
+
["String", null]
|
44
|
+
when "Decimal"
|
45
|
+
["Float", null]
|
46
|
+
when "DateTime", "Datetime"
|
47
|
+
["GraphQL::Types::ISO8601DateTime", null]
|
48
|
+
when "Date"
|
49
|
+
["GraphQL::Types::ISO8601Date", null]
|
50
|
+
else
|
51
|
+
super
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def generate_column_string(column)
|
58
|
+
name = column.name
|
59
|
+
required = column.null ? "" : "!"
|
60
|
+
type = column_type_string(column)
|
61
|
+
"#{name}:#{required}#{type}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def column_type_string(column)
|
65
|
+
column.name == "id" ? "ID" : column.type.to_s.camelize
|
66
|
+
end
|
67
|
+
|
68
|
+
def class_exists?
|
69
|
+
klass.is_a?(Class) && klass.ancestors.include?(ActiveRecord::Base)
|
70
|
+
rescue NameError
|
71
|
+
return false
|
72
|
+
end
|
73
|
+
|
74
|
+
def klass
|
75
|
+
@klass ||= Module.const_get(type_name.camelize)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Graphql
|
3
|
+
module Generators
|
4
|
+
module Relay
|
5
|
+
def install_relay
|
6
|
+
# Add Node, `node(id:)`, and `nodes(ids:)`
|
7
|
+
template("node_type.erb", "#{options[:directory]}/types/node_type.rb")
|
8
|
+
in_root do
|
9
|
+
fields = " # Add `node(id: ID!) and `nodes(ids: [ID!]!)`\n include GraphQL::Types::Relay::HasNodeField\n include GraphQL::Types::Relay::HasNodesField\n\n"
|
10
|
+
inject_into_file "#{options[:directory]}/types/query_type.rb", fields, after: /class .*QueryType\s*<\s*[^\s]+?\n/m, force: false
|
11
|
+
end
|
12
|
+
|
13
|
+
# Add connections and edges
|
14
|
+
template("base_connection.erb", "#{options[:directory]}/types/base_connection.rb")
|
15
|
+
template("base_edge.erb", "#{options[:directory]}/types/base_edge.rb")
|
16
|
+
connectionable_type_files = {
|
17
|
+
"#{options[:directory]}/types/base_object.rb" => /class .*BaseObject\s*<\s*[^\s]+?\n/m,
|
18
|
+
"#{options[:directory]}/types/base_union.rb" => /class .*BaseUnion\s*<\s*[^\s]+?\n/m,
|
19
|
+
"#{options[:directory]}/types/base_interface.rb" => /include GraphQL::Schema::Interface\n/m,
|
20
|
+
}
|
21
|
+
in_root do
|
22
|
+
connectionable_type_files.each do |type_class_file, sentinel|
|
23
|
+
inject_into_file type_class_file, " connection_type_class(Types::BaseConnection)\n", after: sentinel, force: false
|
24
|
+
inject_into_file type_class_file, " edge_type_class(Types::BaseEdge)\n", after: sentinel, force: false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Add object ID hooks & connection plugin
|
29
|
+
schema_code = <<-RUBY
|
30
|
+
|
31
|
+
# Relay-style Object Identification:
|
32
|
+
|
33
|
+
# Return a string UUID for `object`
|
34
|
+
def self.id_from_object(object, type_definition, query_ctx)
|
35
|
+
# For example, use Rails' GlobalID library (https://github.com/rails/globalid):
|
36
|
+
object_id = object.to_global_id.to_s
|
37
|
+
# Remove this redundant prefix to make IDs shorter:
|
38
|
+
object_id = object_id.sub("gid://\#{GlobalID.app}/", "")
|
39
|
+
encoded_id = Base64.urlsafe_encode64(object_id)
|
40
|
+
# Remove the "=" padding
|
41
|
+
encoded_id = encoded_id.sub(/=+/, "")
|
42
|
+
# Add a type hint
|
43
|
+
type_hint = type_definition.graphql_name.first
|
44
|
+
"\#{type_hint}_\#{encoded_id}"
|
45
|
+
end
|
46
|
+
|
47
|
+
# Given a string UUID, find the object
|
48
|
+
def self.object_from_id(encoded_id_with_hint, query_ctx)
|
49
|
+
# For example, use Rails' GlobalID library (https://github.com/rails/globalid):
|
50
|
+
# Split off the type hint
|
51
|
+
_type_hint, encoded_id = encoded_id_with_hint.split("_", 2)
|
52
|
+
# Decode the ID
|
53
|
+
id = Base64.urlsafe_decode64(encoded_id)
|
54
|
+
# Rebuild it for Rails then find the object:
|
55
|
+
full_global_id = "gid://\#{GlobalID.app}/\#{id}"
|
56
|
+
GlobalID::Locator.locate(full_global_id)
|
57
|
+
end
|
58
|
+
RUBY
|
59
|
+
inject_into_file schema_file_path, schema_code, before: /^end\n/m, force: false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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
|
+
class RelayGenerator < Rails::Generators::Base
|
10
|
+
include Core
|
11
|
+
include Relay
|
12
|
+
|
13
|
+
desc "Add base types and fields for Relay-style nodes and connections"
|
14
|
+
source_root File.expand_path('../templates', __FILE__)
|
15
|
+
|
16
|
+
def install_relay
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'generators/graphql/type_generator'
|
3
|
+
|
4
|
+
module Graphql
|
5
|
+
module Generators
|
6
|
+
# Generate a scalar type by given name.
|
7
|
+
#
|
8
|
+
# ```
|
9
|
+
# rails g graphql:scalar Date
|
10
|
+
# ```
|
11
|
+
class ScalarGenerator < TypeGeneratorBase
|
12
|
+
desc "Create a GraphQL::ScalarType with the given name"
|
13
|
+
source_root File.expand_path('../templates', __FILE__)
|
14
|
+
|
15
|
+
def create_type_file
|
16
|
+
template "scalar.erb", "#{options[:directory]}/types/#{type_file_name}.rb"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<% module_namespacing_when_supported do -%>
|
2
|
+
module Types
|
3
|
+
class BaseConnection < Types::BaseObject
|
4
|
+
# add `nodes` and `pageInfo` fields, as well as `edge_type(...)` and `node_nullable(...)` overrides
|
5
|
+
include GraphQL::Types::Relay::ConnectionBehaviors
|
6
|
+
end
|
7
|
+
end
|
8
|
+
<% end -%>
|