Module: GraphQL::Stitching::TypeResolver::KeysParser

Included in:
GraphQL::Stitching::TypeResolver
Defined in:
lib/graphql/stitching/type_resolver/keys.rb

Instance Method Summary collapse

Instance Method Details

#export_key(name) ⇒ Object



117
118
119
# File 'lib/graphql/stitching/type_resolver/keys.rb', line 117

def export_key(name)
  "#{EXPORT_PREFIX}#{name}"
end

#export_key?(name) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
124
125
# File 'lib/graphql/stitching/type_resolver/keys.rb', line 121

def export_key?(name)
  return false unless name

  name.start_with?(EXPORT_PREFIX)
end

#parse_key(template, locations = GraphQL::Stitching::EMPTY_ARRAY) ⇒ Object



127
128
129
# File 'lib/graphql/stitching/type_resolver/keys.rb', line 127

def parse_key(template, locations = GraphQL::Stitching::EMPTY_ARRAY)
  Key.new(parse_field_set(template), locations: locations)
end

#parse_key_with_types(template, subgraph_types_by_location) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/graphql/stitching/type_resolver/keys.rb', line 131

def parse_key_with_types(template, subgraph_types_by_location)
  field_set = parse_field_set(template)
  locations = subgraph_types_by_location.filter_map do |location, subgraph_type|
    location if field_set_matches_type?(field_set, subgraph_type)
  end

  if locations.none?
    message = "Key `#{field_set.to_definition}` does not exist in any location."
    message += " Composite key selections may not be distributed." if field_set.length > 1
    raise CompositionError, message
  end

  assign_field_set_info!(field_set, subgraph_types_by_location[locations.first])
  Key.new(field_set, locations: locations)
end