Class: Graphlyte::Editors::Canonicalize

Inherits:
Object
  • Object
show all
Defined in:
lib/graphlyte/editors/canonicalize.rb

Overview

Reduce the query to a canonical form.

Instance Method Summary collapse

Instance Method Details

#edit(doc) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/graphlyte/editors/canonicalize.rb', line 11

def edit(doc)
  doc = doc.dup
  InlineFragments.new.edit(doc)
  doc.definitions = doc.definitions.sort_by(&:name)
  # TODO: we should also perform the selection Merge operation here.
  order_argments.edit(doc)
end

#order_argmentsObject



19
20
21
22
23
# File 'lib/graphlyte/editors/canonicalize.rb', line 19

def order_argments
  Editor.new
        .on_field { |field| field.arguments = field.arguments&.sort_by(&:name) }
        .on_directive { |dir| dir.arguments = dir.arguments&.sort_by(&:name) }
end