{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleInstances #-}
module Data.Morpheus.Types.SelectionTree where
import Data.Morpheus.Internal.Utils (elems, keyOf)
import Data.Morpheus.Types.Internal.AST.Base (FieldName, VALID)
import Data.Morpheus.Types.Internal.AST.Selection
( Selection (..),
Selection (selectionContent),
SelectionContent (SelectionField, SelectionSet),
)
class SelectionTree nodeType where
isLeaf :: nodeType -> Bool
getChildrenList :: nodeType -> [nodeType]
getName :: nodeType -> FieldName
instance SelectionTree (Selection VALID) where
isLeaf node = case selectionContent node of
SelectionField -> True
_ -> False
getChildrenList node = case selectionContent node of
SelectionField -> mempty
(SelectionSet deeperSel) -> elems deeperSel
getName = keyOf