Skip to content

Commit

Permalink
Allow Variants as well as data type enums
Browse files Browse the repository at this point in the history
  • Loading branch information
finnhodgkin committed Sep 25, 2024
1 parent f9fa0cc commit 5a9f7b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/GraphQL/Client/Args.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Data.Bifunctor (class Bifunctor)
import Data.Maybe (Maybe)
import Data.Newtype (class Newtype)
import Data.Symbol (class IsSymbol)
import Data.Variant (Variant)
import GraphQL.Client.Args.AllowedMismatch (AllowedMismatch)
import GraphQL.Client.AsGql (AsGql)
import GraphQL.Client.NullArray (NullArray)
Expand Down Expand Up @@ -70,7 +71,8 @@ class ArgGqlAt at params arg
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 argToGqlVariant :: (Union r () params) => ArgGqlAt at (Variant params) (Variant r)
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
Expand Down
3 changes: 3 additions & 0 deletions src/GraphQL/Client/ToGqlString.purs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import Data.String.Regex.Flags (global)
import Data.String.Regex.Unsafe (unsafeRegex)
import Data.Symbol (class IsSymbol, reflectSymbol)
import Data.Time (Time)
import Data.Variant (Unvariant(..), Variant, unvariant)
import Foreign (Foreign)
import Foreign.Object (Object)
import Foreign.Object as Object
Expand Down Expand Up @@ -317,6 +318,8 @@ else instance gqlArgStringErrorBoundary :: GqlArgString a => GqlArgString (Error
toGqlArgStringImpl (ErrorBoundary a) = toGqlArgStringImpl a
else instance gqlArgStringAllowedMismatch :: GqlArgString a => GqlArgString (AllowedMismatch t a) where
toGqlArgStringImpl = unwrap >>> toGqlArgStringImpl
else instance gqlargVariant :: GqlArgString (Variant r) where
toGqlArgStringImpl v = unvariant v # \(Unvariant f) -> f \p _ -> reflectSymbol p
else instance gqlArgStringVar :: IsSymbol sym => GqlArgString (Var sym a) where
toGqlArgStringImpl _ = "$" <> reflectSymbol (Proxy :: Proxy sym)
else instance gqlArgStringOrArg ::
Expand Down

0 comments on commit 5a9f7b9

Please sign in to comment.