2015-09-12 15:16:28 +02:00
|
|
|
module Data.GraphQL.AST where
|
2015-09-12 12:54:05 +02:00
|
|
|
|
|
|
|
import Data.Text (Text)
|
|
|
|
|
|
|
|
-- * Name
|
|
|
|
|
|
|
|
type Name = Text
|
|
|
|
|
|
|
|
-- * Document
|
|
|
|
|
|
|
|
newtype Document = Document [Definition] deriving (Eq,Show)
|
|
|
|
|
|
|
|
data Definition = DefinitionOperation OperationDefinition
|
|
|
|
| DefinitionFragment FragmentDefinition
|
|
|
|
| DefinitionType TypeDefinition
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
data OperationDefinition =
|
2015-09-13 13:49:11 +02:00
|
|
|
Query Name [VariableDefinition] [Directive] SelectionSet
|
|
|
|
| Mutation Name [VariableDefinition] [Directive] SelectionSet
|
|
|
|
-- Not official yet
|
|
|
|
-- -- | Subscription Name [VariableDefinition] [Directive] SelectionSet
|
2015-09-12 12:54:05 +02:00
|
|
|
deriving (Eq,Show)
|
|
|
|
|
2015-09-14 11:49:20 +02:00
|
|
|
data VariableDefinition = VariableDefinition Variable Type (Maybe DefaultValue)
|
2015-09-12 12:54:05 +02:00
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
newtype Variable = Variable Name deriving (Eq,Show)
|
|
|
|
|
2015-09-14 11:49:20 +02:00
|
|
|
type SelectionSet = [Selection]
|
2015-09-12 12:54:05 +02:00
|
|
|
|
|
|
|
data Selection = SelectionField Field
|
|
|
|
| SelectionFragmentSpread FragmentSpread
|
|
|
|
| SelectionInlineFragment InlineFragment
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
2015-09-13 13:49:11 +02:00
|
|
|
data Field = Field Alias Name [Argument]
|
|
|
|
[Directive]
|
|
|
|
SelectionSet
|
2015-09-12 12:54:05 +02:00
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
type Alias = Name
|
|
|
|
|
|
|
|
data Argument = Argument Name Value deriving (Eq,Show)
|
|
|
|
|
|
|
|
-- * Fragments
|
|
|
|
|
2015-09-13 13:49:11 +02:00
|
|
|
data FragmentSpread = FragmentSpread Name [Directive]
|
2015-09-12 12:54:05 +02:00
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
data InlineFragment =
|
2015-09-13 13:49:11 +02:00
|
|
|
InlineFragment TypeCondition [Directive] SelectionSet
|
2015-09-12 12:54:05 +02:00
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
data FragmentDefinition =
|
2015-09-13 13:49:11 +02:00
|
|
|
FragmentDefinition Name TypeCondition [Directive] SelectionSet
|
2015-09-12 12:54:05 +02:00
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
type TypeCondition = NamedType
|
|
|
|
|
|
|
|
-- * Values
|
|
|
|
|
|
|
|
data Value = ValueVariable Variable
|
2015-09-13 13:49:11 +02:00
|
|
|
| ValueInt Int -- TODO: Should this be `Integer`?
|
|
|
|
| ValueFloat Double -- TODO: Should this be `Scientific`?
|
2015-09-12 12:54:05 +02:00
|
|
|
| ValueBoolean Bool
|
2015-09-13 13:49:11 +02:00
|
|
|
| ValueString Text
|
2015-09-12 12:54:05 +02:00
|
|
|
| ValueEnum Name
|
|
|
|
| ValueList ListValue
|
|
|
|
| ValueObject ObjectValue
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
newtype ListValue = ListValue [Value] deriving (Eq,Show)
|
|
|
|
|
|
|
|
newtype ObjectValue = ObjectValue [ObjectField] deriving (Eq,Show)
|
|
|
|
|
|
|
|
data ObjectField = ObjectField Name Value deriving (Eq,Show)
|
|
|
|
|
|
|
|
type DefaultValue = Value
|
|
|
|
|
|
|
|
-- * Directives
|
|
|
|
|
2015-09-13 13:49:11 +02:00
|
|
|
data Directive = Directive Name [Argument] deriving (Eq,Show)
|
2015-09-12 12:54:05 +02:00
|
|
|
|
|
|
|
-- * Type Reference
|
|
|
|
|
|
|
|
data Type = TypeNamed NamedType
|
|
|
|
| TypeList ListType
|
|
|
|
| TypeNonNull NonNullType
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
newtype NamedType = NamedType Name deriving (Eq,Show)
|
|
|
|
|
|
|
|
newtype ListType = ListType Type deriving (Eq,Show)
|
|
|
|
|
|
|
|
data NonNullType = NonNullTypeNamed NamedType
|
|
|
|
| NonNullTypeList ListType
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
-- * Type definition
|
|
|
|
|
|
|
|
data TypeDefinition = TypeDefinitionObject ObjectTypeDefinition
|
|
|
|
| TypeDefinitionInterface InterfaceTypeDefinition
|
|
|
|
| TypeDefinitionUnion UnionTypeDefinition
|
|
|
|
| TypeDefinitionScalar ScalarTypeDefinition
|
|
|
|
| TypeDefinitionEnum EnumTypeDefinition
|
|
|
|
| TypeDefinitionInputObject InputObjectTypeDefinition
|
|
|
|
| TypeDefinitionTypeExtension TypeExtensionDefinition
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
2015-09-13 13:49:11 +02:00
|
|
|
data ObjectTypeDefinition = ObjectTypeDefinition Name Interfaces [FieldDefinition]
|
2015-09-12 12:54:05 +02:00
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
type Interfaces = [NamedType]
|
|
|
|
|
2015-09-13 13:49:11 +02:00
|
|
|
data FieldDefinition = FieldDefinition Name ArgumentsDefinition Type
|
2015-09-12 12:54:05 +02:00
|
|
|
deriving (Eq,Show)
|
|
|
|
|
2015-09-13 13:49:11 +02:00
|
|
|
type ArgumentsDefinition = [InputValueDefinition]
|
|
|
|
|
2015-09-14 11:49:20 +02:00
|
|
|
data InputValueDefinition = InputValueDefinition Name Type (Maybe DefaultValue)
|
2015-09-12 12:54:05 +02:00
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
data InterfaceTypeDefinition = InterfaceTypeDefinition Name [FieldDefinition]
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
data UnionTypeDefinition = UnionTypeDefinition Name [NamedType]
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
data ScalarTypeDefinition = ScalarTypeDefinition Name
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
data EnumTypeDefinition = EnumTypeDefinition Name [EnumValueDefinition]
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
newtype EnumValueDefinition = EnumValueDefinition Name
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
data InputObjectTypeDefinition = InputObjectTypeDefinition Name [InputValueDefinition]
|
|
|
|
deriving (Eq,Show)
|
|
|
|
|
|
|
|
newtype TypeExtensionDefinition = TypeExtensionDefinition ObjectTypeDefinition
|
|
|
|
deriving (Eq,Show)
|