Skip to content

Commit

Permalink
add VarTypeName instance for Date
Browse files Browse the repository at this point in the history
  • Loading branch information
noisyscanner committed Sep 6, 2023
1 parent c8861d6 commit 366c903
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/GraphQL/Client/Variables/TypeName.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module GraphQL.Client.Variables.TypeName where
import Prelude

import Data.Argonaut.Core (Json)
import Data.Date (Date)
import Data.Maybe (Maybe)
import Data.String.CodeUnits (dropRight, takeRight)
import Data.Symbol (class IsSymbol, reflectSymbol)
Expand Down Expand Up @@ -38,21 +39,25 @@ instance varTypeNameMaybe :: VarTypeName a => VarTypeName (Maybe a) where
else
inner

data VarTypeNameProps
= VarTypeNameProps
instance VarTypeName Date where
varTypeName _ = "date!"

data VarTypeNameProps = VarTypeNameProps

instance varTypeNameProps ::
(VarTypeName a, IsSymbol sym) =>
( VarTypeName a
, IsSymbol sym
) =>
FoldingWithIndex VarTypeNameProps (Proxy sym) String a String where
foldingWithIndex VarTypeNameProps prop str _ = pre <> reflectSymbol prop <> ": " <> varTypeName (Proxy :: _ a)
where
pre
| str == "" = "$"
| otherwise = str <> ", $"

varTypeNameRecord ::
forall r.
HFoldlWithIndex VarTypeNameProps String { | r } String =>
{ | r } ->
String
varTypeNameRecord
:: forall r
. HFoldlWithIndex VarTypeNameProps String { | r } String
=> { | r }
-> String
varTypeNameRecord r = "( " <> hfoldlWithIndex VarTypeNameProps "" r <> " )"

0 comments on commit 366c903

Please sign in to comment.