packages feed

morpheus-graphql-client 0.20.0 → 0.20.1

raw patch · 5 files changed

+56/−51 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.Morpheus.Client: type family Args a :: Type;
+ Data.Morpheus.Client: type Args a :: Type;

Files

morpheus-graphql-client.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           morpheus-graphql-client-version:        0.20.0+version:        0.20.1 synopsis:       Morpheus GraphQL Client description:    Build GraphQL APIs with your favourite functional language! category:       web, graphql, client
src/Data/Morpheus/Client/Declare/Aeson.hs view
@@ -21,28 +21,25 @@   ( decodeObjectE,     destructRecord,     failExp,+    hasInstance,+    isTypeDeclared,     matchWith,     mkFieldsE,-    isTypeDeclared,-    hasInstance   ) import Data.Morpheus.Client.Internal.Types   ( ClientConstructorDefinition (..),     ClientTypeDefinition (..),     TypeNameTH (..),   )-import Data.Morpheus.Client.Internal.Utils-  ( isEnum,-  ) import Data.Morpheus.CodeGen.Internal.TH-  ( _',-    applyCons,+  ( applyCons,     camelCaseTypeName,     funDSimple,     toCon,     toName,     toString,     v',+    _',   ) import Data.Morpheus.Internal.Utils (IsMap (lookup)) import Data.Morpheus.Types.GQLScalar@@ -71,45 +68,44 @@     cxt,     instanceD,     tupP,- )+  ) import Language.Haskell.TH.Syntax (Dec) import Relude hiding (toString)  aesonDeclarations :: TypeKind -> ClientTypeDefinition -> Q [Dec] aesonDeclarations KindEnum clientDef = do-    a <- deriveIfNotDefined deriveFromJSON ''FromJSON clientDef-    b <- deriveIfNotDefined deriveToJSON ''ToJSON clientDef-    pure (a <> b)+  a <- deriveIfNotDefined deriveFromJSON ''FromJSON clientDef+  b <- deriveIfNotDefined deriveToJSON ''ToJSON clientDef+  pure (a <> b) aesonDeclarations KindScalar clientDef = deriveScalarJSON clientDef aesonDeclarations kind clientDef-    | isResolverType kind = deriveIfNotDefined deriveFromJSON ''FromJSON clientDef-    | otherwise = deriveIfNotDefined deriveToJSON ''ToJSON clientDef+  | isResolverType kind = deriveIfNotDefined deriveFromJSON ''FromJSON clientDef+  | otherwise = deriveIfNotDefined deriveToJSON ''ToJSON clientDef  deriveIfNotDefined :: (ClientTypeDefinition -> Q Dec) -> Name -> ClientTypeDefinition -> Q [Dec] deriveIfNotDefined derivation typeClass clientDef = do-    exists <- isTypeDeclared clientDef-    if exists-        then do-            has <- hasInstance typeClass clientDef-            if has-                then pure []-                else mkDerivation+  exists <- isTypeDeclared clientDef+  if exists+    then do+      has <- hasInstance typeClass clientDef+      if has+        then pure []         else mkDerivation+    else mkDerivation   where     mkDerivation :: Q [Dec]     mkDerivation = do-        derived <- derivation clientDef-        pure [derived]-+      derived <- derivation clientDef+      pure [derived]  failure :: GQLError -> Q a failure = fail . show  deriveScalarJSON :: ClientTypeDefinition -> Q [Dec] deriveScalarJSON clientDef = do-    a <- deriveIfNotDefined deriveScalarFromJSON ''FromJSON clientDef-    b <- deriveIfNotDefined deriveScalarToJSON ''ToJSON clientDef-    pure (a <> b)+  a <- deriveIfNotDefined deriveScalarFromJSON ''FromJSON clientDef+  b <- deriveIfNotDefined deriveScalarToJSON ''ToJSON clientDef+  pure (a <> b)  deriveScalarFromJSON :: ClientTypeDefinition -> DecQ deriveScalarFromJSON ClientTypeDefinition {clientTypeName} =@@ -127,11 +123,14 @@ -- FromJSON deriveFromJSON :: ClientTypeDefinition -> DecQ deriveFromJSON ClientTypeDefinition {clientCons = [], clientTypeName} =-  failure-    $ internal-    $ "Type "-      <> msg (typename clientTypeName)-      <> " Should Have at least one Constructor"+  failure $+    internal $+      "Type "+        <> msg (typename clientTypeName)+        <> " Should Have at least one Constructor"+deriveFromJSON ClientTypeDefinition {clientTypeName, clientCons, clientKind = KindEnum} =+  defineFromJSON clientTypeName $+    aesonFromJSONEnumBody clientTypeName clientCons deriveFromJSON   ClientTypeDefinition     { clientTypeName = clientTypeName@TypeNameTH {namespace},@@ -139,13 +138,9 @@     } =     defineFromJSON clientTypeName $       aesonObject namespace cons-deriveFromJSON typeD@ClientTypeDefinition {clientTypeName, clientCons}-  | isEnum clientCons =-    defineFromJSON clientTypeName $-      aesonFromJSONEnumBody clientTypeName clientCons-  | otherwise =-    defineFromJSON clientTypeName $-      aesonUnionObject typeD+deriveFromJSON typeD@ClientTypeDefinition {clientTypeName} =+  defineFromJSON clientTypeName $+    aesonUnionObject typeD  aesonObject :: [FieldName] -> ClientConstructorDefinition -> ExpQ aesonObject tNamespace con@ClientConstructorDefinition {cName} =@@ -193,7 +188,7 @@ takeValueType :: ((String, Object) -> Parser a) -> Value -> Parser a takeValueType f (Object hMap) = case lookup "__typename" hMap of   Nothing -> fail "key \"__typename\" not found on object"-  Just (String x) -> pure (T.unpack x, hMap) >>= f+  Just (String x) -> f (T.unpack x, hMap)   Just val ->     fail $ "key \"__typename\" should be string but found: " <> show val takeValueType _ _ = fail "expected Object"@@ -235,6 +230,15 @@     fail "Type Should Have at least one Constructor" deriveToJSON   ClientTypeDefinition+    { clientTypeName = clientTypeName@TypeNameTH {typename},+      clientCons,+      clientKind = KindEnum+    } = instanceD (cxt []) typeDef body+    where+      typeDef = applyCons ''ToJSON [typename]+      body = [funDSimple 'toJSON [] (aesonToJSONEnumBody clientTypeName clientCons)]+deriveToJSON+  ClientTypeDefinition     { clientTypeName = TypeNameTH {typename},       clientCons = [ClientConstructorDefinition {cFields}]     } =@@ -251,16 +255,7 @@               AppE                 (VarE 'omitNulls)                 (mkFieldsE typename '(.=) cFields)-deriveToJSON-  ClientTypeDefinition-    { clientTypeName = clientTypeName@TypeNameTH {typename},-      clientCons-    }-    | isEnum clientCons = instanceD (cxt []) typeDef body-    | otherwise = fail "Input Unions are not yet supported"-    where-      typeDef = applyCons ''ToJSON [typename]-      body = [funDSimple 'toJSON [] (aesonToJSONEnumBody clientTypeName clientCons)]+deriveToJSON _ = fail "Input Unions are not yet supported"  omitNulls :: [Pair] -> Value omitNulls = object . filter notNull
test/Case/Enum/Test.hs view
@@ -33,6 +33,7 @@     query MyQuery( $inputCity: City!) {       city(city:$inputCity)       cities+      planets     }   |] @@ -51,6 +52,9 @@                 CityCorinth,                 CityDelphi,                 CityArgos+              ],+            planets =+              [ PlanetEarth               ]           }     )
test/Case/Enum/response.json view
@@ -1,6 +1,7 @@ {   "data": {     "city": "Athens",-    "cities": ["Athens", "Sparta", "Corinth", "delphi", "argos"]+    "cities": ["Athens", "Sparta", "Corinth", "delphi", "argos"],+    "planets": ["Earth"]   } }
test/Case/Enum/schema.gql view
@@ -7,7 +7,12 @@   argos } +enum Planet {+  Earth+}+ type Query {   city(city: City!): City!   cities: [City!]!+  planets: [Planet!]! }