diff --git a/spago.dhall b/spago.dhall index 17c2d2e..3384ef8 100644 --- a/spago.dhall +++ b/spago.dhall @@ -29,6 +29,7 @@ You can edit this file as you like. , "halogen-subscriptions" , "heterogeneous" , "http-methods" + , "identity" , "integers" , "lists" , "maybe" diff --git a/src/GraphQL/Client/QueryReturns.purs b/src/GraphQL/Client/QueryReturns.purs index e5037b8..1c5a617 100644 --- a/src/GraphQL/Client/QueryReturns.purs +++ b/src/GraphQL/Client/QueryReturns.purs @@ -8,6 +8,7 @@ module GraphQL.Client.QueryReturns import Prelude +import Data.Identity (Identity(..)) import Data.Maybe (Maybe) import Data.Newtype (class Newtype, unwrap) import Data.Symbol (class IsSymbol) @@ -55,6 +56,8 @@ else instance queryReturnsGqlType :: QueryReturnsAt at a q t => QueryReturnsAt a queryReturnsAtImpl at _ q = queryReturnsAtImpl at (undefined :: a) q else instance queryReturnsApplyDirective :: QueryReturnsAt at a q t => QueryReturnsAt at a (ApplyDirective name args q) t where queryReturnsAtImpl at a _ = queryReturnsAtImpl at a (undefined :: q) +else instance queryReturnsIdentity :: QueryReturnsAt at a q t => QueryReturnsAt at a (Identity q) (Identity t) where + queryReturnsAtImpl at a _ = Identity $ queryReturnsAtImpl at a (undefined :: q) else instance queryReturnErrorBoundary :: QueryReturnsAt at a q t => QueryReturnsAt at a (ErrorBoundary q) (BoundaryResult Unit t) where queryReturnsAtImpl at a _ = ErrorBoundary.Result $ queryReturnsAtImpl at a (undefined :: q) else instance queryReturnsSpread :: @@ -75,9 +78,9 @@ else instance queryReturnsArray :: QueryReturnsAt at a q t => QueryReturnsAt at else instance queryReturnsMaybe :: QueryReturnsAt at a q t => QueryReturnsAt at (Maybe a) q (Maybe t) where queryReturnsAtImpl at _ q = pure $ queryReturnsAtImpl at (undefined :: a) q else instance queryReturnsUnion :: - HMapWithIndex (PropToSchemaType schema) (Record query) (Record returns) => + HMapWithIndex (PropToSchemaType schema) { | query} { | returns } => QueryReturnsAt at (GqlUnion schema) (GqlUnion query) (UnionReturned returns) where - queryReturnsAtImpl at _ _ = undefined + queryReturnsAtImpl _ _ _ = undefined else instance queryReturnsParamsArgs :: ( QueryReturnsAt at t q result , HMapWithIndex (ArgPropToGql params) { | args } s diff --git a/src/GraphQL/Client/ToGqlString.purs b/src/GraphQL/Client/ToGqlString.purs index f9335d4..fc8b906 100644 --- a/src/GraphQL/Client/ToGqlString.purs +++ b/src/GraphQL/Client/ToGqlString.purs @@ -41,6 +41,7 @@ import Data.DateTime as DT import Data.Enum (class BoundedEnum, fromEnum) import Data.FoldableWithIndex (foldlWithIndex) import Data.Function (on) +import Data.Identity (Identity(..)) import Data.List (List) import Data.List as List import Data.Map (Map) @@ -108,6 +109,8 @@ else instance gqlQueryStringApplyDirective :: <> reflectSymbol (Proxy :: Proxy name) <> gqlArgStringRecordTopLevel args <> toGqlQueryStringImpl opts q +else instance gqlQueryStringIdentity :: GqlQueryString a => GqlQueryString (Identity a) where + toGqlQueryStringImpl opts (Identity a) = toGqlQueryStringImpl opts a else instance gqlQueryStringErrorBoundary :: GqlQueryString a => GqlQueryString (ErrorBoundary a) where toGqlQueryStringImpl opts (ErrorBoundary a) = toGqlQueryStringImpl opts a else instance gqlQueryStringSymbol :: IsSymbol s => GqlQueryString (Proxy s) where @@ -484,4 +487,3 @@ else instance isIgnoreArgOrArg :: (IsIgnoreArg l, IsIgnoreArg r) => IsIgnoreArg ArgR r -> isIgnoreArg r else instance isIgnoreArgOther :: IsIgnoreArg a where isIgnoreArg _ = false - diff --git a/test/GraphQL/Client/QueryReturns.Test.purs b/test/GraphQL/Client/QueryReturns.Test.purs index d078707..5b5cc25 100644 --- a/test/GraphQL/Client/QueryReturns.Test.purs +++ b/test/GraphQL/Client/QueryReturns.Test.purs @@ -2,6 +2,7 @@ module GraphQL.Client.QueryReturns.Test where import Prelude +import Data.Identity (Identity(..)) import Data.Maybe (Maybe(..)) import Data.Newtype (class Newtype) import GraphQL.Client.Alias ((:)) @@ -328,6 +329,23 @@ testDirective = =>> { id } } +testIdentity + :: Proxy + { users :: + Array + { id :: Identity Int + } + } +testIdentity = + queryReturns testSchemaProxy + $ + { users: + { is_in_rec: + [ { int: 0 } ] +++ ((ArgR [ ignoreOrStr true, ignoreOrStr false ]) :: OrArg IgnoreArg _) + } + =>> { id: Identity id } + } + ignoreOrStr :: Boolean -> OrArg IgnoreArg