-- 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.26.0 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: -- -- -- -- prependFailure (or modifyFailure) add more information -- to a parser's error messages. -- -- An example type and instance using typeMismatch and -- prependFailure: -- --
--   -- 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: -- -- -- -- To use the second, simply add a deriving Generic -- clause to your datatype and declare a FromJSON instance for -- your datatype without giving a definition for parseJSON. -- -- For example, the previous example can be simplified to just: -- --
--   {-# 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: -- -- -- -- To use the second, simply add a deriving Generic -- clause to your datatype and declare a ToJSON instance. If you -- require nothing other than defaultOptions, it is sufficient to -- write (and this is the only alternative where the default -- toJSON implementation is sufficient): -- --
--   {-# 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: -- --
    --
  1. toEncoding is more efficient for the common case that the -- output of toJSON is directly serialized to a -- ByteString. Further, expressing either method in terms of the -- other would be non-optimal.
  2. --
  3. The choice of defaults allows a smooth transition for existing -- users: Existing instances that do not define toEncoding still -- compile and have the correct semantics. This is ensured by making the -- default implementation of toEncoding use toJSON. This -- produces correct results, but since it performs an intermediate -- conversion to a Value, it will be less efficient than directly -- emitting an Encoding. (this also means that specifying nothing -- more than instance ToJSON Coord would be sufficient as a -- generically decoding instance, but there probably exists no good -- reason to not specify toEncoding in new instances.)
  4. --
class ToJSON a -- | Convert a Haskell value to a JSON-friendly intermediate type. toJSON :: ToJSON a => a -> Value -- | Encode a Haskell value as JSON. -- -- The default implementation of this method creates an intermediate -- Value using toJSON. This provides source-level -- compatibility for people upgrading from older versions of this -- library, but obviously offers no performance advantage. -- -- To benefit from direct encoding, you must provide an -- implementation for this method. The easiest way to do so is by having -- your types implement Generic using the DeriveGeneric -- extension, and then have GHC generate a method body as follows. -- --
--   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 . toid
--   to . fromid
--   
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. -- --

Error message example

-- --
--   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 :: PrintableValue -> 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 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 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) parseClientTypeDeclarations :: SchemaSource -> Maybe Text -> GQLResult [ClientDeclaration] readSchemaSource :: FilePath -> IO SchemaSource data SchemaSource 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