{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}

module Hasura.RQL.IR.Returning
  ( MutFld,
    MutFldG (..),
    _MCount,
    _MExp,
    _MRet,
    MutFlds,
    MutFldsG,
    MutationOutput,
    MutationOutputG (..),
    buildEmptyMutResp,
    hasNestedFld,
  )
where

import Control.Lens.TH (makePrisms)
import Data.Aeson qualified as J
import Data.HashMap.Strict.InsOrd qualified as OMap
import Data.Kind (Type)
import Hasura.EncJSON
import Hasura.Prelude
import Hasura.RQL.IR.Select
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.Common
import Hasura.SQL.Backend

data MutFldG (b :: BackendType) (r :: Type) v
  = MCount
  | MExp Text
  | MRet (AnnFieldsG b r v)
  deriving stock (a -> MutFldG b r b -> MutFldG b r a
(a -> b) -> MutFldG b r a -> MutFldG b r b
(forall a b. (a -> b) -> MutFldG b r a -> MutFldG b r b)
-> (forall a b. a -> MutFldG b r b -> MutFldG b r a)
-> Functor (MutFldG b r)
forall a b. a -> MutFldG b r b -> MutFldG b r a
forall a b. (a -> b) -> MutFldG b r a -> MutFldG b r b
forall (b :: BackendType) r a b.
Backend b =>
a -> MutFldG b r b -> MutFldG b r a
forall (b :: BackendType) r a b.
Backend b =>
(a -> b) -> MutFldG b r a -> MutFldG b r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> MutFldG b r b -> MutFldG b r a
$c<$ :: forall (b :: BackendType) r a b.
Backend b =>
a -> MutFldG b r b -> MutFldG b r a
fmap :: (a -> b) -> MutFldG b r a -> MutFldG b r b
$cfmap :: forall (b :: BackendType) r a b.
Backend b =>
(a -> b) -> MutFldG b r a -> MutFldG b r b
Functor, MutFldG b r a -> Bool
(a -> m) -> MutFldG b r a -> m
(a -> b -> b) -> b -> MutFldG b r a -> b
(forall m. Monoid m => MutFldG b r m -> m)
-> (forall m a. Monoid m => (a -> m) -> MutFldG b r a -> m)
-> (forall m a. Monoid m => (a -> m) -> MutFldG b r a -> m)
-> (forall a b. (a -> b -> b) -> b -> MutFldG b r a -> b)
-> (forall a b. (a -> b -> b) -> b -> MutFldG b r a -> b)
-> (forall b a. (b -> a -> b) -> b -> MutFldG b r a -> b)
-> (forall b a. (b -> a -> b) -> b -> MutFldG b r a -> b)
-> (forall a. (a -> a -> a) -> MutFldG b r a -> a)
-> (forall a. (a -> a -> a) -> MutFldG b r a -> a)
-> (forall a. MutFldG b r a -> [a])
-> (forall a. MutFldG b r a -> Bool)
-> (forall a. MutFldG b r a -> Int)
-> (forall a. Eq a => a -> MutFldG b r a -> Bool)
-> (forall a. Ord a => MutFldG b r a -> a)
-> (forall a. Ord a => MutFldG b r a -> a)
-> (forall a. Num a => MutFldG b r a -> a)
-> (forall a. Num a => MutFldG b r a -> a)
-> Foldable (MutFldG b r)
forall a. Eq a => a -> MutFldG b r a -> Bool
forall a. Num a => MutFldG b r a -> a
forall a. Ord a => MutFldG b r a -> a
forall m. Monoid m => MutFldG b r m -> m
forall a. MutFldG b r a -> Bool
forall a. MutFldG b r a -> Int
forall a. MutFldG b r a -> [a]
forall a. (a -> a -> a) -> MutFldG b r a -> a
forall m a. Monoid m => (a -> m) -> MutFldG b r a -> m
forall b a. (b -> a -> b) -> b -> MutFldG b r a -> b
forall a b. (a -> b -> b) -> b -> MutFldG b r a -> b
forall (b :: BackendType) r a.
(Backend b, Eq a) =>
a -> MutFldG b r a -> Bool
forall (b :: BackendType) r a.
(Backend b, Num a) =>
MutFldG b r a -> a
forall (b :: BackendType) r a.
(Backend b, Ord a) =>
MutFldG b r a -> a
forall (b :: BackendType) r m.
(Backend b, Monoid m) =>
MutFldG b r m -> m
forall (b :: BackendType) r a. Backend b => MutFldG b r a -> Bool
forall (b :: BackendType) r a. Backend b => MutFldG b r a -> Int
forall (b :: BackendType) r a. Backend b => MutFldG b r a -> [a]
forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> MutFldG b r a -> a
forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> MutFldG b r a -> m
forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> MutFldG b r a -> b
forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> MutFldG b r a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: MutFldG b r a -> a
$cproduct :: forall (b :: BackendType) r a.
(Backend b, Num a) =>
MutFldG b r a -> a
sum :: MutFldG b r a -> a
$csum :: forall (b :: BackendType) r a.
(Backend b, Num a) =>
MutFldG b r a -> a
minimum :: MutFldG b r a -> a
$cminimum :: forall (b :: BackendType) r a.
(Backend b, Ord a) =>
MutFldG b r a -> a
maximum :: MutFldG b r a -> a
$cmaximum :: forall (b :: BackendType) r a.
(Backend b, Ord a) =>
MutFldG b r a -> a
elem :: a -> MutFldG b r a -> Bool
$celem :: forall (b :: BackendType) r a.
(Backend b, Eq a) =>
a -> MutFldG b r a -> Bool
length :: MutFldG b r a -> Int
$clength :: forall (b :: BackendType) r a. Backend b => MutFldG b r a -> Int
null :: MutFldG b r a -> Bool
$cnull :: forall (b :: BackendType) r a. Backend b => MutFldG b r a -> Bool
toList :: MutFldG b r a -> [a]
$ctoList :: forall (b :: BackendType) r a. Backend b => MutFldG b r a -> [a]
foldl1 :: (a -> a -> a) -> MutFldG b r a -> a
$cfoldl1 :: forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> MutFldG b r a -> a
foldr1 :: (a -> a -> a) -> MutFldG b r a -> a
$cfoldr1 :: forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> MutFldG b r a -> a
foldl' :: (b -> a -> b) -> b -> MutFldG b r a -> b
$cfoldl' :: forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> MutFldG b r a -> b
foldl :: (b -> a -> b) -> b -> MutFldG b r a -> b
$cfoldl :: forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> MutFldG b r a -> b
foldr' :: (a -> b -> b) -> b -> MutFldG b r a -> b
$cfoldr' :: forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> MutFldG b r a -> b
foldr :: (a -> b -> b) -> b -> MutFldG b r a -> b
$cfoldr :: forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> MutFldG b r a -> b
foldMap' :: (a -> m) -> MutFldG b r a -> m
$cfoldMap' :: forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> MutFldG b r a -> m
foldMap :: (a -> m) -> MutFldG b r a -> m
$cfoldMap :: forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> MutFldG b r a -> m
fold :: MutFldG b r m -> m
$cfold :: forall (b :: BackendType) r m.
(Backend b, Monoid m) =>
MutFldG b r m -> m
Foldable, Functor (MutFldG b r)
Foldable (MutFldG b r)
Functor (MutFldG b r)
-> Foldable (MutFldG b r)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> MutFldG b r a -> f (MutFldG b r b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    MutFldG b r (f a) -> f (MutFldG b r a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> MutFldG b r a -> m (MutFldG b r b))
-> (forall (m :: * -> *) a.
    Monad m =>
    MutFldG b r (m a) -> m (MutFldG b r a))
-> Traversable (MutFldG b r)
(a -> f b) -> MutFldG b r a -> f (MutFldG b r b)
forall (b :: BackendType) r. Backend b => Functor (MutFldG b r)
forall (b :: BackendType) r. Backend b => Foldable (MutFldG b r)
forall (b :: BackendType) r (m :: * -> *) a.
(Backend b, Monad m) =>
MutFldG b r (m a) -> m (MutFldG b r a)
forall (b :: BackendType) r (f :: * -> *) a.
(Backend b, Applicative f) =>
MutFldG b r (f a) -> f (MutFldG b r a)
forall (b :: BackendType) r (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b) -> MutFldG b r a -> m (MutFldG b r b)
forall (b :: BackendType) r (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b) -> MutFldG b r a -> f (MutFldG b r b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
MutFldG b r (m a) -> m (MutFldG b r a)
forall (f :: * -> *) a.
Applicative f =>
MutFldG b r (f a) -> f (MutFldG b r a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MutFldG b r a -> m (MutFldG b r b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MutFldG b r a -> f (MutFldG b r b)
sequence :: MutFldG b r (m a) -> m (MutFldG b r a)
$csequence :: forall (b :: BackendType) r (m :: * -> *) a.
(Backend b, Monad m) =>
MutFldG b r (m a) -> m (MutFldG b r a)
mapM :: (a -> m b) -> MutFldG b r a -> m (MutFldG b r b)
$cmapM :: forall (b :: BackendType) r (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b) -> MutFldG b r a -> m (MutFldG b r b)
sequenceA :: MutFldG b r (f a) -> f (MutFldG b r a)
$csequenceA :: forall (b :: BackendType) r (f :: * -> *) a.
(Backend b, Applicative f) =>
MutFldG b r (f a) -> f (MutFldG b r a)
traverse :: (a -> f b) -> MutFldG b r a -> f (MutFldG b r b)
$ctraverse :: forall (b :: BackendType) r (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b) -> MutFldG b r a -> f (MutFldG b r b)
$cp2Traversable :: forall (b :: BackendType) r. Backend b => Foldable (MutFldG b r)
$cp1Traversable :: forall (b :: BackendType) r. Backend b => Functor (MutFldG b r)
Traversable)

deriving stock instance
  ( Backend b,
    Show (AnnFieldsG b r v)
  ) =>
  Show (MutFldG b r v)

deriving stock instance
  ( Backend b,
    Eq (AnnFieldsG b r v)
  ) =>
  Eq (MutFldG b r v)

type MutFld b = MutFldG b Void (SQLExpression b)

type MutFldsG b r v = Fields (MutFldG b r v)

data MutationOutputG (b :: BackendType) (r :: Type) v
  = MOutMultirowFields (MutFldsG b r v)
  | MOutSinglerowObject (AnnFieldsG b r v)
  deriving (a -> MutationOutputG b r b -> MutationOutputG b r a
(a -> b) -> MutationOutputG b r a -> MutationOutputG b r b
(forall a b.
 (a -> b) -> MutationOutputG b r a -> MutationOutputG b r b)
-> (forall a b.
    a -> MutationOutputG b r b -> MutationOutputG b r a)
-> Functor (MutationOutputG b r)
forall a b. a -> MutationOutputG b r b -> MutationOutputG b r a
forall a b.
(a -> b) -> MutationOutputG b r a -> MutationOutputG b r b
forall (b :: BackendType) r a b.
Backend b =>
a -> MutationOutputG b r b -> MutationOutputG b r a
forall (b :: BackendType) r a b.
Backend b =>
(a -> b) -> MutationOutputG b r a -> MutationOutputG b r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> MutationOutputG b r b -> MutationOutputG b r a
$c<$ :: forall (b :: BackendType) r a b.
Backend b =>
a -> MutationOutputG b r b -> MutationOutputG b r a
fmap :: (a -> b) -> MutationOutputG b r a -> MutationOutputG b r b
$cfmap :: forall (b :: BackendType) r a b.
Backend b =>
(a -> b) -> MutationOutputG b r a -> MutationOutputG b r b
Functor, MutationOutputG b r a -> Bool
(a -> m) -> MutationOutputG b r a -> m
(a -> b -> b) -> b -> MutationOutputG b r a -> b
(forall m. Monoid m => MutationOutputG b r m -> m)
-> (forall m a. Monoid m => (a -> m) -> MutationOutputG b r a -> m)
-> (forall m a. Monoid m => (a -> m) -> MutationOutputG b r a -> m)
-> (forall a b. (a -> b -> b) -> b -> MutationOutputG b r a -> b)
-> (forall a b. (a -> b -> b) -> b -> MutationOutputG b r a -> b)
-> (forall b a. (b -> a -> b) -> b -> MutationOutputG b r a -> b)
-> (forall b a. (b -> a -> b) -> b -> MutationOutputG b r a -> b)
-> (forall a. (a -> a -> a) -> MutationOutputG b r a -> a)
-> (forall a. (a -> a -> a) -> MutationOutputG b r a -> a)
-> (forall a. MutationOutputG b r a -> [a])
-> (forall a. MutationOutputG b r a -> Bool)
-> (forall a. MutationOutputG b r a -> Int)
-> (forall a. Eq a => a -> MutationOutputG b r a -> Bool)
-> (forall a. Ord a => MutationOutputG b r a -> a)
-> (forall a. Ord a => MutationOutputG b r a -> a)
-> (forall a. Num a => MutationOutputG b r a -> a)
-> (forall a. Num a => MutationOutputG b r a -> a)
-> Foldable (MutationOutputG b r)
forall a. Eq a => a -> MutationOutputG b r a -> Bool
forall a. Num a => MutationOutputG b r a -> a
forall a. Ord a => MutationOutputG b r a -> a
forall m. Monoid m => MutationOutputG b r m -> m
forall a. MutationOutputG b r a -> Bool
forall a. MutationOutputG b r a -> Int
forall a. MutationOutputG b r a -> [a]
forall a. (a -> a -> a) -> MutationOutputG b r a -> a
forall m a. Monoid m => (a -> m) -> MutationOutputG b r a -> m
forall b a. (b -> a -> b) -> b -> MutationOutputG b r a -> b
forall a b. (a -> b -> b) -> b -> MutationOutputG b r a -> b
forall (b :: BackendType) r a.
(Backend b, Eq a) =>
a -> MutationOutputG b r a -> Bool
forall (b :: BackendType) r a.
(Backend b, Num a) =>
MutationOutputG b r a -> a
forall (b :: BackendType) r a.
(Backend b, Ord a) =>
MutationOutputG b r a -> a
forall (b :: BackendType) r m.
(Backend b, Monoid m) =>
MutationOutputG b r m -> m
forall (b :: BackendType) r a.
Backend b =>
MutationOutputG b r a -> Bool
forall (b :: BackendType) r a.
Backend b =>
MutationOutputG b r a -> Int
forall (b :: BackendType) r a.
Backend b =>
MutationOutputG b r a -> [a]
forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> MutationOutputG b r a -> a
forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> MutationOutputG b r a -> m
forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> MutationOutputG b r a -> b
forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> MutationOutputG b r a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: MutationOutputG b r a -> a
$cproduct :: forall (b :: BackendType) r a.
(Backend b, Num a) =>
MutationOutputG b r a -> a
sum :: MutationOutputG b r a -> a
$csum :: forall (b :: BackendType) r a.
(Backend b, Num a) =>
MutationOutputG b r a -> a
minimum :: MutationOutputG b r a -> a
$cminimum :: forall (b :: BackendType) r a.
(Backend b, Ord a) =>
MutationOutputG b r a -> a
maximum :: MutationOutputG b r a -> a
$cmaximum :: forall (b :: BackendType) r a.
(Backend b, Ord a) =>
MutationOutputG b r a -> a
elem :: a -> MutationOutputG b r a -> Bool
$celem :: forall (b :: BackendType) r a.
(Backend b, Eq a) =>
a -> MutationOutputG b r a -> Bool
length :: MutationOutputG b r a -> Int
$clength :: forall (b :: BackendType) r a.
Backend b =>
MutationOutputG b r a -> Int
null :: MutationOutputG b r a -> Bool
$cnull :: forall (b :: BackendType) r a.
Backend b =>
MutationOutputG b r a -> Bool
toList :: MutationOutputG b r a -> [a]
$ctoList :: forall (b :: BackendType) r a.
Backend b =>
MutationOutputG b r a -> [a]
foldl1 :: (a -> a -> a) -> MutationOutputG b r a -> a
$cfoldl1 :: forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> MutationOutputG b r a -> a
foldr1 :: (a -> a -> a) -> MutationOutputG b r a -> a
$cfoldr1 :: forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> MutationOutputG b r a -> a
foldl' :: (b -> a -> b) -> b -> MutationOutputG b r a -> b
$cfoldl' :: forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> MutationOutputG b r a -> b
foldl :: (b -> a -> b) -> b -> MutationOutputG b r a -> b
$cfoldl :: forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> MutationOutputG b r a -> b
foldr' :: (a -> b -> b) -> b -> MutationOutputG b r a -> b
$cfoldr' :: forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> MutationOutputG b r a -> b
foldr :: (a -> b -> b) -> b -> MutationOutputG b r a -> b
$cfoldr :: forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> MutationOutputG b r a -> b
foldMap' :: (a -> m) -> MutationOutputG b r a -> m
$cfoldMap' :: forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> MutationOutputG b r a -> m
foldMap :: (a -> m) -> MutationOutputG b r a -> m
$cfoldMap :: forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> MutationOutputG b r a -> m
fold :: MutationOutputG b r m -> m
$cfold :: forall (b :: BackendType) r m.
(Backend b, Monoid m) =>
MutationOutputG b r m -> m
Foldable, Functor (MutationOutputG b r)
Foldable (MutationOutputG b r)
Functor (MutationOutputG b r)
-> Foldable (MutationOutputG b r)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> MutationOutputG b r a -> f (MutationOutputG b r b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    MutationOutputG b r (f a) -> f (MutationOutputG b r a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> MutationOutputG b r a -> m (MutationOutputG b r b))
-> (forall (m :: * -> *) a.
    Monad m =>
    MutationOutputG b r (m a) -> m (MutationOutputG b r a))
-> Traversable (MutationOutputG b r)
(a -> f b) -> MutationOutputG b r a -> f (MutationOutputG b r b)
forall (b :: BackendType) r.
Backend b =>
Functor (MutationOutputG b r)
forall (b :: BackendType) r.
Backend b =>
Foldable (MutationOutputG b r)
forall (b :: BackendType) r (m :: * -> *) a.
(Backend b, Monad m) =>
MutationOutputG b r (m a) -> m (MutationOutputG b r a)
forall (b :: BackendType) r (f :: * -> *) a.
(Backend b, Applicative f) =>
MutationOutputG b r (f a) -> f (MutationOutputG b r a)
forall (b :: BackendType) r (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b) -> MutationOutputG b r a -> m (MutationOutputG b r b)
forall (b :: BackendType) r (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b) -> MutationOutputG b r a -> f (MutationOutputG b r b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
MutationOutputG b r (m a) -> m (MutationOutputG b r a)
forall (f :: * -> *) a.
Applicative f =>
MutationOutputG b r (f a) -> f (MutationOutputG b r a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MutationOutputG b r a -> m (MutationOutputG b r b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MutationOutputG b r a -> f (MutationOutputG b r b)
sequence :: MutationOutputG b r (m a) -> m (MutationOutputG b r a)
$csequence :: forall (b :: BackendType) r (m :: * -> *) a.
(Backend b, Monad m) =>
MutationOutputG b r (m a) -> m (MutationOutputG b r a)
mapM :: (a -> m b) -> MutationOutputG b r a -> m (MutationOutputG b r b)
$cmapM :: forall (b :: BackendType) r (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b) -> MutationOutputG b r a -> m (MutationOutputG b r b)
sequenceA :: MutationOutputG b r (f a) -> f (MutationOutputG b r a)
$csequenceA :: forall (b :: BackendType) r (f :: * -> *) a.
(Backend b, Applicative f) =>
MutationOutputG b r (f a) -> f (MutationOutputG b r a)
traverse :: (a -> f b) -> MutationOutputG b r a -> f (MutationOutputG b r b)
$ctraverse :: forall (b :: BackendType) r (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b) -> MutationOutputG b r a -> f (MutationOutputG b r b)
$cp2Traversable :: forall (b :: BackendType) r.
Backend b =>
Foldable (MutationOutputG b r)
$cp1Traversable :: forall (b :: BackendType) r.
Backend b =>
Functor (MutationOutputG b r)
Traversable)

deriving stock instance
  ( Backend b,
    Show (MutFldsG b r v),
    Show (AnnFieldsG b r v)
  ) =>
  Show (MutationOutputG b r v)

deriving stock instance
  ( Backend b,
    Eq (MutFldsG b r v),
    Eq (AnnFieldsG b r v)
  ) =>
  Eq (MutationOutputG b r v)

type MutationOutput b = MutationOutputG b Void (SQLExpression b)

type MutFlds b = MutFldsG b Void (SQLExpression b)

buildEmptyMutResp :: MutationOutput backend -> EncJSON
buildEmptyMutResp :: MutationOutput backend -> EncJSON
buildEmptyMutResp = \case
  MOutMultirowFields MutFldsG backend Void (SQLExpression backend)
mutFlds -> InsOrdHashMap FieldName Value -> EncJSON
forall a. ToJSON a => a -> EncJSON
encJFromJValue (InsOrdHashMap FieldName Value -> EncJSON)
-> InsOrdHashMap FieldName Value -> EncJSON
forall a b. (a -> b) -> a -> b
$ [(FieldName, Value)] -> InsOrdHashMap FieldName Value
forall k v. (Eq k, Hashable k) => [(k, v)] -> InsOrdHashMap k v
OMap.fromList ([(FieldName, Value)] -> InsOrdHashMap FieldName Value)
-> [(FieldName, Value)] -> InsOrdHashMap FieldName Value
forall a b. (a -> b) -> a -> b
$ ((FieldName, MutFldG backend Void (SQLExpression backend))
 -> (FieldName, Value))
-> MutFldsG backend Void (SQLExpression backend)
-> [(FieldName, Value)]
forall a b. (a -> b) -> [a] -> [b]
map ((MutFldG backend Void (SQLExpression backend) -> Value)
-> (FieldName, MutFldG backend Void (SQLExpression backend))
-> (FieldName, Value)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second MutFldG backend Void (SQLExpression backend) -> Value
forall (b :: BackendType) r v. MutFldG b r v -> Value
convMutFld) MutFldsG backend Void (SQLExpression backend)
mutFlds
  MOutSinglerowObject AnnFieldsG backend Void (SQLExpression backend)
_ -> Value -> EncJSON
forall a. ToJSON a => a -> EncJSON
encJFromJValue (Value -> EncJSON) -> Value -> EncJSON
forall a b. (a -> b) -> a -> b
$ Object -> Value
J.Object Object
forall a. Monoid a => a
mempty
  where
    convMutFld :: MutFldG b r v -> Value
convMutFld = \case
      MutFldG b r v
MCount -> Int -> Value
forall a. ToJSON a => a -> Value
J.toJSON (Int
0 :: Int)
      MExp Text
e -> Text -> Value
forall a. ToJSON a => a -> Value
J.toJSON Text
e
      MRet AnnFieldsG b r v
_ -> [Value] -> Value
forall a. ToJSON a => a -> Value
J.toJSON ([] :: [J.Value])

hasNestedFld :: MutationOutputG backend r a -> Bool
hasNestedFld :: MutationOutputG backend r a -> Bool
hasNestedFld = \case
  MOutMultirowFields MutFldsG backend r a
flds -> ((FieldName, MutFldG backend r a) -> Bool)
-> MutFldsG backend r a -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (FieldName, MutFldG backend r a) -> Bool
forall a (b :: BackendType) r v. (a, MutFldG b r v) -> Bool
isNestedMutFld MutFldsG backend r a
flds
  MOutSinglerowObject AnnFieldsG backend r a
annFlds -> ((FieldName, AnnFieldG backend r a) -> Bool)
-> AnnFieldsG backend r a -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (FieldName, AnnFieldG backend r a) -> Bool
forall a (b :: BackendType) r v. (a, AnnFieldG b r v) -> Bool
isNestedAnnField AnnFieldsG backend r a
annFlds
  where
    isNestedMutFld :: (a, MutFldG b r v) -> Bool
isNestedMutFld (a
_, MutFldG b r v
mutFld) = case MutFldG b r v
mutFld of
      MRet AnnFieldsG b r v
annFlds -> ((FieldName, AnnFieldG b r v) -> Bool) -> AnnFieldsG b r v -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (FieldName, AnnFieldG b r v) -> Bool
forall a (b :: BackendType) r v. (a, AnnFieldG b r v) -> Bool
isNestedAnnField AnnFieldsG b r v
annFlds
      MutFldG b r v
_ -> Bool
False
    isNestedAnnField :: (a, AnnFieldG b r v) -> Bool
isNestedAnnField (a
_, AnnFieldG b r v
annFld) = case AnnFieldG b r v
annFld of
      AFObjectRelation ObjectRelationSelectG b r v
_ -> Bool
True
      AFArrayRelation ArraySelectG b r v
_ -> Bool
True
      AnnFieldG b r v
_ -> Bool
False

$(makePrisms ''MutFldG)