Class AstSorter

java.lang.Object
graphql.language.AstSorter

@PublicApi public class AstSorter extends Object
A class that helps you sort AST nodes
  • Constructor Details

    • AstSorter

      public AstSorter()
  • Method Details

    • sort

      public <T extends Node> T sort(T nodeToBeSorted)
      This will sort nodes in specific orders and then alphabetically. The order is :
      • Query operation definitions
      • Mutation operation definitions
      • Subscriptions operation definitions
      • Fragment definitions
      • Directive definitions
      • Schema definitions
      • Object Type definitions
      • Interface Type definitions
      • Union Type definitions
      • Enum Type definitions
      • Scalar Type definitions
      • Input Object Type definitions
      After those groupings they will be sorted alphabetic. All arguments and directives on elements will be sorted alphabetically by name.
      Type Parameters:
      T - of type Node
      Parameters:
      nodeToBeSorted - the node to be sorted
      Returns:
      a new sorted node (because Nodes are immutable)
    • comparingTypes

      private Comparator<Type> comparingTypes()
    • comparingSelections

      private Comparator<Selection> comparingSelections()
    • comparingDefinitions

      private Comparator<Definition> comparingDefinitions()
    • sortSelectionSet

      private SelectionSet sortSelectionSet(SelectionSet selectionSet)
    • sort

      private <T> List<T> sort(List<T> items, Comparator<T> comparing)
    • comparing

      private <T, U extends Comparable<? super U>> Comparator<T> comparing(Function<? super T,? extends U> keyExtractor)