{-# 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 InsOrdHashMap
import Data.Kind (Type)
import Hasura.EncJSON
import Hasura.Prelude
import Hasura.RQL.IR.Select
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.BackendType
import Hasura.RQL.Types.Common

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