summaryrefslogtreecommitdiff
path: root/Data/GraphQL/AST.hs
blob: 33786553583dcad5c6ab0d7c05d05a0099a8a880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
-- | This module defines an abstract syntax tree for the @GraphQL@ language based on
--   <https://facebook.github.io/graphql/ Facebook's GraphQL Specification>.
--
-- Target AST for Parser.

module Data.GraphQL.AST where

import Data.Int (Int32)
import Data.List.NonEmpty (NonEmpty)
import Data.Text (Text)

-- * Name

type Name = Text

-- * Document

type Document = NonEmpty Definition

-- * Operations

data Definition = DefinitionOperation OperationDefinition
                | DefinitionFragment  FragmentDefinition
                  deriving (Eq,Show)

data OperationDefinition = OperationSelectionSet SelectionSet
                         | OperationDefinition   OperationType
                                                 (Maybe Name)
                                                 VariableDefinitions
                                                 Directives
                                                 SelectionSet
                           deriving (Eq,Show)

data OperationType = Query | Mutation deriving (Eq,Show)

-- * SelectionSet

type SelectionSet = NonEmpty Selection

type SelectionSetOpt = [Selection]

data Selection = SelectionField          Field
               | SelectionFragmentSpread FragmentSpread
               | SelectionInlineFragment InlineFragment
                 deriving (Eq,Show)

-- * Field

data Field = Field (Maybe Alias) Name Arguments Directives SelectionSetOpt
             deriving (Eq,Show)

type Alias = Name

-- * Arguments

type Arguments = [Argument]

data Argument = Argument Name Value deriving (Eq,Show)

-- * Fragments

data FragmentSpread = FragmentSpread Name Directives deriving (Eq,Show)

data InlineFragment = InlineFragment (Maybe TypeCondition) Directives SelectionSet
                      deriving (Eq,Show)

data FragmentDefinition =
  FragmentDefinition FragmentName TypeCondition Directives SelectionSet
  deriving (Eq,Show)

type FragmentName = Name

type TypeCondition = Name

-- Input Values

data Value = ValueVariable Variable
           | ValueInt IntValue
           | ValueFloat FloatValue
           | ValueString StringValue
           | ValueBoolean BooleanValue
           | ValueNull
           | ValueEnum EnumValue
           | ValueList ListValue
           | ValueObject ObjectValue
             deriving (Eq,Show)

type IntValue = Int32

-- GraphQL Float is double precison
type FloatValue = Double

type StringValue = Text

type BooleanValue = Bool

type EnumValue = Name

type ListValue = [Value]

type ObjectValue = [ObjectField]

data ObjectField = ObjectField Name Value deriving (Eq,Show)

-- * Variables

type VariableDefinitions = [VariableDefinition]

data VariableDefinition = VariableDefinition Variable Type (Maybe DefaultValue)
                          deriving (Eq,Show)

type Variable = Name

type DefaultValue = Value

-- * Input Types

data Type = TypeNamed   Name
          | TypeList    Type
          | TypeNonNull NonNullType
            deriving (Eq,Show)

data NonNullType = NonNullTypeNamed Name
                 | NonNullTypeList  Type
                   deriving (Eq,Show)

-- * Directives

type Directives = [Directive]

data Directive = Directive Name [Argument] deriving (Eq,Show)