diff --git a/CHANGELOG.md b/CHANGELOG.md index dafe975..612fc1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. ## Unreleased +### Deprecated +- `Language.GraphQL.AST.Arguments`. Use `[Language.GraphQL.AST.Argument]` + instead. +- `Language.GraphQL.AST.Directives`. Use `[Language.GraphQL.AST.Directives]` + instead. +- `Language.GraphQL.AST.VariableDefinitions`. Use + `[Language.GraphQL.AST.VariableDefinition]` instead. + +### Added +- Module documentation. ## [0.5.0.1] - 2019-09-10 ### Added diff --git a/src/Language/GraphQL/AST.hs b/src/Language/GraphQL/AST.hs index 0c0ed89..dc7f6ac 100644 --- a/src/Language/GraphQL/AST.hs +++ b/src/Language/GraphQL/AST.hs @@ -45,18 +45,20 @@ 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) +data Definition + = DefinitionOperation OperationDefinition + | DefinitionFragment FragmentDefinition + deriving (Eq, Show) -- | Operation definition. -data OperationDefinition = OperationSelectionSet SelectionSet - | OperationDefinition OperationType - (Maybe Name) - VariableDefinitions - Directives - SelectionSet - deriving (Eq, Show) +data OperationDefinition + = OperationSelectionSet SelectionSet + | OperationDefinition OperationType + (Maybe Name) + [VariableDefinition] + [Directive] + SelectionSet + deriving (Eq, Show) -- | GraphQL has 3 operation types: queries, mutations and subscribtions. -- @@ -73,7 +75,7 @@ type SelectionSetOpt = [Selection] -- | Single selection element. data Selection - = SelectionField Field + = SelectionField Field | SelectionFragmentSpread FragmentSpread | SelectionInlineFragment InlineFragment deriving (Eq, Show) @@ -82,12 +84,13 @@ data Selection -- | GraphQL field. data Field - = Field (Maybe Alias) Name Arguments Directives SelectionSetOpt + = Field (Maybe Alias) Name [Argument] [Directive] SelectionSetOpt deriving (Eq, Show) -- * Arguments -- | Argument list. +{-# DEPRECATED Arguments "Use [Argument] instead" #-} type Arguments = [Argument] -- | Argument. @@ -96,15 +99,15 @@ data Argument = Argument Name Value deriving (Eq,Show) -- * Fragments -- | Fragment spread. -data FragmentSpread = FragmentSpread Name Directives deriving (Eq, Show) +data FragmentSpread = FragmentSpread Name [Directive] deriving (Eq, Show) -- | Inline fragment. -data InlineFragment = InlineFragment (Maybe TypeCondition) Directives SelectionSet +data InlineFragment = InlineFragment (Maybe TypeCondition) [Directive] SelectionSet deriving (Eq, Show) -- | Fragment definition. data FragmentDefinition - = FragmentDefinition Name TypeCondition Directives SelectionSet + = FragmentDefinition Name TypeCondition [Directive] SelectionSet deriving (Eq, Show) {-# DEPRECATED FragmentName "Use Name instead" #-} @@ -135,6 +138,7 @@ data ObjectField = ObjectField Name Value deriving (Eq, Show) -- * Variables -- | Variable definition list. +{-# DEPRECATED VariableDefinitions "Use [VariableDefinition] instead" #-} type VariableDefinitions = [VariableDefinition] -- | Variable definition. @@ -158,6 +162,7 @@ data NonNullType = NonNullTypeNamed Name -- * Directives -- | Directive list. +{-# DEPRECATED Directives "Use [Directive] instead" #-} type Directives = [Directive] -- | Directive. diff --git a/src/Language/GraphQL/Encoder.hs b/src/Language/GraphQL/Encoder.hs index 63a0ef2..b3ec655 100644 --- a/src/Language/GraphQL/Encoder.hs +++ b/src/Language/GraphQL/Encoder.hs @@ -67,11 +67,11 @@ operationDefinition formatter (OperationDefinition Mutation name vars dirs sels) = "mutation " <> node formatter name vars dirs sels node :: Formatter - -> Maybe Name - -> VariableDefinitions - -> Directives - -> SelectionSet - -> Text + -> Maybe Name + -> [VariableDefinition] + -> [Directive] + -> SelectionSet + -> Text node formatter name vars dirs sels = Text.Lazy.fromStrict (fold name) <> optempty (variableDefinitions formatter) vars @@ -170,7 +170,7 @@ directive :: Formatter -> Directive -> Text directive formatter (Directive name args) = "@" <> Text.Lazy.fromStrict name <> optempty (arguments formatter) args -directives :: Formatter -> Directives -> Text +directives :: Formatter -> [Directive] -> Text directives formatter@(Pretty _) = Text.Lazy.cons ' ' . spaces (directive formatter) directives Minified = spaces (directive Minified) diff --git a/src/Language/GraphQL/Parser.hs b/src/Language/GraphQL/Parser.hs index 6d403b2..bbe1de7 100644 --- a/src/Language/GraphQL/Parser.hs +++ b/src/Language/GraphQL/Parser.hs @@ -69,7 +69,7 @@ alias = try $ name <* colon -- * Arguments -arguments :: Parser Arguments +arguments :: Parser [Argument] arguments = parens $ some argument argument :: Parser Argument @@ -135,7 +135,7 @@ objectField = ObjectField <$> name <* symbol ":" <*> value -- * Variables -variableDefinitions :: Parser VariableDefinitions +variableDefinitions :: Parser [VariableDefinition] variableDefinitions = parens $ some variableDefinition variableDefinition :: Parser VariableDefinition @@ -164,7 +164,7 @@ nonNullType = NonNullTypeNamed <$> name <* bang -- * Directives -directives :: Parser Directives +directives :: Parser [Directive] directives = some directive directive :: Parser Directive