morpheus-graphql-client 0.24.3 → 0.25.0
raw patch · 9 files changed
+50/−114 lines, 9 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: defineByDocument :: IO ByteString -> ExecutableSource -> Q [Dec]
- Data.Morpheus.Client: defineByDocumentFile :: FilePath -> ExecutableSource -> Q [Dec]
- Data.Morpheus.Client: defineByDocumentFile' :: Q FilePath -> ExecutableSource -> Q [Dec]
- Data.Morpheus.Client: defineByIntrospection :: IO ByteString -> ExecutableSource -> Q [Dec]
- Data.Morpheus.Client: defineByIntrospectionFile :: FilePath -> ExecutableSource -> Q [Dec]
- Data.Morpheus.Client: defineByIntrospectionFile' :: Q FilePath -> ExecutableSource -> Q [Dec]
- Data.Morpheus.Client: gql :: QuasiQuoter
- Data.Morpheus.Client.CodeGen.AST: [Printable] :: forall a. (Show a, Lift a) => a -> Printable
- Data.Morpheus.Client.CodeGen.AST: data Printable
- Data.Morpheus.Client.CodeGen.AST: instance Data.Morpheus.CodeGen.TH.PrintExp Data.Morpheus.Client.CodeGen.AST.Printable
- Data.Morpheus.Client.CodeGen.AST: instance Prettyprinter.Internal.Pretty Data.Morpheus.Client.CodeGen.AST.Printable
+ Data.Morpheus.Client: __name :: RequestType a => f a -> FieldName
+ Data.Morpheus.Client: __query :: RequestType a => f a -> String
+ Data.Morpheus.Client: __type :: RequestType a => f a -> OperationType
+ Data.Morpheus.Client: class RequestType a where {
+ Data.Morpheus.Client: type RequestArgs a :: Type;
- Data.Morpheus.Client.CodeGen.AST: PrintableMethod :: Printable -> ClientMethod
+ Data.Morpheus.Client.CodeGen.AST: PrintableMethod :: PrintableValue -> ClientMethod
Files
- morpheus-graphql-client.cabal +3/−3
- src/Data/Morpheus/Client.hs +3/−63
- src/Data/Morpheus/Client/CodeGen/AST.hs +2/−12
- src/Data/Morpheus/Client/CodeGen/Interpreting/Arguments.hs +14/−2
- src/Data/Morpheus/Client/CodeGen/Interpreting/Core.hs +6/−11
- src/Data/Morpheus/Client/CodeGen/Interpreting/Local.hs +13/−15
- src/Data/Morpheus/Client/CodeGen/Interpreting/PreDeclarations.hs +4/−4
- src/Data/Morpheus/Client/Schema/JSON/Types.hs +0/−2
- test/Spec/Utils.hs +5/−2
morpheus-graphql-client.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: morpheus-graphql-client-version: 0.24.3+version: 0.25.0 synopsis: Morpheus GraphQL Client description: Build GraphQL APIs with your favorite functional language! category: web, graphql, client@@ -94,7 +94,7 @@ , file-embed >=0.0.10 && <1.0.0 , modern-uri >=0.1.0.0 && <1.0.0 , morpheus-graphql-code-gen-utils- , morpheus-graphql-core >=0.24.0 && <0.25.0+ , morpheus-graphql-core >=0.25.0 && <0.26.0 , morpheus-graphql-subscriptions , mtl >=2.0.0 && <3.0.0 , prettyprinter >=1.7.0 && <2.0.0@@ -137,7 +137,7 @@ , modern-uri >=0.1.0.0 && <1.0.0 , morpheus-graphql-client , morpheus-graphql-code-gen-utils- , morpheus-graphql-core >=0.24.0 && <0.25.0+ , morpheus-graphql-core >=0.25.0 && <0.26.0 , morpheus-graphql-subscriptions , mtl >=2.0.0 && <3.0.0 , prettyprinter >=1.7.0 && <2.0.0
src/Data/Morpheus/Client.hs view
@@ -26,31 +26,19 @@ request, forEach, single,- -- DEPRECATED EXPORTS- gql,- defineByDocument,- defineByDocumentFile,- defineByDocumentFile',- defineByIntrospection,- defineByIntrospectionFile,- defineByIntrospectionFile', parseClientTypeDeclarations, readSchemaSource, SchemaSource,+ RequestType (..), ) where -import Data.ByteString.Lazy (ByteString)-import qualified Data.ByteString.Lazy as L- ( readFile,- ) import Data.Morpheus.Client.CodeGen.Declare ( clientTypeDeclarations, declareGlobalTypes, declareGlobalTypesByName, declareLocalTypes, declareLocalTypesInline,- internalLegacyLocalDeclareTypes, parseClientTypeDeclarations, raw, )@@ -58,6 +46,7 @@ import Data.Morpheus.Client.Fetch ( Fetch (..), )+import Data.Morpheus.Client.Fetch.RequestType import Data.Morpheus.Client.Fetch.ResponseStream ( GQLClient, ResponseStream,@@ -67,8 +56,7 @@ withHeaders, ) import Data.Morpheus.Client.Fetch.Types- ( ExecutableSource,- FetchError (..),+ ( FetchError (..), GQLClientResult, SchemaSource (..), )@@ -80,51 +68,3 @@ import Data.Morpheus.Types.Internal.AST ( ScalarValue (..), )-import Language.Haskell.TH-import Language.Haskell.TH.Quote (QuasiQuoter)-import Language.Haskell.TH.Syntax- ( qAddDependentFile,- )-import Relude hiding (ByteString)--{-# DEPRECATED gql "use raw" #-}-gql :: QuasiQuoter-gql = raw---- DEPRECATED: Legacy Code Exports--{-# DEPRECATED defineByDocumentFile' "use declareLocalTypes" #-}---- | 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.-defineByDocumentFile' :: Q FilePath -> ExecutableSource -> Q [Dec]-defineByDocumentFile' qFilePath args = qFilePath >>= flip defineByDocumentFile args--{-# DEPRECATED defineByIntrospectionFile' "use declareLocalTypes" #-}---- | 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.-defineByIntrospectionFile' :: Q FilePath -> ExecutableSource -> Q [Dec]-defineByIntrospectionFile' path args = path >>= flip defineByIntrospectionFile args---- with file--{-# DEPRECATED defineByIntrospectionFile "use declareLocalTypes" #-}-defineByIntrospectionFile :: FilePath -> ExecutableSource -> Q [Dec]-defineByIntrospectionFile filePath args = do- qAddDependentFile filePath- defineByIntrospection (L.readFile filePath) args--{-# DEPRECATED defineByDocumentFile "use declareLocalTypes" #-}-defineByDocumentFile :: FilePath -> ExecutableSource -> Q [Dec]-defineByDocumentFile filePath args = do- qAddDependentFile filePath- defineByDocument (L.readFile filePath) args---- direct--{-# DEPRECATED defineByDocument "use clientTypeDeclarations" #-}-defineByDocument :: IO ByteString -> ExecutableSource -> Q [Dec]-defineByDocument doc = internalLegacyLocalDeclareTypes (GQL <$> doc)--{-# DEPRECATED defineByIntrospection "use clientTypeDeclarations" #-}-defineByIntrospection :: IO ByteString -> ExecutableSource -> Q [Dec]-defineByIntrospection doc = internalLegacyLocalDeclareTypes (JSON <$> doc)
src/Data/Morpheus/Client/CodeGen/AST.hs view
@@ -14,7 +14,6 @@ ClientPreDeclaration (..), DERIVING_MODE (..), MValue (..),- Printable (..), RequestTypeDefinition (..), UnionPat (..), ClientTypeDefinition (..),@@ -31,6 +30,7 @@ ( CodeGenConstructor (..), CodeGenType, CodeGenTypeName,+ PrintableValue (..), TypeClassInstance, printTHName, )@@ -44,7 +44,6 @@ ) import Data.Morpheus.Types.Internal.AST (FieldName, OperationType, TypeKind, TypeName, unpackName) import Language.Haskell.TH-import Language.Haskell.TH.Syntax (Lift (..)) import Prettyprinter ( Doc, Pretty (..),@@ -90,17 +89,8 @@ pretty (ClientTypeDeclaration def) = pretty def pretty (InstanceDeclaration _ def) = pretty def -data Printable where- Printable :: forall a. (Show a, Lift a) => a -> Printable--instance Pretty Printable where- pretty (Printable x) = pretty (show x :: String)--instance PrintExp Printable where- printExp (Printable x) = [|x|]- data ClientMethod- = PrintableMethod Printable+ = PrintableMethod PrintableValue | FunctionNameMethod Name | MatchMethod ValueMatch | ToJSONObjectMethod Name [(FieldName, Name, Name)]
src/Data/Morpheus/Client/CodeGen/Interpreting/Arguments.hs view
@@ -19,7 +19,14 @@ import Data.Morpheus.Client.CodeGen.Interpreting.Core ( defaultDerivations, )-import Data.Morpheus.CodeGen.Internal.AST (CodeGenConstructor (..), CodeGenField (..), CodeGenType (..), FIELD_TYPE_WRAPPER (..), fromTypeName, getFullName)+import Data.Morpheus.CodeGen.Internal.AST+ ( CodeGenConstructor (..),+ CodeGenField (..),+ CodeGenType (..),+ FIELD_TYPE_WRAPPER (..),+ fromTypeName,+ getFullName,+ ) import Data.Morpheus.Types.Internal.AST ( RAW, TypeName,@@ -38,7 +45,12 @@ def = CodeGenType { cgTypeName,- cgConstructors = [CodeGenConstructor {constructorName = cgTypeName, constructorFields = packAsCodeGenField <$> toList variables}],+ cgConstructors =+ [ CodeGenConstructor+ { constructorName = cgTypeName,+ constructorFields = packAsCodeGenField <$> toList variables+ }+ ], cgDerivations = defaultDerivations } cgTypeName = fromTypeName $ operationTypeName <> "Args"
src/Data/Morpheus/Client/CodeGen/Interpreting/Core.hs view
@@ -16,7 +16,7 @@ deprecationWarning, printClientType, defaultDerivations,- gqlWarning,+ warning, LocalContext (..), runLocalM, withPosition,@@ -42,9 +42,6 @@ fromTypeName, ) import Data.Morpheus.Core (Config (..), VALIDATION_MODE (WITHOUT_VARIABLES))-import Data.Morpheus.Error- ( deprecatedField,- ) import Data.Morpheus.Internal.Ext ( GQLResult, Result (..),@@ -55,6 +52,7 @@ ) import Data.Morpheus.Types.Internal.AST ( ANY,+ Description, Directives, FieldDefinition (..), FieldName,@@ -64,7 +62,6 @@ OUT, Position, RAW,- Ref (..), Schema (..), TRUE, TypeContent (..),@@ -152,13 +149,11 @@ (p : ps) -> CodeGenTypeName {namespace = reverse ps, typeParameters = [], typename = coerce p} [] -> CodeGenTypeName {namespace = [], typeParameters = [], typename = tName} -deprecationWarning :: Directives VALID -> (FieldName, Ref FieldName) -> LocalM ()-deprecationWarning dirs (typename, ref) = case lookupDeprecated dirs of- Just deprecation -> gqlWarning $ deprecatedField typename ref (lookupDeprecatedReason deprecation)- Nothing -> pure ()+deprecationWarning :: (Maybe Description -> GQLError) -> Directives s -> LocalM ()+deprecationWarning f = traverse_ warning . toList . fmap (f . lookupDeprecatedReason) . lookupDeprecated -gqlWarning :: GQLError -> LocalM ()-gqlWarning w = LocalM $ lift $ Success {result = (), warnings = [w]}+warning :: GQLError -> LocalM ()+warning w = LocalM $ lift $ Success {result = (), warnings = [w]} defaultDerivations :: [DerivingClass] defaultDerivations = [GENERIC, SHOW, CLASS_EQ]
src/Data/Morpheus/Client/CodeGen/Interpreting/Local.hs view
@@ -28,18 +28,19 @@ existFragment, getNameByPath, getType,- gqlWarning, lookupField, registerFragment, removeDuplicates, runLocalM, typeFrom,+ warning, ) import Data.Morpheus.Client.CodeGen.Interpreting.PreDeclarations ( mapPreDeclarations, ) import Data.Morpheus.CodeGen.Internal.AST (CodeGenConstructor (..), CodeGenField (..), CodeGenType (..), CodeGenTypeName (..), FIELD_TYPE_WRAPPER (..), fromTypeName, getFullName) import Data.Morpheus.Core (validateRequest)+import Data.Morpheus.Error (deprecatedField) import Data.Morpheus.Internal.Ext ( GQLResult, )@@ -56,7 +57,6 @@ Operation (..), Position (..), PropName (..),- Ref (..), Schema (..), Selection (..), SelectionContent (..),@@ -144,7 +144,7 @@ checkTypename pos path iFace UnionTag {..} | any (member "__typename") (unionTagSelection : toList iFace) = pure () | otherwise =- gqlWarning $+ warning $ withPath ("missing \"__typename\" for selection " <> msg unionTagName <> ". this can lead to undesired behavior at runtime!") (map (PropName . unpackName) path)@@ -246,15 +246,13 @@ selectionPosition } = lookupField selectionName typeContent >>= processFieldDefinition where- --- processFieldDefinition- FieldDefinition- { fieldType = TypeRef {..},- fieldDirectives- } =- checkDeprecated *> (trans <$> getType typeConName)- where- trans x = (x, TypeRef {typeConName = getFullName (typeFrom path x), ..})- ------------------------------------------------------------------- checkDeprecated :: LocalM ()- checkDeprecated = deprecationWarning fieldDirectives (coerce typeName, Ref selectionName selectionPosition)+ processFieldDefinition FieldDefinition {fieldType = TypeRef {..}, ..} = do+ deprecationWarning fieldWarnings fieldDirectives+ typeDef <- getType typeConName+ pure (typeDef, TypeRef {typeConName = getFullName (typeFrom path typeDef), ..})+ where+ fieldWarnings reason =+ ( deprecatedField typeName selectionName reason+ `at` selectionPosition+ )+ `withPath` map (PropName . unpackName) path
src/Data/Morpheus/Client/CodeGen/Interpreting/PreDeclarations.hs view
@@ -25,7 +25,6 @@ ClientPreDeclaration (..), DERIVING_MODE (..), MValue (..),- Printable (..), RequestTypeDefinition (..), UnionPat (..), )@@ -40,6 +39,7 @@ CodeGenType (..), CodeGenTypeName (typename), MethodArgument (..),+ PrintableValue (..), TypeClassInstance (..), fromTypeName, getFullName,@@ -78,9 +78,9 @@ } where typeClassMethods =- [ ('__name, ProxyArgument, PrintableMethod $ Printable requestName),- ('__query, ProxyArgument, PrintableMethod $ Printable requestQuery),- ('__type, ProxyArgument, PrintableMethod $ Printable requestType)+ [ ('__name, ProxyArgument, PrintableMethod $ PrintableValue requestName),+ ('__query, ProxyArgument, PrintableMethod $ PrintableValue requestQuery),+ ('__type, ProxyArgument, PrintableMethod $ PrintableValue requestType) ] -- FromJSON
src/Data/Morpheus/Client/Schema/JSON/Types.hs view
@@ -40,8 +40,6 @@ queryType :: TypeRef, mutationType :: Maybe TypeRef, subscriptionType :: Maybe TypeRef- -- TODO: directives- -- directives: [__Directive] } deriving (Generic, Show, FromJSON)
test/Spec/Utils.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE NoImplicitPrelude #-}@@ -8,12 +9,13 @@ ) where -import Data.Aeson (FromJSON)+import Data.Aeson (FromJSON, ToJSON) import qualified Data.ByteString.Lazy as L (readFile) import Data.ByteString.Lazy.Char8 (ByteString) import Data.Morpheus.Client ( Fetch (..), FetchError,+ RequestType (..), ) import Relude hiding (ByteString, exp) import Test.Tasty@@ -34,8 +36,9 @@ mockJSON p _ = getFile (p <> ".json") assertFetch ::- ( Fetch a,+ ( RequestType a, FromJSON a,+ ToJSON (RequestArgs a), Eq a, Show a ) =>