morpheus-graphql-client 0.16.0 → 0.17.0
raw patch · 19 files changed
+185/−97 lines, 19 filesdep ~morpheus-graphql-corePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: morpheus-graphql-core
API changes (from Hackage documentation)
- Data.Morpheus.Client: class GQLScalar a
- Data.Morpheus.Client: parseValue :: GQLScalar a => ScalarValue -> Either Text a
- Data.Morpheus.Client: scalarValidator :: GQLScalar a => f a -> ScalarDefinition
- Data.Morpheus.Client: serialize :: GQLScalar a => a -> ScalarValue
+ Data.Morpheus.Client: class DecodeScalar a
+ Data.Morpheus.Client: class EncodeScalar a
+ Data.Morpheus.Client: decodeScalar :: DecodeScalar a => ScalarValue -> Either Text a
+ Data.Morpheus.Client: encodeScalar :: EncodeScalar a => a -> ScalarValue
- Data.Morpheus.Client: Float :: Float -> ScalarValue
+ Data.Morpheus.Client: Float :: Double -> ScalarValue
- Data.Morpheus.Client: defineByDocument :: IO ByteString -> (GQLQuery, String) -> Q [Dec]
+ Data.Morpheus.Client: defineByDocument :: IO ByteString -> (ExecutableDocument, String) -> Q [Dec]
- Data.Morpheus.Client: defineByDocumentFile :: FilePath -> (GQLQuery, String) -> Q [Dec]
+ Data.Morpheus.Client: defineByDocumentFile :: FilePath -> (ExecutableDocument, String) -> Q [Dec]
- Data.Morpheus.Client: defineByIntrospection :: IO ByteString -> (GQLQuery, String) -> Q [Dec]
+ Data.Morpheus.Client: defineByIntrospection :: IO ByteString -> (ExecutableDocument, String) -> Q [Dec]
- Data.Morpheus.Client: defineByIntrospectionFile :: FilePath -> (GQLQuery, String) -> Q [Dec]
+ Data.Morpheus.Client: defineByIntrospectionFile :: FilePath -> (ExecutableDocument, String) -> Q [Dec]
- Data.Morpheus.Client: defineQuery :: IO (Eventless (Schema VALID)) -> (GQLQuery, String) -> Q [Dec]
+ Data.Morpheus.Client: defineQuery :: IO (Eventless (Schema VALID)) -> (ExecutableDocument, String) -> Q [Dec]
Files
- changelog.md +11/−0
- morpheus-graphql-client.cabal +5/−4
- src/Data/Morpheus/Client.hs +25/−14
- src/Data/Morpheus/Client/Build.hs +8/−8
- src/Data/Morpheus/Client/Declare/Aeson.hs +17/−15
- src/Data/Morpheus/Client/Declare/Type.hs +8/−4
- src/Data/Morpheus/Client/Fetch.hs +3/−1
- src/Data/Morpheus/Client/Internal/TH.hs +1/−2
- src/Data/Morpheus/Client/Internal/Types.hs +13/−2
- src/Data/Morpheus/Client/Internal/Utils.hs +28/−0
- src/Data/Morpheus/Client/JSONSchema/Parse.hs +8/−8
- src/Data/Morpheus/Client/JSONSchema/Types.hs +13/−0
- src/Data/Morpheus/Client/Transform/Core.hs +6/−7
- src/Data/Morpheus/Client/Transform/Inputs.hs +6/−3
- src/Data/Morpheus/Client/Transform/Selection.hs +7/−6
- test/Case/Github/Test.hs +9/−6
- test/Case/JSON/Custom/Query.hs +4/−7
- test/Case/LowercaseTypeName/Test.hs +9/−6
- test/Spec/Utils.hs +4/−4
changelog.md view
@@ -1,5 +1,16 @@ # Changelog +## 0.17.0 - 25.02.2021++### Breaking changes++- `GQLScalar` was replaced with `EncodeScalar` and `DecodeScalar` type-classes.++### Minor Changes++- more likely to rebuild when a file loaded by `defineByDocumentFile` or+ `defineByIntrospectionFile` is changed+ ## 0.16.0 - 05.11.2020 ### Minor Changes
morpheus-graphql-client.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 429de07c8ee5d1c020878cf8ab48c03e9911bd2b7657e44273b73cbc0defddd5+-- hash: e02463ebba831a7d044e68be7f21aa39b4fba099002f076f46478158b913b2a7 name: morpheus-graphql-client-version: 0.16.0+version: 0.17.0 synopsis: Morpheus GraphQL Client description: Build GraphQL APIs with your favourite functional language! category: web, graphql, client@@ -51,6 +51,7 @@ Data.Morpheus.Client.Fetch Data.Morpheus.Client.Internal.TH Data.Morpheus.Client.Internal.Types+ Data.Morpheus.Client.Internal.Utils Data.Morpheus.Client.JSONSchema.Parse Data.Morpheus.Client.JSONSchema.TypeKind Data.Morpheus.Client.JSONSchema.TypeRef@@ -66,7 +67,7 @@ aeson >=1.4.4.0 && <=1.6 , base >=4.7 && <5 , bytestring >=0.10.4 && <0.11- , morpheus-graphql-core >=0.16.0 && <0.17.0+ , morpheus-graphql-core >=0.17.0 && <0.18.0 , mtl >=2.0 && <=3.0 , relude >=0.3.0 , template-haskell >=2.0 && <=3.0@@ -97,7 +98,7 @@ , bytestring >=0.10.4 && <0.11 , directory >=1.0 , morpheus-graphql-client- , morpheus-graphql-core >=0.16.0 && <0.17.0+ , morpheus-graphql-core >=0.17.0 && <0.18.0 , mtl >=2.0 && <=3.0 , relude >=0.3.0 , tasty
src/Data/Morpheus/Client.hs view
@@ -10,7 +10,8 @@ defineByIntrospection, defineByIntrospectionFile, ScalarValue (..),- GQLScalar (..),+ DecodeScalar (..),+ EncodeScalar (..), ID (..), ) where@@ -29,34 +30,44 @@ ( decodeIntrospection, ) import Data.Morpheus.Core- ( parseFullGQLDocument,+ ( parseFullSchema, )+import Data.Morpheus.Internal.Ext+ ( Eventless,+ ) import Data.Morpheus.QuasiQuoter (gql)-import Data.Morpheus.Types.GQLScalar (GQLScalar (..))+import Data.Morpheus.Types.GQLScalar+ ( DecodeScalar (..),+ EncodeScalar (..),+ ) import Data.Morpheus.Types.ID (ID (..)) import Data.Morpheus.Types.Internal.AST- ( GQLQuery,+ ( ExecutableDocument, ScalarValue (..), Schema, VALID, )-import Data.Morpheus.Types.Internal.Resolving- ( Eventless,- ) import Language.Haskell.TH+import Language.Haskell.TH.Syntax+ ( qAddDependentFile,+ ) import Relude hiding (ByteString) -defineByDocumentFile :: FilePath -> (GQLQuery, String) -> Q [Dec]-defineByDocumentFile = defineByDocument . L.readFile+defineByDocumentFile :: FilePath -> (ExecutableDocument, String) -> Q [Dec]+defineByDocumentFile filePath args = do+ qAddDependentFile filePath+ defineByDocument (L.readFile filePath) args -defineByIntrospectionFile :: FilePath -> (GQLQuery, String) -> Q [Dec]-defineByIntrospectionFile = defineByIntrospection . L.readFile+defineByIntrospectionFile :: FilePath -> (ExecutableDocument, String) -> Q [Dec]+defineByIntrospectionFile filePath args = do+ qAddDependentFile filePath+ defineByIntrospection (L.readFile filePath) args -defineByDocument :: IO ByteString -> (GQLQuery, String) -> Q [Dec]+defineByDocument :: IO ByteString -> (ExecutableDocument, String) -> Q [Dec] defineByDocument doc = defineQuery (schemaByDocument doc) schemaByDocument :: IO ByteString -> IO (Eventless (Schema VALID))-schemaByDocument documentGQL = parseFullGQLDocument <$> documentGQL+schemaByDocument = fmap parseFullSchema -defineByIntrospection :: IO ByteString -> (GQLQuery, String) -> Q [Dec]+defineByIntrospection :: IO ByteString -> (ExecutableDocument, String) -> Q [Dec] defineByIntrospection json = defineQuery (decodeIntrospection <$> json)
src/Data/Morpheus/Client/Build.hs view
@@ -28,20 +28,20 @@ ( gqlWarnings, renderGQLErrors, )+import Data.Morpheus.Internal.Ext+ ( Eventless,+ Result (..),+ ) import Data.Morpheus.Types.Internal.AST- ( GQLQuery (..),+ ( ExecutableDocument (..), Operation (..), Schema, VALID, )-import Data.Morpheus.Types.Internal.Resolving- ( Eventless,- Result (..),- ) import Language.Haskell.TH import Relude -defineQuery :: IO (Eventless (Schema VALID)) -> (GQLQuery, String) -> Q [Dec]+defineQuery :: IO (Eventless (Schema VALID)) -> (ExecutableDocument, String) -> Q [Dec] defineQuery ioSchema (query, src) = do schema <- runIO ioSchema case schema >>= (`validateWith` query) of@@ -51,10 +51,10 @@ warnings } -> gqlWarnings warnings >> declareClient src result -validateWith :: Schema VALID -> GQLQuery -> Eventless ClientDefinition+validateWith :: Schema VALID -> ExecutableDocument -> Eventless ClientDefinition validateWith schema- rawRequest@GQLQuery+ rawRequest@ExecutableDocument { operation = Operation {operationArguments} } = do validOperation <- validateRequest Config {debug = False, validationMode = WITHOUT_VARIABLES} schema rawRequest
src/Data/Morpheus/Client/Declare/Aeson.hs view
@@ -28,14 +28,18 @@ mkFieldsE, ) import Data.Morpheus.Client.Internal.Types- ( ClientTypeDefinition (..),+ ( ClientConsD,+ ClientTypeDefinition (..), TypeNameTH (..), )+import Data.Morpheus.Client.Internal.Utils+ ( isEnum,+ ) import Data.Morpheus.Internal.TH ( _', applyCons, funDSimple,- toConE,+ toCon, toName, toString, v',@@ -53,9 +57,7 @@ Message, TypeKind (..), TypeName (..),- VALID,- isEnum,- isOutputObject,+ isResolverType, msg, toFieldName, )@@ -80,7 +82,7 @@ aesonDeclarations KindEnum = [deriveFromJSON, deriveToJSON] aesonDeclarations KindScalar = deriveScalarJSON aesonDeclarations kind- | isOutputObject kind || kind == KindUnion = [deriveFromJSON]+ | isResolverType kind = [deriveFromJSON] | otherwise = [deriveToJSON] failure :: Message -> Q a@@ -124,7 +126,7 @@ defineFromJSON clientTypeName $ aesonUnionObject typeD -aesonObject :: [FieldName] -> ConsD cat VALID -> ExpQ+aesonObject :: [FieldName] -> ClientConsD cat -> ExpQ aesonObject tNamespace con@ConsD {cName} = withBody <$> aesonObjectBody tNamespace con@@ -136,7 +138,7 @@ name :: Exp name = toString (nameSpaceType tNamespace cName) -aesonObjectBody :: [FieldName] -> ConsD cat VALID -> ExpQ+aesonObjectBody :: [FieldName] -> ClientConsD cat -> ExpQ aesonObjectBody namespace ConsD {cName, cFields} = decodeObjectE entry@@ -155,9 +157,9 @@ clientTypeName = TypeNameTH {namespace, typename} } = appE (varE 'takeValueType) $- matchWith elseCond f clientCons+ matchWith elseCondition f clientCons where- elseCond =+ elseCondition = (tupP [_', v'],) . aesonObjectBody namespace@@ -185,19 +187,19 @@ typeDef = applyCons ''FromJSON [namespaced name] body = [funDSimple 'parseJSON [] expr] -aesonFromJSONEnumBody :: TypeNameTH -> [ConsD cat VALID] -> ExpQ+aesonFromJSONEnumBody :: TypeNameTH -> [ClientConsD cat] -> ExpQ aesonFromJSONEnumBody TypeNameTH {typename} = matchWith (Just (v', failExp)) f where- f :: ConsD cat VALID -> (PatQ, ExpQ)+ f :: ClientConsD cat -> (PatQ, ExpQ) f ConsD {cName} = ( toString cName,- appE (varE 'pure) $ toConE $ nameSpaceType [toFieldName typename] cName+ appE (varE 'pure) $ toCon $ nameSpaceType [toFieldName typename] cName ) -aesonToJSONEnumBody :: TypeNameTH -> [ConsD cat VALID] -> ExpQ+aesonToJSONEnumBody :: TypeNameTH -> [ClientConsD cat] -> ExpQ aesonToJSONEnumBody TypeNameTH {typename} = matchWith Nothing f where- f :: ConsD cat VALID -> (PatQ, ExpQ)+ f :: ClientConsD cat -> (PatQ, ExpQ) f ConsD {cName} = ( conP (toName $ nameSpaceType [toFieldName typename] cName) [], toString cName
src/Data/Morpheus/Client/Declare/Type.hs view
@@ -11,13 +11,17 @@ where import Data.Morpheus.Client.Internal.Types- ( ClientTypeDefinition (..),+ ( ClientConsD,+ ClientTypeDefinition (..), TypeNameTH (..), )+import Data.Morpheus.Client.Internal.Utils+ ( isEnum,+ ) import Data.Morpheus.Internal.TH ( declareTypeRef,- isEnum, nameSpaceType,+ toCon, toName, ) import Data.Morpheus.Types.Internal.AST@@ -52,7 +56,7 @@ where derive className = DerivClause Nothing [ConT className] -declareCons :: TypeNameTH -> [ConsD ANY VALID] -> [Con]+declareCons :: TypeNameTH -> [ClientConsD ANY] -> [Con] declareCons TypeNameTH {namespace, typename} clientCons | isEnum clientCons = map consE clientCons | otherwise = map consR clientCons@@ -67,7 +71,7 @@ declareField FieldDefinition {fieldName, fieldType} = ( toName fieldName, Bang NoSourceUnpackedness NoSourceStrictness,- declareTypeRef fieldType+ declareTypeRef toCon fieldType ) mkConName :: [FieldName] -> TypeName -> Name
src/Data/Morpheus/Client/Fetch.hs view
@@ -21,6 +21,9 @@ import qualified Data.Aeson as A import qualified Data.Aeson.Types as A import Data.ByteString.Lazy (ByteString)+import Data.Morpheus.Client.JSONSchema.Types+ ( JSONResponse (..),+ ) import Data.Morpheus.Internal.TH ( applyCons, toCon,@@ -28,7 +31,6 @@ ) import Data.Morpheus.Types.IO ( GQLRequest (..),- JSONResponse (..), ) import Data.Morpheus.Types.Internal.AST ( FieldName,
src/Data/Morpheus/Client/Internal/TH.hs view
@@ -26,7 +26,6 @@ toName, toString, toVar,- toVarE, v', vars, )@@ -55,7 +54,7 @@ failExp :: ExpQ failExp = appE- (toVarE 'fail)+ (toVar 'fail) ( uInfixE (appE (varE 'show) v') (varE '(<>))
src/Data/Morpheus/Client/Internal/Types.hs view
@@ -4,21 +4,32 @@ ( ClientTypeDefinition (..), TypeNameTH (..), ClientDefinition (..),+ ClientConsD, ) where import Data.Morpheus.Types.Internal.AST ( ANY, ConsD (..),+ FieldDefinition,+ FieldName, TypeKind,- TypeNameTH (..),+ TypeName, VALID, ) import Relude +data TypeNameTH = TypeNameTH+ { namespace :: [FieldName],+ typename :: TypeName+ }+ deriving (Show)++type ClientConsD c = ConsD (FieldDefinition c VALID)+ data ClientTypeDefinition = ClientTypeDefinition { clientTypeName :: TypeNameTH,- clientCons :: [ConsD ANY VALID],+ clientCons :: [ClientConsD ANY], clientKind :: TypeKind } deriving (Show)
+ src/Data/Morpheus/Client/Internal/Utils.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE NoImplicitPrelude #-}++module Data.Morpheus.Client.Internal.Utils+ ( removeDuplicates,+ isEnum,+ )+where++import Data.Morpheus.Types.Internal.AST+ ( ConsD (..),+ )+import Relude++removeDuplicates :: Eq a => [a] -> [a]+removeDuplicates = fst . splitDuplicates++-- elems -> (unique elements, duplicate elems)+splitDuplicates :: Eq a => [a] -> ([a], [a])+splitDuplicates = collectElems ([], [])+ where+ collectElems :: Eq a => ([a], [a]) -> [a] -> ([a], [a])+ collectElems collected [] = collected+ collectElems (collected, errors) (x : xs)+ | x `elem` collected = collectElems (collected, errors <> [x]) xs+ | otherwise = collectElems (collected <> [x], errors) xs++isEnum :: [ConsD f] -> Bool+isEnum = all (null . cFields)
src/Data/Morpheus/Client/JSONSchema/Parse.hs view
@@ -20,6 +20,7 @@ Field (..), InputValue (..), Introspection (..),+ JSONResponse (..), Schema (..), Type (..), )@@ -28,17 +29,19 @@ validateSchema, ) import Data.Morpheus.Error (globalErrorMessage)+import Data.Morpheus.Internal.Ext+ ( Eventless,+ ) import Data.Morpheus.Internal.Utils ( Failure (..), fromElems, )-import Data.Morpheus.Types.IO (JSONResponse (..)) import qualified Data.Morpheus.Types.Internal.AST as AST ( Schema, ) import Data.Morpheus.Types.Internal.AST ( ANY,- ArgumentsDefinition (..),+ ArgumentDefinition (..), CONST, DataTypeWrapper (..), FieldDefinition,@@ -65,9 +68,6 @@ toAny, toHSWrappers, )-import Data.Morpheus.Types.Internal.Resolving- ( Eventless,- ) import Relude hiding ( ByteString, Type,@@ -148,10 +148,10 @@ parse Field {fieldName, fieldArgs, fieldType} = do (wrappers, typename) <- fieldTypeFromJSON fieldType args <- traverse genArg fieldArgs >>= fromElems- pure $ mkObjectField (ArgumentsDefinition Nothing args) fieldName wrappers typename+ pure $ mkObjectField args fieldName wrappers typename where genArg InputValue {inputName = argName, inputType = argType} =- uncurry (mkInputValue argName) <$> fieldTypeFromJSON argType+ ArgumentDefinition . uncurry (mkInputValue argName) <$> fieldTypeFromJSON argType instance ParseJSONSchema InputValue (FieldDefinition IN CONST) where parse InputValue {inputName, inputType} = uncurry (mkInputValue inputName) <$> fieldTypeFromJSON inputType@@ -167,4 +167,4 @@ fieldTypeRec acc Type {kind = NON_NULL, ofType = Just ofType} = fieldTypeRec (NonNullType : acc) ofType fieldTypeRec acc Type {name = Just name} = pure (acc, name)- fieldTypeRec _ x = decoderError $ "Unsuported Field" <> msg (show x)+ fieldTypeRec _ x = decoderError $ "Unsupported Field" <> msg (show x)
src/Data/Morpheus/Client/JSONSchema/Types.hs view
@@ -12,6 +12,7 @@ Field (..), InputValue (..), EnumValue (..),+ JSONResponse (..), ) where @@ -22,6 +23,7 @@ import Data.Morpheus.Client.JSONSchema.TypeRef (TypeRef) import Data.Morpheus.Types.Internal.AST ( FieldName,+ GQLError, TypeName, ) import Relude hiding (Type)@@ -90,3 +92,14 @@ parseJSON = withObject "EnumValue" objectParser where objectParser o = EnumValue <$> o .: "name"++instance FromJSON a => FromJSON (JSONResponse a) where+ parseJSON = withObject "JSONResponse" objectParser+ where+ objectParser o = JSONResponse <$> o .:? "data" <*> o .:? "errors"++data JSONResponse a = JSONResponse+ { responseData :: Maybe a,+ responseErrors :: Maybe [GQLError]+ }+ deriving (Generic, Show, ToJSON)
src/Data/Morpheus/Client/Transform/Core.hs view
@@ -20,7 +20,6 @@ ) where -import Control.Monad (foldM) import Data.Morpheus.Client.Internal.Types ( ClientTypeDefinition (..), )@@ -28,6 +27,10 @@ ( deprecatedField, globalErrorMessage, )+import Data.Morpheus.Internal.Ext+ ( Eventless,+ Result (..),+ ) import Data.Morpheus.Internal.Utils ( Failure (..), nameSpaceType,@@ -56,10 +59,6 @@ msg, toGQLError, )-import Data.Morpheus.Types.Internal.Resolving- ( Eventless,- Result (..),- ) import Relude type Env = (Schema VALID, VariableDefinitions RAW)@@ -85,7 +84,7 @@ newtype UpdateT m a = UpdateT {updateTState :: a -> m a} resolveUpdates :: Monad m => a -> [UpdateT m a] -> m a-resolveUpdates a = foldM (&) a . fmap updateTState+resolveUpdates a = foldlM (&) a . fmap updateTState compileError :: Message -> GQLErrors compileError x =@@ -116,7 +115,7 @@ __typeFrom DataUnion {} = nameSpaceType path typeName __typeFrom _ = typeName -deprecationWarning :: Directives VALID -> (FieldName, Ref) -> Converter ()+deprecationWarning :: Directives VALID -> (FieldName, Ref FieldName) -> Converter () deprecationWarning dirs (typename, ref) = case lookupDeprecated dirs of Just deprecation -> Converter $ lift $ Success {result = (), warnings, events = []} where
src/Data/Morpheus/Client/Transform/Inputs.hs view
@@ -13,9 +13,13 @@ where import Data.Morpheus.Client.Internal.Types- ( ClientTypeDefinition (..),+ ( ClientConsD,+ ClientTypeDefinition (..), TypeNameTH (..), )+import Data.Morpheus.Client.Internal.Utils+ ( removeDuplicates,+ ) import Data.Morpheus.Client.Transform.Core ( Converter (..), UpdateT (..),@@ -46,7 +50,6 @@ VariableDefinitions, getOperationName, mkConsEnum,- removeDuplicates, toAny, ) import Relude hiding (empty)@@ -152,7 +155,7 @@ ] subTypes _ = pure [] -mkInputType :: TypeName -> TypeKind -> [ConsD ANY VALID] -> ClientTypeDefinition+mkInputType :: TypeName -> TypeKind -> [ClientConsD ANY] -> ClientTypeDefinition mkInputType typename clientKind clientCons = ClientTypeDefinition { clientTypeName = TypeNameTH [] typename,
src/Data/Morpheus/Client/Transform/Selection.hs view
@@ -13,12 +13,16 @@ where import Data.Morpheus.Client.Internal.Types- ( ClientDefinition (..),+ ( ClientConsD,+ ClientDefinition (..), ClientTypeDefinition (..), TypeNameTH (..), ) import Data.Morpheus.Client.Transform.Core (Converter (..), compileError, deprecationWarning, getType, leafType, typeFrom) import Data.Morpheus.Client.Transform.Inputs (renderNonOutputTypes, renderOperationArguments)+import Data.Morpheus.Internal.Ext+ ( Eventless,+ ) import Data.Morpheus.Internal.Utils ( Failure (..), elems,@@ -53,9 +57,6 @@ toAny, toFieldName, )-import Data.Morpheus.Types.Internal.Resolving- ( Eventless,- ) import Relude hiding (empty, show) import Prelude (show) @@ -116,7 +117,7 @@ TypeDefinition ANY VALID -> SelectionSet VALID -> Converter- ( ConsD ANY VALID,+ ( ClientConsD ANY, [ClientTypeDefinition], [TypeName] )@@ -220,7 +221,7 @@ checkDeprecated *> (trans <$> getType typeConName) where trans x =- (x, alias {typeConName = typeFrom path x, typeArgs = Nothing})+ (x, alias {typeConName = typeFrom path x}) ------------------------------------------------------------------ checkDeprecated :: Converter () checkDeprecated =
test/Case/Github/Test.hs view
@@ -17,8 +17,9 @@ ( ByteString, ) import Data.Morpheus.Client- ( Fetch (..),- GQLScalar (..),+ ( DecodeScalar (..),+ EncodeScalar (..),+ Fetch (..), ScalarValue (..), gql, )@@ -51,10 +52,12 @@ } deriving (Eq, Show) -instance GQLScalar GitTimestamp where- parseValue (String x) = pure (GitTimestamp x)- parseValue _ = Left ""- serialize (GitTimestamp x) = String x+instance DecodeScalar GitTimestamp where+ decodeScalar (String x) = pure (GitTimestamp x)+ decodeScalar _ = Left ""++instance EncodeScalar GitTimestamp where+ encodeScalar (GitTimestamp x) = String x defineClientWith "Github"
test/Case/JSON/Custom/Query.hs view
@@ -17,8 +17,8 @@ ( ByteString, ) import Data.Morpheus.Client- ( Fetch (..),- GQLScalar (..),+ ( EncodeScalar (..),+ Fetch (..), ScalarValue (..), gql, )@@ -36,7 +36,6 @@ ) import Prelude ( ($),- Applicative (..), Either (..), Eq (..), IO,@@ -50,10 +49,8 @@ } deriving (Eq, Show) -instance GQLScalar GitTimestamp where- parseValue (String x) = pure (GitTimestamp x)- parseValue _ = Left ""- serialize (GitTimestamp x) = String x+instance EncodeScalar GitTimestamp where+ encodeScalar (GitTimestamp x) = String x defineClientWithJSON "JSON/Custom"
test/Case/LowercaseTypeName/Test.hs view
@@ -18,8 +18,9 @@ ( ByteString, ) import Data.Morpheus.Client- ( Fetch (..),- GQLScalar (..),+ ( DecodeScalar (..),+ EncodeScalar (..),+ Fetch (..), ScalarValue (..), gql, )@@ -50,10 +51,12 @@ } deriving (Show, Eq) -instance GQLScalar Uuid where- parseValue (String x) = pure (Uuid x)- parseValue _ = Left "not valid uid"- serialize = String . uuid+instance EncodeScalar Uuid where+ encodeScalar = String . uuid++instance DecodeScalar Uuid where+ decodeScalar (String x) = pure (Uuid x)+ decodeScalar _ = Left "not valid uid" defineClientWith "LowercaseTypeName"
test/Spec/Utils.hs view
@@ -17,8 +17,8 @@ defineByIntrospectionFile, ) import Data.Morpheus.Types.Internal.AST- ( FieldName (..),- GQLQuery,+ ( ExecutableDocument,+ FieldName (..), ) import Data.Semigroup ((<>)) import qualified Data.Text as T@@ -52,7 +52,7 @@ defineClientWith :: FieldName ->- (GQLQuery, String) ->+ (ExecutableDocument, String) -> Q [Dec] defineClientWith url exp = do p <- fixFilePath (path url <> "/schema.gql")@@ -60,7 +60,7 @@ defineClientWithJSON :: FieldName ->- (GQLQuery, String) ->+ (ExecutableDocument, String) -> Q [Dec] defineClientWithJSON url exp = do p <- fixFilePath (path url <> "/schema.json")