graphql 1.11.6 → 1.13.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of graphql might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/generators/graphql/core.rb +3 -8
- data/lib/generators/graphql/enum_generator.rb +4 -10
- 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_generator.rb +17 -7
- data/lib/generators/graphql/interface_generator.rb +7 -7
- data/lib/generators/graphql/loader_generator.rb +1 -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 +6 -30
- data/lib/generators/graphql/mutation_update_generator.rb +22 -0
- data/lib/generators/graphql/object_generator.rb +12 -38
- data/lib/generators/graphql/orm_mutations_base.rb +40 -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 +4 -2
- 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/enum.erb +5 -1
- data/lib/generators/graphql/templates/graphql_controller.erb +2 -2
- data/lib/generators/graphql/templates/input.erb +9 -0
- data/lib/generators/graphql/templates/interface.erb +4 -2
- data/lib/generators/graphql/templates/mutation.erb +1 -1
- 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 +5 -3
- data/lib/generators/graphql/templates/query_type.erb +1 -3
- data/lib/generators/graphql/templates/scalar.erb +3 -1
- data/lib/generators/graphql/templates/schema.erb +19 -34
- data/lib/generators/graphql/templates/union.erb +4 -2
- data/lib/generators/graphql/type_generator.rb +47 -10
- data/lib/generators/graphql/union_generator.rb +5 -5
- data/lib/graphql/analysis/analyze_query.rb +7 -0
- data/lib/graphql/analysis/ast/field_usage.rb +28 -1
- data/lib/graphql/analysis/ast/query_complexity.rb +10 -14
- data/lib/graphql/analysis/ast/visitor.rb +14 -5
- data/lib/graphql/analysis/ast.rb +11 -2
- data/lib/graphql/argument.rb +1 -1
- data/lib/graphql/backtrace/inspect_result.rb +0 -1
- data/lib/graphql/backtrace/legacy_tracer.rb +56 -0
- data/lib/graphql/backtrace/table.rb +34 -3
- data/lib/graphql/backtrace/traced_error.rb +0 -1
- data/lib/graphql/backtrace/tracer.rb +40 -10
- data/lib/graphql/backtrace.rb +28 -19
- data/lib/graphql/backwards_compatibility.rb +2 -1
- data/lib/graphql/base_type.rb +6 -4
- data/lib/graphql/boolean_type.rb +1 -1
- data/lib/graphql/compatibility/execution_specification.rb +1 -0
- data/lib/graphql/compatibility/lazy_execution_specification.rb +2 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +2 -0
- data/lib/graphql/compatibility/schema_parser_specification.rb +2 -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/date_encoding_error.rb +16 -0
- data/lib/graphql/define/assign_global_id_field.rb +1 -1
- data/lib/graphql/define/instance_definable.rb +48 -3
- data/lib/graphql/define/type_definer.rb +5 -5
- data/lib/graphql/deprecated_dsl.rb +18 -5
- data/lib/graphql/deprecation.rb +9 -0
- data/lib/graphql/directive/deprecated_directive.rb +1 -1
- data/lib/graphql/directive/include_directive.rb +1 -1
- data/lib/graphql/directive/skip_directive.rb +1 -1
- data/lib/graphql/directive.rb +1 -5
- data/lib/graphql/enum_type.rb +9 -3
- data/lib/graphql/execution/errors.rb +110 -7
- data/lib/graphql/execution/execute.rb +8 -1
- data/lib/graphql/execution/interpreter/arguments.rb +57 -5
- data/lib/graphql/execution/interpreter/arguments_cache.rb +49 -15
- data/lib/graphql/execution/interpreter/handles_raw_value.rb +0 -7
- data/lib/graphql/execution/interpreter/resolve.rb +37 -25
- data/lib/graphql/execution/interpreter/runtime.rb +670 -294
- data/lib/graphql/execution/interpreter.rb +16 -16
- data/lib/graphql/execution/lazy.rb +5 -1
- data/lib/graphql/execution/lookahead.rb +2 -2
- data/lib/graphql/execution/multiplex.rb +39 -23
- data/lib/graphql/field.rb +1 -1
- data/lib/graphql/float_type.rb +1 -1
- data/lib/graphql/function.rb +4 -0
- data/lib/graphql/id_type.rb +1 -1
- data/lib/graphql/input_object_type.rb +3 -1
- data/lib/graphql/int_type.rb +1 -1
- data/lib/graphql/integer_decoding_error.rb +17 -0
- data/lib/graphql/integer_encoding_error.rb +18 -2
- data/lib/graphql/interface_type.rb +4 -2
- data/lib/graphql/internal_representation/document.rb +2 -2
- data/lib/graphql/internal_representation/rewrite.rb +1 -1
- data/lib/graphql/introspection/directive_location_enum.rb +2 -2
- data/lib/graphql/introspection/directive_type.rb +11 -5
- data/lib/graphql/introspection/entry_points.rb +2 -2
- data/lib/graphql/introspection/enum_value_type.rb +2 -2
- data/lib/graphql/introspection/field_type.rb +3 -3
- data/lib/graphql/introspection/input_value_type.rb +10 -4
- data/lib/graphql/introspection/schema_type.rb +10 -5
- data/lib/graphql/introspection/type_type.rb +18 -12
- data/lib/graphql/introspection.rb +5 -2
- data/lib/graphql/invalid_null_error.rb +1 -1
- data/lib/graphql/language/block_string.rb +2 -6
- data/lib/graphql/language/cache.rb +37 -0
- data/lib/graphql/language/document_from_schema_definition.rb +60 -26
- data/lib/graphql/language/lexer.rb +50 -28
- data/lib/graphql/language/lexer.rl +2 -4
- data/lib/graphql/language/nodes.rb +14 -4
- data/lib/graphql/language/parser.rb +856 -825
- data/lib/graphql/language/parser.y +28 -11
- data/lib/graphql/language/printer.rb +10 -1
- data/lib/graphql/language/sanitized_printer.rb +5 -5
- data/lib/graphql/language/token.rb +0 -4
- data/lib/graphql/language.rb +1 -0
- data/lib/graphql/name_validator.rb +0 -4
- data/lib/graphql/object_type.rb +4 -4
- data/lib/graphql/pagination/active_record_relation_connection.rb +47 -3
- data/lib/graphql/pagination/connection.rb +19 -1
- data/lib/graphql/pagination/connections.rb +45 -30
- data/lib/graphql/pagination/relation_connection.rb +69 -28
- data/lib/graphql/parse_error.rb +0 -1
- data/lib/graphql/query/arguments.rb +2 -2
- data/lib/graphql/query/arguments_cache.rb +1 -2
- data/lib/graphql/query/context.rb +22 -4
- data/lib/graphql/query/executor.rb +0 -1
- data/lib/graphql/query/input_validation_result.rb +9 -0
- data/lib/graphql/query/literal_input.rb +1 -1
- data/lib/graphql/query/null_context.rb +21 -9
- data/lib/graphql/query/serial_execution/field_resolution.rb +1 -1
- data/lib/graphql/query/serial_execution.rb +1 -0
- data/lib/graphql/query/validation_pipeline.rb +3 -4
- data/lib/graphql/query/variable_validation_error.rb +3 -3
- data/lib/graphql/query/variables.rb +35 -4
- data/lib/graphql/query.rb +20 -8
- data/lib/graphql/railtie.rb +9 -1
- data/lib/graphql/rake_task.rb +3 -0
- data/lib/graphql/relay/array_connection.rb +2 -2
- data/lib/graphql/relay/base_connection.rb +7 -0
- data/lib/graphql/relay/connection_instrumentation.rb +4 -4
- data/lib/graphql/relay/connection_type.rb +16 -3
- data/lib/graphql/relay/edges_instrumentation.rb +0 -1
- data/lib/graphql/relay/global_id_resolve.rb +1 -2
- data/lib/graphql/relay/mutation.rb +2 -1
- data/lib/graphql/relay/node.rb +3 -0
- data/lib/graphql/relay/page_info.rb +1 -1
- data/lib/graphql/relay/range_add.rb +14 -5
- data/lib/graphql/relay/type_extensions.rb +2 -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/scalar_type.rb +3 -1
- data/lib/graphql/schema/addition.rb +247 -0
- data/lib/graphql/schema/argument.rb +177 -21
- data/lib/graphql/schema/build_from_definition.rb +150 -55
- data/lib/graphql/schema/default_type_error.rb +2 -0
- data/lib/graphql/schema/directive/feature.rb +1 -1
- data/lib/graphql/schema/directive/flagged.rb +57 -0
- data/lib/graphql/schema/directive/include.rb +1 -1
- data/lib/graphql/schema/directive/skip.rb +1 -1
- data/lib/graphql/schema/directive/transform.rb +14 -2
- data/lib/graphql/schema/directive.rb +103 -4
- data/lib/graphql/schema/enum.rb +72 -11
- data/lib/graphql/schema/enum_value.rb +18 -6
- data/lib/graphql/schema/field/connection_extension.rb +4 -2
- data/lib/graphql/schema/field/scope_extension.rb +1 -1
- data/lib/graphql/schema/field.rb +332 -111
- data/lib/graphql/schema/field_extension.rb +89 -2
- data/lib/graphql/schema/find_inherited_value.rb +4 -1
- data/lib/graphql/schema/finder.rb +5 -5
- data/lib/graphql/schema/input_object.rb +79 -55
- data/lib/graphql/schema/interface.rb +12 -20
- data/lib/graphql/schema/introspection_system.rb +1 -1
- data/lib/graphql/schema/list.rb +21 -4
- data/lib/graphql/schema/loader.rb +11 -0
- data/lib/graphql/schema/member/accepts_definition.rb +15 -3
- data/lib/graphql/schema/member/base_dsl_methods.rb +5 -16
- data/lib/graphql/schema/member/build_type.rb +4 -7
- data/lib/graphql/schema/member/cached_graphql_definition.rb +29 -2
- data/lib/graphql/schema/member/has_arguments.rb +166 -74
- 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 +77 -22
- data/lib/graphql/schema/member/has_interfaces.rb +100 -0
- data/lib/graphql/schema/member/has_validators.rb +31 -0
- data/lib/graphql/schema/member/instrumentation.rb +0 -1
- data/lib/graphql/schema/member/type_system_helpers.rb +1 -1
- data/lib/graphql/schema/member/validates_input.rb +2 -2
- data/lib/graphql/schema/member.rb +5 -0
- data/lib/graphql/schema/middleware_chain.rb +1 -1
- data/lib/graphql/schema/non_null.rb +9 -3
- data/lib/graphql/schema/object.rb +40 -80
- data/lib/graphql/schema/printer.rb +16 -20
- data/lib/graphql/schema/relay_classic_mutation.rb +38 -4
- data/lib/graphql/schema/resolver/has_payload_type.rb +29 -2
- data/lib/graphql/schema/resolver.rb +110 -64
- data/lib/graphql/schema/scalar.rb +18 -2
- data/lib/graphql/schema/subscription.rb +55 -9
- data/lib/graphql/schema/timeout_middleware.rb +3 -1
- data/lib/graphql/schema/traversal.rb +1 -1
- data/lib/graphql/schema/type_expression.rb +1 -1
- data/lib/graphql/schema/type_membership.rb +18 -4
- data/lib/graphql/schema/union.rb +8 -1
- data/lib/graphql/schema/validation.rb +4 -2
- 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 +126 -53
- data/lib/graphql/schema.rb +262 -281
- data/lib/graphql/static_validation/all_rules.rb +2 -0
- data/lib/graphql/static_validation/base_visitor.rb +9 -6
- data/lib/graphql/static_validation/definition_dependencies.rb +0 -1
- data/lib/graphql/static_validation/error.rb +3 -1
- data/lib/graphql/static_validation/literal_validator.rb +1 -1
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +4 -2
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible_error.rb +6 -2
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +3 -2
- data/lib/graphql/static_validation/rules/arguments_are_defined_error.rb +4 -2
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +90 -47
- data/lib/graphql/static_validation/rules/fields_will_merge_error.rb +25 -4
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +2 -2
- 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/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 +4 -2
- data/lib/graphql/static_validation/rules/required_input_object_attributes_are_present.rb +5 -5
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +14 -8
- data/lib/graphql/static_validation/validation_context.rb +12 -2
- data/lib/graphql/static_validation/validation_timeout_error.rb +25 -0
- data/lib/graphql/static_validation/validator.rb +41 -10
- data/lib/graphql/static_validation.rb +1 -0
- data/lib/graphql/string_encoding_error.rb +13 -3
- data/lib/graphql/string_type.rb +1 -1
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +39 -8
- data/lib/graphql/subscriptions/broadcast_analyzer.rb +0 -3
- data/lib/graphql/subscriptions/event.rb +68 -32
- data/lib/graphql/subscriptions/instrumentation.rb +0 -1
- data/lib/graphql/subscriptions/serialize.rb +34 -5
- data/lib/graphql/subscriptions/subscription_root.rb +1 -1
- data/lib/graphql/subscriptions.rb +34 -39
- data/lib/graphql/tracing/active_support_notifications_tracing.rb +8 -21
- data/lib/graphql/tracing/appoptics_tracing.rb +3 -1
- data/lib/graphql/tracing/appsignal_tracing.rb +15 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +24 -2
- data/lib/graphql/tracing/notifications_tracing.rb +59 -0
- data/lib/graphql/tracing/platform_tracing.rb +24 -12
- data/lib/graphql/tracing/prometheus_tracing/graphql_collector.rb +4 -1
- data/lib/graphql/tracing/skylight_tracing.rb +1 -1
- data/lib/graphql/tracing.rb +2 -2
- data/lib/graphql/types/big_int.rb +5 -1
- data/lib/graphql/types/int.rb +10 -3
- data/lib/graphql/types/iso_8601_date.rb +13 -5
- data/lib/graphql/types/iso_8601_date_time.rb +8 -1
- data/lib/graphql/types/relay/base_connection.rb +6 -91
- data/lib/graphql/types/relay/base_edge.rb +2 -34
- data/lib/graphql/types/relay/connection_behaviors.rb +174 -0
- data/lib/graphql/types/relay/default_relay.rb +31 -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 +2 -4
- data/lib/graphql/types/relay/node_behaviors.rb +15 -0
- data/lib/graphql/types/relay/node_field.rb +3 -22
- data/lib/graphql/types/relay/nodes_field.rb +16 -18
- data/lib/graphql/types/relay/page_info.rb +2 -14
- data/lib/graphql/types/relay/page_info_behaviors.rb +25 -0
- data/lib/graphql/types/relay.rb +11 -3
- data/lib/graphql/types/string.rb +8 -2
- data/lib/graphql/unauthorized_error.rb +1 -1
- data/lib/graphql/union_type.rb +3 -1
- data/lib/graphql/upgrader/member.rb +1 -0
- data/lib/graphql/upgrader/schema.rb +1 -0
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +68 -37
- data/readme.md +3 -6
- metadata +83 -113
- data/lib/graphql/execution/interpreter/hash_response.rb +0 -46
- data/lib/graphql/types/relay/base_field.rb +0 -22
- data/lib/graphql/types/relay/base_interface.rb +0 -29
- data/lib/graphql/types/relay/base_object.rb +0 -26
- /data/lib/generators/graphql/{templates → install/templates}/base_mutation.erb +0 -0
- /data/lib/generators/graphql/{templates → install/templates}/mutation_type.erb +0 -0
@@ -15,9 +15,9 @@ class GraphqlController < ApplicationController
|
|
15
15
|
}
|
16
16
|
result = <%= schema_name %>.execute(query, variables: variables, context: context, operation_name: operation_name)
|
17
17
|
render json: result
|
18
|
-
rescue => e
|
18
|
+
rescue StandardError => e
|
19
19
|
raise e unless Rails.env.development?
|
20
|
-
handle_error_in_development
|
20
|
+
handle_error_in_development(e)
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
<% module_namespacing_when_supported do -%>
|
2
4
|
module Types
|
3
|
-
module <%=
|
5
|
+
module <%= ruby_class_name %>
|
4
6
|
include Types::BaseInterface
|
5
|
-
<% normalized_fields.each do |f| %> <%= f.
|
7
|
+
<% normalized_fields.each do |f| %> <%= f.to_object_field %>
|
6
8
|
<% end %> end
|
7
9
|
end
|
8
10
|
<% end -%>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
<% module_namespacing_when_supported do -%>
|
4
|
+
module Mutations
|
5
|
+
class <%= class_name %>Create < BaseMutation
|
6
|
+
description "Creates a new <%= file_name %>"
|
7
|
+
|
8
|
+
field :<%= file_name %>, Types::<%= options[:namespaced_types] ? 'Objects::' : '' %><%= class_name %>Type, null: false
|
9
|
+
|
10
|
+
argument :<%= file_name %>_input, Types::<%= options[:namespaced_types] ? 'Inputs::' : '' %><%= class_name %>InputType, required: true
|
11
|
+
|
12
|
+
def resolve(<%= file_name %>_input:)
|
13
|
+
<%= singular_table_name %> = ::<%= orm_class.build(class_name, "**#{file_name}_input") %>
|
14
|
+
raise GraphQL::ExecutionError.new "Error creating <%= file_name %>", extensions: <%= singular_table_name %>.errors.to_hash unless <%= orm_instance.save %>
|
15
|
+
|
16
|
+
{ <%= file_name %>: <%= singular_table_name %> }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
<% end -%>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
<% module_namespacing_when_supported do -%>
|
4
|
+
module Mutations
|
5
|
+
class <%= class_name %>Delete < BaseMutation
|
6
|
+
description "Deletes a <%= file_name %> by ID"
|
7
|
+
|
8
|
+
field :<%= file_name %>, Types::<%= options[:namespaced_types] ? 'Objects::' : '' %><%= class_name %>Type, null: false
|
9
|
+
|
10
|
+
argument :id, ID, required: true
|
11
|
+
|
12
|
+
def resolve(id:)
|
13
|
+
<%= singular_table_name %> = ::<%= orm_class.find(class_name, "id") %>
|
14
|
+
raise GraphQL::ExecutionError.new "Error deleting <%= file_name %>", extensions: <%= singular_table_name %>.errors.to_hash unless <%= orm_instance.destroy %>
|
15
|
+
|
16
|
+
{ <%= file_name %>: <%= singular_table_name %> }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
<% end -%>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
<% module_namespacing_when_supported do -%>
|
4
|
+
module Mutations
|
5
|
+
class <%= class_name %>Update < BaseMutation
|
6
|
+
description "Updates a <%= file_name %> by id"
|
7
|
+
|
8
|
+
field :<%= file_name %>, Types::<%= options[:namespaced_types] ? 'Objects::' : '' %><%= class_name %>Type, null: false
|
9
|
+
|
10
|
+
argument :id, ID, required: true
|
11
|
+
argument :<%= file_name %>_input, Types::<%= options[:namespaced_types] ? 'Inputs::' : '' %><%= class_name %>InputType, required: true
|
12
|
+
|
13
|
+
def resolve(id:, <%= file_name %>_input:)
|
14
|
+
<%= singular_table_name %> = ::<%= orm_class.find(class_name, "id") %>
|
15
|
+
raise GraphQL::ExecutionError.new "Error updating <%= file_name %>", extensions: <%= singular_table_name %>.errors.to_hash unless <%= orm_instance.update("**#{file_name}_input") %>
|
16
|
+
|
17
|
+
{ <%= file_name %>: <%= singular_table_name %> }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
<% end -%>
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
<% module_namespacing_when_supported do -%>
|
2
4
|
module Types
|
3
|
-
class <%=
|
4
|
-
<% if options.node %> implements GraphQL::Relay::Node
|
5
|
-
<% end %><% normalized_fields.each do |f| %> <%= f.
|
5
|
+
class <%= ruby_class_name %> < Types::BaseObject
|
6
|
+
<% if options.node %> implements GraphQL::Types::Relay::Node
|
7
|
+
<% end %><% normalized_fields.each do |f| %> <%= f.to_object_field %>
|
6
8
|
<% end %> end
|
7
9
|
end
|
8
10
|
<% end -%>
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
<% module_namespacing_when_supported do -%>
|
2
4
|
module Types
|
3
|
-
class <%=
|
5
|
+
class <%= ruby_class_name %> < Types::BaseScalar
|
4
6
|
def self.coerce_input(input_value, context)
|
5
7
|
# Override this to prepare a client-provided GraphQL value for your Ruby code
|
6
8
|
input_value
|
@@ -1,42 +1,27 @@
|
|
1
1
|
<% module_namespacing_when_supported do -%>
|
2
2
|
class <%= schema_name %> < GraphQL::Schema
|
3
3
|
query(Types::QueryType)
|
4
|
-
|
5
|
-
#
|
6
|
-
use GraphQL::
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
#
|
17
|
-
|
18
|
-
# - encodes it with base64:
|
19
|
-
# GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Given a string UUID, find the object
|
23
|
-
def self.object_from_id(id, query_ctx)
|
24
|
-
# For example, to decode the UUIDs generated above:
|
25
|
-
# type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
|
26
|
-
#
|
27
|
-
# Then, based on `type_name` and `id`
|
28
|
-
# find an object in your application
|
29
|
-
# ...
|
4
|
+
<% if options[:batch] %>
|
5
|
+
# GraphQL::Batch setup:
|
6
|
+
use GraphQL::Batch
|
7
|
+
<% else %>
|
8
|
+
# For batch-loading (see https://graphql-ruby.org/dataloader/overview.html)
|
9
|
+
use GraphQL::Dataloader
|
10
|
+
<% end %>
|
11
|
+
# GraphQL-Ruby calls this when something goes wrong while running a query:
|
12
|
+
def self.type_error(err, context)
|
13
|
+
# if err.is_a?(GraphQL::InvalidNullError)
|
14
|
+
# # report to your bug tracker here
|
15
|
+
# return nil
|
16
|
+
# end
|
17
|
+
super
|
30
18
|
end
|
31
19
|
|
32
|
-
#
|
33
|
-
def self.resolve_type(
|
34
|
-
# TODO: Implement this
|
35
|
-
# to return the correct type for `obj`
|
20
|
+
# Union and Interface Resolution
|
21
|
+
def self.resolve_type(abstract_type, obj, ctx)
|
22
|
+
# TODO: Implement this method
|
23
|
+
# to return the correct GraphQL object type for `obj`
|
36
24
|
raise(GraphQL::RequiredImplementationMissingError)
|
37
25
|
end
|
38
|
-
|
39
|
-
# GraphQL::Batch setup:
|
40
|
-
use GraphQL::Batch
|
41
|
-
<% end %>end
|
26
|
+
end
|
42
27
|
<% end -%>
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
<% module_namespacing_when_supported do -%>
|
2
4
|
module Types
|
3
|
-
class <%=
|
4
|
-
<% if
|
5
|
+
class <%= ruby_class_name %> < Types::BaseUnion
|
6
|
+
<% if custom_fields.any? %> possible_types <%= normalized_possible_types.join(", ") %>
|
5
7
|
<% end %> end
|
6
8
|
end
|
7
9
|
<% end -%>
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'rails/generators'
|
2
3
|
require 'rails/generators/base'
|
3
4
|
require 'graphql'
|
4
5
|
require 'active_support'
|
@@ -7,14 +8,28 @@ require_relative 'core'
|
|
7
8
|
|
8
9
|
module Graphql
|
9
10
|
module Generators
|
10
|
-
class TypeGeneratorBase < Rails::Generators::
|
11
|
+
class TypeGeneratorBase < Rails::Generators::NamedBase
|
11
12
|
include Core
|
12
13
|
|
13
|
-
|
14
|
-
type: :
|
15
|
-
required:
|
16
|
-
|
17
|
-
|
14
|
+
class_option 'namespaced_types',
|
15
|
+
type: :boolean,
|
16
|
+
required: false,
|
17
|
+
default: false,
|
18
|
+
banner: "Namespaced",
|
19
|
+
desc: "If the generated types will be namespaced"
|
20
|
+
|
21
|
+
argument :custom_fields,
|
22
|
+
type: :array,
|
23
|
+
default: [],
|
24
|
+
banner: "name:type name:type ...",
|
25
|
+
desc: "Fields for this object (type may be expressed as Ruby or GraphQL)"
|
26
|
+
|
27
|
+
|
28
|
+
attr_accessor :graphql_type
|
29
|
+
|
30
|
+
def create_type_file
|
31
|
+
template "#{graphql_type}.erb", "#{options[:directory]}/types#{subdirectory}/#{type_file_name}.rb"
|
32
|
+
end
|
18
33
|
|
19
34
|
# Take a type expression in any combination of GraphQL or Ruby styles
|
20
35
|
# and return it in a specified output style
|
@@ -60,12 +75,12 @@ module Graphql
|
|
60
75
|
|
61
76
|
# @return [String] The user-provided type name, normalized to Ruby code
|
62
77
|
def type_ruby_name
|
63
|
-
@type_ruby_name ||= self.class.normalize_type_expression(
|
78
|
+
@type_ruby_name ||= self.class.normalize_type_expression(name, mode: :ruby)[0]
|
64
79
|
end
|
65
80
|
|
66
81
|
# @return [String] The user-provided type name, as a GraphQL name
|
67
82
|
def type_graphql_name
|
68
|
-
@type_graphql_name ||= self.class.normalize_type_expression(
|
83
|
+
@type_graphql_name ||= self.class.normalize_type_expression(name, mode: :graphql)[0]
|
69
84
|
end
|
70
85
|
|
71
86
|
# @return [String] The user-provided type name, as a file name (without extension)
|
@@ -82,6 +97,24 @@ module Graphql
|
|
82
97
|
}
|
83
98
|
end
|
84
99
|
|
100
|
+
def ruby_class_name
|
101
|
+
class_prefix =
|
102
|
+
if options[:namespaced_types]
|
103
|
+
"#{graphql_type.pluralize.camelize}::"
|
104
|
+
else
|
105
|
+
""
|
106
|
+
end
|
107
|
+
@ruby_class_name || class_prefix + type_ruby_name.sub(/^Types::/, "")
|
108
|
+
end
|
109
|
+
|
110
|
+
def subdirectory
|
111
|
+
if options[:namespaced_types]
|
112
|
+
"/#{graphql_type.pluralize}"
|
113
|
+
else
|
114
|
+
""
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
85
118
|
class NormalizedField
|
86
119
|
def initialize(name, type_expr, null)
|
87
120
|
@name = name
|
@@ -89,8 +122,12 @@ module Graphql
|
|
89
122
|
@null = null
|
90
123
|
end
|
91
124
|
|
92
|
-
def
|
93
|
-
"field :#{@name}, #{@type_expr}, null:
|
125
|
+
def to_object_field
|
126
|
+
"field :#{@name}, #{@type_expr}#{@null ? '' : ', null: false'}"
|
127
|
+
end
|
128
|
+
|
129
|
+
def to_input_argument
|
130
|
+
"argument :#{@name}, #{@type_expr}, required: false"
|
94
131
|
end
|
95
132
|
end
|
96
133
|
end
|
@@ -19,14 +19,14 @@ module Graphql
|
|
19
19
|
banner: "type type ...",
|
20
20
|
desc: "Possible types for this union (expressed as Ruby or GraphQL)"
|
21
21
|
|
22
|
-
def create_type_file
|
23
|
-
template "union.erb", "#{options[:directory]}/types/#{type_file_name}.rb"
|
24
|
-
end
|
25
|
-
|
26
22
|
private
|
27
23
|
|
24
|
+
def graphql_type
|
25
|
+
"union"
|
26
|
+
end
|
27
|
+
|
28
28
|
def normalized_possible_types
|
29
|
-
|
29
|
+
custom_fields.map { |t| self.class.normalize_type_expression(t, mode: :ruby)[0] }
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -3,6 +3,11 @@ module GraphQL
|
|
3
3
|
module Analysis
|
4
4
|
module_function
|
5
5
|
|
6
|
+
def use(schema_class)
|
7
|
+
schema = schema_class.is_a?(Class) ? schema_class : schema_class.target
|
8
|
+
schema.analysis_engine = self
|
9
|
+
end
|
10
|
+
|
6
11
|
# @return [void]
|
7
12
|
def analyze_multiplex(multiplex, analyzers)
|
8
13
|
multiplex.trace("analyze_multiplex", { multiplex: multiplex }) do
|
@@ -38,6 +43,8 @@ module GraphQL
|
|
38
43
|
# @param analyzers [Array<#call>] Objects that respond to `#call(memo, visit_type, irep_node)`
|
39
44
|
# @return [Array<Any>] Results from those analyzers
|
40
45
|
def analyze_query(query, analyzers, multiplex_states: [])
|
46
|
+
GraphQL::Deprecation.warn "Legacy analysis will be removed in GraphQL-Ruby 2.0, please upgrade to AST Analysis: https://graphql-ruby.org/queries/ast_analysis.html (schema: #{query.schema})"
|
47
|
+
|
41
48
|
query.trace("analyze_query", { query: query }) do
|
42
49
|
analyzers_to_run = analyzers.select do |analyzer|
|
43
50
|
if analyzer.respond_to?(:analyze?)
|
@@ -7,6 +7,7 @@ module GraphQL
|
|
7
7
|
super
|
8
8
|
@used_fields = Set.new
|
9
9
|
@used_deprecated_fields = Set.new
|
10
|
+
@used_deprecated_arguments = Set.new
|
10
11
|
end
|
11
12
|
|
12
13
|
def on_leave_field(node, parent, visitor)
|
@@ -14,14 +15,40 @@ module GraphQL
|
|
14
15
|
field = "#{visitor.parent_type_definition.graphql_name}.#{field_defn.graphql_name}"
|
15
16
|
@used_fields << field
|
16
17
|
@used_deprecated_fields << field if field_defn.deprecation_reason
|
18
|
+
arguments = visitor.query.arguments_for(node, visitor.field_definition)
|
19
|
+
# If there was an error when preparing this argument object,
|
20
|
+
# then this might be an error or something:
|
21
|
+
if arguments.respond_to?(:argument_values)
|
22
|
+
extract_deprecated_arguments(arguments.argument_values)
|
23
|
+
end
|
17
24
|
end
|
18
25
|
|
19
26
|
def result
|
20
27
|
{
|
21
28
|
used_fields: @used_fields.to_a,
|
22
|
-
used_deprecated_fields: @used_deprecated_fields.to_a
|
29
|
+
used_deprecated_fields: @used_deprecated_fields.to_a,
|
30
|
+
used_deprecated_arguments: @used_deprecated_arguments.to_a,
|
23
31
|
}
|
24
32
|
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def extract_deprecated_arguments(argument_values)
|
37
|
+
argument_values.each_pair do |_argument_name, argument|
|
38
|
+
if argument.definition.deprecation_reason
|
39
|
+
@used_deprecated_arguments << argument.definition.path
|
40
|
+
end
|
41
|
+
|
42
|
+
if argument.definition.type.kind.input_object?
|
43
|
+
extract_deprecated_arguments(argument.value.arguments.argument_values) # rubocop:disable Development/ContextIsPassedCop -- runtime args instance
|
44
|
+
elsif argument.definition.type.list? && !argument.value.nil?
|
45
|
+
argument
|
46
|
+
.value
|
47
|
+
.select { |value| value.respond_to?(:arguments) }
|
48
|
+
.each { |value| extract_deprecated_arguments(value.arguments.argument_values) } # rubocop:disable Development/ContextIsPassedCop -- runtime args instance
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
25
52
|
end
|
26
53
|
end
|
27
54
|
end
|
@@ -23,18 +23,22 @@ module GraphQL
|
|
23
23
|
|
24
24
|
attr_reader :field_definition, :response_path, :query
|
25
25
|
|
26
|
-
# @param
|
26
|
+
# @param parent_type [Class] The owner of `field_definition`
|
27
27
|
# @param field_definition [GraphQL::Field, GraphQL::Schema::Field] Used for getting the `.complexity` configuration
|
28
28
|
# @param query [GraphQL::Query] Used for `query.possible_types`
|
29
29
|
# @param response_path [Array<String>] The path to the response key for the field
|
30
|
-
def initialize(
|
31
|
-
@
|
30
|
+
def initialize(parent_type, field_definition, query, response_path)
|
31
|
+
@parent_type = parent_type
|
32
32
|
@field_definition = field_definition
|
33
33
|
@query = query
|
34
34
|
@response_path = response_path
|
35
35
|
@scoped_children = nil
|
36
|
+
@nodes = []
|
36
37
|
end
|
37
38
|
|
39
|
+
# @return [Array<GraphQL::Language::Nodes::Field>]
|
40
|
+
attr_reader :nodes
|
41
|
+
|
38
42
|
# Returns true if this field has no selections, ie, it's a scalar.
|
39
43
|
# We need a quick way to check whether we should continue traversing.
|
40
44
|
def terminal?
|
@@ -50,16 +54,7 @@ module GraphQL
|
|
50
54
|
end
|
51
55
|
|
52
56
|
def own_complexity(child_complexity)
|
53
|
-
|
54
|
-
case defined_complexity
|
55
|
-
when Proc
|
56
|
-
arguments = @query.arguments_for(@node, @field_definition)
|
57
|
-
defined_complexity.call(@query.context, arguments.keyword_arguments, child_complexity)
|
58
|
-
when Numeric
|
59
|
-
defined_complexity + child_complexity
|
60
|
-
else
|
61
|
-
raise("Invalid complexity: #{defined_complexity.inspect} on #{@field_definition.name}")
|
62
|
-
end
|
57
|
+
@field_definition.calculate_complexity(query: @query, nodes: @nodes, child_complexity: child_complexity)
|
63
58
|
end
|
64
59
|
end
|
65
60
|
|
@@ -79,7 +74,8 @@ module GraphQL
|
|
79
74
|
# then the query would have been rejected as invalid.
|
80
75
|
complexities_on_type = @complexities_on_type_by_query[visitor.query] ||= [ScopedTypeComplexity.new(nil, nil, query, visitor.response_path)]
|
81
76
|
|
82
|
-
complexity = complexities_on_type.last.scoped_children[parent_type][field_key] ||= ScopedTypeComplexity.new(
|
77
|
+
complexity = complexities_on_type.last.scoped_children[parent_type][field_key] ||= ScopedTypeComplexity.new(parent_type, visitor.field_definition, visitor.query, visitor.response_path)
|
78
|
+
complexity.nodes.push(node)
|
83
79
|
# Push it on the stack.
|
84
80
|
complexities_on_type.push(complexity)
|
85
81
|
end
|
@@ -19,6 +19,7 @@ module GraphQL
|
|
19
19
|
@field_definitions = []
|
20
20
|
@argument_definitions = []
|
21
21
|
@directive_definitions = []
|
22
|
+
@rescued_errors = []
|
22
23
|
@query = query
|
23
24
|
@schema = query.schema
|
24
25
|
@response_path = []
|
@@ -32,6 +33,9 @@ module GraphQL
|
|
32
33
|
# @return [Array<GraphQL::ObjectType>] Types whose scope we've entered
|
33
34
|
attr_reader :object_types
|
34
35
|
|
36
|
+
# @return [Array<GraphQL::AnalysisError]
|
37
|
+
attr_reader :rescued_errors
|
38
|
+
|
35
39
|
def visit
|
36
40
|
return unless @document
|
37
41
|
super
|
@@ -96,7 +100,8 @@ module GraphQL
|
|
96
100
|
def on_field(node, parent)
|
97
101
|
@response_path.push(node.alias || node.name)
|
98
102
|
parent_type = @object_types.last
|
99
|
-
|
103
|
+
# This could be nil if the previous field wasn't found:
|
104
|
+
field_definition = parent_type && @schema.get_field(parent_type, node.name, @query.context)
|
100
105
|
@field_definitions.push(field_definition)
|
101
106
|
if !field_definition.nil?
|
102
107
|
next_object_type = field_definition.type.unwrap
|
@@ -134,14 +139,14 @@ module GraphQL
|
|
134
139
|
argument_defn = if (arg = @argument_definitions.last)
|
135
140
|
arg_type = arg.type.unwrap
|
136
141
|
if arg_type.kind.input_object?
|
137
|
-
arg_type.
|
142
|
+
arg_type.get_argument(node.name, @query.context)
|
138
143
|
else
|
139
144
|
nil
|
140
145
|
end
|
141
146
|
elsif (directive_defn = @directive_definitions.last)
|
142
|
-
directive_defn.
|
147
|
+
directive_defn.get_argument(node.name, @query.context)
|
143
148
|
elsif (field_defn = @field_definitions.last)
|
144
|
-
field_defn.
|
149
|
+
field_defn.get_argument(node.name, @query.context)
|
145
150
|
else
|
146
151
|
nil
|
147
152
|
end
|
@@ -239,7 +244,11 @@ module GraphQL
|
|
239
244
|
|
240
245
|
def call_analyzers(method, node, parent)
|
241
246
|
@analyzers.each do |analyzer|
|
242
|
-
|
247
|
+
begin
|
248
|
+
analyzer.public_send(method, node, parent, self)
|
249
|
+
rescue AnalysisError => err
|
250
|
+
@rescued_errors << err
|
251
|
+
end
|
243
252
|
end
|
244
253
|
end
|
245
254
|
|
data/lib/graphql/analysis/ast.rb
CHANGED
@@ -13,7 +13,12 @@ module GraphQL
|
|
13
13
|
module_function
|
14
14
|
|
15
15
|
def use(schema_class)
|
16
|
-
schema_class.analysis_engine
|
16
|
+
if schema_class.analysis_engine == self
|
17
|
+
definition_line = caller(2, 1).first
|
18
|
+
GraphQL::Deprecation.warn("GraphQL::Analysis::AST is now the default; remove `use GraphQL::Analysis::AST` from the schema definition (#{definition_line})")
|
19
|
+
else
|
20
|
+
schema_class.analysis_engine = self
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
24
|
# Analyze a multiplex, and all queries within.
|
@@ -67,7 +72,11 @@ module GraphQL
|
|
67
72
|
|
68
73
|
visitor.visit
|
69
74
|
|
70
|
-
|
75
|
+
if visitor.rescued_errors.any?
|
76
|
+
visitor.rescued_errors
|
77
|
+
else
|
78
|
+
query_analyzers.map(&:result)
|
79
|
+
end
|
71
80
|
else
|
72
81
|
[]
|
73
82
|
end
|
data/lib/graphql/argument.rb
CHANGED
@@ -3,7 +3,7 @@ module GraphQL
|
|
3
3
|
# @api deprecated
|
4
4
|
class Argument
|
5
5
|
include GraphQL::Define::InstanceDefinable
|
6
|
-
|
6
|
+
deprecated_accepts_definitions :name, :type, :description, :default_value, :as, :prepare, :method_access, :deprecation_reason
|
7
7
|
attr_reader :default_value
|
8
8
|
attr_accessor :description, :name, :as, :deprecation_reason
|
9
9
|
attr_accessor :ast_node
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
class Backtrace
|
4
|
+
module LegacyTracer
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# Implement the {GraphQL::Tracing} API.
|
8
|
+
def trace(key, metadata)
|
9
|
+
case key
|
10
|
+
when "lex", "parse"
|
11
|
+
# No context here, don't have a query yet
|
12
|
+
nil
|
13
|
+
when "execute_multiplex", "analyze_multiplex"
|
14
|
+
# No query context yet
|
15
|
+
nil
|
16
|
+
when "validate", "analyze_query", "execute_query", "execute_query_lazy"
|
17
|
+
query = metadata[:query] || metadata[:queries].first
|
18
|
+
push_data = query
|
19
|
+
multiplex = query.multiplex
|
20
|
+
when "execute_field", "execute_field_lazy"
|
21
|
+
# The interpreter passes `query:`, legacy passes `context:`
|
22
|
+
context = metadata[:context] || ((q = metadata[:query]) && q.context)
|
23
|
+
push_data = context
|
24
|
+
multiplex = context.query.multiplex
|
25
|
+
else
|
26
|
+
# Custom key, no backtrace data for this
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
if push_data
|
31
|
+
multiplex.context[:last_graphql_backtrace_context] = push_data
|
32
|
+
end
|
33
|
+
|
34
|
+
if key == "execute_multiplex"
|
35
|
+
begin
|
36
|
+
yield
|
37
|
+
rescue StandardError => err
|
38
|
+
# This is an unhandled error from execution,
|
39
|
+
# Re-raise it with a GraphQL trace.
|
40
|
+
potential_context = metadata[:multiplex].context[:last_graphql_backtrace_context]
|
41
|
+
|
42
|
+
if potential_context.is_a?(GraphQL::Query::Context) || potential_context.is_a?(GraphQL::Query::Context::FieldResolutionContext)
|
43
|
+
raise TracedError.new(err, potential_context)
|
44
|
+
else
|
45
|
+
raise
|
46
|
+
end
|
47
|
+
ensure
|
48
|
+
metadata[:multiplex].context.delete(:last_graphql_backtrace_context)
|
49
|
+
end
|
50
|
+
else
|
51
|
+
yield
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|