diff options
Diffstat (limited to 'src/Language/GraphQL/Type')
| -rw-r--r-- | src/Language/GraphQL/Type/Definition.hs | 24 | ||||
| -rw-r--r-- | src/Language/GraphQL/Type/Directive.hs | 13 | ||||
| -rw-r--r-- | src/Language/GraphQL/Type/In.hs | 22 | ||||
| -rw-r--r-- | src/Language/GraphQL/Type/Out.hs | 56 | ||||
| -rw-r--r-- | src/Language/GraphQL/Type/Schema.hs | 11 |
5 files changed, 52 insertions, 74 deletions
diff --git a/src/Language/GraphQL/Type/Definition.hs b/src/Language/GraphQL/Type/Definition.hs index aecb64a..0f92857 100644 --- a/src/Language/GraphQL/Type/Definition.hs +++ b/src/Language/GraphQL/Type/Definition.hs @@ -4,6 +4,8 @@ module Language.GraphQL.Type.Definition ( EnumType(..) , ScalarType(..) + , Subs + , Value(..) , boolean , float , id @@ -11,11 +13,33 @@ module Language.GraphQL.Type.Definition , string ) where +import Data.Int (Int32) +import Data.HashMap.Strict (HashMap) import Data.Set (Set) +import Data.String (IsString(..)) import Data.Text (Text) import Language.GraphQL.AST.Document (Name) import Prelude hiding (id) +-- | Represents accordingly typed GraphQL values. +data Value + = Int Int32 + | Float Double -- ^ GraphQL Float is double precision. + | String Text + | Boolean Bool + | Null + | Enum Name + | List [Value] -- ^ Arbitrary nested list. + | Object (HashMap Name Value) + deriving (Eq, Show) + +instance IsString Value where + fromString = String . fromString + +-- | Contains variables for the query. The key of the map is a variable name, +-- and the value is the variable value. +type Subs = HashMap Name Value + -- | Scalar type definition. -- -- The leaf values of any request and input values to arguments are Scalars (or diff --git a/src/Language/GraphQL/Type/Directive.hs b/src/Language/GraphQL/Type/Directive.hs index 9675df8..261bf04 100644 --- a/src/Language/GraphQL/Type/Directive.hs +++ b/src/Language/GraphQL/Type/Directive.hs @@ -1,12 +1,17 @@ {-# LANGUAGE OverloadedStrings #-} module Language.GraphQL.Type.Directive - ( selection + ( Directive(..) + , selection ) where import qualified Data.HashMap.Strict as HashMap import Language.GraphQL.AST.Core -import qualified Language.GraphQL.Type.In as In +import Language.GraphQL.Type.Definition + +-- | Directive. +data Directive = Directive Name Arguments + deriving (Eq, Show) -- | Directive processing status. data Status @@ -37,7 +42,7 @@ skip = handle skip' where skip' directive'@(Directive "skip" (Arguments arguments)) = case HashMap.lookup "if" arguments of - (Just (In.Boolean True)) -> Skip + (Just (Boolean True)) -> Skip _ -> Include directive' skip' directive' = Continue directive' @@ -46,6 +51,6 @@ include = handle include' where include' directive'@(Directive "include" (Arguments arguments)) = case HashMap.lookup "if" arguments of - (Just (In.Boolean True)) -> Include directive' + (Just (Boolean True)) -> Include directive' _ -> Skip include' directive' = Continue directive' diff --git a/src/Language/GraphQL/Type/In.hs b/src/Language/GraphQL/Type/In.hs index c2e8ded..c662797 100644 --- a/src/Language/GraphQL/Type/In.hs +++ b/src/Language/GraphQL/Type/In.hs @@ -10,7 +10,6 @@ module Language.GraphQL.Type.In , InputField(..) , InputObjectType(..) , Type(..) - , Value(..) , isNonNullType , pattern EnumBaseType , pattern ListBaseType @@ -19,8 +18,6 @@ module Language.GraphQL.Type.In ) where import Data.HashMap.Strict (HashMap) -import Data.Int (Int32) -import Data.String (IsString(..)) import Data.Text (Text) import Language.GraphQL.AST.Document (Name) import Language.GraphQL.Type.Definition @@ -36,6 +33,10 @@ data InputObjectType = InputObjectType Name (Maybe Text) (HashMap Name InputField) -- | These types may be used as input types for arguments and directives. +-- +-- GraphQL distinguishes between "wrapping" and "named" types. Each wrapping +-- type can wrap other wrapping or named types. Wrapping types are lists and +-- Non-Null types (named types are nullable by default). data Type = NamedScalarType ScalarType | NamedEnumType EnumType @@ -46,21 +47,6 @@ data Type | NonNullInputObjectType InputObjectType | NonNullListType Type --- | Represents accordingly typed GraphQL values. -data Value - = Int Int32 - | Float Double -- ^ GraphQL Float is double precision - | String Text - | Boolean Bool - | Null - | Enum Name - | List [Value] - | Object (HashMap Name Value) - deriving (Eq, Show) - -instance IsString Value where - fromString = String . fromString - -- | Field argument definition. data Argument = Argument (Maybe Text) Type (Maybe Value) diff --git a/src/Language/GraphQL/Type/Out.hs b/src/Language/GraphQL/Type/Out.hs index fe2d4f2..4808d09 100644 --- a/src/Language/GraphQL/Type/Out.hs +++ b/src/Language/GraphQL/Type/Out.hs @@ -1,5 +1,4 @@ {-# LANGUAGE ExplicitForAll #-} -{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-} @@ -13,7 +12,6 @@ module Language.GraphQL.Type.Out , ObjectType(..) , Type(..) , UnionType(..) - , Value(..) , isNonNullType , pattern EnumBaseType , pattern InterfaceBaseType @@ -24,12 +22,8 @@ module Language.GraphQL.Type.Out ) where import Data.HashMap.Strict (HashMap) -import qualified Data.HashMap.Strict as HashMap -import Data.Int (Int32) -import Data.String (IsString(..)) import Data.Text (Text) -import qualified Data.Text as Text -import Language.GraphQL.AST.Document (Name) +import Language.GraphQL.AST.Core import Language.GraphQL.Trans import Language.GraphQL.Type.Definition import qualified Language.GraphQL.Type.In as In @@ -60,9 +54,13 @@ data Field m = Field (Maybe Text) -- ^ Description. (Type m) -- ^ Field type. (HashMap Name In.Argument) -- ^ Arguments. - (ActionT m (Value m)) -- ^ Resolver. + (ActionT m Value) -- ^ Resolver. -- | These types may be used as output types as the result of fields. +-- +-- GraphQL distinguishes between "wrapping" and "named" types. Each wrapping +-- type can wrap other wrapping or named types. Wrapping types are lists and +-- Non-Null types (named types are nullable by default). data Type m = NamedScalarType ScalarType | NamedEnumType EnumType @@ -77,48 +75,6 @@ data Type m | NonNullUnionType (UnionType m) | NonNullListType (Type m) --- | GraphQL distinguishes between "wrapping" and "named" types. Each wrapping --- type can wrap other wrapping or named types. Wrapping types are lists and --- Non-Null types (named types are nullable by default). --- --- This 'Value' type doesn\'t reflect this distinction exactly but it is used --- in the resolvers to take into account that the returned value can be nullable --- or an (arbitrary nested) list. -data Value m - = Int Int32 - | Float Double - | String Text - | Boolean Bool - | Null - | Enum Name - | List [Value m] -- ^ Arbitrary nested list. - | Object (HashMap Name (ActionT m (Value m))) - -instance IsString (Value m) where - fromString = String . fromString - -instance Show (Value m) where - show (Int integer) = "Int " ++ show integer - show (Float float') = "Float " ++ show float' - show (String text) = Text.unpack $ "String " <> text - show (Boolean True) = "Boolean True" - show (Boolean False) = "Boolean False" - show Null = "Null" - show (Enum enum) = Text.unpack $ "Enum " <> enum - show (List list) = show list - show (Object object) = Text.unpack - $ "Object [" <> Text.intercalate ", " (HashMap.keys object) <> "]" - -instance Eq (Value m) where - (Int this) == (Int that) = this == that - (Float this) == (Float that) = this == that - (String this) == (String that) = this == that - (Boolean this) == (Boolean that) = this == that - (Enum this) == (Enum that) = this == that - (List this) == (List that) = this == that - (Object this) == (Object that) = HashMap.keys this == HashMap.keys that - _ == _ = False - -- | Matches either 'NamedScalarType' or 'NonNullScalarType'. pattern ScalarBaseType :: forall m. ScalarType -> Type m pattern ScalarBaseType scalarType <- (isScalarType -> Just scalarType) diff --git a/src/Language/GraphQL/Type/Schema.hs b/src/Language/GraphQL/Type/Schema.hs index 74ab974..b6055c5 100644 --- a/src/Language/GraphQL/Type/Schema.hs +++ b/src/Language/GraphQL/Type/Schema.hs @@ -2,14 +2,15 @@ -- | Schema Definition. module Language.GraphQL.Type.Schema - ( Schema(..) + ( CompositeType(..) + , Schema(..) , Type(..) , collectReferencedTypes ) where import Data.HashMap.Strict (HashMap) import qualified Data.HashMap.Strict as HashMap -import Language.GraphQL.AST.Core (Name) +import Language.GraphQL.AST.Document (Name) import qualified Language.GraphQL.Type.Definition as Definition import qualified Language.GraphQL.Type.In as In import qualified Language.GraphQL.Type.Out as Out @@ -23,6 +24,12 @@ data Type m | InterfaceType (Out.InterfaceType m) | UnionType (Out.UnionType m) +-- | These types may describe the parent context of a selection set. +data CompositeType m + = CompositeUnionType (Out.UnionType m) + | CompositeObjectType (Out.ObjectType m) + | CompositeInterfaceType (Out.InterfaceType m) + -- | A Schema is created by supplying the root types of each type of operation, -- query and mutation (optional). A schema definition is then supplied to the -- validator and executor. |
