module GraphQL::StaticValidation::FieldsWillMerge
Constants
- EXCLUSIVE_COMPARISON
- NONEXCLUSIVE_COMPARISON
- NO_ARGS
-
Validates that a selection set is valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.
Optimized algorithm based on: tech.new-work.se/graphql-overlapping-fields-can-be-merged-fast-ea6e92e0a01
Instead of comparing fields, fields-vs-fragments, and fragments-vs-fragments separately (which leads to exponential recursion through nested fragments), we flatten all fragment spreads into a single field map and compare within it.
Public Class Methods
Source
# File lib/graphql/static_validation/rules/fields_will_merge.rb, line 54 def initialize(*) super @conflict_count = 0 @max_errors = context.max_errors @fragments = context.fragments # Track which sub-selection node pairs have been compared to prevent # infinite recursion with cyclic fragments @compared_sub_selections = {}.compare_by_identity @compared_field_groups = {} @field_group_signatures = {}.compare_by_identity @field_selection_signatures = {}.compare_by_identity # Cache collect_fields results for sub-selection comparison @sub_fields_cache = {}.compare_by_identity @allow_legacy_invalid_field_conflicts = @schema.allow_legacy_invalid_field_conflicts # Unless legacy conflicts are rejected, use the legacy check, which is the same as previous versions. # It uses `legacy_mutually_exclusive?` and the caches above. The spec check uses `@spec_caches`. @legacy_exclusivity = @allow_legacy_invalid_field_conflicts != false @spec_caches = nil @mutually_exclusive_cache = nil # True when the spec check can find conflicts which the legacy check doesn't find @spec_check_needed = false # During the legacy check, true when the spec rule treats the parent fields as mutually exclusive @spec_inherited_exclusive = false # The pairs of nodes which have a conflict in the legacy check @legacy_conflict_nodes = nil # When this is true, record conflicts in `@spec_conflicts` instead of adding errors @find_spec_conflicts = false @spec_conflicts = nil end
Calls superclass method
Public Instance Methods
Source
# File lib/graphql/static_validation/rules/fields_will_merge.rb, line 90 def on_field(node, _parent) if !node.selections.empty? && selections_may_conflict?(node.selections) check_selection_set(node, type_definition) end super end
Calls superclass method
# File lib/graphql/static_validation/rules/fields_will_merge.rb, line 85 def on_operation_definition(node, _parent) check_selection_set(node, type_definition) super end
Calls superclass method