module Data.Morpheus.Parsing.Internal.Pattern
( inputValueDefinition
, fieldsDefinition
, typDeclaration
, optionalDirectives
) where
import Text.Megaparsec (label, many)
import Data.Morpheus.Parsing.Internal.Create (createField)
import Data.Morpheus.Parsing.Internal.Internal (Parser)
import Data.Morpheus.Parsing.Internal.Terms (keyword, optDescription, litAssignment, operator, parseAssignment,
parseMaybeTuple, parseName, parseType, setOf)
import Data.Morpheus.Parsing.Internal.Value (parseDefaultValue, parseValue)
import Data.Morpheus.Types.Internal.Data (DataField, Key, Name)
inputValueDefinition :: Parser (Key, DataField)
inputValueDefinition = label "InputValueDefinition" $ do
_description <- optDescription
name <- parseName
litAssignment
type_ <- parseType
_ <- parseDefaultValue
_ <- optionalDirectives
pure (name, createField [] name type_)
argumentsDefinition :: Parser [(Key, DataField)]
argumentsDefinition = label "ArgumentsDefinition" $ parseMaybeTuple inputValueDefinition
fieldsDefinition :: Parser [(Key, DataField)]
fieldsDefinition = label "FieldsDefinition" $ setOf fieldDefinition
fieldDefinition :: Parser (Key, DataField)
fieldDefinition = label "FieldDefinition" $ do
_description <- optDescription
name <- parseName
args <- argumentsDefinition
litAssignment
type_ <- parseType
_ <- optionalDirectives
pure (name, createField args name type_)
optionalDirectives :: Parser [()]
optionalDirectives = label "Directives" $ many directive
directive :: Parser ()
directive = label "Directive" $ do
operator '@'
_name <- parseName
_args <- parseMaybeTuple (parseAssignment parseName parseValue)
pure ()
typDeclaration :: Name -> Parser Name
typDeclaration kind = do
keyword kind
parseName