-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Morpheus GraphQL Client -- -- Build GraphQL APIs with your favorite functional language! @package morpheus-graphql-client @version 0.24.2 module Data.Morpheus.Client.CodeGen.Internal -- | A type that can be converted from JSON, with the possibility of -- failure. -- -- In many cases, you can get the compiler to generate parsing code for -- you (see below). To begin, let's cover writing an instance by hand. -- -- There are various reasons a conversion could fail. For example, an -- Object could be missing a required key, an Array could -- be of the wrong size, or a value could be of an incompatible type. -- -- The basic ways to signal a failed conversion are as follows: -- --
-- -- Allow ourselves to write Text literals.
-- {-# LANGUAGE OverloadedStrings #-}
--
-- data Coord = Coord { x :: Double, y :: Double }
--
-- instance FromJSON Coord where
-- parseJSON (Object v) = Coord
-- <$> v .: "x"
-- <*> v .: "y"
--
-- -- We do not expect a non-Object value here.
-- -- We could use empty to fail, but typeMismatch
-- -- gives a much more informative error message.
-- parseJSON invalid =
-- prependFailure "parsing Coord failed, "
-- (typeMismatch "Object" invalid)
--
--
-- For this common case of only being concerned with a single type of
-- JSON value, the functions withObject, withScientific,
-- etc. are provided. Their use is to be preferred when possible, since
-- they are more terse. Using withObject, we can rewrite the above
-- instance (assuming the same language extension and data type) as:
--
-- -- instance FromJSON Coord where -- parseJSON = withObject "Coord" $ \v -> Coord -- <$> v .: "x" -- <*> v .: "y" ---- -- Instead of manually writing your FromJSON instance, there are -- two options to do it automatically: -- --
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics
--
-- data Coord = Coord { x :: Double, y :: Double } deriving Generic
--
-- instance FromJSON Coord
--
--
-- or using the DerivingVia extension
--
-- -- deriving via Generically Coord instance FromJSON Coord ---- -- The default implementation will be equivalent to parseJSON = -- genericParseJSON defaultOptions; if you need -- different options, you can customize the generic decoding by defining: -- --
-- customOptions = defaultOptions
-- { fieldLabelModifier = map toUpper
-- }
--
-- instance FromJSON Coord where
-- parseJSON = genericParseJSON customOptions
--
class FromJSON a
parseJSON :: FromJSON a => Value -> Parser a
parseJSONList :: FromJSON a => Value -> Parser [a]
-- | A type that can be converted to JSON.
--
-- Instances in general must specify toJSON and
-- should (but don't need to) specify toEncoding.
--
-- An example type and instance:
--
--
-- -- Allow ourselves to write Text literals.
-- {-# LANGUAGE OverloadedStrings #-}
--
-- data Coord = Coord { x :: Double, y :: Double }
--
-- instance ToJSON Coord where
-- toJSON (Coord x y) = object ["x" .= x, "y" .= y]
--
-- toEncoding (Coord x y) = pairs ("x" .= x <> "y" .= y)
--
--
-- Instead of manually writing your ToJSON instance, there are two
-- options to do it automatically:
--
--
-- {-# LANGUAGE DeriveGeneric #-}
--
-- import GHC.Generics
--
-- data Coord = Coord { x :: Double, y :: Double } deriving Generic
--
-- instance ToJSON Coord where
-- toEncoding = genericToEncoding defaultOptions
--
--
-- or more conveniently using the DerivingVia extension
--
-- -- deriving via Generically Coord instance ToJSON Coord ---- -- If on the other hand you wish to customize the generic decoding, you -- have to implement both methods: -- --
-- customOptions = defaultOptions
-- { fieldLabelModifier = map toUpper
-- }
--
-- instance ToJSON Coord where
-- toJSON = genericToJSON customOptions
-- toEncoding = genericToEncoding customOptions
--
--
-- Previous versions of this library only had the toJSON method.
-- Adding toEncoding had two reasons:
--
-- -- instance ToJSON Coord where -- toEncoding = genericToEncoding defaultOptions --toEncoding :: ToJSON a => a -> Encoding toJSONList :: ToJSON a => [a] -> Value toEncodingList :: ToJSON a => [a] -> Encoding class RequestType a where { type RequestArgs a :: Type; } __name :: RequestType a => f a -> FieldName __query :: RequestType a => f a -> String __type :: RequestType a => f a -> OperationType -- | Representable types of kind *. This class is derivable in GHC -- with the DeriveGeneric flag on. -- -- A Generic instance must satisfy the following laws: -- --
-- from . to ≡ id -- to . from ≡ id --class Generic a data OperationType Query :: OperationType Subscription :: OperationType Mutation :: OperationType scalarFromJSON :: (Monad m, MonadFail m, DecodeScalar a) => Value -> m a scalarToJSON :: EncodeScalar a => a -> Value invalidConstructorError :: (MonadFail m, Show a) => a -> m b withUnion :: ((String, Value) -> Parser a) -> Value -> Parser a omitNulls :: [Pair] -> Value (.=) :: (KeyValue kv, ToJSON v) => Key -> v -> kv infixr 8 .= -- | withObject name f value applies f to the -- Object when value is an Object and fails -- otherwise. -- --
-- withObject "MyType" f (String "oops") -- -- Error: "parsing MyType failed, expected Object, but encountered String" --withObject :: String -> (Object -> Parser a) -> Value -> Parser a -- | Retrieve the value associated with the given key of an Object. -- The result is empty if the key is not present or the value -- cannot be converted to the desired type. -- -- This accessor is appropriate if the key and value must be -- present in an object for it to be valid. If the key and value are -- optional, use .:? instead. (.:) :: FromJSON a => Object -> Key -> Parser a -- | Retrieve the value associated with the given key of an Object. -- The result is Nothing if the key is not present or if its value -- is Null, or empty if the value cannot be converted to -- the desired type. -- -- This accessor is most useful if the key and value can be absent from -- an object without affecting its validity. If the key and value are -- mandatory, use .: instead. (.:?) :: FromJSON a => Object -> Key -> Parser (Maybe a) module Data.Morpheus.Client.CodeGen.AST type AesonField = (Name, Name, FieldName) data ClientDeclaration InstanceDeclaration :: DERIVING_MODE -> TypeClassInstance ClientMethod -> ClientDeclaration ClientTypeDeclaration :: CodeGenType -> ClientDeclaration data ClientMethod PrintableMethod :: Printable -> ClientMethod FunctionNameMethod :: Name -> ClientMethod MatchMethod :: ValueMatch -> ClientMethod ToJSONObjectMethod :: Name -> [(FieldName, Name, Name)] -> ClientMethod FromJSONObjectMethod :: TypeName -> [AesonField] -> ClientMethod FromJSONUnionMethod :: [([UnionPat], (Name, Maybe Name))] -> ClientMethod data ClientPreDeclaration ToJSONClass :: DERIVING_MODE -> CodeGenType -> ClientPreDeclaration FromJSONClass :: DERIVING_MODE -> CodeGenType -> ClientPreDeclaration FromJSONUnionClass :: CodeGenTypeName -> [(UnionPat, (CodeGenTypeName, Maybe String))] -> ClientPreDeclaration FromJSONObjectClass :: CodeGenTypeName -> CodeGenConstructor -> ClientPreDeclaration RequestTypeClass :: RequestTypeDefinition -> ClientPreDeclaration ClientType :: CodeGenType -> ClientPreDeclaration data DERIVING_MODE SCALAR_MODE :: DERIVING_MODE ENUM_MODE :: DERIVING_MODE TYPE_MODE :: DERIVING_MODE data MValue MFrom :: TypeName -> TypeName -> MValue MTo :: TypeName -> TypeName -> MValue MFunction :: String -> Name -> MValue data Printable [Printable] :: forall a. (Show a, Lift a) => a -> Printable data RequestTypeDefinition RequestTypeDefinition :: TypeName -> TypeName -> OperationType -> String -> RequestTypeDefinition [requestName] :: RequestTypeDefinition -> TypeName [requestArgs] :: RequestTypeDefinition -> TypeName [requestType] :: RequestTypeDefinition -> OperationType [requestQuery] :: RequestTypeDefinition -> String data UnionPat UString :: TypeName -> UnionPat UVar :: String -> UnionPat data ClientTypeDefinition ClientTypeDefinition :: CodeGenTypeName -> [CodeGenConstructor] -> TypeKind -> ClientTypeDefinition [clientTypeName] :: ClientTypeDefinition -> CodeGenTypeName [clientCons] :: ClientTypeDefinition -> [CodeGenConstructor] [clientKind] :: ClientTypeDefinition -> TypeKind instance GHC.Show.Show Data.Morpheus.Client.CodeGen.AST.ClientTypeDefinition instance GHC.Show.Show Data.Morpheus.Client.CodeGen.AST.RequestTypeDefinition instance Prettyprinter.Internal.Pretty Data.Morpheus.Client.CodeGen.AST.ClientDeclaration instance Prettyprinter.Internal.Pretty Data.Morpheus.Client.CodeGen.AST.ClientMethod instance Data.Morpheus.CodeGen.TH.PrintExp Data.Morpheus.Client.CodeGen.AST.ClientMethod instance Prettyprinter.Internal.Pretty Data.Morpheus.Client.CodeGen.AST.Printable instance Data.Morpheus.CodeGen.TH.PrintExp Data.Morpheus.Client.CodeGen.AST.Printable module Data.Morpheus.Client -- | QuasiQuoter to insert multiple lines of text in Haskell raw :: QuasiQuoter class (RequestType a, ToJSON (Args a), FromJSON a) => Fetch a where { type Args a :: Type; } fetch :: (Fetch a, Monad m) => (ByteString -> m ByteString) -> Args a -> m (Either (FetchError a) a) data FetchError a FetchErrorParseFailure :: String -> FetchError a FetchErrorProducedErrors :: GQLErrors -> Maybe a -> FetchError a FetchErrorNoResult :: FetchError a -- | Primitive Values for GQLScalar: ScalarValue, -- ScalarValue, ScalarValue, Boolean. for -- performance reason type Text represents GraphQl -- ScalarValue value data ScalarValue Int :: Int -> ScalarValue Float :: Double -> ScalarValue String :: Text -> ScalarValue Boolean :: Bool -> ScalarValue Value :: Value -> ScalarValue -- | GraphQL Scalar parser class DecodeScalar a decodeScalar :: DecodeScalar a => ScalarValue -> Either Text a -- | GraphQL Scalar Serializer class EncodeScalar a encodeScalar :: EncodeScalar a => a -> ScalarValue -- | default GraphQL type, parses only ScalarValue and -- ScalarValue values, serialized always as ScalarValue newtype ID ID :: Text -> ID [unpackID] :: ID -> Text -- | declares input, enum and scalar types for specified schema -- -- Example where the schema is defined in SDL format -- --
-- declareGlobalTypes "schema.gql" ---- -- Example with schema as introspection in JSON format. -- --
-- declareGlobalTypes "schema.json" --declareGlobalTypes :: FilePath -> Q [Dec] -- | declares global types like declareGlobalTypes, while enabling -- to select only the types that are needed. declareGlobalTypesByName :: FilePath -> [TypeName] -> Q [Dec] -- | declares object, interface and union types for specified schema and -- query. -- -- Example where the schema is defined in SDL format -- --
-- declareLocalTypes "schema.gql" "query.gql" ---- -- Example with schema as introspection in JSON format. -- --
-- declareLocalTypes "schema.json" "query.gql" --declareLocalTypes :: FilePath -> FilePath -> Q [Dec] -- | inline version of declareLocalTypes, however instead of -- specifying the file path, you can simply pass the query as text using -- QuasiQuoter raw -- --
-- declareLocalTypesInline "schema.gql"
-- [raw|
-- query GetUsers {
-- users {
-- name
-- }
-- }
-- ]
--
--
declareLocalTypesInline :: FilePath -> ExecutableSource -> Q [Dec]
-- | declares global or local types, depending on whether the second
-- argument is specified or not
clientTypeDeclarations :: SchemaSource -> Maybe ExecutableSource -> Q [Dec]
data GQLClient
type GQLClientResult (a :: Type) = (Either (FetchError a) a)
data ResponseStream a
withHeaders :: GQLClient -> [Header] -> GQLClient
request :: (ClientTypeConstraint a, MonadFail m) => GQLClient -> Args a -> m (ResponseStream a)
-- | returns loop listening subscription events forever. if you want to run
-- it in background use forkIO
forEach :: (MonadIO m, MonadUnliftIO m, MonadFail m) => (GQLClientResult a -> m ()) -> ResponseStream a -> m ()
-- | returns first response from the server
single :: MonadIO m => ResponseStream a -> m (GQLClientResult a)
-- | Deprecated: use raw
gql :: QuasiQuoter
-- | Deprecated: use clientTypeDeclarations
defineByDocument :: IO ByteString -> ExecutableSource -> Q [Dec]
-- | Deprecated: use declareLocalTypes
defineByDocumentFile :: FilePath -> ExecutableSource -> Q [Dec]
-- | This variant exposes 'Q FilePath' enabling the use of TH to generate
-- the FilePath. For example,
-- https://hackage.haskell.org/package/file-embed-0.0.13.0/docs/Data-FileEmbed.html#v:makeRelativeToProject
-- can be used to handle multi package projects more reliably.
-- | Deprecated: use declareLocalTypes
defineByDocumentFile' :: Q FilePath -> ExecutableSource -> Q [Dec]
-- | Deprecated: use clientTypeDeclarations
defineByIntrospection :: IO ByteString -> ExecutableSource -> Q [Dec]
-- | Deprecated: use declareLocalTypes
defineByIntrospectionFile :: FilePath -> ExecutableSource -> Q [Dec]
-- | This variant exposes 'Q FilePath' enabling the use of TH to generate
-- the FilePath. For example,
-- https://hackage.haskell.org/package/file-embed-0.0.13.0/docs/Data-FileEmbed.html#v:makeRelativeToProject
-- can be used to handle multi package projects more reliably.
-- | Deprecated: use declareLocalTypes
defineByIntrospectionFile' :: Q FilePath -> ExecutableSource -> Q [Dec]
parseClientTypeDeclarations :: SchemaSource -> Maybe Text -> GQLResult [ClientDeclaration]
readSchemaSource :: FilePath -> IO SchemaSource
data SchemaSource