summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2019-08-29 07:40:50 +0200
committerEugen Wissner <belka@caraus.de>2019-08-29 07:40:50 +0200
commitc1943c1979a0bfd37dae3a87d863f06938176baf (patch)
tree751ab644dc5e0feaba374a528bb3ab4eebf51105 /src
parent5175586def05410890023ab340b8381045de6811 (diff)
downloadgraphql-c1943c1979a0bfd37dae3a87d863f06938176baf.tar.gz
Document all public symbols.
Mostly basic documentation. Fixes #4.
Diffstat (limited to 'src')
-rw-r--r--src/Language/GraphQL/AST.hs67
-rw-r--r--src/Language/GraphQL/AST/Transform.hs3
-rw-r--r--src/Language/GraphQL/Parser.hs2
3 files changed, 51 insertions, 21 deletions
diff --git a/src/Language/GraphQL/AST.hs b/src/Language/GraphQL/AST.hs
index 667e4d7..8f40c10 100644
--- a/src/Language/GraphQL/AST.hs
+++ b/src/Language/GraphQL/AST.hs
@@ -39,63 +39,82 @@ import Language.GraphQL.AST.Core ( Alias
-- * Document
+-- | GraphQL document.
type Document = NonEmpty Definition
-- * Operations
+-- | Top-level definition of a document, either an operation or a fragment.
data Definition = DefinitionOperation OperationDefinition
| DefinitionFragment FragmentDefinition
- deriving (Eq,Show)
+ deriving (Eq, Show)
+-- | Operation definition.
data OperationDefinition = OperationSelectionSet SelectionSet
| OperationDefinition OperationType
(Maybe Name)
VariableDefinitions
Directives
SelectionSet
- deriving (Eq,Show)
+ deriving (Eq, Show)
-data OperationType = Query | Mutation deriving (Eq,Show)
+-- | GraphQL has 3 operation types: queries, mutations and subscribtions.
+--
+-- Currently only queries and mutations are supported.
+data OperationType = Query | Mutation deriving (Eq, Show)
--- * SelectionSet
+-- * Selections
+-- | "Top-level" selection, selection on a operation.
type SelectionSet = NonEmpty Selection
type SelectionSetOpt = [Selection]
-data Selection = SelectionField Field
- | SelectionFragmentSpread FragmentSpread
- | SelectionInlineFragment InlineFragment
- deriving (Eq,Show)
+-- | Single selection element.
+data Selection
+ = SelectionField Field
+ | SelectionFragmentSpread FragmentSpread
+ | SelectionInlineFragment InlineFragment
+ deriving (Eq, Show)
-- * Field
-data Field = Field (Maybe Alias) Name Arguments Directives SelectionSetOpt
- deriving (Eq,Show)
+-- | GraphQL field.
+data Field
+ = Field (Maybe Alias) Name Arguments Directives SelectionSetOpt
+ deriving (Eq, Show)
-- * Arguments
+-- | Argument list.
type Arguments = [Argument]
+-- | Argument.
data Argument = Argument Name Value deriving (Eq,Show)
-- * Fragments
-data FragmentSpread = FragmentSpread Name Directives deriving (Eq,Show)
+-- | Fragment spread.
+data FragmentSpread = FragmentSpread Name Directives deriving (Eq, Show)
+-- | Inline fragment.
data InlineFragment = InlineFragment (Maybe TypeCondition) Directives SelectionSet
- deriving (Eq,Show)
+ deriving (Eq, Show)
-data FragmentDefinition =
- FragmentDefinition FragmentName TypeCondition Directives SelectionSet
- deriving (Eq,Show)
+-- | Fragment definition.
+data FragmentDefinition
+ = FragmentDefinition Name TypeCondition Directives SelectionSet
+ deriving (Eq, Show)
+{-# DEPRECATED FragmentName "Use Name instead" #-}
type FragmentName = Name
+-- | Type condition.
type TypeCondition = Name
-- * Input values
+-- | Input value.
data Value = ValueVariable Name
| ValueInt Int32
| ValueFloat Double
@@ -107,28 +126,38 @@ data Value = ValueVariable Name
| ValueObject [ObjectField]
deriving (Eq, Show)
+-- | Key-value pair.
+--
+-- A list of 'ObjectField's represents a GraphQL object type.
data ObjectField = ObjectField Name Value deriving (Eq, Show)
-- * Variables
+-- | Variable definition list.
type VariableDefinitions = [VariableDefinition]
+-- | Variable definition.
data VariableDefinition = VariableDefinition Name Type (Maybe Value)
- deriving (Eq,Show)
+ deriving (Eq, Show)
-- * Input types
+-- | Type representation.
data Type = TypeNamed Name
| TypeList Type
| TypeNonNull NonNullType
- deriving (Eq,Show)
+ deriving (Eq, Show)
+
+-- | Helper type to represent Non-Null types and lists of such types.
data NonNullType = NonNullTypeNamed Name
| NonNullTypeList Type
- deriving (Eq,Show)
+ deriving (Eq, Show)
-- * Directives
+-- | Directive list.
type Directives = [Directive]
-data Directive = Directive Name [Argument] deriving (Eq,Show)
+-- | Directive.
+data Directive = Directive Name [Argument] deriving (Eq, Show)
diff --git a/src/Language/GraphQL/AST/Transform.hs b/src/Language/GraphQL/AST/Transform.hs
index 63a2c72..99e0f3e 100644
--- a/src/Language/GraphQL/AST/Transform.hs
+++ b/src/Language/GraphQL/AST/Transform.hs
@@ -18,7 +18,8 @@ import qualified Language.GraphQL.Schema as Schema
-- empty list is returned.
type Fragmenter = Core.Name -> [Core.Field]
--- TODO: Replace Maybe by MonadThrow with CustomError
+-- | Rewrites the original syntax tree into an intermediate representation used
+-- for query execution.
document :: Schema.Subs -> Full.Document -> Maybe Core.Document
document subs doc = operations subs fr ops
where
diff --git a/src/Language/GraphQL/Parser.hs b/src/Language/GraphQL/Parser.hs
index 4bc17b9..17482d7 100644
--- a/src/Language/GraphQL/Parser.hs
+++ b/src/Language/GraphQL/Parser.hs
@@ -94,7 +94,7 @@ fragmentDefinition = FragmentDefinition
<*> opt directives
<*> selectionSet
-fragmentName :: Parser FragmentName
+fragmentName :: Parser Name
fragmentName = but (symbol "on") *> name
typeCondition :: Parser TypeCondition