{-# LANGUAGE UndecidableInstances #-}

module Hasura.RQL.Types.Roles.Internal
  ( CheckPermission (..),
    CombineRolePermInfo (..),
    rolePermInfoToCombineRolePermInfo,
    maybeToCheckPermission,
  )
where

import Data.HashMap.Strict qualified as HashMap
import Data.HashSet qualified as Set
import Data.Semigroup (Any (..), Max (..))
import Hasura.Prelude
import Hasura.RQL.IR.BoolExp
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.BackendType
import Hasura.RQL.Types.SchemaCache
import Hasura.RemoteSchema.SchemaCache.Types
import Hasura.Table.Cache
import Language.GraphQL.Draft.Syntax qualified as G

-- | 'CheckPermission' is a type which can be used to combine multiple
--   permissions when the permission type implements the @OnlyRelevantEq@
--   instance
data CheckPermission permissionType
  = CPUndefined
  | CPInconsistent
  | CPDefined permissionType
  deriving stock (Int -> CheckPermission permissionType -> ShowS
[CheckPermission permissionType] -> ShowS
CheckPermission permissionType -> String
(Int -> CheckPermission permissionType -> ShowS)
-> (CheckPermission permissionType -> String)
-> ([CheckPermission permissionType] -> ShowS)
-> Show (CheckPermission permissionType)
forall permissionType.
Show permissionType =>
Int -> CheckPermission permissionType -> ShowS
forall permissionType.
Show permissionType =>
[CheckPermission permissionType] -> ShowS
forall permissionType.
Show permissionType =>
CheckPermission permissionType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall permissionType.
Show permissionType =>
Int -> CheckPermission permissionType -> ShowS
showsPrec :: Int -> CheckPermission permissionType -> ShowS
$cshow :: forall permissionType.
Show permissionType =>
CheckPermission permissionType -> String
show :: CheckPermission permissionType -> String
$cshowList :: forall permissionType.
Show permissionType =>
[CheckPermission permissionType] -> ShowS
showList :: [CheckPermission permissionType] -> ShowS
Show, CheckPermission permissionType
-> CheckPermission permissionType -> Bool
(CheckPermission permissionType
 -> CheckPermission permissionType -> Bool)
-> (CheckPermission permissionType
    -> CheckPermission permissionType -> Bool)
-> Eq (CheckPermission permissionType)
forall permissionType.
Eq permissionType =>
CheckPermission permissionType
-> CheckPermission permissionType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall permissionType.
Eq permissionType =>
CheckPermission permissionType
-> CheckPermission permissionType -> Bool
== :: CheckPermission permissionType
-> CheckPermission permissionType -> Bool
$c/= :: forall permissionType.
Eq permissionType =>
CheckPermission permissionType
-> CheckPermission permissionType -> Bool
/= :: CheckPermission permissionType
-> CheckPermission permissionType -> Bool
Eq)

instance
  (OnlyRelevantEq permissionType) =>
  Semigroup (CheckPermission permissionType)
  where
  CheckPermission permissionType
CPUndefined <> :: CheckPermission permissionType
-> CheckPermission permissionType -> CheckPermission permissionType
<> CheckPermission permissionType
a = CheckPermission permissionType
a
  CheckPermission permissionType
a <> CheckPermission permissionType
CPUndefined = CheckPermission permissionType
a
  CheckPermission permissionType
CPInconsistent <> CheckPermission permissionType
_ = CheckPermission permissionType
forall permissionType. CheckPermission permissionType
CPInconsistent
  CheckPermission permissionType
_ <> CheckPermission permissionType
CPInconsistent = CheckPermission permissionType
forall permissionType. CheckPermission permissionType
CPInconsistent
  CPDefined permissionType
d1 <> CPDefined permissionType
d2
    | permissionType
d1 permissionType -> permissionType -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ permissionType
d2 = permissionType -> CheckPermission permissionType
forall permissionType.
permissionType -> CheckPermission permissionType
CPDefined permissionType
d1
    | Bool
otherwise = CheckPermission permissionType
forall permissionType. CheckPermission permissionType
CPInconsistent

instance
  (OnlyRelevantEq permissionType) =>
  Monoid (CheckPermission permissionType)
  where
  mempty :: CheckPermission permissionType
mempty = CheckPermission permissionType
forall permissionType. CheckPermission permissionType
CPUndefined

-- | CombineRolePermInfo acts as an intermediate type to be able to
--   combine multiple role permissions into one, using the `Monoid`
--   instance. Multiple role permissions are combined for inherited
--   role permissions where this is used.
data CombineRolePermInfo (b :: BackendType) = CombineRolePermInfo
  { forall (b :: BackendType).
CombineRolePermInfo b -> CheckPermission (InsPermInfo b)
crpiInsPerm :: CheckPermission (InsPermInfo b),
    forall (b :: BackendType).
CombineRolePermInfo b -> Maybe (CombinedSelPermInfo b)
crpiSelPerm :: Maybe (CombinedSelPermInfo b),
    forall (b :: BackendType).
CombineRolePermInfo b -> CheckPermission (UpdPermInfo b)
crpiUpdPerm :: CheckPermission (UpdPermInfo b),
    forall (b :: BackendType).
CombineRolePermInfo b -> CheckPermission (DelPermInfo b)
crpiDelPerm :: CheckPermission (DelPermInfo b)
  }

instance
  ( Backend b,
    Semigroup (CheckPermission (DelPermInfo b)),
    Semigroup (CheckPermission (InsPermInfo b)),
    Semigroup (CheckPermission (UpdPermInfo b)),
    Semigroup (CombinedSelPermInfo b)
  ) =>
  Semigroup (CombineRolePermInfo b)
  where
  CombineRolePermInfo CheckPermission (InsPermInfo b)
insPermL Maybe (CombinedSelPermInfo b)
selPermL CheckPermission (UpdPermInfo b)
updPermL CheckPermission (DelPermInfo b)
delPermL
    <> :: CombineRolePermInfo b
-> CombineRolePermInfo b -> CombineRolePermInfo b
<> CombineRolePermInfo CheckPermission (InsPermInfo b)
insPermR Maybe (CombinedSelPermInfo b)
selPermR CheckPermission (UpdPermInfo b)
updPermR CheckPermission (DelPermInfo b)
delPermR =
      CheckPermission (InsPermInfo b)
-> Maybe (CombinedSelPermInfo b)
-> CheckPermission (UpdPermInfo b)
-> CheckPermission (DelPermInfo b)
-> CombineRolePermInfo b
forall (b :: BackendType).
CheckPermission (InsPermInfo b)
-> Maybe (CombinedSelPermInfo b)
-> CheckPermission (UpdPermInfo b)
-> CheckPermission (DelPermInfo b)
-> CombineRolePermInfo b
CombineRolePermInfo
        (CheckPermission (InsPermInfo b)
insPermL CheckPermission (InsPermInfo b)
-> CheckPermission (InsPermInfo b)
-> CheckPermission (InsPermInfo b)
forall a. Semigroup a => a -> a -> a
<> CheckPermission (InsPermInfo b)
insPermR)
        (Maybe (CombinedSelPermInfo b)
selPermL Maybe (CombinedSelPermInfo b)
-> Maybe (CombinedSelPermInfo b) -> Maybe (CombinedSelPermInfo b)
forall a. Semigroup a => a -> a -> a
<> Maybe (CombinedSelPermInfo b)
selPermR)
        (CheckPermission (UpdPermInfo b)
updPermL CheckPermission (UpdPermInfo b)
-> CheckPermission (UpdPermInfo b)
-> CheckPermission (UpdPermInfo b)
forall a. Semigroup a => a -> a -> a
<> CheckPermission (UpdPermInfo b)
updPermR)
        (CheckPermission (DelPermInfo b)
delPermL CheckPermission (DelPermInfo b)
-> CheckPermission (DelPermInfo b)
-> CheckPermission (DelPermInfo b)
forall a. Semigroup a => a -> a -> a
<> CheckPermission (DelPermInfo b)
delPermR)

instance
  ( Backend b,
    Monoid (CheckPermission (DelPermInfo b)),
    Monoid (CheckPermission (InsPermInfo b)),
    Monoid (CheckPermission (UpdPermInfo b)),
    Monoid (Maybe (CombinedSelPermInfo b))
  ) =>
  Monoid (CombineRolePermInfo b)
  where
  mempty :: CombineRolePermInfo b
mempty = CheckPermission (InsPermInfo b)
-> Maybe (CombinedSelPermInfo b)
-> CheckPermission (UpdPermInfo b)
-> CheckPermission (DelPermInfo b)
-> CombineRolePermInfo b
forall (b :: BackendType).
CheckPermission (InsPermInfo b)
-> Maybe (CombinedSelPermInfo b)
-> CheckPermission (UpdPermInfo b)
-> CheckPermission (DelPermInfo b)
-> CombineRolePermInfo b
CombineRolePermInfo CheckPermission (InsPermInfo b)
forall a. Monoid a => a
mempty Maybe (CombinedSelPermInfo b)
forall a. Monoid a => a
mempty CheckPermission (UpdPermInfo b)
forall a. Monoid a => a
mempty CheckPermission (DelPermInfo b)
forall a. Monoid a => a
mempty

rolePermInfoToCombineRolePermInfo :: RolePermInfo b -> CombineRolePermInfo b
rolePermInfoToCombineRolePermInfo :: forall (b :: BackendType). RolePermInfo b -> CombineRolePermInfo b
rolePermInfoToCombineRolePermInfo RolePermInfo {Maybe (DelPermInfo b)
Maybe (UpdPermInfo b)
Maybe (SelPermInfo b)
Maybe (InsPermInfo b)
_permIns :: Maybe (InsPermInfo b)
_permSel :: Maybe (SelPermInfo b)
_permUpd :: Maybe (UpdPermInfo b)
_permDel :: Maybe (DelPermInfo b)
_permIns :: forall (b :: BackendType). RolePermInfo b -> Maybe (InsPermInfo b)
_permSel :: forall (b :: BackendType). RolePermInfo b -> Maybe (SelPermInfo b)
_permUpd :: forall (b :: BackendType). RolePermInfo b -> Maybe (UpdPermInfo b)
_permDel :: forall (b :: BackendType). RolePermInfo b -> Maybe (DelPermInfo b)
..} =
  CheckPermission (InsPermInfo b)
-> Maybe (CombinedSelPermInfo b)
-> CheckPermission (UpdPermInfo b)
-> CheckPermission (DelPermInfo b)
-> CombineRolePermInfo b
forall (b :: BackendType).
CheckPermission (InsPermInfo b)
-> Maybe (CombinedSelPermInfo b)
-> CheckPermission (UpdPermInfo b)
-> CheckPermission (DelPermInfo b)
-> CombineRolePermInfo b
CombineRolePermInfo
    (Maybe (InsPermInfo b) -> CheckPermission (InsPermInfo b)
forall a. Maybe a -> CheckPermission a
maybeToCheckPermission Maybe (InsPermInfo b)
_permIns)
    (SelPermInfo b -> CombinedSelPermInfo b
forall {b :: BackendType}. SelPermInfo b -> CombinedSelPermInfo b
modifySingleSelectPerm (SelPermInfo b -> CombinedSelPermInfo b)
-> Maybe (SelPermInfo b) -> Maybe (CombinedSelPermInfo b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (SelPermInfo b)
_permSel)
    (Maybe (UpdPermInfo b) -> CheckPermission (UpdPermInfo b)
forall a. Maybe a -> CheckPermission a
maybeToCheckPermission Maybe (UpdPermInfo b)
_permUpd)
    (Maybe (DelPermInfo b) -> CheckPermission (DelPermInfo b)
forall a. Maybe a -> CheckPermission a
maybeToCheckPermission Maybe (DelPermInfo b)
_permDel)
  where
    modifySingleSelectPerm :: SelPermInfo b -> CombinedSelPermInfo b
modifySingleSelectPerm SelPermInfo {Bool
Maybe Int
HashMap ComputedFieldName (AnnRedactionExpPartialSQL b)
HashMap (Column b) (AnnRedactionExpPartialSQL b)
HashSet Text
AnnBoolExpPartialSQL b
AllowedRootFields SubscriptionRootFieldType
AllowedRootFields QueryRootFieldType
spiCols :: HashMap (Column b) (AnnRedactionExpPartialSQL b)
spiComputedFields :: HashMap ComputedFieldName (AnnRedactionExpPartialSQL b)
spiFilter :: AnnBoolExpPartialSQL b
spiLimit :: Maybe Int
spiAllowAgg :: Bool
spiRequiredHeaders :: HashSet Text
spiAllowedQueryRootFields :: AllowedRootFields QueryRootFieldType
spiAllowedSubscriptionRootFields :: AllowedRootFields SubscriptionRootFieldType
spiCols :: forall (b :: BackendType).
SelPermInfo b -> HashMap (Column b) (AnnRedactionExpPartialSQL b)
spiComputedFields :: forall (b :: BackendType).
SelPermInfo b
-> HashMap ComputedFieldName (AnnRedactionExpPartialSQL b)
spiFilter :: forall (b :: BackendType). SelPermInfo b -> AnnBoolExpPartialSQL b
spiLimit :: forall (b :: BackendType). SelPermInfo b -> Maybe Int
spiAllowAgg :: forall (b :: BackendType). SelPermInfo b -> Bool
spiRequiredHeaders :: forall (b :: BackendType). SelPermInfo b -> HashSet Text
spiAllowedQueryRootFields :: forall (b :: BackendType).
SelPermInfo b -> AllowedRootFields QueryRootFieldType
spiAllowedSubscriptionRootFields :: forall (b :: BackendType).
SelPermInfo b -> AllowedRootFields SubscriptionRootFieldType
..} =
      let colsWithRedactionExp :: HashMap (Column b) (AnnRedactionExpPartialSQL b)
colsWithRedactionExp = HashMap (Column b) (AnnRedactionExpPartialSQL b)
spiCols HashMap (Column b) (AnnRedactionExpPartialSQL b)
-> AnnRedactionExpPartialSQL b
-> HashMap (Column b) (AnnRedactionExpPartialSQL b)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> AnnBoolExpPartialSQL b -> AnnRedactionExpPartialSQL b
forall (b :: BackendType) v.
GBoolExp b (AnnBoolExpFld b v) -> AnnRedactionExp b v
RedactIfFalse AnnBoolExpPartialSQL b
spiFilter
          scalarCompFieldsWithRedactionExp :: HashMap ComputedFieldName (AnnRedactionExpPartialSQL b)
scalarCompFieldsWithRedactionExp = HashMap ComputedFieldName (AnnRedactionExpPartialSQL b)
spiComputedFields HashMap ComputedFieldName (AnnRedactionExpPartialSQL b)
-> AnnRedactionExpPartialSQL b
-> HashMap ComputedFieldName (AnnRedactionExpPartialSQL b)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> AnnBoolExpPartialSQL b -> AnnRedactionExpPartialSQL b
forall (b :: BackendType) v.
GBoolExp b (AnnBoolExpFld b v) -> AnnRedactionExp b v
RedactIfFalse AnnBoolExpPartialSQL b
spiFilter
       in [HashMap (Column b) (AnnRedactionExpPartialSQL b)]
-> [HashMap ComputedFieldName (AnnRedactionExpPartialSQL b)]
-> [AnnBoolExpPartialSQL b]
-> Maybe (Max Int)
-> Any
-> HashSet Text
-> AllowedRootFields QueryRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
-> CombinedSelPermInfo b
forall (b :: BackendType).
[HashMap (Column b) (AnnRedactionExpPartialSQL b)]
-> [HashMap ComputedFieldName (AnnRedactionExpPartialSQL b)]
-> [AnnBoolExpPartialSQL b]
-> Maybe (Max Int)
-> Any
-> HashSet Text
-> AllowedRootFields QueryRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
-> CombinedSelPermInfo b
CombinedSelPermInfo
            [HashMap (Column b) (AnnRedactionExpPartialSQL b)
colsWithRedactionExp]
            [HashMap ComputedFieldName (AnnRedactionExpPartialSQL b)
scalarCompFieldsWithRedactionExp]
            [AnnBoolExpPartialSQL b
spiFilter]
            (Int -> Max Int
forall a. a -> Max a
Max (Int -> Max Int) -> Maybe Int -> Maybe (Max Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Int
spiLimit)
            (Bool -> Any
Any Bool
spiAllowAgg)
            HashSet Text
spiRequiredHeaders
            AllowedRootFields QueryRootFieldType
spiAllowedQueryRootFields
            AllowedRootFields SubscriptionRootFieldType
spiAllowedSubscriptionRootFields

-- | `OnlyRelevantEq` is a type class to implement checking if
--   two types have the relevant info of a type equal. This typeclass is almost
--   like the `Eq` typeclass but gives the flexibility of having custom
--   rules to check the equality of only the relevant data. Some use cases of
--   it are:
--
--   1. When comparing two `G.ScalarTypeDefinition`, the description of the type
--      doesn't matter.
--   2. The directives are represented as a list, but the order of the directives don't matter
--
--   Note: When there's nothing there to discard in a type, the `OnlyRelevantEq` can be derived
--   as (if needed)
--
--   instance OnlyRelevantEq a where
--     (==~) = (==)
--
--   NOTE: Do not export this type class from this module, as it is only intended to be used in
--   the context of inherited roles. If you think this typeclass fits your use case, then please
--   discuss this with Karthikeyan or in Slack thread to make this a generic typeclass.
class OnlyRelevantEq a where
  infix 4 ==~ -- same as (==)
  (==~) :: a -> a -> Bool

instance (Backend b, Hashable a) => OnlyRelevantEq (GBoolExp b a) where
  BoolAnd [GBoolExp b a]
boolExpL ==~ :: GBoolExp b a -> GBoolExp b a -> Bool
==~ BoolAnd [GBoolExp b a]
boolExpR = [GBoolExp b a] -> HashSet (GBoolExp b a)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [GBoolExp b a]
boolExpL HashSet (GBoolExp b a) -> HashSet (GBoolExp b a) -> Bool
forall a. Eq a => a -> a -> Bool
== [GBoolExp b a] -> HashSet (GBoolExp b a)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [GBoolExp b a]
boolExpR
  BoolOr [GBoolExp b a]
boolExpL ==~ BoolOr [GBoolExp b a]
boolExpR = [GBoolExp b a] -> HashSet (GBoolExp b a)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [GBoolExp b a]
boolExpL HashSet (GBoolExp b a) -> HashSet (GBoolExp b a) -> Bool
forall a. Eq a => a -> a -> Bool
== [GBoolExp b a] -> HashSet (GBoolExp b a)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [GBoolExp b a]
boolExpR
  BoolNot GBoolExp b a
boolExpL ==~ BoolNot GBoolExp b a
boolExpR = GBoolExp b a
boolExpL GBoolExp b a -> GBoolExp b a -> Bool
forall a. Eq a => a -> a -> Bool
== GBoolExp b a
boolExpR
  BoolExists GExists b a
boolExpL ==~ BoolExists GExists b a
boolExpR = GExists b a
boolExpL GExists b a -> GExists b a -> Bool
forall a. Eq a => a -> a -> Bool
== GExists b a
boolExpR
  BoolField a
boolExpL ==~ BoolField a
boolExpR = a
boolExpL a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
boolExpR
  GBoolExp b a
_ ==~ GBoolExp b a
_ = Bool
False

instance
  ( Eq (AnnComputedFieldBoolExp b a)
  ) =>
  OnlyRelevantEq (AnnComputedFieldBoolExp b a)
  where
  ==~ :: AnnComputedFieldBoolExp b a -> AnnComputedFieldBoolExp b a -> Bool
(==~) = AnnComputedFieldBoolExp b a -> AnnComputedFieldBoolExp b a -> Bool
forall a. Eq a => a -> a -> Bool
(==)

instance
  ( Backend b,
    Hashable (OpExpG b a),
    OnlyRelevantEq (AnnBoolExp b a),
    OnlyRelevantEq (AnnComputedFieldBoolExp b a)
  ) =>
  OnlyRelevantEq (AnnBoolExpFld b a)
  where
  AnnBoolExpFld b a
annBoolExpFldL ==~ :: AnnBoolExpFld b a -> AnnBoolExpFld b a -> Bool
==~ AnnBoolExpFld b a
annBoolExpFldR =
    case (AnnBoolExpFld b a
annBoolExpFldL, AnnBoolExpFld b a
annBoolExpFldR) of
      (AVColumn ColumnInfo b
colInfoL [OpExpG b a]
opExpsL, AVColumn ColumnInfo b
colInfoR [OpExpG b a]
opExpsR) ->
        ColumnInfo b
colInfoL ColumnInfo b -> ColumnInfo b -> Bool
forall a. Eq a => a -> a -> Bool
== ColumnInfo b
colInfoR Bool -> Bool -> Bool
&& [OpExpG b a] -> HashSet (OpExpG b a)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [OpExpG b a]
opExpsL HashSet (OpExpG b a) -> HashSet (OpExpG b a) -> Bool
forall a. Eq a => a -> a -> Bool
== [OpExpG b a] -> HashSet (OpExpG b a)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [OpExpG b a]
opExpsR
      (AVRelationship RelInfo b
relInfoL (RelationshipFilters AnnBoolExp b a
permsL AnnBoolExp b a
annBoolExpL), AVRelationship RelInfo b
relInfoR (RelationshipFilters AnnBoolExp b a
permsR AnnBoolExp b a
annBoolExpR)) ->
        RelInfo b
relInfoL RelInfo b -> RelInfo b -> Bool
forall a. Eq a => a -> a -> Bool
== RelInfo b
relInfoR Bool -> Bool -> Bool
&& AnnBoolExp b a
annBoolExpL AnnBoolExp b a -> AnnBoolExp b a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ AnnBoolExp b a
annBoolExpR Bool -> Bool -> Bool
&& AnnBoolExp b a
permsL AnnBoolExp b a -> AnnBoolExp b a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ AnnBoolExp b a
permsR
      (AVComputedField AnnComputedFieldBoolExp b a
annCompFldBoolExpL, AVComputedField AnnComputedFieldBoolExp b a
annCompFldBoolExpR) ->
        AnnComputedFieldBoolExp b a
annCompFldBoolExpL AnnComputedFieldBoolExp b a -> AnnComputedFieldBoolExp b a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ AnnComputedFieldBoolExp b a
annCompFldBoolExpR
      (AnnBoolExpFld b a
_, AnnBoolExpFld b a
_) -> Bool
False

instance
  ( Backend b,
    OnlyRelevantEq (AnnBoolExpPartialSQL b)
  ) =>
  OnlyRelevantEq (InsPermInfo b)
  where
  (InsPermInfo HashSet (Column b)
colsL AnnBoolExpPartialSQL b
checkL HashMap (Column b) (PartialSQLExp b)
setL Bool
backendOnlyL HashSet Text
reqHeadersL Maybe (ValidateInput ResolvedWebhook)
validateInputL)
    ==~ :: InsPermInfo b -> InsPermInfo b -> Bool
==~ (InsPermInfo HashSet (Column b)
colsR AnnBoolExpPartialSQL b
checkR HashMap (Column b) (PartialSQLExp b)
setR Bool
backendOnlyR HashSet Text
reqHeadersR Maybe (ValidateInput ResolvedWebhook)
validateInputR) =
      HashSet (Column b)
colsL
        HashSet (Column b) -> HashSet (Column b) -> Bool
forall a. Eq a => a -> a -> Bool
== HashSet (Column b)
colsR
        Bool -> Bool -> Bool
&& AnnBoolExpPartialSQL b
checkL
        AnnBoolExpPartialSQL b -> AnnBoolExpPartialSQL b -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ AnnBoolExpPartialSQL b
checkR
        Bool -> Bool -> Bool
&& HashMap (Column b) (PartialSQLExp b)
setL
        HashMap (Column b) (PartialSQLExp b)
-> HashMap (Column b) (PartialSQLExp b) -> Bool
forall a. Eq a => a -> a -> Bool
== HashMap (Column b) (PartialSQLExp b)
setR
        Bool -> Bool -> Bool
&& Bool
backendOnlyL
        Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
backendOnlyR
        Bool -> Bool -> Bool
&& HashSet Text
reqHeadersL
        HashSet Text -> HashSet Text -> Bool
forall a. Eq a => a -> a -> Bool
== HashSet Text
reqHeadersR
        Bool -> Bool -> Bool
&& Maybe (ValidateInput ResolvedWebhook)
validateInputL
        Maybe (ValidateInput ResolvedWebhook)
-> Maybe (ValidateInput ResolvedWebhook) -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (ValidateInput ResolvedWebhook)
validateInputR

instance
  ( Backend b,
    OnlyRelevantEq (AnnBoolExpPartialSQL b)
  ) =>
  OnlyRelevantEq (UpdPermInfo b)
  where
  (UpdPermInfo HashSet (Column b)
colsL TableName b
tableL AnnBoolExpPartialSQL b
filterL Maybe (AnnBoolExpPartialSQL b)
checkL HashMap (Column b) (PartialSQLExp b)
setL Bool
backendOnlyL HashSet Text
reqHeadersL Maybe (ValidateInput ResolvedWebhook)
validateInputL)
    ==~ :: UpdPermInfo b -> UpdPermInfo b -> Bool
==~ (UpdPermInfo HashSet (Column b)
colsR TableName b
tableR AnnBoolExpPartialSQL b
filterR Maybe (AnnBoolExpPartialSQL b)
checkR HashMap (Column b) (PartialSQLExp b)
setR Bool
backendOnlyR HashSet Text
reqHeadersR Maybe (ValidateInput ResolvedWebhook)
validateInputR) =
      HashSet (Column b)
colsL
        HashSet (Column b) -> HashSet (Column b) -> Bool
forall a. Eq a => a -> a -> Bool
== HashSet (Column b)
colsR
        Bool -> Bool -> Bool
&& TableName b
tableL
        TableName b -> TableName b -> Bool
forall a. Eq a => a -> a -> Bool
== TableName b
tableR
        Bool -> Bool -> Bool
&& AnnBoolExpPartialSQL b
filterL
        AnnBoolExpPartialSQL b -> AnnBoolExpPartialSQL b -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ AnnBoolExpPartialSQL b
filterR
        Bool -> Bool -> Bool
&& Maybe (AnnBoolExpPartialSQL b)
checkL
        Maybe (AnnBoolExpPartialSQL b)
-> Maybe (AnnBoolExpPartialSQL b) -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ Maybe (AnnBoolExpPartialSQL b)
checkR
        Bool -> Bool -> Bool
&& HashMap (Column b) (PartialSQLExp b)
setL
        HashMap (Column b) (PartialSQLExp b)
-> HashMap (Column b) (PartialSQLExp b) -> Bool
forall a. Eq a => a -> a -> Bool
== HashMap (Column b) (PartialSQLExp b)
setR
        Bool -> Bool -> Bool
&& Bool
backendOnlyL
        Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
backendOnlyR
        Bool -> Bool -> Bool
&& HashSet Text
reqHeadersL
        HashSet Text -> HashSet Text -> Bool
forall a. Eq a => a -> a -> Bool
== HashSet Text
reqHeadersR
        Bool -> Bool -> Bool
&& Maybe (ValidateInput ResolvedWebhook)
validateInputL
        Maybe (ValidateInput ResolvedWebhook)
-> Maybe (ValidateInput ResolvedWebhook) -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (ValidateInput ResolvedWebhook)
validateInputR

instance
  ( Backend b,
    OnlyRelevantEq (AnnBoolExpPartialSQL b)
  ) =>
  OnlyRelevantEq (DelPermInfo b)
  where
  (DelPermInfo TableName b
tableL AnnBoolExpPartialSQL b
filterL Bool
backendOnlyL HashSet Text
reqHeadersL Maybe (ValidateInput ResolvedWebhook)
validateInputL)
    ==~ :: DelPermInfo b -> DelPermInfo b -> Bool
==~ (DelPermInfo TableName b
tableR AnnBoolExpPartialSQL b
filterR Bool
backendOnlyR HashSet Text
reqHeadersR Maybe (ValidateInput ResolvedWebhook)
validateInputR) =
      TableName b
tableL
        TableName b -> TableName b -> Bool
forall a. Eq a => a -> a -> Bool
== TableName b
tableR
        Bool -> Bool -> Bool
&& AnnBoolExpPartialSQL b
filterL
        AnnBoolExpPartialSQL b -> AnnBoolExpPartialSQL b -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ AnnBoolExpPartialSQL b
filterR
        Bool -> Bool -> Bool
&& Bool
backendOnlyL
        Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
backendOnlyR
        Bool -> Bool -> Bool
&& HashSet Text
reqHeadersL
        HashSet Text -> HashSet Text -> Bool
forall a. Eq a => a -> a -> Bool
== HashSet Text
reqHeadersR
        Bool -> Bool -> Bool
&& Maybe (ValidateInput ResolvedWebhook)
validateInputL
        Maybe (ValidateInput ResolvedWebhook)
-> Maybe (ValidateInput ResolvedWebhook) -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (ValidateInput ResolvedWebhook)
validateInputR

instance OnlyRelevantEq RemoteSchemaInputValueDefinition where
  RemoteSchemaInputValueDefinition InputValueDefinition
defnL Maybe (Value RemoteSchemaVariable)
presetL
    ==~ :: RemoteSchemaInputValueDefinition
-> RemoteSchemaInputValueDefinition -> Bool
==~ RemoteSchemaInputValueDefinition InputValueDefinition
defnR Maybe (Value RemoteSchemaVariable)
presetR =
      InputValueDefinition
defnL InputValueDefinition -> InputValueDefinition -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ InputValueDefinition
defnR Bool -> Bool -> Bool
&& Maybe (Value RemoteSchemaVariable)
presetL Maybe (Value RemoteSchemaVariable)
-> Maybe (Value RemoteSchemaVariable) -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (Value RemoteSchemaVariable)
presetR

instance OnlyRelevantEq RemoteSchemaIntrospection where
  RemoteSchemaIntrospection HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
typeDefinitionsL
    ==~ :: RemoteSchemaIntrospection -> RemoteSchemaIntrospection -> Bool
==~ RemoteSchemaIntrospection HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
typeDefinitionsR =
      [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
forall a. Ord a => [a] -> [a]
sort (HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
forall k v. HashMap k v -> [v]
HashMap.elems HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
typeDefinitionsL) [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition] -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
forall a. Ord a => [a] -> [a]
sort (HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
forall k v. HashMap k v -> [v]
HashMap.elems HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
typeDefinitionsR)

instance OnlyRelevantEq IntrospectionResult where
  IntrospectionResult (RemoteSchemaIntrospection HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
typeDefnsL) Name
queryRootL Maybe Name
mutationRootL Maybe Name
subsRootL
    ==~ :: IntrospectionResult -> IntrospectionResult -> Bool
==~ IntrospectionResult (RemoteSchemaIntrospection HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
typeDefnsR) Name
queryRootR Maybe Name
mutationRootR Maybe Name
subsRootR =
      [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
forall a. Ord a => [a] -> [a]
sort (HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
forall k v. HashMap k v -> [v]
HashMap.elems HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
typeDefnsL)
        [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition] -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
forall a. Ord a => [a] -> [a]
sort (HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
forall k v. HashMap k v -> [v]
HashMap.elems HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
typeDefnsR)
        Bool -> Bool -> Bool
&& Name
queryRootL
        Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
queryRootR
        Bool -> Bool -> Bool
&& Maybe Name
mutationRootL
        Maybe Name -> Maybe Name -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe Name
mutationRootR
        Bool -> Bool -> Bool
&& Maybe Name
subsRootL
        Maybe Name -> Maybe Name -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe Name
subsRootR

instance (OnlyRelevantEq a) => OnlyRelevantEq (Maybe a) where
  ==~ :: Maybe a -> Maybe a -> Bool
(==~) Maybe a
l Maybe a
r =
    case (Maybe a
l, Maybe a
r) of
      (Just a
l', Just a
r') -> a
l' a -> a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ a
r'
      (Maybe a
Nothing, Maybe a
Nothing) -> Bool
True
      (Maybe a, Maybe a)
_ -> Bool
False

instance OnlyRelevantEq G.Name where
  ==~ :: Name -> Name -> Bool
(==~) = Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
(==)

instance (OnlyRelevantEq a) => OnlyRelevantEq [a] where
  [a]
l ==~ :: [a] -> [a] -> Bool
==~ [a]
r =
    ([a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
r Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
r)
      Bool -> Bool -> Bool
&& ((Bool -> Bool) -> [Bool] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
True) ((a -> a -> Bool) -> [a] -> [a] -> [Bool]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith a -> a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
(==~) [a]
l [a]
r))

instance OnlyRelevantEq G.ScalarTypeDefinition where
  G.ScalarTypeDefinition Maybe Description
_descL Name
nameL [Directive Void]
directivesL
    ==~ :: ScalarTypeDefinition -> ScalarTypeDefinition -> Bool
==~ G.ScalarTypeDefinition Maybe Description
_descR Name
nameR [Directive Void]
directivesR =
      Name
nameL Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
nameR Bool -> Bool -> Bool
&& [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesL HashSet (Directive Void) -> HashSet (Directive Void) -> Bool
forall a. Eq a => a -> a -> Bool
== [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesR

instance (OnlyRelevantEq a, Ord a) => OnlyRelevantEq (G.FieldDefinition a) where
  G.FieldDefinition Maybe Description
_descL Name
nameL [a]
argumentsL GType
typeL [Directive Void]
directivesL
    ==~ :: FieldDefinition a -> FieldDefinition a -> Bool
==~ G.FieldDefinition Maybe Description
_descR Name
nameR [a]
argumentsR GType
typeR [Directive Void]
directivesR =
      Name
nameL
        Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
nameR
        Bool -> Bool -> Bool
&& [a] -> [a]
forall a. Ord a => [a] -> [a]
sort [a]
argumentsL
        [a] -> [a] -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ [a] -> [a]
forall a. Ord a => [a] -> [a]
sort [a]
argumentsR
        Bool -> Bool -> Bool
&& GType
typeL
        GType -> GType -> Bool
forall a. Eq a => a -> a -> Bool
== GType
typeR
        Bool -> Bool -> Bool
&& [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesL
        HashSet (Directive Void) -> HashSet (Directive Void) -> Bool
forall a. Eq a => a -> a -> Bool
== [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesR

instance (OnlyRelevantEq a, Ord a) => OnlyRelevantEq (G.ObjectTypeDefinition a) where
  G.ObjectTypeDefinition Maybe Description
_descL Name
nameL [Name]
implementsInterfacesL [Directive Void]
directivesL [FieldDefinition a]
fieldDefnsL
    ==~ :: ObjectTypeDefinition a -> ObjectTypeDefinition a -> Bool
==~ G.ObjectTypeDefinition Maybe Description
_descR Name
nameR [Name]
implementsInterfacesR [Directive Void]
directivesR [FieldDefinition a]
fieldDefnsR =
      Name
nameL
        Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
nameR
        Bool -> Bool -> Bool
&& [Name] -> HashSet Name
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Name]
implementsInterfacesL
        HashSet Name -> HashSet Name -> Bool
forall a. Eq a => a -> a -> Bool
== [Name] -> HashSet Name
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Name]
implementsInterfacesR
        Bool -> Bool -> Bool
&& [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesL
        HashSet (Directive Void) -> HashSet (Directive Void) -> Bool
forall a. Eq a => a -> a -> Bool
== [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesR
        Bool -> Bool -> Bool
&& [FieldDefinition a] -> [FieldDefinition a]
forall a. Ord a => [a] -> [a]
sort [FieldDefinition a]
fieldDefnsL
        [FieldDefinition a] -> [FieldDefinition a] -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ [FieldDefinition a] -> [FieldDefinition a]
forall a. Ord a => [a] -> [a]
sort [FieldDefinition a]
fieldDefnsR

instance (OnlyRelevantEq a, Ord a) => OnlyRelevantEq (G.InterfaceTypeDefinition [G.Name] a) where
  G.InterfaceTypeDefinition Maybe Description
_descL Name
nameL [Directive Void]
directivesL [FieldDefinition a]
fieldDefnsL [Name]
possibleTypesL
    ==~ :: InterfaceTypeDefinition [Name] a
-> InterfaceTypeDefinition [Name] a -> Bool
==~ G.InterfaceTypeDefinition Maybe Description
_descR Name
nameR [Directive Void]
directivesR [FieldDefinition a]
fieldDefnsR [Name]
possibleTypesR =
      Name
nameL
        Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
nameR
        Bool -> Bool -> Bool
&& [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesL
        HashSet (Directive Void) -> HashSet (Directive Void) -> Bool
forall a. Eq a => a -> a -> Bool
== [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesR
        Bool -> Bool -> Bool
&& [FieldDefinition a] -> [FieldDefinition a]
forall a. Ord a => [a] -> [a]
sort [FieldDefinition a]
fieldDefnsL
        [FieldDefinition a] -> [FieldDefinition a] -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ [FieldDefinition a] -> [FieldDefinition a]
forall a. Ord a => [a] -> [a]
sort [FieldDefinition a]
fieldDefnsR
        Bool -> Bool -> Bool
&& [Name] -> HashSet Name
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Name]
possibleTypesL
        HashSet Name -> HashSet Name -> Bool
forall a. Eq a => a -> a -> Bool
== [Name] -> HashSet Name
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Name]
possibleTypesR

instance OnlyRelevantEq G.UnionTypeDefinition where
  G.UnionTypeDefinition Maybe Description
_descL Name
nameL [Directive Void]
directivesL [Name]
membersL
    ==~ :: UnionTypeDefinition -> UnionTypeDefinition -> Bool
==~ G.UnionTypeDefinition Maybe Description
_descR Name
nameR [Directive Void]
directivesR [Name]
membersR =
      Name
nameL
        Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
nameR
        Bool -> Bool -> Bool
&& [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesL
        HashSet (Directive Void) -> HashSet (Directive Void) -> Bool
forall a. Eq a => a -> a -> Bool
== [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesR
        Bool -> Bool -> Bool
&& [Name] -> HashSet Name
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Name]
membersL
        HashSet Name -> HashSet Name -> Bool
forall a. Eq a => a -> a -> Bool
== [Name] -> HashSet Name
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Name]
membersR

instance (OnlyRelevantEq a, Ord a) => OnlyRelevantEq (G.InputObjectTypeDefinition a) where
  G.InputObjectTypeDefinition Maybe Description
_descL Name
nameL [Directive Void]
directivesL [a]
defnsL
    ==~ :: InputObjectTypeDefinition a -> InputObjectTypeDefinition a -> Bool
==~ G.InputObjectTypeDefinition Maybe Description
_descR Name
nameR [Directive Void]
directivesR [a]
defnsR =
      Name
nameL
        Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
nameR
        Bool -> Bool -> Bool
&& [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesL
        HashSet (Directive Void) -> HashSet (Directive Void) -> Bool
forall a. Eq a => a -> a -> Bool
== [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesR
        Bool -> Bool -> Bool
&& [a] -> [a]
forall a. Ord a => [a] -> [a]
sort [a]
defnsL
        [a] -> [a] -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ [a] -> [a]
forall a. Ord a => [a] -> [a]
sort [a]
defnsR

instance OnlyRelevantEq G.EnumValueDefinition where
  G.EnumValueDefinition Maybe Description
_descL EnumValue
nameL [Directive Void]
directivesL
    ==~ :: EnumValueDefinition -> EnumValueDefinition -> Bool
==~ G.EnumValueDefinition Maybe Description
_descR EnumValue
nameR [Directive Void]
directivesR =
      EnumValue
nameL EnumValue -> EnumValue -> Bool
forall a. Eq a => a -> a -> Bool
== EnumValue
nameR Bool -> Bool -> Bool
&& [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesL HashSet (Directive Void) -> HashSet (Directive Void) -> Bool
forall a. Eq a => a -> a -> Bool
== [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesR

instance OnlyRelevantEq G.EnumTypeDefinition where
  G.EnumTypeDefinition Maybe Description
_descL Name
nameL [Directive Void]
directivesL [EnumValueDefinition]
valueDefnsL
    ==~ :: EnumTypeDefinition -> EnumTypeDefinition -> Bool
==~ G.EnumTypeDefinition Maybe Description
_descR Name
nameR [Directive Void]
directivesR [EnumValueDefinition]
valueDefnsR =
      Name
nameL
        Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
nameR
        Bool -> Bool -> Bool
&& [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesL
        HashSet (Directive Void) -> HashSet (Directive Void) -> Bool
forall a. Eq a => a -> a -> Bool
== [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesR
        Bool -> Bool -> Bool
&& [EnumValueDefinition] -> [EnumValueDefinition]
forall a. Ord a => [a] -> [a]
sort [EnumValueDefinition]
valueDefnsL
        [EnumValueDefinition] -> [EnumValueDefinition] -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ [EnumValueDefinition] -> [EnumValueDefinition]
forall a. Ord a => [a] -> [a]
sort [EnumValueDefinition]
valueDefnsR

instance (OnlyRelevantEq a, Ord a) => OnlyRelevantEq (G.TypeDefinition [G.Name] a) where
  G.TypeDefinitionScalar ScalarTypeDefinition
scalarDefnL ==~ :: TypeDefinition [Name] a -> TypeDefinition [Name] a -> Bool
==~ G.TypeDefinitionScalar ScalarTypeDefinition
scalarDefnR = ScalarTypeDefinition
scalarDefnL ScalarTypeDefinition -> ScalarTypeDefinition -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ ScalarTypeDefinition
scalarDefnR
  G.TypeDefinitionObject ObjectTypeDefinition a
objDefnL ==~ G.TypeDefinitionObject ObjectTypeDefinition a
objDefnR = ObjectTypeDefinition a
objDefnL ObjectTypeDefinition a -> ObjectTypeDefinition a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ ObjectTypeDefinition a
objDefnR
  G.TypeDefinitionInterface InterfaceTypeDefinition [Name] a
interfaceDefnL ==~ G.TypeDefinitionInterface InterfaceTypeDefinition [Name] a
interfaceDefnR = InterfaceTypeDefinition [Name] a
interfaceDefnL InterfaceTypeDefinition [Name] a
-> InterfaceTypeDefinition [Name] a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ InterfaceTypeDefinition [Name] a
interfaceDefnR
  G.TypeDefinitionUnion UnionTypeDefinition
unionDefnL ==~ G.TypeDefinitionUnion UnionTypeDefinition
unionDefnR = UnionTypeDefinition
unionDefnL UnionTypeDefinition -> UnionTypeDefinition -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ UnionTypeDefinition
unionDefnR
  G.TypeDefinitionEnum EnumTypeDefinition
enumDefnL ==~ G.TypeDefinitionEnum EnumTypeDefinition
enumDefnR = EnumTypeDefinition
enumDefnL EnumTypeDefinition -> EnumTypeDefinition -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ EnumTypeDefinition
enumDefnR
  G.TypeDefinitionInputObject InputObjectTypeDefinition a
inpObjDefnL ==~ G.TypeDefinitionInputObject InputObjectTypeDefinition a
inpObjDefnR = InputObjectTypeDefinition a
inpObjDefnL InputObjectTypeDefinition a -> InputObjectTypeDefinition a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
==~ InputObjectTypeDefinition a
inpObjDefnR
  TypeDefinition [Name] a
_ ==~ TypeDefinition [Name] a
_ = Bool
False

instance OnlyRelevantEq G.InputValueDefinition where
  G.InputValueDefinition Maybe Description
_descL Name
nameL GType
typeL Maybe (Value Void)
defaultValueL [Directive Void]
directivesL
    ==~ :: InputValueDefinition -> InputValueDefinition -> Bool
==~ G.InputValueDefinition Maybe Description
_descR Name
nameR GType
typeR Maybe (Value Void)
defaultValueR [Directive Void]
directivesR =
      Name
nameL
        Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
nameR
        Bool -> Bool -> Bool
&& GType
typeL
        GType -> GType -> Bool
forall a. Eq a => a -> a -> Bool
== GType
typeR
        Bool -> Bool -> Bool
&& Maybe (Value Void)
defaultValueL
        Maybe (Value Void) -> Maybe (Value Void) -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe (Value Void)
defaultValueR
        Bool -> Bool -> Bool
&& [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesL
        HashSet (Directive Void) -> HashSet (Directive Void) -> Bool
forall a. Eq a => a -> a -> Bool
== [Directive Void] -> HashSet (Directive Void)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Directive Void]
directivesR

maybeToCheckPermission :: Maybe a -> CheckPermission a
maybeToCheckPermission :: forall a. Maybe a -> CheckPermission a
maybeToCheckPermission = CheckPermission a
-> (a -> CheckPermission a) -> Maybe a -> CheckPermission a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe CheckPermission a
forall permissionType. CheckPermission permissionType
CPUndefined a -> CheckPermission a
forall permissionType.
permissionType -> CheckPermission permissionType
CPDefined