summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/AST/Document.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2020-05-22 10:11:48 +0200
committerEugen Wissner <belka@caraus.de>2020-05-22 10:11:48 +0200
commit26cc53ce0678d48bf7d5550df65171e6bf5288d2 (patch)
tree4b823c8d481463f2d2eb43beeea06310b2c51e5e /src/Language/GraphQL/AST/Document.hs
parentc3ecfece0358d79dd1da6efbe6ab83e63bf50f88 (diff)
downloadgraphql-26cc53ce0678d48bf7d5550df65171e6bf5288d2.tar.gz
Reject variables as default values
Diffstat (limited to 'src/Language/GraphQL/AST/Document.hs')
-rw-r--r--src/Language/GraphQL/AST/Document.hs41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/Language/GraphQL/AST/Document.hs b/src/Language/GraphQL/AST/Document.hs
index 3b13691..430e92a 100644
--- a/src/Language/GraphQL/AST/Document.hs
+++ b/src/Language/GraphQL/AST/Document.hs
@@ -8,6 +8,7 @@ module Language.GraphQL.AST.Document
( Alias
, Argument(..)
, ArgumentsDefinition(..)
+ , ConstValue(..)
, Definition(..)
, Description(..)
, Directive(..)
@@ -197,7 +198,7 @@ type TypeCondition = Name
-- ** Input Values
--- | Input value.
+-- | Input value (literal or variable).
data Value
= Variable Name
| Int Int32
@@ -207,18 +208,46 @@ data Value
| Null
| Enum Name
| List [Value]
- | Object [ObjectField]
+ | Object [ObjectField Value]
+ deriving (Eq, Show)
+
+-- | Constant input value.
+data ConstValue
+ = ConstInt Int32
+ | ConstFloat Double
+ | ConstString Text
+ | ConstBoolean Bool
+ | ConstNull
+ | ConstEnum Name
+ | ConstList [ConstValue]
+ | ConstObject [ObjectField ConstValue]
deriving (Eq, Show)
-- | Key-value pair.
--
--- A list of 'ObjectField's represents a GraphQL object type.
-data ObjectField = ObjectField Name Value deriving (Eq, Show)
+-- A list of 'ObjectField's represents a GraphQL object type.
+data ObjectField a = ObjectField Name a
+ deriving (Eq, Show)
-- ** Variables
-- | Variable definition.
-data VariableDefinition = VariableDefinition Name Type (Maybe Value)
+--
+-- Each operation can include a list of variables:
+--
+-- @
+-- query (protagonist: String = "Zarathustra") {
+-- getAuthor(protagonist: $protagonist)
+-- }
+-- @
+--
+-- This query defines an optional variable @protagonist@ of type @String@,
+-- its default value is "Zarathustra". If no default value is defined and no
+-- value is provided, a variable can still be @null@ if its type is nullable.
+--
+-- Variables are usually passed along with the query, but not in the query
+-- itself. They make queries reusable.
+data VariableDefinition = VariableDefinition Name Type (Maybe ConstValue)
deriving (Eq, Show)
-- ** Type References
@@ -445,7 +474,7 @@ instance Monoid ArgumentsDefinition where
--
-- The input type "Point2D" contains two value definitions: "x" and "y".
data InputValueDefinition
- = InputValueDefinition Description Name Type (Maybe Value) [Directive]
+ = InputValueDefinition Description Name Type (Maybe ConstValue) [Directive]
deriving (Eq, Show)
-- ** Unions