Try type parsers in a different order

This commit is contained in:
2019-11-22 08:00:50 +01:00
parent 73e21661b4
commit 625d7100ca
5 changed files with 23 additions and 13 deletions

View File

@ -3,7 +3,7 @@
-- | This module defines a bunch of small parsers used to parse individual
-- lexemes.
module Language.GraphQL.AST.Lexer
module Language.GraphQL.AST.Lexer
( Parser
, amp
, at

View File

@ -152,9 +152,9 @@ defaultValue = equals *> value
-- * Input Types
type_ :: Parser Type
type_ = try (TypeNamed <$> name <* but "!")
<|> TypeList <$> brackets type_
<|> TypeNonNull <$> nonNullType
type_ = try (TypeNonNull <$> nonNullType)
<|> TypeList <$> brackets type_
<|> TypeNamed <$> name
<?> "type_ error!"
nonNullType :: Parser NonNullType

View File

@ -13,12 +13,10 @@ import Control.Monad (foldM, unless)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Reader (ReaderT, ask, runReaderT)
import Control.Monad.Trans.State (StateT, evalStateT, gets, modify)
import Data.Foldable (toList)
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import qualified Data.List.NonEmpty as NonEmpty
import Data.Sequence (Seq, (<|), (><))
import qualified Data.Sequence as Sequence
import qualified Language.GraphQL.AST as Full
import qualified Language.GraphQL.AST.Core as Core
import qualified Language.GraphQL.Schema as Schema
@ -99,10 +97,9 @@ collectFragments = do
fragmentDefinition ::
Full.FragmentDefinition ->
TransformT (Seq Core.Selection)
fragmentDefinition (Full.FragmentDefinition name _tc _dirs sels) = do
fragmentDefinition (Full.FragmentDefinition name _tc _dirs selections) = do
modify deleteFragmentDefinition
selections <- traverse selection sels
let newValue = either id pure =<< Sequence.fromList (toList selections)
newValue <- appendSelection selections
modify $ insertFragment newValue
liftJust newValue
where