graphql 1.13.17 → 2.0.20
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/install_generator.rb +1 -1
- data/lib/generators/graphql/relay.rb +3 -17
- data/lib/generators/graphql/templates/schema.erb +3 -0
- data/lib/graphql/analysis/ast/field_usage.rb +3 -1
- data/lib/graphql/analysis/ast/max_query_complexity.rb +0 -1
- data/lib/graphql/analysis/ast/query_complexity.rb +1 -1
- data/lib/graphql/analysis/ast/query_depth.rb +0 -1
- data/lib/graphql/analysis/ast/visitor.rb +43 -36
- data/lib/graphql/analysis/ast.rb +2 -12
- data/lib/graphql/analysis.rb +0 -7
- data/lib/graphql/backtrace/table.rb +2 -20
- data/lib/graphql/backtrace/tracer.rb +2 -3
- data/lib/graphql/backtrace.rb +2 -8
- data/lib/graphql/dataloader/null_dataloader.rb +3 -1
- data/lib/graphql/dataloader/source.rb +9 -0
- data/lib/graphql/dataloader.rb +4 -1
- data/lib/graphql/dig.rb +1 -1
- data/lib/graphql/execution/errors.rb +12 -82
- data/lib/graphql/execution/interpreter/resolve.rb +26 -0
- data/lib/graphql/execution/interpreter/runtime.rb +159 -120
- data/lib/graphql/execution/interpreter.rb +187 -78
- data/lib/graphql/execution/lazy.rb +7 -21
- data/lib/graphql/execution/lookahead.rb +44 -40
- data/lib/graphql/execution/multiplex.rb +3 -174
- data/lib/graphql/execution.rb +11 -4
- data/lib/graphql/introspection/directive_type.rb +2 -2
- data/lib/graphql/introspection/dynamic_fields.rb +3 -8
- data/lib/graphql/introspection/entry_points.rb +2 -15
- data/lib/graphql/introspection/field_type.rb +1 -1
- data/lib/graphql/introspection/schema_type.rb +2 -2
- data/lib/graphql/introspection/type_type.rb +13 -6
- data/lib/graphql/introspection.rb +4 -3
- data/lib/graphql/language/document_from_schema_definition.rb +18 -35
- data/lib/graphql/language/lexer.rb +216 -1488
- data/lib/graphql/language/nodes.rb +65 -39
- data/lib/graphql/language/parser.rb +376 -364
- data/lib/graphql/language/parser.y +49 -44
- data/lib/graphql/language/printer.rb +37 -21
- data/lib/graphql/language/visitor.rb +191 -83
- data/lib/graphql/pagination/active_record_relation_connection.rb +0 -8
- data/lib/graphql/pagination/array_connection.rb +4 -2
- data/lib/graphql/pagination/connection.rb +31 -4
- data/lib/graphql/pagination/connections.rb +3 -28
- data/lib/graphql/pagination/relation_connection.rb +2 -0
- data/lib/graphql/query/context.rb +155 -196
- data/lib/graphql/query/input_validation_result.rb +1 -1
- data/lib/graphql/query/null_context.rb +0 -3
- data/lib/graphql/query/validation_pipeline.rb +10 -34
- data/lib/graphql/query/variables.rb +7 -20
- data/lib/graphql/query.rb +32 -42
- data/lib/graphql/railtie.rb +0 -104
- data/lib/graphql/rake_task/validate.rb +1 -1
- data/lib/graphql/rake_task.rb +29 -1
- data/lib/graphql/relay/range_add.rb +9 -20
- data/lib/graphql/relay.rb +0 -15
- data/lib/graphql/schema/addition.rb +7 -9
- data/lib/graphql/schema/argument.rb +36 -43
- data/lib/graphql/schema/build_from_definition.rb +32 -18
- data/lib/graphql/schema/directive/one_of.rb +12 -0
- data/lib/graphql/schema/directive/transform.rb +1 -1
- data/lib/graphql/schema/directive.rb +12 -23
- data/lib/graphql/schema/enum.rb +28 -39
- data/lib/graphql/schema/enum_value.rb +5 -25
- data/lib/graphql/schema/field/connection_extension.rb +4 -0
- data/lib/graphql/schema/field.rb +237 -339
- data/lib/graphql/schema/input_object.rb +56 -67
- data/lib/graphql/schema/interface.rb +0 -35
- data/lib/graphql/schema/introspection_system.rb +3 -8
- data/lib/graphql/schema/late_bound_type.rb +8 -2
- data/lib/graphql/schema/list.rb +0 -6
- data/lib/graphql/schema/loader.rb +1 -2
- data/lib/graphql/schema/member/base_dsl_methods.rb +17 -19
- data/lib/graphql/schema/member/build_type.rb +5 -7
- data/lib/graphql/schema/member/has_arguments.rb +146 -55
- data/lib/graphql/schema/member/has_ast_node.rb +12 -0
- data/lib/graphql/schema/member/has_deprecation_reason.rb +3 -4
- data/lib/graphql/schema/member/has_directives.rb +81 -59
- data/lib/graphql/schema/member/has_fields.rb +17 -4
- data/lib/graphql/schema/member/has_interfaces.rb +49 -10
- data/lib/graphql/schema/member/has_validators.rb +31 -5
- data/lib/graphql/schema/member/relay_shortcuts.rb +47 -2
- data/lib/graphql/schema/member/type_system_helpers.rb +17 -0
- data/lib/graphql/schema/member/validates_input.rb +1 -1
- data/lib/graphql/schema/member.rb +0 -6
- data/lib/graphql/schema/mutation.rb +0 -9
- data/lib/graphql/schema/non_null.rb +1 -7
- data/lib/graphql/schema/object.rb +15 -52
- data/lib/graphql/schema/relay_classic_mutation.rb +53 -42
- data/lib/graphql/schema/resolver/has_payload_type.rb +20 -10
- data/lib/graphql/schema/resolver.rb +41 -42
- data/lib/graphql/schema/scalar.rb +7 -22
- data/lib/graphql/schema/subscription.rb +0 -7
- data/lib/graphql/schema/timeout.rb +24 -28
- data/lib/graphql/schema/type_membership.rb +3 -0
- data/lib/graphql/schema/union.rb +10 -17
- data/lib/graphql/schema/warden.rb +34 -8
- data/lib/graphql/schema/wrapper.rb +0 -5
- data/lib/graphql/schema.rb +241 -973
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/base_visitor.rb +4 -21
- data/lib/graphql/static_validation/definition_dependencies.rb +7 -1
- data/lib/graphql/static_validation/error.rb +2 -2
- data/lib/graphql/static_validation/literal_validator.rb +19 -1
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +11 -5
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +12 -12
- 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/unique_directives_per_location.rb +12 -6
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
- data/lib/graphql/static_validation/validator.rb +3 -25
- data/lib/graphql/static_validation.rb +0 -2
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +7 -1
- data/lib/graphql/subscriptions/default_subscription_resolve_extension.rb +38 -1
- data/lib/graphql/subscriptions/event.rb +3 -8
- data/lib/graphql/subscriptions/instrumentation.rb +0 -51
- data/lib/graphql/subscriptions.rb +32 -20
- data/lib/graphql/tracing/active_support_notifications_trace.rb +16 -0
- data/lib/graphql/tracing/appoptics_trace.rb +231 -0
- data/lib/graphql/tracing/appsignal_trace.rb +71 -0
- data/lib/graphql/tracing/data_dog_trace.rb +148 -0
- data/lib/graphql/tracing/data_dog_tracing.rb +2 -0
- data/lib/graphql/tracing/new_relic_trace.rb +75 -0
- data/lib/graphql/tracing/notifications_trace.rb +41 -0
- data/lib/graphql/tracing/platform_trace.rb +107 -0
- data/lib/graphql/tracing/platform_tracing.rb +26 -40
- data/lib/graphql/tracing/prometheus_trace.rb +89 -0
- data/lib/graphql/tracing/prometheus_tracing.rb +3 -3
- data/lib/graphql/tracing/scout_trace.rb +72 -0
- data/lib/graphql/tracing/statsd_trace.rb +56 -0
- data/lib/graphql/tracing.rb +136 -40
- data/lib/graphql/type_kinds.rb +6 -3
- data/lib/graphql/types/iso_8601_date.rb +4 -1
- data/lib/graphql/types/iso_8601_date_time.rb +4 -0
- data/lib/graphql/types/relay/base_connection.rb +16 -6
- data/lib/graphql/types/relay/connection_behaviors.rb +29 -27
- data/lib/graphql/types/relay/edge_behaviors.rb +16 -5
- data/lib/graphql/types/relay/node_behaviors.rb +12 -2
- data/lib/graphql/types/relay/page_info_behaviors.rb +7 -2
- data/lib/graphql/types/relay.rb +0 -3
- data/lib/graphql/types/string.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/lib/graphql.rb +13 -74
- metadata +30 -133
- data/lib/graphql/analysis/analyze_query.rb +0 -98
- data/lib/graphql/analysis/field_usage.rb +0 -45
- data/lib/graphql/analysis/max_query_complexity.rb +0 -26
- data/lib/graphql/analysis/max_query_depth.rb +0 -26
- data/lib/graphql/analysis/query_complexity.rb +0 -88
- data/lib/graphql/analysis/query_depth.rb +0 -43
- data/lib/graphql/analysis/reducer_state.rb +0 -48
- data/lib/graphql/argument.rb +0 -131
- data/lib/graphql/authorization.rb +0 -82
- data/lib/graphql/backtrace/legacy_tracer.rb +0 -56
- data/lib/graphql/backwards_compatibility.rb +0 -61
- data/lib/graphql/base_type.rb +0 -232
- data/lib/graphql/boolean_type.rb +0 -2
- data/lib/graphql/compatibility/execution_specification/counter_schema.rb +0 -53
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +0 -200
- data/lib/graphql/compatibility/execution_specification.rb +0 -436
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +0 -111
- data/lib/graphql/compatibility/lazy_execution_specification.rb +0 -215
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +0 -87
- data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +0 -79
- data/lib/graphql/compatibility/query_parser_specification.rb +0 -266
- data/lib/graphql/compatibility/schema_parser_specification.rb +0 -682
- data/lib/graphql/compatibility.rb +0 -5
- data/lib/graphql/define/assign_argument.rb +0 -12
- data/lib/graphql/define/assign_connection.rb +0 -13
- data/lib/graphql/define/assign_enum_value.rb +0 -18
- data/lib/graphql/define/assign_global_id_field.rb +0 -11
- data/lib/graphql/define/assign_mutation_function.rb +0 -34
- data/lib/graphql/define/assign_object_field.rb +0 -42
- data/lib/graphql/define/defined_object_proxy.rb +0 -53
- data/lib/graphql/define/instance_definable.rb +0 -255
- data/lib/graphql/define/no_definition_error.rb +0 -7
- data/lib/graphql/define/non_null_with_bang.rb +0 -16
- data/lib/graphql/define/type_definer.rb +0 -31
- data/lib/graphql/define.rb +0 -31
- data/lib/graphql/deprecated_dsl.rb +0 -55
- data/lib/graphql/directive/deprecated_directive.rb +0 -2
- data/lib/graphql/directive/include_directive.rb +0 -2
- data/lib/graphql/directive/skip_directive.rb +0 -2
- data/lib/graphql/directive.rb +0 -107
- data/lib/graphql/enum_type.rb +0 -133
- data/lib/graphql/execution/execute.rb +0 -333
- data/lib/graphql/execution/flatten.rb +0 -40
- data/lib/graphql/execution/instrumentation.rb +0 -92
- data/lib/graphql/execution/lazy/resolve.rb +0 -91
- data/lib/graphql/execution/typecast.rb +0 -50
- data/lib/graphql/field/resolve.rb +0 -59
- data/lib/graphql/field.rb +0 -226
- data/lib/graphql/float_type.rb +0 -2
- data/lib/graphql/function.rb +0 -128
- data/lib/graphql/id_type.rb +0 -2
- data/lib/graphql/input_object_type.rb +0 -138
- data/lib/graphql/int_type.rb +0 -2
- data/lib/graphql/interface_type.rb +0 -72
- data/lib/graphql/internal_representation/document.rb +0 -27
- data/lib/graphql/internal_representation/node.rb +0 -206
- data/lib/graphql/internal_representation/print.rb +0 -51
- data/lib/graphql/internal_representation/rewrite.rb +0 -184
- data/lib/graphql/internal_representation/scope.rb +0 -88
- data/lib/graphql/internal_representation/visit.rb +0 -36
- data/lib/graphql/internal_representation.rb +0 -7
- data/lib/graphql/language/lexer.rl +0 -260
- data/lib/graphql/list_type.rb +0 -80
- data/lib/graphql/non_null_type.rb +0 -71
- data/lib/graphql/object_type.rb +0 -130
- data/lib/graphql/query/arguments.rb +0 -189
- data/lib/graphql/query/arguments_cache.rb +0 -24
- data/lib/graphql/query/executor.rb +0 -52
- data/lib/graphql/query/literal_input.rb +0 -136
- data/lib/graphql/query/serial_execution/field_resolution.rb +0 -92
- data/lib/graphql/query/serial_execution/operation_resolution.rb +0 -19
- data/lib/graphql/query/serial_execution/selection_resolution.rb +0 -23
- data/lib/graphql/query/serial_execution/value_resolution.rb +0 -87
- data/lib/graphql/query/serial_execution.rb +0 -40
- data/lib/graphql/relay/array_connection.rb +0 -83
- data/lib/graphql/relay/base_connection.rb +0 -189
- data/lib/graphql/relay/connection_instrumentation.rb +0 -54
- data/lib/graphql/relay/connection_resolve.rb +0 -43
- data/lib/graphql/relay/connection_type.rb +0 -54
- data/lib/graphql/relay/edge.rb +0 -27
- data/lib/graphql/relay/edge_type.rb +0 -19
- data/lib/graphql/relay/edges_instrumentation.rb +0 -39
- data/lib/graphql/relay/global_id_resolve.rb +0 -17
- data/lib/graphql/relay/mongo_relation_connection.rb +0 -50
- data/lib/graphql/relay/mutation/instrumentation.rb +0 -23
- data/lib/graphql/relay/mutation/resolve.rb +0 -56
- data/lib/graphql/relay/mutation/result.rb +0 -38
- data/lib/graphql/relay/mutation.rb +0 -106
- data/lib/graphql/relay/node.rb +0 -39
- data/lib/graphql/relay/page_info.rb +0 -7
- data/lib/graphql/relay/relation_connection.rb +0 -188
- data/lib/graphql/relay/type_extensions.rb +0 -32
- data/lib/graphql/scalar_type.rb +0 -91
- data/lib/graphql/schema/catchall_middleware.rb +0 -35
- data/lib/graphql/schema/default_parse_error.rb +0 -10
- data/lib/graphql/schema/default_type_error.rb +0 -17
- data/lib/graphql/schema/member/accepts_definition.rb +0 -164
- data/lib/graphql/schema/member/cached_graphql_definition.rb +0 -58
- data/lib/graphql/schema/member/instrumentation.rb +0 -131
- data/lib/graphql/schema/middleware_chain.rb +0 -82
- data/lib/graphql/schema/possible_types.rb +0 -44
- data/lib/graphql/schema/rescue_middleware.rb +0 -60
- data/lib/graphql/schema/timeout_middleware.rb +0 -88
- data/lib/graphql/schema/traversal.rb +0 -228
- data/lib/graphql/schema/validation.rb +0 -313
- data/lib/graphql/static_validation/default_visitor.rb +0 -15
- data/lib/graphql/static_validation/no_validate_visitor.rb +0 -10
- data/lib/graphql/string_type.rb +0 -2
- data/lib/graphql/subscriptions/subscription_root.rb +0 -76
- data/lib/graphql/tracing/skylight_tracing.rb +0 -70
- data/lib/graphql/types/relay/default_relay.rb +0 -31
- data/lib/graphql/types/relay/node_field.rb +0 -24
- data/lib/graphql/types/relay/nodes_field.rb +0 -43
- data/lib/graphql/union_type.rb +0 -115
- data/lib/graphql/upgrader/member.rb +0 -937
- data/lib/graphql/upgrader/schema.rb +0 -38
@@ -2,7 +2,6 @@
|
|
2
2
|
module GraphQL
|
3
3
|
class Schema
|
4
4
|
class InputObject < GraphQL::Schema::Member
|
5
|
-
extend GraphQL::Schema::Member::AcceptsDefinition
|
6
5
|
extend Forwardable
|
7
6
|
extend GraphQL::Schema::Member::HasArguments
|
8
7
|
extend GraphQL::Schema::Member::HasArguments::ArgumentObjectLoader
|
@@ -13,49 +12,28 @@ module GraphQL
|
|
13
12
|
|
14
13
|
# @return [GraphQL::Query::Context] The context for this query
|
15
14
|
attr_reader :context
|
16
|
-
# @return [GraphQL::
|
15
|
+
# @return [GraphQL::Execution::Interpereter::Arguments] The underlying arguments instance
|
17
16
|
attr_reader :arguments
|
18
17
|
|
19
18
|
# Ruby-like hash behaviors, read-only
|
20
19
|
def_delegators :@ruby_style_hash, :keys, :values, :each, :map, :any?, :empty?
|
21
20
|
|
22
|
-
def initialize(arguments
|
21
|
+
def initialize(arguments, ruby_kwargs:, context:, defaults_used:)
|
23
22
|
@context = context
|
24
|
-
|
25
|
-
|
26
|
-
@arguments = arguments
|
27
|
-
else
|
28
|
-
@arguments = self.class.arguments_class.new(arguments, context: context, defaults_used: defaults_used)
|
29
|
-
# Symbolized, underscored hash:
|
30
|
-
@ruby_style_hash = @arguments.to_kwargs
|
31
|
-
end
|
23
|
+
@ruby_style_hash = ruby_kwargs
|
24
|
+
@arguments = arguments
|
32
25
|
# Apply prepares, not great to have it duplicated here.
|
33
|
-
maybe_lazies = []
|
34
26
|
self.class.arguments(context).each_value do |arg_defn|
|
35
27
|
ruby_kwargs_key = arg_defn.keyword
|
36
|
-
|
37
28
|
if @ruby_style_hash.key?(ruby_kwargs_key)
|
38
|
-
loads = arg_defn.loads
|
39
|
-
# Resolvers do this loading themselves;
|
40
|
-
# With the interpreter, it's done during `coerce_arguments`
|
41
|
-
if loads && !arg_defn.from_resolver? && !context.interpreter?
|
42
|
-
value = @ruby_style_hash[ruby_kwargs_key]
|
43
|
-
loaded_value = arg_defn.load_and_authorize_value(self, value, context)
|
44
|
-
maybe_lazies << context.schema.after_lazy(loaded_value) do |loaded_value|
|
45
|
-
overwrite_argument(ruby_kwargs_key, loaded_value)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
29
|
# Weirdly, procs are applied during coercion, but not methods.
|
50
30
|
# Probably because these methods require a `self`.
|
51
|
-
if arg_defn.prepare.is_a?(Symbol) || context.nil?
|
31
|
+
if arg_defn.prepare.is_a?(Symbol) || context.nil?
|
52
32
|
prepared_value = arg_defn.prepare_value(self, @ruby_style_hash[ruby_kwargs_key])
|
53
33
|
overwrite_argument(ruby_kwargs_key, prepared_value)
|
54
34
|
end
|
55
35
|
end
|
56
36
|
end
|
57
|
-
|
58
|
-
@maybe_lazies = maybe_lazies
|
59
37
|
end
|
60
38
|
|
61
39
|
def to_h
|
@@ -68,12 +46,10 @@ module GraphQL
|
|
68
46
|
|
69
47
|
def prepare
|
70
48
|
if @context
|
71
|
-
@context
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
self
|
76
|
-
end
|
49
|
+
object = @context[:current_object]
|
50
|
+
# Pass this object's class with `as` so that messages are rendered correctly from inherited validators
|
51
|
+
Schema::Validator.validate!(self.class.validators, object, @context, @ruby_style_hash, as: self.class)
|
52
|
+
self
|
77
53
|
else
|
78
54
|
self
|
79
55
|
end
|
@@ -83,7 +59,6 @@ module GraphQL
|
|
83
59
|
# Authorize each argument (but this doesn't apply if `prepare` is implemented):
|
84
60
|
if value.respond_to?(:key?)
|
85
61
|
arguments(ctx).each do |_name, input_obj_arg|
|
86
|
-
input_obj_arg = input_obj_arg.type_class
|
87
62
|
if value.key?(input_obj_arg.keyword) &&
|
88
63
|
!input_obj_arg.authorized?(obj, value[input_obj_arg.keyword], ctx)
|
89
64
|
return false
|
@@ -94,6 +69,19 @@ module GraphQL
|
|
94
69
|
true
|
95
70
|
end
|
96
71
|
|
72
|
+
def self.one_of
|
73
|
+
if !one_of?
|
74
|
+
if all_argument_definitions.any? { |arg| arg.type.non_null? }
|
75
|
+
raise ArgumentError, "`one_of` may not be used with required arguments -- add `required: false` to argument definitions to use `one_of`"
|
76
|
+
end
|
77
|
+
directive(GraphQL::Schema::Directive::OneOf)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.one_of?
|
82
|
+
directives.any? { |d| d.is_a?(GraphQL::Schema::Directive::OneOf) }
|
83
|
+
end
|
84
|
+
|
97
85
|
def unwrap_value(value)
|
98
86
|
case value
|
99
87
|
when Array
|
@@ -132,11 +120,16 @@ module GraphQL
|
|
132
120
|
end
|
133
121
|
|
134
122
|
class << self
|
135
|
-
# @return [Class<GraphQL::Arguments>]
|
136
|
-
attr_accessor :arguments_class
|
137
|
-
|
138
123
|
def argument(*args, **kwargs, &block)
|
139
124
|
argument_defn = super(*args, **kwargs, &block)
|
125
|
+
if one_of?
|
126
|
+
if argument_defn.type.non_null?
|
127
|
+
raise ArgumentError, "Argument '#{argument_defn.path}' must be nullable because it is part of a OneOf type, add `required: false`."
|
128
|
+
end
|
129
|
+
if argument_defn.default_value?
|
130
|
+
raise ArgumentError, "Argument '#{argument_defn.path}' cannot have a default value because it is part of a OneOf type, remove `default_value: ...`."
|
131
|
+
end
|
132
|
+
end
|
140
133
|
# Add a method access
|
141
134
|
method_name = argument_defn.keyword
|
142
135
|
class_eval <<-RUBY, __FILE__, __LINE__
|
@@ -147,25 +140,6 @@ module GraphQL
|
|
147
140
|
argument_defn
|
148
141
|
end
|
149
142
|
|
150
|
-
prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
|
151
|
-
|
152
|
-
def to_graphql
|
153
|
-
type_defn = GraphQL::InputObjectType.new
|
154
|
-
type_defn.name = graphql_name
|
155
|
-
type_defn.description = description
|
156
|
-
type_defn.metadata[:type_class] = self
|
157
|
-
type_defn.mutation = mutation
|
158
|
-
type_defn.ast_node = ast_node
|
159
|
-
all_argument_definitions.each do |arg|
|
160
|
-
type_defn.arguments[arg.graphql_definition(silence_deprecation_warning: true).name] = arg.graphql_definition(silence_deprecation_warning: true) # rubocop:disable Development/ContextIsPassedCop -- legacy-related
|
161
|
-
end
|
162
|
-
# Make a reference to a classic-style Arguments class
|
163
|
-
self.arguments_class = GraphQL::Query::Arguments.construct_arguments_class(type_defn)
|
164
|
-
# But use this InputObject class at runtime
|
165
|
-
type_defn.arguments_class = self
|
166
|
-
type_defn
|
167
|
-
end
|
168
|
-
|
169
143
|
def kind
|
170
144
|
GraphQL::TypeKinds::INPUT_OBJECT
|
171
145
|
end
|
@@ -174,18 +148,15 @@ module GraphQL
|
|
174
148
|
INVALID_OBJECT_MESSAGE = "Expected %{object} to be a key-value object responding to `to_h` or `to_unsafe_h`."
|
175
149
|
|
176
150
|
def validate_non_null_input(input, ctx, max_errors: nil)
|
177
|
-
result = GraphQL::Query::InputValidationResult.new
|
178
151
|
warden = ctx.warden
|
179
152
|
|
180
153
|
if input.is_a?(Array)
|
181
|
-
|
182
|
-
return result
|
154
|
+
return GraphQL::Query::InputValidationResult.from_problem(INVALID_OBJECT_MESSAGE % { object: JSON.generate(input, quirks_mode: true) })
|
183
155
|
end
|
184
156
|
|
185
157
|
if !(input.respond_to?(:to_h) || input.respond_to?(:to_unsafe_h))
|
186
158
|
# We're not sure it'll act like a hash, so reject it:
|
187
|
-
|
188
|
-
return result
|
159
|
+
return GraphQL::Query::InputValidationResult.from_problem(INVALID_OBJECT_MESSAGE % { object: JSON.generate(input, quirks_mode: true) })
|
189
160
|
end
|
190
161
|
|
191
162
|
# Inject missing required arguments
|
@@ -197,18 +168,36 @@ module GraphQL
|
|
197
168
|
m
|
198
169
|
end
|
199
170
|
|
200
|
-
|
171
|
+
result = nil
|
201
172
|
[input, missing_required_inputs].each do |args_to_validate|
|
202
173
|
args_to_validate.each do |argument_name, value|
|
203
174
|
argument = warden.get_argument(self, argument_name)
|
204
175
|
# Items in the input that are unexpected
|
205
|
-
|
176
|
+
if argument.nil?
|
177
|
+
result ||= Query::InputValidationResult.new
|
206
178
|
result.add_problem("Field is not defined on #{self.graphql_name}", [argument_name])
|
207
|
-
|
179
|
+
else
|
180
|
+
# Items in the input that are expected, but have invalid values
|
181
|
+
argument_result = argument.type.validate_input(value, ctx)
|
182
|
+
result ||= Query::InputValidationResult.new
|
183
|
+
if !argument_result.valid?
|
184
|
+
result.merge_result!(argument_name, argument_result)
|
185
|
+
end
|
208
186
|
end
|
209
|
-
|
210
|
-
|
211
|
-
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
if one_of?
|
191
|
+
if input.size == 1
|
192
|
+
input.each do |name, value|
|
193
|
+
if value.nil?
|
194
|
+
result ||= Query::InputValidationResult.new
|
195
|
+
result.add_problem("'#{graphql_name}' requires exactly one argument, but '#{name}' was `null`.")
|
196
|
+
end
|
197
|
+
end
|
198
|
+
else
|
199
|
+
result ||= Query::InputValidationResult.new
|
200
|
+
result.add_problem("'#{graphql_name}' requires exactly one argument, but #{input.size} were provided.")
|
212
201
|
end
|
213
202
|
end
|
214
203
|
|
@@ -4,8 +4,6 @@ module GraphQL
|
|
4
4
|
module Interface
|
5
5
|
include GraphQL::Schema::Member::GraphQLTypeNames
|
6
6
|
module DefinitionMethods
|
7
|
-
include GraphQL::Schema::Member::CachedGraphQLDefinition
|
8
|
-
include GraphQL::Relay::TypeExtensions
|
9
7
|
include GraphQL::Schema::Member::BaseDSLMethods
|
10
8
|
# ConfigurationExtension's responsibilities are in `def included` below
|
11
9
|
include GraphQL::Schema::Member::TypeSystemHelpers
|
@@ -30,16 +28,6 @@ module GraphQL
|
|
30
28
|
true
|
31
29
|
end
|
32
30
|
|
33
|
-
# The interface is accessible if any of its possible types are accessible
|
34
|
-
def accessible?(context)
|
35
|
-
context.schema.possible_types(self, context).each do |type|
|
36
|
-
if context.schema.accessible?(type, context)
|
37
|
-
return true
|
38
|
-
end
|
39
|
-
end
|
40
|
-
false
|
41
|
-
end
|
42
|
-
|
43
31
|
def type_membership_class(membership_class = nil)
|
44
32
|
if membership_class
|
45
33
|
@type_membership_class = membership_class
|
@@ -100,34 +88,11 @@ module GraphQL
|
|
100
88
|
end
|
101
89
|
end
|
102
90
|
|
103
|
-
prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
|
104
|
-
|
105
|
-
def to_graphql
|
106
|
-
type_defn = GraphQL::InterfaceType.new
|
107
|
-
type_defn.name = graphql_name
|
108
|
-
type_defn.description = description
|
109
|
-
type_defn.orphan_types = orphan_types
|
110
|
-
type_defn.type_membership_class = self.type_membership_class
|
111
|
-
type_defn.ast_node = ast_node
|
112
|
-
fields.each do |field_name, field_inst| # rubocop:disable Development/ContextIsPassedCop -- legacy-related
|
113
|
-
field_defn = field_inst.graphql_definition(silence_deprecation_warning: true)
|
114
|
-
type_defn.fields[field_defn.name] = field_defn # rubocop:disable Development/ContextIsPassedCop -- legacy-related
|
115
|
-
end
|
116
|
-
type_defn.metadata[:type_class] = self
|
117
|
-
if respond_to?(:resolve_type)
|
118
|
-
type_defn.resolve_type = method(:resolve_type)
|
119
|
-
end
|
120
|
-
type_defn
|
121
|
-
end
|
122
|
-
|
123
91
|
def kind
|
124
92
|
GraphQL::TypeKinds::INTERFACE
|
125
93
|
end
|
126
94
|
end
|
127
95
|
|
128
|
-
# Extend this _after_ `DefinitionMethods` is defined, so it will be used
|
129
|
-
extend GraphQL::Schema::Member::AcceptsDefinition
|
130
|
-
|
131
96
|
extend DefinitionMethods
|
132
97
|
|
133
98
|
def unwrap
|
@@ -89,9 +89,9 @@ module GraphQL
|
|
89
89
|
case late_bound_type
|
90
90
|
when GraphQL::Schema::LateBoundType
|
91
91
|
@schema.get_type(late_bound_type.name)
|
92
|
-
when GraphQL::Schema::List
|
92
|
+
when GraphQL::Schema::List
|
93
93
|
resolve_late_binding(late_bound_type.of_type).to_list_type
|
94
|
-
when GraphQL::Schema::NonNull
|
94
|
+
when GraphQL::Schema::NonNull
|
95
95
|
resolve_late_binding(late_bound_type.of_type).to_non_null_type
|
96
96
|
when Module
|
97
97
|
# It's a normal type -- no change required
|
@@ -103,12 +103,7 @@ module GraphQL
|
|
103
103
|
|
104
104
|
def load_constant(class_name)
|
105
105
|
const = @custom_namespace.const_get(class_name)
|
106
|
-
|
107
|
-
dup_type_class(const)
|
108
|
-
else
|
109
|
-
# Use `.to_graphql` to get a freshly-made version, not shared between schemas
|
110
|
-
const.deprecated_to_graphql
|
111
|
-
end
|
106
|
+
dup_type_class(const)
|
112
107
|
rescue NameError
|
113
108
|
# Dup the built-in so that the cached fields aren't shared
|
114
109
|
dup_type_class(@built_in_namespace.const_get(class_name))
|
@@ -9,6 +9,8 @@ module GraphQL
|
|
9
9
|
alias :graphql_name :name
|
10
10
|
def initialize(local_name)
|
11
11
|
@name = local_name
|
12
|
+
@to_non_null_type = nil
|
13
|
+
@to_list_type = nil
|
12
14
|
end
|
13
15
|
|
14
16
|
def unwrap
|
@@ -16,17 +18,21 @@ module GraphQL
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def to_non_null_type
|
19
|
-
@to_non_null_type ||= GraphQL::
|
21
|
+
@to_non_null_type ||= GraphQL::Schema::NonNull.new(self)
|
20
22
|
end
|
21
23
|
|
22
24
|
def to_list_type
|
23
|
-
@to_list_type ||= GraphQL::
|
25
|
+
@to_list_type ||= GraphQL::Schema::List.new(self)
|
24
26
|
end
|
25
27
|
|
26
28
|
def inspect
|
27
29
|
"#<LateBoundType @name=#{name}>"
|
28
30
|
end
|
29
31
|
|
32
|
+
def non_null?
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
30
36
|
alias :to_s :inspect
|
31
37
|
end
|
32
38
|
end
|
data/lib/graphql/schema/list.rb
CHANGED
@@ -8,12 +8,6 @@ module GraphQL
|
|
8
8
|
class List < GraphQL::Schema::Wrapper
|
9
9
|
include Schema::Member::ValidatesInput
|
10
10
|
|
11
|
-
prepend Schema::Member::CachedGraphQLDefinition::DeprecatedToGraphQL
|
12
|
-
|
13
|
-
def to_graphql
|
14
|
-
@of_type.graphql_definition(silence_deprecation_warning: true).to_list_type
|
15
|
-
end
|
16
|
-
|
17
11
|
# @return [GraphQL::TypeKinds::LIST]
|
18
12
|
def kind
|
19
13
|
GraphQL::TypeKinds::LIST
|
@@ -142,7 +142,7 @@ module GraphQL
|
|
142
142
|
Class.new(GraphQL::Schema::Scalar) do
|
143
143
|
graphql_name(type["name"])
|
144
144
|
description(type["description"])
|
145
|
-
specified_by_url(type["
|
145
|
+
specified_by_url(type["specifiedByURL"])
|
146
146
|
end
|
147
147
|
end
|
148
148
|
when "UNION"
|
@@ -202,7 +202,6 @@ module GraphQL
|
|
202
202
|
description: arg["description"],
|
203
203
|
deprecation_reason: arg["deprecationReason"],
|
204
204
|
required: false,
|
205
|
-
method_access: false,
|
206
205
|
camelize: false,
|
207
206
|
}
|
208
207
|
|
@@ -22,14 +22,10 @@ module GraphQL
|
|
22
22
|
GraphQL::NameValidator.validate!(new_name)
|
23
23
|
@graphql_name = new_name
|
24
24
|
else
|
25
|
-
|
25
|
+
@graphql_name ||= default_graphql_name
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def overridden_graphql_name
|
30
|
-
defined?(@graphql_name) ? @graphql_name : nil
|
31
|
-
end
|
32
|
-
|
33
29
|
# Just a convenience method to point out that people should use graphql_name instead
|
34
30
|
def name(new_name = nil)
|
35
31
|
return super() if new_name.nil?
|
@@ -50,7 +46,7 @@ module GraphQL
|
|
50
46
|
elsif defined?(@description)
|
51
47
|
@description
|
52
48
|
else
|
53
|
-
nil
|
49
|
+
@description = nil
|
54
50
|
end
|
55
51
|
end
|
56
52
|
|
@@ -60,8 +56,12 @@ module GraphQL
|
|
60
56
|
def inherited(child_class)
|
61
57
|
child_class.introspection(introspection)
|
62
58
|
child_class.description(description)
|
63
|
-
|
64
|
-
|
59
|
+
child_class.default_graphql_name = nil
|
60
|
+
|
61
|
+
if defined?(@graphql_name) && @graphql_name && (self.name.nil? || graphql_name != default_graphql_name)
|
62
|
+
child_class.graphql_name(graphql_name)
|
63
|
+
else
|
64
|
+
child_class.graphql_name = nil
|
65
65
|
end
|
66
66
|
super
|
67
67
|
end
|
@@ -79,7 +79,7 @@ module GraphQL
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def introspection?
|
82
|
-
introspection
|
82
|
+
!!@introspection
|
83
83
|
end
|
84
84
|
|
85
85
|
# The mutation this type was derived from, if it was derived from a mutation
|
@@ -94,11 +94,6 @@ module GraphQL
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
# @return [GraphQL::BaseType] Convert this type to a legacy-style object.
|
98
|
-
def to_graphql
|
99
|
-
raise GraphQL::RequiredImplementationMissingError
|
100
|
-
end
|
101
|
-
|
102
97
|
alias :unwrap :itself
|
103
98
|
|
104
99
|
# Creates the default name for a schema member.
|
@@ -107,8 +102,7 @@ module GraphQL
|
|
107
102
|
def default_graphql_name
|
108
103
|
@default_graphql_name ||= begin
|
109
104
|
raise GraphQL::RequiredImplementationMissingError, 'Anonymous class should declare a `graphql_name`' if name.nil?
|
110
|
-
|
111
|
-
name.split("::").last.sub(/Type\Z/, "")
|
105
|
+
-name.split("::").last.sub(/Type\Z/, "")
|
112
106
|
end
|
113
107
|
end
|
114
108
|
|
@@ -116,13 +110,17 @@ module GraphQL
|
|
116
110
|
true
|
117
111
|
end
|
118
112
|
|
119
|
-
def
|
113
|
+
def authorized?(object, context)
|
120
114
|
true
|
121
115
|
end
|
122
116
|
|
123
|
-
def
|
124
|
-
|
117
|
+
def default_relay
|
118
|
+
false
|
125
119
|
end
|
120
|
+
|
121
|
+
protected
|
122
|
+
|
123
|
+
attr_writer :default_graphql_name, :graphql_name
|
126
124
|
end
|
127
125
|
end
|
128
126
|
end
|
@@ -35,18 +35,16 @@ module GraphQL
|
|
35
35
|
else
|
36
36
|
maybe_type = constantize(type_expr)
|
37
37
|
case maybe_type
|
38
|
-
when GraphQL::BaseType
|
39
|
-
maybe_type
|
40
38
|
when Module
|
41
39
|
# This is a way to check that it's the right kind of module:
|
42
|
-
if maybe_type.respond_to?(:
|
40
|
+
if maybe_type.respond_to?(:kind)
|
43
41
|
maybe_type
|
44
42
|
else
|
45
43
|
raise ArgumentError, "Unexpected class/module found for GraphQL type: #{type_expr} (must be type definition class/module)"
|
46
44
|
end
|
47
45
|
end
|
48
46
|
end
|
49
|
-
when GraphQL::
|
47
|
+
when GraphQL::Schema::LateBoundType
|
50
48
|
type_expr
|
51
49
|
when Array
|
52
50
|
case type_expr.length
|
@@ -68,7 +66,7 @@ module GraphQL
|
|
68
66
|
type_expr
|
69
67
|
when Module
|
70
68
|
# This is a way to check that it's the right kind of module:
|
71
|
-
if type_expr.respond_to?(:
|
69
|
+
if type_expr.respond_to?(:kind)
|
72
70
|
type_expr
|
73
71
|
else
|
74
72
|
# Eg `String` => GraphQL::Types::String
|
@@ -100,7 +98,7 @@ module GraphQL
|
|
100
98
|
|
101
99
|
def to_type_name(something)
|
102
100
|
case something
|
103
|
-
when GraphQL::
|
101
|
+
when GraphQL::Schema::LateBoundType
|
104
102
|
something.unwrap.name
|
105
103
|
when Array
|
106
104
|
to_type_name(something.first)
|
@@ -122,7 +120,7 @@ module GraphQL
|
|
122
120
|
def camelize(string)
|
123
121
|
return string if string == '_'
|
124
122
|
return string unless string.include?("_")
|
125
|
-
camelized = string.split('_').
|
123
|
+
camelized = string.split('_').each(&:capitalize!).join
|
126
124
|
camelized[0] = camelized[0].downcase
|
127
125
|
if (match_data = string.match(/\A(_+)/))
|
128
126
|
camelized = "#{match_data[0]}#{camelized}"
|