From fd63f421d8423ac94113c54b2a0c55755023dc9f Mon Sep 17 00:00:00 2001 From: Rory Campbell Date: Fri, 15 Sep 2023 15:38:04 +0100 Subject: [PATCH] put AsGql first and add at to notnull class --- src/GraphQL/Client/Args.purs | 71 ++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/GraphQL/Client/Args.purs b/src/GraphQL/Client/Args.purs index 3d3c27a..568104e 100644 --- a/src/GraphQL/Client/Args.purs +++ b/src/GraphQL/Client/Args.purs @@ -59,31 +59,30 @@ guardArg b args = onlyArgs :: forall a. a -> Args a Unit onlyArgs a = Args a unit - class ArgGql :: forall param arg. param -> arg -> Constraint -class ArgGql params args +class ArgGql params args instance ArgGqlAt any params args => ArgGql params args class ArgGqlAt :: forall param arg. Symbol -> param -> arg -> Constraint class ArgGqlAt at params arg -instance argToGqlNotNull :: (IsNotNull param arg, ArgGqlAt at param arg) => ArgGqlAt at (NotNull param) arg -else instance argToGqlIgnore :: ArgGqlAt at param IgnoreArg -else instance argAsGql :: ArgGqlAt at param arg => ArgGqlAt at (AsGql gqlName param) arg -else instance argVarJson :: ArgGqlAt at Json (Var sym Json) -- Json can only be used with a variable -else instance argToGqlJsonNotAllowed :: TE.Fail (TE.Text "A `Json` query argument can only be used as a variable ") => ArgGqlAt at Json Json -else instance argVar :: ArgGqlAt at param arg => ArgGqlAt at param (Var sym arg) -else instance argToGqlArrayNull :: ArgGqlAt at (Array param) NullArray -else instance argToGqlArrayAnds :: (ArgGqlAt at (Array param) a1, ArgGqlAt at (Array param) a2) => ArgGqlAt at (Array param) (AndArgs a1 a2) -else instance argToGqlOrArg :: (ArgGqlAt at param argL, ArgGqlAt at param argR) => ArgGqlAt at param (OrArg argL argR) -else instance argToGqlMaybe :: ArgGqlAt at param arg => ArgGqlAt at param (Maybe arg) -else instance argToGqlArray :: ArgGqlAt at param arg => ArgGqlAt at (Array param) (Array arg) -else instance argToGqlArrayOne :: ArgGqlAt at param arg => ArgGqlAt at (Array param) arg -else instance argToGqlRecord :: RecordArg p a u => ArgGqlAt at { | p } { | a } -else instance allowedArgMismatch :: ArgGqlAt at p schemaType => ArgGqlAt at p (AllowedMismatch schemaType a) -else instance argGqlIdentity :: ArgGqlAt at a a -else instance argToGqlNewtypeRecord :: (Newtype n { | p }, RecordArg p a u) => ArgGqlAt at n { | a } +instance argAsGql :: ArgGqlAt at param arg => ArgGqlAt at (AsGql gqlName param) arg +else instance argToGqlNotNull :: (IsNotNull at param arg, ArgGqlAt at param arg) => ArgGqlAt at (NotNull param) arg +else instance argToGqlIgnore :: ArgGqlAt at param IgnoreArg +else instance argVarJson :: ArgGqlAt at Json (Var sym Json) -- Json can only be used with a variable +else instance argToGqlJsonNotAllowed :: TE.Fail (TE.Text "A `Json` query argument can only be used as a variable ") => ArgGqlAt at Json Json +else instance argVar :: ArgGqlAt at param arg => ArgGqlAt at param (Var sym arg) +else instance argToGqlArrayNull :: ArgGqlAt at (Array param) NullArray +else instance argToGqlArrayAnds :: (ArgGqlAt at (Array param) a1, ArgGqlAt at (Array param) a2) => ArgGqlAt at (Array param) (AndArgs a1 a2) +else instance argToGqlOrArg :: (ArgGqlAt at param argL, ArgGqlAt at param argR) => ArgGqlAt at param (OrArg argL argR) +else instance argToGqlMaybe :: ArgGqlAt at param arg => ArgGqlAt at param (Maybe arg) +else instance argToGqlArray :: ArgGqlAt at param arg => ArgGqlAt at (Array param) (Array arg) +else instance argToGqlArrayOne :: ArgGqlAt at param arg => ArgGqlAt at (Array param) arg +else instance argToGqlRecord :: RecordArg p a u => ArgGqlAt at { | p } { | a } +else instance allowedArgMismatch :: ArgGqlAt at p schemaType => ArgGqlAt at p (AllowedMismatch schemaType a) +else instance argGqlIdentity :: ArgGqlAt at a a +else instance argToGqlNewtypeRecord :: (Newtype n { | p }, RecordArg p a u) => ArgGqlAt at n { | a } else instance argMismatch :: ( TE.Fail ( TE.Above @@ -92,16 +91,17 @@ else instance argMismatch :: (TE.Text " ") ( TE.Above (TE.Beside (TE.Text "Schema: ") (TE.Quote param)) - (TE.Above (TE.Beside (TE.Text "Query: ") (TE.Quote arg)) - (TE.Beside (TE.Text "At: ") (TE.Quote at))) + ( TE.Above (TE.Beside (TE.Text "Query: ") (TE.Quote arg)) + (TE.Beside (TE.Text "At: ") (TE.Quote at)) + ) ) ) ) ) => ArgGqlAt at param arg -class IsNotNull :: forall k1 k2. k1 -> k2 -> Constraint -class IsNotNull param arg +class IsNotNull :: forall k1 k2. Symbol -> k1 -> k2 -> Constraint +class IsNotNull at param arg instance ( TE.Fail @@ -111,12 +111,14 @@ instance (TE.Text " ") ( TE.Above (TE.Beside (TE.Text "Schema: ") (TE.Quote param)) - (TE.Beside (TE.Text "Query: ") (TE.Quote (Maybe arg))) + ( TE.Above (TE.Beside (TE.Text "Query: ") (TE.Quote arg)) + (TE.Beside (TE.Text "At: ") (TE.Quote at)) + ) ) ) ) ) => - IsNotNull param (Maybe arg) + IsNotNull at param (Maybe arg) else instance ( TE.Fail @@ -126,22 +128,24 @@ else instance (TE.Text " ") ( TE.Above (TE.Beside (TE.Text "Schema: ") (TE.Quote param)) - (TE.Beside (TE.Text "Query: ") (TE.Quote IgnoreArg)) + ( TE.Above (TE.Beside (TE.Text "Query: ") (TE.Quote IgnoreArg)) + (TE.Beside (TE.Text "At: ") (TE.Quote at)) + ) ) ) ) ) => - IsNotNull param IgnoreArg + IsNotNull at param IgnoreArg else instance - ( IsNotNull param arg + ( IsNotNull at param arg ) => - IsNotNull (AsGql gqlName param) arg + IsNotNull at (AsGql gqlName param) arg else instance - ( IsNotNull param l - , IsNotNull param r + ( IsNotNull at param l + , IsNotNull at param r ) => - IsNotNull param (OrArg l r) -else instance IsNotNull param arg + IsNotNull at param (OrArg l r) +else instance IsNotNull at param arg class HMapWithIndex (ArgPropToGql p) { | a } u <= RecordArg p a u @@ -179,6 +183,3 @@ else instance argsSatisifyOthers_ :: FoldingWithIndex (ArgsSatisifyNotNullsProps args) (Proxy sym) Unit param Unit where foldingWithIndex (ArgsSatisifyNotNullsProps _) _ _ _ = unit - - -