Document all public symbols.

Mostly basic documentation. Fixes #4.
This commit is contained in:
Eugen Wissner 2019-08-29 07:40:50 +02:00
parent 5175586def
commit c1943c1979
6 changed files with 56 additions and 22 deletions

View File

@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
### Added ### Added
- Minimal documentation for all public symbols. - Minimal documentation for all public symbols.
### Deprecated
- Language.GraphQL.AST.FragmentName. Replaced with Language.GraphQL.AST.Name.
## [0.5.0.0] - 2019-08-14 ## [0.5.0.0] - 2019-08-14
### Added ### Added
- `executeWithName` executes an operation with the given name. - `executeWithName` executes an operation with the given name.

View File

@ -20,6 +20,7 @@ test() {
test_docs() { test_docs() {
$STACK --no-terminal ghc -- -Wall -fno-code docs/tutorial/tutorial.lhs $STACK --no-terminal ghc -- -Wall -fno-code docs/tutorial/tutorial.lhs
$STACK --no-terminal haddock --no-haddock-deps
} }
setup_lint() { setup_lint() {

View File

@ -39,63 +39,82 @@ import Language.GraphQL.AST.Core ( Alias
-- * Document -- * Document
-- | GraphQL document.
type Document = NonEmpty Definition type Document = NonEmpty Definition
-- * Operations -- * Operations
-- | Top-level definition of a document, either an operation or a fragment.
data Definition = DefinitionOperation OperationDefinition data Definition = DefinitionOperation OperationDefinition
| DefinitionFragment FragmentDefinition | DefinitionFragment FragmentDefinition
deriving (Eq,Show) deriving (Eq, Show)
-- | Operation definition.
data OperationDefinition = OperationSelectionSet SelectionSet data OperationDefinition = OperationSelectionSet SelectionSet
| OperationDefinition OperationType | OperationDefinition OperationType
(Maybe Name) (Maybe Name)
VariableDefinitions VariableDefinitions
Directives Directives
SelectionSet 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 SelectionSet = NonEmpty Selection
type SelectionSetOpt = [Selection] type SelectionSetOpt = [Selection]
data Selection = SelectionField Field -- | Single selection element.
| SelectionFragmentSpread FragmentSpread data Selection
| SelectionInlineFragment InlineFragment = SelectionField Field
deriving (Eq,Show) | SelectionFragmentSpread FragmentSpread
| SelectionInlineFragment InlineFragment
deriving (Eq, Show)
-- * Field -- * Field
data Field = Field (Maybe Alias) Name Arguments Directives SelectionSetOpt -- | GraphQL field.
deriving (Eq,Show) data Field
= Field (Maybe Alias) Name Arguments Directives SelectionSetOpt
deriving (Eq, Show)
-- * Arguments -- * Arguments
-- | Argument list.
type Arguments = [Argument] type Arguments = [Argument]
-- | Argument.
data Argument = Argument Name Value deriving (Eq,Show) data Argument = Argument Name Value deriving (Eq,Show)
-- * Fragments -- * 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 data InlineFragment = InlineFragment (Maybe TypeCondition) Directives SelectionSet
deriving (Eq,Show) deriving (Eq, Show)
data FragmentDefinition = -- | Fragment definition.
FragmentDefinition FragmentName TypeCondition Directives SelectionSet data FragmentDefinition
deriving (Eq,Show) = FragmentDefinition Name TypeCondition Directives SelectionSet
deriving (Eq, Show)
{-# DEPRECATED FragmentName "Use Name instead" #-}
type FragmentName = Name type FragmentName = Name
-- | Type condition.
type TypeCondition = Name type TypeCondition = Name
-- * Input values -- * Input values
-- | Input value.
data Value = ValueVariable Name data Value = ValueVariable Name
| ValueInt Int32 | ValueInt Int32
| ValueFloat Double | ValueFloat Double
@ -107,28 +126,38 @@ data Value = ValueVariable Name
| ValueObject [ObjectField] | ValueObject [ObjectField]
deriving (Eq, Show) deriving (Eq, Show)
-- | Key-value pair.
--
-- A list of 'ObjectField's represents a GraphQL object type.
data ObjectField = ObjectField Name Value deriving (Eq, Show) data ObjectField = ObjectField Name Value deriving (Eq, Show)
-- * Variables -- * Variables
-- | Variable definition list.
type VariableDefinitions = [VariableDefinition] type VariableDefinitions = [VariableDefinition]
-- | Variable definition.
data VariableDefinition = VariableDefinition Name Type (Maybe Value) data VariableDefinition = VariableDefinition Name Type (Maybe Value)
deriving (Eq,Show) deriving (Eq, Show)
-- * Input types -- * Input types
-- | Type representation.
data Type = TypeNamed Name data Type = TypeNamed Name
| TypeList Type | TypeList Type
| TypeNonNull NonNullType | TypeNonNull NonNullType
deriving (Eq,Show) deriving (Eq, Show)
-- | Helper type to represent Non-Null types and lists of such types.
data NonNullType = NonNullTypeNamed Name data NonNullType = NonNullTypeNamed Name
| NonNullTypeList Type | NonNullTypeList Type
deriving (Eq,Show) deriving (Eq, Show)
-- * Directives -- * Directives
-- | Directive list.
type Directives = [Directive] type Directives = [Directive]
data Directive = Directive Name [Argument] deriving (Eq,Show) -- | Directive.
data Directive = Directive Name [Argument] deriving (Eq, Show)

View File

@ -18,7 +18,8 @@ import qualified Language.GraphQL.Schema as Schema
-- empty list is returned. -- empty list is returned.
type Fragmenter = Core.Name -> [Core.Field] 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 :: Schema.Subs -> Full.Document -> Maybe Core.Document
document subs doc = operations subs fr ops document subs doc = operations subs fr ops
where where

View File

@ -94,7 +94,7 @@ fragmentDefinition = FragmentDefinition
<*> opt directives <*> opt directives
<*> selectionSet <*> selectionSet
fragmentName :: Parser FragmentName fragmentName :: Parser Name
fragmentName = but (symbol "on") *> name fragmentName = but (symbol "on") *> name
typeCondition :: Parser TypeCondition typeCondition :: Parser TypeCondition

View File

@ -1,4 +1,4 @@
resolver: lts-14.2 resolver: lts-14.3
packages: packages:
- '.' - '.'
extra-deps: [] extra-deps: []