diff options
Diffstat (limited to 'src/Language/GraphQL/AST.hs')
| -rw-r--r-- | src/Language/GraphQL/AST.hs | 110 |
1 files changed, 64 insertions, 46 deletions
diff --git a/src/Language/GraphQL/AST.hs b/src/Language/GraphQL/AST.hs index 6794ae3..44bf969 100644 --- a/src/Language/GraphQL/AST.hs +++ b/src/Language/GraphQL/AST.hs @@ -5,14 +5,11 @@ module Language.GraphQL.AST ( Alias , Argument(..) - , Arguments , Definition(..) , Directive(..) - , Directives , Document , Field(..) , FragmentDefinition(..) - , FragmentName , FragmentSpread(..) , InlineFragment(..) , Name @@ -27,22 +24,23 @@ module Language.GraphQL.AST , TypeCondition , Value(..) , VariableDefinition(..) - , VariableDefinitions ) where import Data.Int (Int32) import Data.List.NonEmpty (NonEmpty) import Data.Text (Text) -import Language.GraphQL.AST.Core ( Alias - , Name - , TypeCondition - ) -- * Document -- | GraphQL document. type Document = NonEmpty Definition +-- | Name +type Name = Text + +-- | Directive. +data Directive = Directive Name [Argument] deriving (Eq, Show) + -- * Operations -- | Top-level definition of a document, either an operation or a fragment. @@ -68,7 +66,7 @@ data OperationType = Query | Mutation deriving (Eq, Show) -- * Selections --- | "Top-level" selection, selection on a operation. +-- | "Top-level" selection, selection on an operation or fragment. type SelectionSet = NonEmpty Selection -- | Field selection. @@ -83,18 +81,56 @@ data Selection -- * Field --- | GraphQL field. +-- | Single GraphQL field. +-- +-- The only required property of a field is its name. Optionally it can also +-- have an alias, arguments or a list of subfields. +-- +-- Given the following query: +-- +-- @ +-- { +-- zuck: user(id: 4) { +-- id +-- name +-- } +-- } +-- @ +-- +-- * "user", "id" and "name" are field names. +-- * "user" has two subfields, "id" and "name". +-- * "zuck" is an alias for "user". "id" and "name" have no aliases. +-- * "id: 4" is an argument for "user". "id" and "name" don't have any +-- arguments. data Field = Field (Maybe Alias) Name [Argument] [Directive] SelectionSetOpt deriving (Eq, Show) --- * Arguments - --- | Argument list. -{-# DEPRECATED Arguments "Use [Argument] instead" #-} -type Arguments = [Argument] +-- | Alternative field name. +-- +-- @ +-- { +-- smallPic: profilePic(size: 64) +-- bigPic: profilePic(size: 1024) +-- } +-- @ +-- +-- Here "smallPic" and "bigPic" are aliases for the same field, "profilePic", +-- used to distinquish between profile pictures with different arguments +-- (sizes). +type Alias = Name --- | Argument. +-- | Single argument. +-- +-- @ +-- { +-- user(id: 4) { +-- name +-- } +-- } +-- @ +-- +-- Here "id" is an argument for the field "user" and its value is 4. data Argument = Argument Name Value deriving (Eq,Show) -- * Fragments @@ -111,21 +147,18 @@ data FragmentDefinition = FragmentDefinition Name TypeCondition [Directive] SelectionSet deriving (Eq, Show) -{-# DEPRECATED FragmentName "Use Name instead" #-} -type FragmentName = Name - --- * Input values +-- * Inputs -- | Input value. -data Value = ValueVariable Name - | ValueInt Int32 - | ValueFloat Double - | ValueString Text - | ValueBoolean Bool - | ValueNull - | ValueEnum Name - | ValueList [Value] - | ValueObject [ObjectField] +data Value = Variable Name + | Int Int32 + | Float Double + | String Text + | Boolean Bool + | Null + | Enum Name + | List [Value] + | Object [ObjectField] deriving (Eq, Show) -- | Key-value pair. @@ -133,17 +166,12 @@ data Value = ValueVariable Name -- A list of 'ObjectField's represents a GraphQL object type. data ObjectField = ObjectField Name Value deriving (Eq, Show) --- * Variables - --- | Variable definition list. -{-# DEPRECATED VariableDefinitions "Use [VariableDefinition] instead" #-} -type VariableDefinitions = [VariableDefinition] - -- | Variable definition. data VariableDefinition = VariableDefinition Name Type (Maybe Value) deriving (Eq, Show) --- * Input types +-- | Type condition. +type TypeCondition = Name -- | Type representation. data Type = TypeNamed Name @@ -151,17 +179,7 @@ data Type = TypeNamed Name | TypeNonNull NonNullType deriving (Eq, Show) - -- | Helper type to represent Non-Null types and lists of such types. data NonNullType = NonNullTypeNamed Name | NonNullTypeList Type deriving (Eq, Show) - --- * Directives - --- | Directive list. -{-# DEPRECATED Directives "Use [Directive] instead" #-} -type Directives = [Directive] - --- | Directive. -data Directive = Directive Name [Argument] deriving (Eq, Show) |
