Reuse common types from AST.Core
This commit is contained in:
parent
74801b0483
commit
bc6a7dddd1
@ -6,7 +6,6 @@ module Language.GraphQL.AST
|
|||||||
( Alias
|
( Alias
|
||||||
, Argument(..)
|
, Argument(..)
|
||||||
, Arguments
|
, Arguments
|
||||||
, DefaultValue
|
|
||||||
, Definition(..)
|
, Definition(..)
|
||||||
, Directive(..)
|
, Directive(..)
|
||||||
, Directives
|
, Directives
|
||||||
@ -16,11 +15,9 @@ module Language.GraphQL.AST
|
|||||||
, FragmentName
|
, FragmentName
|
||||||
, FragmentSpread(..)
|
, FragmentSpread(..)
|
||||||
, InlineFragment(..)
|
, InlineFragment(..)
|
||||||
, ListValue
|
|
||||||
, Name
|
, Name
|
||||||
, NonNullType(..)
|
, NonNullType(..)
|
||||||
, ObjectField(..)
|
, ObjectField(..)
|
||||||
, ObjectValue
|
|
||||||
, OperationDefinition(..)
|
, OperationDefinition(..)
|
||||||
, OperationType(..)
|
, OperationType(..)
|
||||||
, Selection(..)
|
, Selection(..)
|
||||||
@ -29,7 +26,6 @@ module Language.GraphQL.AST
|
|||||||
, Type(..)
|
, Type(..)
|
||||||
, TypeCondition
|
, TypeCondition
|
||||||
, Value(..)
|
, Value(..)
|
||||||
, Variable
|
|
||||||
, VariableDefinition(..)
|
, VariableDefinition(..)
|
||||||
, VariableDefinitions
|
, VariableDefinitions
|
||||||
) where
|
) where
|
||||||
@ -37,10 +33,9 @@ module Language.GraphQL.AST
|
|||||||
import Data.Int (Int32)
|
import Data.Int (Int32)
|
||||||
import Data.List.NonEmpty (NonEmpty)
|
import Data.List.NonEmpty (NonEmpty)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
|
import Language.GraphQL.AST.Core ( Alias
|
||||||
-- * Name
|
, Name
|
||||||
|
)
|
||||||
type Name = Text
|
|
||||||
|
|
||||||
-- * Document
|
-- * Document
|
||||||
|
|
||||||
@ -78,8 +73,6 @@ data Selection = SelectionField Field
|
|||||||
data Field = Field (Maybe Alias) Name Arguments Directives SelectionSetOpt
|
data Field = Field (Maybe Alias) Name Arguments Directives SelectionSetOpt
|
||||||
deriving (Eq,Show)
|
deriving (Eq,Show)
|
||||||
|
|
||||||
type Alias = Name
|
|
||||||
|
|
||||||
-- * Arguments
|
-- * Arguments
|
||||||
|
|
||||||
type Arguments = [Argument]
|
type Arguments = [Argument]
|
||||||
@ -101,48 +94,29 @@ type FragmentName = Name
|
|||||||
|
|
||||||
type TypeCondition = Name
|
type TypeCondition = Name
|
||||||
|
|
||||||
-- Input Values
|
-- * Input values
|
||||||
|
|
||||||
data Value = ValueVariable Variable
|
data Value = ValueVariable Name
|
||||||
| ValueInt IntValue
|
| ValueInt Int32
|
||||||
| ValueFloat FloatValue
|
| ValueFloat Double
|
||||||
| ValueString StringValue
|
| ValueString Text
|
||||||
| ValueBoolean BooleanValue
|
| ValueBoolean Bool
|
||||||
| ValueNull
|
| ValueNull
|
||||||
| ValueEnum EnumValue
|
| ValueEnum Name
|
||||||
| ValueList ListValue
|
| ValueList [Value]
|
||||||
| ValueObject ObjectValue
|
| ValueObject [ObjectField]
|
||||||
deriving (Eq,Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
type IntValue = Int32
|
data ObjectField = ObjectField Name Value deriving (Eq, Show)
|
||||||
|
|
||||||
-- GraphQL Float is double precison
|
|
||||||
type FloatValue = Double
|
|
||||||
|
|
||||||
type StringValue = Text
|
|
||||||
|
|
||||||
type BooleanValue = Bool
|
|
||||||
|
|
||||||
type EnumValue = Name
|
|
||||||
|
|
||||||
type ListValue = [Value]
|
|
||||||
|
|
||||||
type ObjectValue = [ObjectField]
|
|
||||||
|
|
||||||
data ObjectField = ObjectField Name Value deriving (Eq,Show)
|
|
||||||
|
|
||||||
-- * Variables
|
-- * Variables
|
||||||
|
|
||||||
type VariableDefinitions = [VariableDefinition]
|
type VariableDefinitions = [VariableDefinition]
|
||||||
|
|
||||||
data VariableDefinition = VariableDefinition Variable Type (Maybe DefaultValue)
|
data VariableDefinition = VariableDefinition Name Type (Maybe Value)
|
||||||
deriving (Eq,Show)
|
deriving (Eq,Show)
|
||||||
|
|
||||||
type Variable = Name
|
-- * Input types
|
||||||
|
|
||||||
type DefaultValue = Value
|
|
||||||
|
|
||||||
-- * Input Types
|
|
||||||
|
|
||||||
data Type = TypeNamed Name
|
data Type = TypeNamed Name
|
||||||
| TypeList Type
|
| TypeList Type
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
-- | This is the AST meant to be executed.
|
-- | This is the AST meant to be executed.
|
||||||
module Language.GraphQL.AST.Core
|
module Language.GraphQL.AST.Core
|
||||||
( Argument(..)
|
( Alias
|
||||||
|
, Argument(..)
|
||||||
, Document
|
, Document
|
||||||
, Field(..)
|
, Field(..)
|
||||||
, Name
|
, Name
|
||||||
@ -15,6 +16,7 @@ import Data.String
|
|||||||
|
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
|
|
||||||
|
-- | Name
|
||||||
type Name = Text
|
type Name = Text
|
||||||
|
|
||||||
type Document = NonEmpty Operation
|
type Document = NonEmpty Operation
|
||||||
|
@ -10,16 +10,13 @@ import Data.Either (partitionEithers)
|
|||||||
import Data.Foldable (fold, foldMap)
|
import Data.Foldable (fold, foldMap)
|
||||||
import qualified Data.List.NonEmpty as NonEmpty
|
import qualified Data.List.NonEmpty as NonEmpty
|
||||||
import Data.Monoid (Alt(Alt,getAlt), (<>))
|
import Data.Monoid (Alt(Alt,getAlt), (<>))
|
||||||
import Data.Text (Text)
|
|
||||||
import qualified Language.GraphQL.AST as Full
|
import qualified Language.GraphQL.AST as Full
|
||||||
import qualified Language.GraphQL.AST.Core as Core
|
import qualified Language.GraphQL.AST.Core as Core
|
||||||
import qualified Language.GraphQL.Schema as Schema
|
import qualified Language.GraphQL.Schema as Schema
|
||||||
|
|
||||||
type Name = Text
|
|
||||||
|
|
||||||
-- | Replaces a fragment name by a list of 'Field'. If the name doesn't match an
|
-- | Replaces a fragment name by a list of 'Field'. If the name doesn't match an
|
||||||
-- empty list is returned.
|
-- empty list is returned.
|
||||||
type Fragmenter = Name -> [Core.Field]
|
type Fragmenter = Core.Name -> [Core.Field]
|
||||||
|
|
||||||
-- TODO: Replace Maybe by MonadThrow with CustomError
|
-- TODO: Replace Maybe by MonadThrow with CustomError
|
||||||
document :: Schema.Subs -> Full.Document -> Maybe Core.Document
|
document :: Schema.Subs -> Full.Document -> Maybe Core.Document
|
||||||
|
@ -41,10 +41,10 @@ variableDefinition :: VariableDefinition -> Text
|
|||||||
variableDefinition (VariableDefinition var ty dv) =
|
variableDefinition (VariableDefinition var ty dv) =
|
||||||
variable var <> ":" <> type_ ty <> maybe mempty defaultValue dv
|
variable var <> ":" <> type_ ty <> maybe mempty defaultValue dv
|
||||||
|
|
||||||
defaultValue :: DefaultValue -> Text
|
defaultValue :: Value -> Text
|
||||||
defaultValue val = "=" <> value val
|
defaultValue val = "=" <> value val
|
||||||
|
|
||||||
variable :: Variable -> Text
|
variable :: Name -> Text
|
||||||
variable var = "$" <> var
|
variable var = "$" <> var
|
||||||
|
|
||||||
selectionSet :: SelectionSet -> Text
|
selectionSet :: SelectionSet -> Text
|
||||||
@ -113,10 +113,10 @@ booleanValue False = "false"
|
|||||||
stringValue :: Text -> Text
|
stringValue :: Text -> Text
|
||||||
stringValue = quotes
|
stringValue = quotes
|
||||||
|
|
||||||
listValue :: ListValue -> Text
|
listValue :: [Value] -> Text
|
||||||
listValue = bracketsCommas value
|
listValue = bracketsCommas value
|
||||||
|
|
||||||
objectValue :: ObjectValue -> Text
|
objectValue :: [ObjectField] -> Text
|
||||||
objectValue = bracesCommas objectField
|
objectValue = bracesCommas objectField
|
||||||
|
|
||||||
objectField :: ObjectField -> Text
|
objectField :: ObjectField -> Text
|
||||||
|
@ -140,10 +140,10 @@ variableDefinition = VariableDefinition <$> variable
|
|||||||
<* colon
|
<* colon
|
||||||
<*> type_
|
<*> type_
|
||||||
<*> optional defaultValue
|
<*> optional defaultValue
|
||||||
variable :: Parser Variable
|
variable :: Parser Name
|
||||||
variable = dollar *> name
|
variable = dollar *> name
|
||||||
|
|
||||||
defaultValue :: Parser DefaultValue
|
defaultValue :: Parser Value
|
||||||
defaultValue = equals *> value
|
defaultValue = equals *> value
|
||||||
|
|
||||||
-- * Input Types
|
-- * Input Types
|
||||||
|
Loading…
Reference in New Issue
Block a user