{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE ViewPatterns #-}
module Language.GraphQL.Type.In
( Argument(..)
, Arguments
, InputField(..)
, InputObjectType(..)
, Type(..)
, isNonNullType
, pattern EnumBaseType
, pattern ListBaseType
, pattern InputObjectBaseType
, pattern ScalarBaseType
) where
import Data.HashMap.Strict (HashMap)
import Data.Text (Text)
import qualified Data.Text as Text
import Language.GraphQL.AST.Document (Name)
import qualified Language.GraphQL.Type.Definition as Definition
data InputField = InputField (Maybe Text) Type (Maybe Definition.Value)
data InputObjectType = InputObjectType
Name (Maybe Text) (HashMap Name InputField)
instance Eq InputObjectType where
(InputObjectType Name
this Maybe Name
_ HashMap Name InputField
_) == :: InputObjectType -> InputObjectType -> Bool
== (InputObjectType Name
that Maybe Name
_ HashMap Name InputField
_) = Name
this Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
that
instance Show InputObjectType where
show :: InputObjectType -> String
show (InputObjectType Name
typeName Maybe Name
_ HashMap Name InputField
_) = Name -> String
Text.unpack Name
typeName
data Type
= NamedScalarType Definition.ScalarType
| NamedEnumType Definition.EnumType
| NamedInputObjectType InputObjectType
| ListType Type
| NonNullScalarType Definition.ScalarType
| NonNullEnumType Definition.EnumType
| NonNullInputObjectType InputObjectType
| NonNullListType Type
deriving Type -> Type -> Bool
(Type -> Type -> Bool) -> (Type -> Type -> Bool) -> Eq Type
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Type -> Type -> Bool
$c/= :: Type -> Type -> Bool
== :: Type -> Type -> Bool
$c== :: Type -> Type -> Bool
Eq
instance Show Type where
show :: Type -> String
show (NamedScalarType ScalarType
scalarType) = ScalarType -> String
forall a. Show a => a -> String
show ScalarType
scalarType
show (NamedEnumType EnumType
enumType) = EnumType -> String
forall a. Show a => a -> String
show EnumType
enumType
show (NamedInputObjectType InputObjectType
inputObjectType) = InputObjectType -> String
forall a. Show a => a -> String
show InputObjectType
inputObjectType
show (ListType Type
baseType) = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
"[", Type -> String
forall a. Show a => a -> String
show Type
baseType, String
"]"]
show (NonNullScalarType ScalarType
scalarType) = Char
'!' Char -> ShowS
forall a. a -> [a] -> [a]
: ScalarType -> String
forall a. Show a => a -> String
show ScalarType
scalarType
show (NonNullEnumType EnumType
enumType) = Char
'!' Char -> ShowS
forall a. a -> [a] -> [a]
: EnumType -> String
forall a. Show a => a -> String
show EnumType
enumType
show (NonNullInputObjectType InputObjectType
inputObjectType) = Char
'!' Char -> ShowS
forall a. a -> [a] -> [a]
: InputObjectType -> String
forall a. Show a => a -> String
show InputObjectType
inputObjectType
show (NonNullListType Type
baseType) = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
"![", Type -> String
forall a. Show a => a -> String
show Type
baseType, String
"]"]
data Argument = Argument (Maybe Text) Type (Maybe Definition.Value)
type Arguments = HashMap Name Argument
pattern ScalarBaseType :: Definition.ScalarType -> Type
pattern $mScalarBaseType :: forall r. Type -> (ScalarType -> r) -> (Void# -> r) -> r
ScalarBaseType scalarType <- (isScalarType -> Just scalarType)
pattern EnumBaseType :: Definition.EnumType -> Type
pattern enumType <- (isEnumType -> Just enumType)
pattern InputObjectBaseType :: InputObjectType -> Type
pattern $mInputObjectBaseType :: forall r. Type -> (InputObjectType -> r) -> (Void# -> r) -> r
InputObjectBaseType objectType <- (isInputObjectType -> Just objectType)
pattern ListBaseType :: Type -> Type
pattern $mListBaseType :: forall r. Type -> (Type -> r) -> (Void# -> r) -> r
ListBaseType listType <- (isListType -> Just listType)
{-# COMPLETE EnumBaseType, ListBaseType, InputObjectBaseType, ScalarBaseType #-}
isScalarType :: Type -> Maybe Definition.ScalarType
isScalarType :: Type -> Maybe ScalarType
isScalarType (NamedScalarType ScalarType
inputType) = ScalarType -> Maybe ScalarType
forall a. a -> Maybe a
Just ScalarType
inputType
isScalarType (NonNullScalarType ScalarType
inputType) = ScalarType -> Maybe ScalarType
forall a. a -> Maybe a
Just ScalarType
inputType
isScalarType Type
_ = Maybe ScalarType
forall a. Maybe a
Nothing
isInputObjectType :: Type -> Maybe InputObjectType
isInputObjectType :: Type -> Maybe InputObjectType
isInputObjectType (NamedInputObjectType InputObjectType
inputType) = InputObjectType -> Maybe InputObjectType
forall a. a -> Maybe a
Just InputObjectType
inputType
isInputObjectType (NonNullInputObjectType InputObjectType
inputType) = InputObjectType -> Maybe InputObjectType
forall a. a -> Maybe a
Just InputObjectType
inputType
isInputObjectType Type
_ = Maybe InputObjectType
forall a. Maybe a
Nothing
isEnumType :: Type -> Maybe Definition.EnumType
isEnumType :: Type -> Maybe EnumType
isEnumType (NamedEnumType EnumType
inputType) = EnumType -> Maybe EnumType
forall a. a -> Maybe a
Just EnumType
inputType
isEnumType (NonNullEnumType EnumType
inputType) = EnumType -> Maybe EnumType
forall a. a -> Maybe a
Just EnumType
inputType
isEnumType Type
_ = Maybe EnumType
forall a. Maybe a
Nothing
isListType :: Type -> Maybe Type
isListType :: Type -> Maybe Type
isListType (ListType Type
inputType) = Type -> Maybe Type
forall a. a -> Maybe a
Just Type
inputType
isListType (NonNullListType Type
inputType) = Type -> Maybe Type
forall a. a -> Maybe a
Just Type
inputType
isListType Type
_ = Maybe Type
forall a. Maybe a
Nothing
isNonNullType :: Type -> Bool
isNonNullType :: Type -> Bool
isNonNullType (NonNullScalarType ScalarType
_) = Bool
True
isNonNullType (NonNullEnumType EnumType
_) = Bool
True
isNonNullType (NonNullInputObjectType InputObjectType
_) = Bool
True
isNonNullType (NonNullListType Type
_) = Bool
True
isNonNullType Type
_ = Bool
False