graphql 1.2.6 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql.rb +3 -1
- data/lib/graphql/analysis.rb +1 -0
- data/lib/graphql/analysis/analyze_query.rb +1 -0
- data/lib/graphql/analysis/field_usage.rb +1 -0
- data/lib/graphql/analysis/max_query_complexity.rb +1 -0
- data/lib/graphql/analysis/max_query_depth.rb +1 -0
- data/lib/graphql/analysis/query_complexity.rb +1 -0
- data/lib/graphql/analysis/query_depth.rb +1 -0
- data/lib/graphql/analysis/reducer_state.rb +1 -0
- data/lib/graphql/analysis_error.rb +1 -0
- data/lib/graphql/argument.rb +1 -0
- data/lib/graphql/base_type.rb +16 -7
- data/lib/graphql/boolean_type.rb +1 -0
- data/lib/graphql/compatibility.rb +2 -0
- data/lib/graphql/compatibility/execution_specification.rb +113 -192
- data/lib/graphql/compatibility/execution_specification/counter_schema.rb +53 -0
- data/lib/graphql/compatibility/execution_specification/specification_schema.rb +195 -0
- data/lib/graphql/compatibility/lazy_execution_specification.rb +186 -0
- data/lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb +97 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +1 -0
- data/lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb +1 -0
- data/lib/graphql/compatibility/query_parser_specification/query_assertions.rb +1 -0
- data/lib/graphql/compatibility/schema_parser_specification.rb +1 -0
- data/lib/graphql/define.rb +1 -0
- data/lib/graphql/define/assign_argument.rb +1 -0
- data/lib/graphql/define/assign_connection.rb +1 -0
- data/lib/graphql/define/assign_enum_value.rb +1 -0
- data/lib/graphql/define/assign_global_id_field.rb +1 -0
- data/lib/graphql/define/assign_object_field.rb +1 -0
- data/lib/graphql/define/defined_object_proxy.rb +1 -0
- data/lib/graphql/define/instance_definable.rb +11 -12
- data/lib/graphql/define/non_null_with_bang.rb +1 -0
- data/lib/graphql/define/type_definer.rb +1 -0
- data/lib/graphql/directive.rb +1 -0
- data/lib/graphql/directive/deprecated_directive.rb +1 -0
- data/lib/graphql/directive/include_directive.rb +1 -0
- data/lib/graphql/directive/skip_directive.rb +1 -0
- data/lib/graphql/enum_type.rb +8 -1
- data/lib/graphql/execution.rb +5 -0
- data/lib/graphql/execution/directive_checks.rb +1 -0
- data/lib/graphql/execution/execute.rb +222 -0
- data/lib/graphql/execution/field_result.rb +52 -0
- data/lib/graphql/execution/lazy.rb +59 -0
- data/lib/graphql/execution/lazy/lazy_method_map.rb +38 -0
- data/lib/graphql/execution/lazy/resolve.rb +68 -0
- data/lib/graphql/execution/selection_result.rb +84 -0
- data/lib/graphql/execution/typecast.rb +4 -4
- data/lib/graphql/execution_error.rb +1 -0
- data/lib/graphql/field.rb +68 -18
- data/lib/graphql/field/resolve.rb +1 -0
- data/lib/graphql/float_type.rb +1 -0
- data/lib/graphql/id_type.rb +1 -0
- data/lib/graphql/input_object_type.rb +6 -0
- data/lib/graphql/int_type.rb +1 -0
- data/lib/graphql/interface_type.rb +6 -0
- data/lib/graphql/internal_representation.rb +2 -1
- data/lib/graphql/internal_representation/node.rb +2 -1
- data/lib/graphql/internal_representation/rewrite.rb +1 -0
- data/lib/graphql/internal_representation/selection.rb +85 -0
- data/lib/graphql/introspection.rb +1 -0
- data/lib/graphql/introspection/arguments_field.rb +1 -0
- data/lib/graphql/introspection/directive_location_enum.rb +1 -0
- data/lib/graphql/introspection/directive_type.rb +1 -0
- data/lib/graphql/introspection/enum_value_type.rb +1 -0
- data/lib/graphql/introspection/enum_values_field.rb +1 -0
- data/lib/graphql/introspection/field_type.rb +1 -0
- data/lib/graphql/introspection/fields_field.rb +1 -0
- data/lib/graphql/introspection/input_fields_field.rb +1 -0
- data/lib/graphql/introspection/input_value_type.rb +2 -1
- data/lib/graphql/introspection/interfaces_field.rb +1 -0
- data/lib/graphql/introspection/introspection_query.rb +1 -0
- data/lib/graphql/introspection/of_type_field.rb +1 -0
- data/lib/graphql/introspection/possible_types_field.rb +1 -0
- data/lib/graphql/introspection/schema_field.rb +1 -0
- data/lib/graphql/introspection/schema_type.rb +1 -0
- data/lib/graphql/introspection/type_by_name_field.rb +1 -0
- data/lib/graphql/introspection/type_kind_enum.rb +1 -0
- data/lib/graphql/introspection/type_type.rb +1 -0
- data/lib/graphql/introspection/typename_field.rb +1 -0
- data/lib/graphql/invalid_null_error.rb +17 -7
- data/lib/graphql/language.rb +10 -0
- data/lib/graphql/language/comments.rb +2 -1
- data/lib/graphql/language/definition_slice.rb +1 -0
- data/lib/graphql/language/generation.rb +25 -24
- data/lib/graphql/language/nodes.rb +1 -0
- data/lib/graphql/language/token.rb +1 -0
- data/lib/graphql/language/visitor.rb +1 -0
- data/lib/graphql/list_type.rb +1 -0
- data/lib/graphql/non_null_type.rb +2 -1
- data/lib/graphql/object_type.rb +12 -0
- data/lib/graphql/query.rb +40 -43
- data/lib/graphql/query/arguments.rb +1 -0
- data/lib/graphql/query/context.rb +31 -7
- data/lib/graphql/query/executor.rb +8 -1
- data/lib/graphql/query/input_validation_result.rb +1 -0
- data/lib/graphql/query/literal_input.rb +1 -0
- data/lib/graphql/query/serial_execution.rb +3 -4
- data/lib/graphql/query/serial_execution/field_resolution.rb +15 -10
- data/lib/graphql/query/serial_execution/operation_resolution.rb +3 -5
- data/lib/graphql/query/serial_execution/selection_resolution.rb +4 -5
- data/lib/graphql/query/serial_execution/value_resolution.rb +26 -11
- data/lib/graphql/query/variable_validation_error.rb +1 -0
- data/lib/graphql/query/variables.rb +1 -0
- data/lib/graphql/relay.rb +1 -0
- data/lib/graphql/relay/array_connection.rb +3 -2
- data/lib/graphql/relay/base_connection.rb +20 -8
- data/lib/graphql/relay/connection_field.rb +1 -0
- data/lib/graphql/relay/connection_resolve.rb +14 -1
- data/lib/graphql/relay/connection_type.rb +1 -0
- data/lib/graphql/relay/edge.rb +1 -0
- data/lib/graphql/relay/edge_type.rb +1 -0
- data/lib/graphql/relay/global_id_resolve.rb +1 -0
- data/lib/graphql/relay/mutation.rb +13 -0
- data/lib/graphql/relay/node.rb +1 -0
- data/lib/graphql/relay/page_info.rb +1 -0
- data/lib/graphql/relay/relation_connection.rb +3 -2
- data/lib/graphql/runtime_type_error.rb +4 -0
- data/lib/graphql/scalar_type.rb +2 -1
- data/lib/graphql/schema.rb +116 -26
- data/lib/graphql/schema/base_64_encoder.rb +14 -0
- data/lib/graphql/schema/build_from_definition.rb +4 -0
- data/lib/graphql/schema/catchall_middleware.rb +1 -0
- data/lib/graphql/schema/default_type_error.rb +15 -0
- data/lib/graphql/schema/instrumented_field_map.rb +1 -0
- data/lib/graphql/schema/invalid_type_error.rb +1 -0
- data/lib/graphql/schema/loader.rb +5 -1
- data/lib/graphql/schema/middleware_chain.rb +1 -0
- data/lib/graphql/schema/possible_types.rb +1 -0
- data/lib/graphql/schema/printer.rb +3 -2
- data/lib/graphql/schema/reduce_types.rb +1 -0
- data/lib/graphql/schema/rescue_middleware.rb +3 -2
- data/lib/graphql/schema/timeout_middleware.rb +1 -0
- data/lib/graphql/schema/type_expression.rb +1 -0
- data/lib/graphql/schema/type_map.rb +1 -0
- data/lib/graphql/schema/unique_within_type.rb +1 -0
- data/lib/graphql/schema/validation.rb +57 -1
- data/lib/graphql/schema/warden.rb +1 -0
- data/lib/graphql/static_validation.rb +1 -0
- data/lib/graphql/static_validation/all_rules.rb +1 -0
- data/lib/graphql/static_validation/arguments_validator.rb +1 -0
- data/lib/graphql/static_validation/literal_validator.rb +1 -0
- data/lib/graphql/static_validation/message.rb +1 -0
- data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -0
- data/lib/graphql/static_validation/rules/arguments_are_defined.rb +1 -0
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -0
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +1 -0
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -0
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -0
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +6 -3
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +1 -0
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_named.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -0
- data/lib/graphql/static_validation/rules/fragments_are_used.rb +1 -0
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -0
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +1 -0
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -0
- data/lib/graphql/static_validation/rules/unique_directives_per_location.rb +1 -0
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -0
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +1 -0
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -0
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +1 -0
- data/lib/graphql/static_validation/type_stack.rb +1 -0
- data/lib/graphql/static_validation/validation_context.rb +2 -1
- data/lib/graphql/static_validation/validator.rb +2 -1
- data/lib/graphql/string_type.rb +1 -0
- data/lib/graphql/type_kinds.rb +1 -0
- data/lib/graphql/union_type.rb +13 -0
- data/lib/graphql/unresolved_type_error.rb +26 -5
- data/lib/graphql/version.rb +2 -1
- data/readme.md +1 -5
- data/spec/graphql/analysis/analyze_query_spec.rb +1 -0
- data/spec/graphql/analysis/field_usage_spec.rb +1 -0
- data/spec/graphql/analysis/max_query_complexity_spec.rb +1 -0
- data/spec/graphql/analysis/max_query_depth_spec.rb +1 -0
- data/spec/graphql/analysis/query_complexity_spec.rb +1 -0
- data/spec/graphql/analysis/query_depth_spec.rb +1 -0
- data/spec/graphql/argument_spec.rb +1 -0
- data/spec/graphql/base_type_spec.rb +13 -0
- data/spec/graphql/boolean_type_spec.rb +1 -0
- data/spec/graphql/compatibility/execution_specification_spec.rb +1 -0
- data/spec/graphql/compatibility/lazy_execution_specification_spec.rb +4 -0
- data/spec/graphql/compatibility/query_parser_specification_spec.rb +1 -0
- data/spec/graphql/compatibility/schema_parser_specification_spec.rb +1 -0
- data/spec/graphql/define/assign_argument_spec.rb +1 -0
- data/spec/graphql/define/instance_definable_spec.rb +1 -0
- data/spec/graphql/directive_spec.rb +1 -0
- data/spec/graphql/enum_type_spec.rb +10 -0
- data/spec/graphql/execution/execute_spec.rb +5 -0
- data/spec/graphql/execution/lazy_spec.rb +252 -0
- data/spec/graphql/execution/typecast_spec.rb +1 -0
- data/spec/graphql/execution_error_spec.rb +1 -0
- data/spec/graphql/field_spec.rb +17 -0
- data/spec/graphql/float_type_spec.rb +1 -0
- data/spec/graphql/id_type_spec.rb +1 -0
- data/spec/graphql/input_object_type_spec.rb +10 -0
- data/spec/graphql/int_type_spec.rb +1 -0
- data/spec/graphql/interface_type_spec.rb +10 -0
- data/spec/graphql/internal_representation/rewrite_spec.rb +1 -0
- data/spec/graphql/introspection/directive_type_spec.rb +1 -0
- data/spec/graphql/introspection/input_value_type_spec.rb +1 -0
- data/spec/graphql/introspection/introspection_query_spec.rb +1 -0
- data/spec/graphql/introspection/schema_type_spec.rb +1 -0
- data/spec/graphql/introspection/type_type_spec.rb +1 -0
- data/spec/graphql/language/definition_slice_spec.rb +1 -0
- data/spec/graphql/language/equality_spec.rb +1 -0
- data/spec/graphql/language/generation_spec.rb +1 -0
- data/spec/graphql/language/lexer_spec.rb +1 -0
- data/spec/graphql/language/nodes_spec.rb +1 -0
- data/spec/graphql/language/parser_spec.rb +1 -0
- data/spec/graphql/language/visitor_spec.rb +1 -0
- data/spec/graphql/list_type_spec.rb +1 -0
- data/spec/graphql/non_null_type_spec.rb +17 -0
- data/spec/graphql/object_type_spec.rb +19 -0
- data/spec/graphql/query/arguments_spec.rb +1 -0
- data/spec/graphql/query/context_spec.rb +1 -0
- data/spec/graphql/query/executor_spec.rb +1 -0
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +1 -0
- data/spec/graphql/query/variables_spec.rb +1 -0
- data/spec/graphql/query_spec.rb +25 -0
- data/spec/graphql/relay/array_connection_spec.rb +1 -0
- data/spec/graphql/relay/base_connection_spec.rb +33 -4
- data/spec/graphql/relay/connection_field_spec.rb +1 -0
- data/spec/graphql/relay/connection_type_spec.rb +1 -0
- data/spec/graphql/relay/mutation_spec.rb +6 -0
- data/spec/graphql/relay/node_spec.rb +1 -0
- data/spec/graphql/relay/page_info_spec.rb +1 -0
- data/spec/graphql/relay/relation_connection_spec.rb +1 -0
- data/spec/graphql/scalar_type_spec.rb +1 -0
- data/spec/graphql/schema/build_from_definition_spec.rb +9 -1
- data/spec/graphql/schema/catchall_middleware_spec.rb +1 -0
- data/spec/graphql/schema/loader_spec.rb +7 -0
- data/spec/graphql/schema/middleware_chain_spec.rb +1 -0
- data/spec/graphql/schema/printer_spec.rb +1 -0
- data/spec/graphql/schema/reduce_types_spec.rb +1 -0
- data/spec/graphql/schema/rescue_middleware_spec.rb +1 -0
- data/spec/graphql/schema/timeout_middleware_spec.rb +1 -0
- data/spec/graphql/schema/type_expression_spec.rb +1 -0
- data/spec/graphql/schema/unique_within_type_spec.rb +1 -0
- data/spec/graphql/schema/validation_spec.rb +55 -0
- data/spec/graphql/schema/warden_spec.rb +1 -0
- data/spec/graphql/schema_spec.rb +39 -0
- data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +515 -31
- data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fragments_are_named_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/mutation_root_exists_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/subscription_root_exists_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/unique_directives_per_location_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +1 -0
- data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +1 -0
- data/spec/graphql/static_validation/type_stack_spec.rb +1 -0
- data/spec/graphql/static_validation/validator_spec.rb +1 -0
- data/spec/graphql/string_type_spec.rb +1 -0
- data/spec/graphql/union_type_spec.rb +11 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/dairy_app.rb +1 -0
- data/spec/support/dairy_data.rb +1 -0
- data/spec/support/minimum_input_object.rb +1 -0
- data/spec/support/star_wars_data.rb +1 -0
- data/spec/support/star_wars_schema.rb +30 -7
- data/spec/support/static_validation_helpers.rb +1 -0
- metadata +24 -5
- data/lib/graphql/internal_representation/selections.rb +0 -41
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
# An Interface contains a collection of types which implement some of the same fields.
|
3
4
|
#
|
@@ -31,6 +32,11 @@ module GraphQL
|
|
31
32
|
@fields = {}
|
32
33
|
end
|
33
34
|
|
35
|
+
def initialize_copy(other)
|
36
|
+
super
|
37
|
+
@fields = other.fields.dup
|
38
|
+
end
|
39
|
+
|
34
40
|
def kind
|
35
41
|
GraphQL::TypeKinds::INTERFACE
|
36
42
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "set"
|
2
3
|
|
3
4
|
module GraphQL
|
@@ -114,7 +115,7 @@ module GraphQL
|
|
114
115
|
|
115
116
|
def inspect(indent = 0)
|
116
117
|
own_indent = " " * indent
|
117
|
-
self_inspect = "#{own_indent}<Node #{name} #{skipped? ? "(skipped)" : ""}(#{definition_name} -> #{return_type})>"
|
118
|
+
self_inspect = "#{own_indent}<Node #{name} #{skipped? ? "(skipped)" : ""}(#{definition_name} -> #{return_type})>".dup
|
118
119
|
if typed_children.any?
|
119
120
|
self_inspect << " {"
|
120
121
|
typed_children.each do |type_defn, children|
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module GraphQL
|
3
|
+
module InternalRepresentation
|
4
|
+
# A selection is a single field on an object.
|
5
|
+
# It's "backed" by one or more {Node}s.
|
6
|
+
class Selection
|
7
|
+
def initialize(query:, nodes:)
|
8
|
+
@irep_node = nodes.first
|
9
|
+
@definition_name = @irep_node.definition_name
|
10
|
+
@name = @irep_node.name
|
11
|
+
|
12
|
+
@skipped = nodes.any?(&:skipped?)
|
13
|
+
@query = query
|
14
|
+
@typed_child_nodes = build_typed_selections(query, nodes)
|
15
|
+
@typed_subselections = Hash.new { |h, k| h[k] = {} }
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [String] name of the field in this selection
|
19
|
+
attr_reader :definition_name
|
20
|
+
|
21
|
+
# @return [String] the key of this selection in the result (may be the field's alias)
|
22
|
+
attr_reader :name
|
23
|
+
|
24
|
+
# @return [Node] A "representative" node for this selection. Legacy. In the case that a selection appears in multiple nodes, is this valuable?
|
25
|
+
attr_reader :irep_node
|
26
|
+
|
27
|
+
# @return [Boolean] true if _any_ of the backing nodes are skipped
|
28
|
+
def skipped?
|
29
|
+
@skipped
|
30
|
+
end
|
31
|
+
|
32
|
+
# Call the block with each name & subselection whose conditions match `type`
|
33
|
+
# @param type [GraphQL::BaseType] The type to get selections on
|
34
|
+
# @yieldparam name [String] the key in the child selection
|
35
|
+
# @yieldparam subselection [Selection] the selection for that key
|
36
|
+
def each_selection(type:)
|
37
|
+
subselections = @typed_subselections[type]
|
38
|
+
@typed_child_nodes[type].each do |name, child_nodes|
|
39
|
+
subselection = subselections[name] ||= self.class.new(query: @query, nodes: child_nodes)
|
40
|
+
if !subselection.skipped?
|
41
|
+
yield(name, subselection)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Turn `nodes` into a two-dimensional hash, based on type information from `query`
|
49
|
+
# @return [Hash] A 2d mapping of `{ type => { name => nodes } }`
|
50
|
+
def build_typed_selections(query, nodes)
|
51
|
+
selections = Hash.new { |h,k| h[k] = Hash.new { |h2, k2| h2[k2] = [] } }
|
52
|
+
|
53
|
+
object_types = Set.new
|
54
|
+
|
55
|
+
warden = query.warden
|
56
|
+
ctx = query.context
|
57
|
+
|
58
|
+
# Find the object types which are possible among typed children
|
59
|
+
nodes.each do |node|
|
60
|
+
node.typed_children.each_key do |type_cond|
|
61
|
+
object_types.merge(warden.possible_types(type_cond))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# For each object types, find the irep_nodes
|
66
|
+
# which may apply to it, then add the children
|
67
|
+
# of that node to this object's children
|
68
|
+
nodes.each do |node|
|
69
|
+
node.typed_children.each do |type_cond, children|
|
70
|
+
object_types.each do |obj_type|
|
71
|
+
obj_selections = selections[obj_type]
|
72
|
+
if GraphQL::Execution::Typecast.compatible?(obj_type, type_cond, ctx)
|
73
|
+
children.each do |name, irep_node|
|
74
|
+
obj_selections[name] << irep_node
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
selections
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
GraphQL::Introspection::InputValueType = GraphQL::ObjectType.define do
|
2
3
|
name "__InputValue"
|
3
4
|
description "Arguments provided to Fields or Directives and the input fields of an "\
|
@@ -10,7 +11,7 @@ GraphQL::Introspection::InputValueType = GraphQL::ObjectType.define do
|
|
10
11
|
resolve ->(obj, args, ctx) {
|
11
12
|
if obj.default_value?
|
12
13
|
value = obj.default_value
|
13
|
-
value.nil? ? 'null' :
|
14
|
+
value.nil? ? 'null' : GraphQL::Language.serialize(obj.type.coerce_result(value))
|
14
15
|
else
|
15
16
|
nil
|
16
17
|
end
|
@@ -1,12 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
# Raised automatically when a field's resolve function returns `nil`
|
3
4
|
# for a non-null field.
|
4
|
-
class InvalidNullError < GraphQL::
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class InvalidNullError < GraphQL::RuntimeTypeError
|
6
|
+
# @return [GraphQL::BaseType] The owner of {#field}
|
7
|
+
attr_reader :parent_type
|
8
|
+
|
9
|
+
# @return [GraphQL::Field] The field which failed to return a value
|
10
|
+
attr_reader :field
|
11
|
+
|
12
|
+
# @return [nil, GraphQL::ExecutionError] The invalid value for this field
|
13
|
+
attr_reader :value
|
14
|
+
|
15
|
+
def initialize(parent_type, field, value)
|
16
|
+
@parent_type = parent_type
|
17
|
+
@field = field
|
8
18
|
@value = value
|
9
|
-
super("Cannot return null for non-nullable field #{@
|
19
|
+
super("Cannot return null for non-nullable field #{@parent_type.name}.#{@field.name}")
|
10
20
|
end
|
11
21
|
|
12
22
|
# @return [Hash] An entry for the response's "errors" key
|
@@ -14,9 +24,9 @@ module GraphQL
|
|
14
24
|
{ "message" => message }
|
15
25
|
end
|
16
26
|
|
17
|
-
# @
|
27
|
+
# @deprecated always false
|
18
28
|
def parent_error?
|
19
|
-
|
29
|
+
false
|
20
30
|
end
|
21
31
|
end
|
22
32
|
end
|
data/lib/graphql/language.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "graphql/language/definition_slice"
|
2
3
|
require "graphql/language/generation"
|
3
4
|
require "graphql/language/lexer"
|
@@ -6,3 +7,12 @@ require "graphql/language/parser"
|
|
6
7
|
require "graphql/language/token"
|
7
8
|
require "graphql/language/visitor"
|
8
9
|
require "graphql/language/comments"
|
10
|
+
|
11
|
+
module GraphQL
|
12
|
+
module Language
|
13
|
+
# @api private
|
14
|
+
def self.serialize(value)
|
15
|
+
JSON.generate(value, quirks_mode: true)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
module Language
|
3
4
|
module Comments
|
@@ -6,7 +7,7 @@ module GraphQL
|
|
6
7
|
def commentize(description, indent: '')
|
7
8
|
lines = description.split("\n")
|
8
9
|
|
9
|
-
comment = ''
|
10
|
+
comment = ''.dup
|
10
11
|
|
11
12
|
lines.each do |line|
|
12
13
|
if line == ''
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module GraphQL
|
2
3
|
module Language
|
3
4
|
# Exposes {.generate}, which turns AST nodes back into query strings.
|
@@ -19,17 +20,17 @@ module GraphQL
|
|
19
20
|
when Nodes::Document
|
20
21
|
node.definitions.map { |d| generate(d) }.join("\n\n")
|
21
22
|
when Nodes::Argument
|
22
|
-
"#{node.name}: #{generate(node.value)}"
|
23
|
+
"#{node.name}: #{generate(node.value)}".dup
|
23
24
|
when Nodes::Directive
|
24
|
-
out = "@#{node.name}"
|
25
|
+
out = "@#{node.name}".dup
|
25
26
|
out << "(#{node.arguments.map { |a| generate(a) }.join(", ")})" if node.arguments.any?
|
26
27
|
out
|
27
28
|
when Nodes::Enum
|
28
|
-
"#{node.name}"
|
29
|
+
"#{node.name}".dup
|
29
30
|
when Nodes::NullValue
|
30
|
-
"null"
|
31
|
+
"null".dup
|
31
32
|
when Nodes::Field
|
32
|
-
out = "#{indent}"
|
33
|
+
out = "#{indent}".dup
|
33
34
|
out << "#{node.alias}: " if node.alias
|
34
35
|
out << "#{node.name}"
|
35
36
|
out << "(#{node.arguments.map { |a| generate(a) }.join(", ")})" if node.arguments.any?
|
@@ -37,7 +38,7 @@ module GraphQL
|
|
37
38
|
out << generate_selections(node.selections, indent: indent)
|
38
39
|
out
|
39
40
|
when Nodes::FragmentDefinition
|
40
|
-
out = "#{indent}fragment #{node.name}"
|
41
|
+
out = "#{indent}fragment #{node.name}".dup
|
41
42
|
if node.type
|
42
43
|
out << " on #{generate(node.type)}"
|
43
44
|
end
|
@@ -45,11 +46,11 @@ module GraphQL
|
|
45
46
|
out << generate_selections(node.selections, indent: indent)
|
46
47
|
out
|
47
48
|
when Nodes::FragmentSpread
|
48
|
-
out = "#{indent}...#{node.name}"
|
49
|
+
out = "#{indent}...#{node.name}".dup
|
49
50
|
out << generate_directives(node.directives)
|
50
51
|
out
|
51
52
|
when Nodes::InlineFragment
|
52
|
-
out = "#{indent}..."
|
53
|
+
out = "#{indent}...".dup
|
53
54
|
if node.type
|
54
55
|
out << " on #{generate(node.type)}"
|
55
56
|
end
|
@@ -59,24 +60,24 @@ module GraphQL
|
|
59
60
|
when Nodes::InputObject
|
60
61
|
generate(node.to_h)
|
61
62
|
when Nodes::ListType
|
62
|
-
"[#{generate(node.of_type)}]"
|
63
|
+
"[#{generate(node.of_type)}]".dup
|
63
64
|
when Nodes::NonNullType
|
64
|
-
"#{generate(node.of_type)}!"
|
65
|
+
"#{generate(node.of_type)}!".dup
|
65
66
|
when Nodes::OperationDefinition
|
66
|
-
out = "#{indent}#{node.operation_type}"
|
67
|
+
out = "#{indent}#{node.operation_type}".dup
|
67
68
|
out << " #{node.name}" if node.name
|
68
69
|
out << "(#{node.variables.map { |v| generate(v) }.join(", ")})" if node.variables.any?
|
69
70
|
out << generate_directives(node.directives)
|
70
71
|
out << generate_selections(node.selections, indent: indent)
|
71
72
|
out
|
72
73
|
when Nodes::TypeName
|
73
|
-
"#{node.name}"
|
74
|
+
"#{node.name}".dup
|
74
75
|
when Nodes::VariableDefinition
|
75
|
-
out = "$#{node.name}: #{generate(node.type)}"
|
76
|
+
out = "$#{node.name}: #{generate(node.type)}".dup
|
76
77
|
out << " = #{generate(node.default_value)}" unless node.default_value.nil?
|
77
78
|
out
|
78
79
|
when Nodes::VariableIdentifier
|
79
|
-
"$#{node.name}"
|
80
|
+
"$#{node.name}".dup
|
80
81
|
when Nodes::SchemaDefinition
|
81
82
|
if (node.query.nil? || node.query == 'Query') &&
|
82
83
|
(node.mutation.nil? || node.mutation == 'Mutation') &&
|
@@ -84,7 +85,7 @@ module GraphQL
|
|
84
85
|
return
|
85
86
|
end
|
86
87
|
|
87
|
-
out = "schema {\n"
|
88
|
+
out = "schema {\n".dup
|
88
89
|
out << " query: #{node.query}\n" if node.query
|
89
90
|
out << " mutation: #{node.mutation}\n" if node.mutation
|
90
91
|
out << " subscription: #{node.subscription}\n" if node.subscription
|
@@ -100,7 +101,7 @@ module GraphQL
|
|
100
101
|
out << " implements " << node.interfaces.map(&:name).join(", ") unless node.interfaces.empty?
|
101
102
|
out << generate_field_definitions(node.fields)
|
102
103
|
when Nodes::InputValueDefinition
|
103
|
-
out = "#{node.name}: #{generate(node.type)}"
|
104
|
+
out = "#{node.name}: #{generate(node.type)}".dup
|
104
105
|
out << " = #{generate(node.default_value)}" unless node.default_value.nil?
|
105
106
|
out << generate_directives(node.directives)
|
106
107
|
when Nodes::FieldDefinition
|
@@ -129,7 +130,7 @@ module GraphQL
|
|
129
130
|
end
|
130
131
|
out << "}"
|
131
132
|
when Nodes::EnumValueDefinition
|
132
|
-
out = " #{node.name}"
|
133
|
+
out = " #{node.name}".dup
|
133
134
|
out << generate_directives(node.directives)
|
134
135
|
out << "\n"
|
135
136
|
when Nodes::InputObjectTypeDefinition
|
@@ -150,11 +151,11 @@ module GraphQL
|
|
150
151
|
when Nodes::AbstractNode
|
151
152
|
node.to_query_string(indent: indent)
|
152
153
|
when FalseClass, Float, Integer, NilClass, String, TrueClass
|
153
|
-
|
154
|
+
GraphQL::Language.serialize(node)
|
154
155
|
when Array
|
155
|
-
"[#{node.map { |v| generate(v) }.join(", ")}]"
|
156
|
+
"[#{node.map { |v| generate(v) }.join(", ")}]".dup
|
156
157
|
when Hash
|
157
|
-
"{#{node.map { |k, v| "#{k}: #{generate(v)}" }.join(", ")}}"
|
158
|
+
"{#{node.map { |k, v| "#{k}: #{generate(v)}" }.join(", ")}}".dup
|
158
159
|
else
|
159
160
|
raise TypeError
|
160
161
|
end
|
@@ -172,7 +173,7 @@ module GraphQL
|
|
172
173
|
|
173
174
|
def generate_selections(selections, indent: "")
|
174
175
|
if selections.any?
|
175
|
-
out = " {\n"
|
176
|
+
out = " {\n".dup
|
176
177
|
selections.each do |selection|
|
177
178
|
out << generate(selection, indent: indent + " ") << "\n"
|
178
179
|
end
|
@@ -183,14 +184,14 @@ module GraphQL
|
|
183
184
|
end
|
184
185
|
|
185
186
|
def generate_description(node, indent: '', first_in_block: true)
|
186
|
-
return '' unless node.description
|
187
|
+
return ''.dup unless node.description
|
187
188
|
|
188
|
-
description = indent != '' && !first_in_block ? "\n" : ""
|
189
|
+
description = indent != '' && !first_in_block ? "\n".dup : "".dup
|
189
190
|
description << GraphQL::Language::Comments.commentize(node.description, indent: indent)
|
190
191
|
end
|
191
192
|
|
192
193
|
def generate_field_definitions(fields)
|
193
|
-
out = " {\n"
|
194
|
+
out = " {\n".dup
|
194
195
|
fields.each.with_index do |field, i|
|
195
196
|
out << generate_description(field, indent: ' ', first_in_block: i == 0)
|
196
197
|
out << " #{generate(field)}\n"
|