Skip to content

Commit 2f7af43

Browse files
committed
Add instance for AndArgs
1 parent f9c5b57 commit 2f7af43

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/GraphQL/Client/Variables.purs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import Data.String.CodeUnits (charAt)
3636
import Data.Symbol (class IsSymbol, reflectSymbol)
3737
import GraphQL.Client.Alias (Alias)
3838
import GraphQL.Client.Alias.Dynamic (Spread)
39-
import GraphQL.Client.Args (AndArg, Args, NotNull, OrArg)
39+
import GraphQL.Client.Args (AndArg, AndArgs, Args, NotNull, OrArg)
4040
import GraphQL.Client.AsGql (AsGql)
4141
import GraphQL.Client.Directive (ApplyDirective(..))
4242
import GraphQL.Client.ErrorBoundary (ErrorBoundary)
@@ -126,6 +126,15 @@ else instance getVarAndArg ::
126126
) =>
127127
GetVar (AndArg l r) { | var } where
128128
getVar _ = Proxy
129+
else instance getVarAndArgs ::
130+
( GetVar l { | varL }
131+
, GetVar r { | varR }
132+
, Row.Union varR varL trash
133+
, Row.Union varL varR trash -- keep both union directions to make sure value type is the same
134+
, Row.Nub trash var
135+
) =>
136+
GetVar (AndArgs l r) { | var } where
137+
getVar _ = Proxy
129138
else instance getVarOrArg ::
130139
( GetVar l { | varL }
131140
, GetVar r { | varR }
@@ -229,19 +238,19 @@ else instance varsTypeCheckedWithoutVars ::
229238

230239
else instance varsTypeCheckedIdentity ::
231240
GetVar query {} =>
232-
VarsTypeChecked schema (Identity query) where
241+
VarsTypeChecked schema (Identity query) where
233242
getVarsJson _ _ = jsonEmptyObject
234243
getVarsTypeNames _ _ = ""
235244

236245
else instance varsTypeCheckedErrorBoundary ::
237246
GetVar query {} =>
238247
VarsTypeChecked schema (ErrorBoundary query) where
239248
getVarsJson _ _ = jsonEmptyObject
240-
getVarsTypeNames _ _ = ""
249+
getVarsTypeNames _ _ = ""
241250

242251
else instance varsTypeCheckedUnion ::
243252
GetVar { | query } {} =>
244-
VarsTypeChecked schema (GqlUnion query) where
253+
VarsTypeChecked schema (GqlUnion query) where
245254
getVarsJson _ _ = jsonEmptyObject
246255
getVarsTypeNames _ _ = ""
247256

test/GraphQL/Client/Variable.Test.purs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Prelude
55
import Data.Maybe (Maybe(..))
66
import GraphQL.Client.Alias ((:))
77
import GraphQL.Client.Alias.Dynamic (Spread(..))
8-
import GraphQL.Client.Args (OrArg(..), (++), (=>>))
8+
import GraphQL.Client.Args (OrArg(..), (++), (=>>), (+++))
99
import GraphQL.Client.AsGql (AsGql)
1010
import GraphQL.Client.Variable (Var(..))
1111
import GraphQL.Client.Variables (class GetGqlQueryVars, getQueryVars, getVarsTypeNames, withVars)
@@ -284,6 +284,20 @@ testArgs
284284
}
285285
testArgs = getQueryVars ((Var :: _ "idVar" Int) =>> { name: unit })
286286

287+
testAndArg
288+
:: Proxy
289+
{ aVar :: Int
290+
, bVar :: Number
291+
}
292+
testAndArg =
293+
getQueryVars
294+
( { a:
295+
Var :: _ "aVar" Int
296+
}
297+
++ { b: Var :: _ "bVar" Number }
298+
=>> { name: unit }
299+
)
300+
287301
testAndArgs
288302
:: Proxy
289303
{ aVar :: Int
@@ -294,7 +308,7 @@ testAndArgs =
294308
( { a:
295309
Var :: _ "aVar" Int
296310
}
297-
++ { b: Var :: _ "bVar" Number }
311+
+++ { b: Var :: _ "bVar" Number }
298312
=>> { name: unit }
299313
)
300314

0 commit comments

Comments
 (0)