Skip to content

Commit 5a9f7b9

Browse files
committed
Allow Variants as well as data type enums
1 parent f9fa0cc commit 5a9f7b9

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/GraphQL/Client/Args.purs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Data.Bifunctor (class Bifunctor)
77
import Data.Maybe (Maybe)
88
import Data.Newtype (class Newtype)
99
import Data.Symbol (class IsSymbol)
10+
import Data.Variant (Variant)
1011
import GraphQL.Client.Args.AllowedMismatch (AllowedMismatch)
1112
import GraphQL.Client.AsGql (AsGql)
1213
import GraphQL.Client.NullArray (NullArray)
@@ -70,7 +71,8 @@ class ArgGqlAt at params arg
7071
instance argAsGql :: ArgGqlAt at param arg => ArgGqlAt at (AsGql gqlName param) arg
7172
else instance argToGqlNotNull :: (IsNotNull at param arg, ArgGqlAt at param arg) => ArgGqlAt at (NotNull param) arg
7273
else instance argToGqlIgnore :: ArgGqlAt at param IgnoreArg
73-
else instance argVarJson :: ArgGqlAt at Json (Var sym Json) -- Json can only be used with a variable
74+
else instance argToGqlVariant :: (Union r () params) => ArgGqlAt at (Variant params) (Variant r)
75+
else instance argVarJson :: ArgGqlAt at Json (Var sym Json) -- Json can only be used with a variable
7476
else instance argToGqlJsonNotAllowed :: TE.Fail (TE.Text "A `Json` query argument can only be used as a variable ") => ArgGqlAt at Json Json
7577
else instance argVar :: ArgGqlAt at param arg => ArgGqlAt at param (Var sym arg)
7678
else instance argToGqlArrayNull :: ArgGqlAt at (Array param) NullArray

src/GraphQL/Client/ToGqlString.purs

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Data.String.Regex.Flags (global)
5656
import Data.String.Regex.Unsafe (unsafeRegex)
5757
import Data.Symbol (class IsSymbol, reflectSymbol)
5858
import Data.Time (Time)
59+
import Data.Variant (Unvariant(..), Variant, unvariant)
5960
import Foreign (Foreign)
6061
import Foreign.Object (Object)
6162
import Foreign.Object as Object
@@ -317,6 +318,8 @@ else instance gqlArgStringErrorBoundary :: GqlArgString a => GqlArgString (Error
317318
toGqlArgStringImpl (ErrorBoundary a) = toGqlArgStringImpl a
318319
else instance gqlArgStringAllowedMismatch :: GqlArgString a => GqlArgString (AllowedMismatch t a) where
319320
toGqlArgStringImpl = unwrap >>> toGqlArgStringImpl
321+
else instance gqlargVariant :: GqlArgString (Variant r) where
322+
toGqlArgStringImpl v = unvariant v # \(Unvariant f) -> f \p _ -> reflectSymbol p
320323
else instance gqlArgStringVar :: IsSymbol sym => GqlArgString (Var sym a) where
321324
toGqlArgStringImpl _ = "$" <> reflectSymbol (Proxy :: Proxy sym)
322325
else instance gqlArgStringOrArg ::

0 commit comments

Comments
 (0)