{-# LANGUAGE UndecidableInstances #-}

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

import Data.HashMap.Strict qualified as Map
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.RemoteSchema
import Hasura.RQL.Types.SchemaCache
import Hasura.RQL.Types.Table
import Hasura.SQL.Backend
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
showList :: [CheckPermission permissionType] -> ShowS
$cshowList :: forall permissionType.
Show permissionType =>
[CheckPermission permissionType] -> ShowS
show :: CheckPermission permissionType -> String
$cshow :: forall permissionType.
Show permissionType =>
CheckPermission permissionType -> String
showsPrec :: Int -> CheckPermission permissionType -> ShowS
$cshowsPrec :: forall permissionType.
Show permissionType =>
Int -> 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
/= :: CheckPermission permissionType
-> CheckPermission permissionType -> Bool
$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
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
`relevantEq` 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
  { CombineRolePermInfo b -> CheckPermission (InsPermInfo b)
crpiInsPerm :: CheckPermission (InsPermInfo b),
    CombineRolePermInfo b -> Maybe (CombinedSelPermInfo b)
crpiSelPerm :: Maybe (CombinedSelPermInfo b),
    CombineRolePermInfo b -> CheckPermission (UpdPermInfo b)
crpiUpdPerm :: CheckPermission (UpdPermInfo b),
    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 :: RolePermInfo b -> CombineRolePermInfo b
rolePermInfoToCombineRolePermInfo RolePermInfo {Maybe (DelPermInfo b)
Maybe (UpdPermInfo b)
Maybe (SelPermInfo b)
Maybe (InsPermInfo b)
_permDel :: forall (b :: BackendType). RolePermInfo b -> Maybe (DelPermInfo b)
_permUpd :: forall (b :: BackendType). RolePermInfo b -> Maybe (UpdPermInfo b)
_permSel :: forall (b :: BackendType). RolePermInfo b -> Maybe (SelPermInfo b)
_permIns :: forall (b :: BackendType). RolePermInfo b -> Maybe (InsPermInfo b)
_permDel :: Maybe (DelPermInfo b)
_permUpd :: Maybe (UpdPermInfo b)
_permSel :: Maybe (SelPermInfo b)
_permIns :: Maybe (InsPermInfo 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 (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
HashMap
  ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
HashSet Text
AnnBoolExpPartialSQL b
AllowedRootFields SubscriptionRootFieldType
AllowedRootFields QueryRootFieldType
spiAllowedSubscriptionRootFields :: forall (b :: BackendType).
SelPermInfo b -> AllowedRootFields SubscriptionRootFieldType
spiAllowedQueryRootFields :: forall (b :: BackendType).
SelPermInfo b -> AllowedRootFields QueryRootFieldType
spiRequiredHeaders :: forall (b :: BackendType). SelPermInfo b -> HashSet Text
spiAllowAgg :: forall (b :: BackendType). SelPermInfo b -> Bool
spiLimit :: forall (b :: BackendType). SelPermInfo b -> Maybe Int
spiFilter :: forall (b :: BackendType). SelPermInfo b -> AnnBoolExpPartialSQL b
spiComputedFields :: forall (b :: BackendType).
SelPermInfo b
-> HashMap
     ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
spiCols :: forall (b :: BackendType).
SelPermInfo b
-> HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
spiAllowedSubscriptionRootFields :: AllowedRootFields SubscriptionRootFieldType
spiAllowedQueryRootFields :: AllowedRootFields QueryRootFieldType
spiRequiredHeaders :: HashSet Text
spiAllowAgg :: Bool
spiLimit :: Maybe Int
spiFilter :: AnnBoolExpPartialSQL b
spiComputedFields :: HashMap
  ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
spiCols :: HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
..} =
      let columnCaseBoolExp :: AnnColumnCaseBoolExpPartialSQL b
columnCaseBoolExp = (AnnBoolExpFld b (PartialSQLExp b)
 -> AnnColumnCaseBoolExpField b (PartialSQLExp b))
-> AnnBoolExpPartialSQL b -> AnnColumnCaseBoolExpPartialSQL b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AnnBoolExpFld b (PartialSQLExp b)
-> AnnColumnCaseBoolExpField b (PartialSQLExp b)
forall (backend :: BackendType) field.
AnnBoolExpFld backend field
-> AnnColumnCaseBoolExpField backend field
AnnColumnCaseBoolExpField AnnBoolExpPartialSQL b
spiFilter
          colsWithColCaseBoolExp :: HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
colsWithColCaseBoolExp = HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
spiCols HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> Maybe (AnnColumnCaseBoolExpPartialSQL b)
-> HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> AnnColumnCaseBoolExpPartialSQL b
-> Maybe (AnnColumnCaseBoolExpPartialSQL b)
forall a. a -> Maybe a
Just AnnColumnCaseBoolExpPartialSQL b
columnCaseBoolExp
          scalarCompFieldsWithColCaseBoolExp :: HashMap
  ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
scalarCompFieldsWithColCaseBoolExp = HashMap
  ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
spiComputedFields HashMap
  ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
-> Maybe (AnnColumnCaseBoolExpPartialSQL b)
-> HashMap
     ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> AnnColumnCaseBoolExpPartialSQL b
-> Maybe (AnnColumnCaseBoolExpPartialSQL b)
forall a. a -> Maybe a
Just AnnColumnCaseBoolExpPartialSQL b
columnCaseBoolExp
       in [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [HashMap
      ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [AnnBoolExpPartialSQL b]
-> Maybe (Max Int)
-> Any
-> HashSet Text
-> AllowedRootFields QueryRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
-> CombinedSelPermInfo b
forall (b :: BackendType).
[HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [HashMap
      ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))]
-> [AnnBoolExpPartialSQL b]
-> Maybe (Max Int)
-> Any
-> HashSet Text
-> AllowedRootFields QueryRootFieldType
-> AllowedRootFields SubscriptionRootFieldType
-> CombinedSelPermInfo b
CombinedSelPermInfo
            [HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))
colsWithColCaseBoolExp]
            [HashMap
  ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))
scalarCompFieldsWithColCaseBoolExp]
            [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
--     relevantEq = (==)
--
--   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
  relevantEq :: a -> a -> Bool

instance (Backend b, Eq a, Hashable a) => OnlyRelevantEq (GBoolExp b a) where
  BoolAnd [GBoolExp b a]
boolExpL relevantEq :: GBoolExp b a -> GBoolExp b a -> Bool
`relevantEq` 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 `relevantEq` 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 `relevantEq` 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 `relevantEq` 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 `relevantEq` BoolField a
boolExpR = a
boolExpL a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
boolExpR
  GBoolExp b a
_ `relevantEq` GBoolExp b a
_ = Bool
False

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

instance
  ( Backend b,
    Eq (OpExpG b a),
    Hashable (OpExpG b a),
    OnlyRelevantEq (AnnBoolExp b a),
    OnlyRelevantEq (AnnComputedFieldBoolExp b a)
  ) =>
  OnlyRelevantEq (AnnBoolExpFld b a)
  where
  AnnBoolExpFld b a
annBoolExpFldL relevantEq :: AnnBoolExpFld b a -> AnnBoolExpFld b a -> Bool
`relevantEq` 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 AnnBoolExp b a
annBoolExpL, AVRelationship RelInfo b
relInfoR 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
`relevantEq` AnnBoolExp b a
annBoolExpR
      (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
`relevantEq` 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 PreSetColsPartial b
setL Bool
backendOnlyL HashSet Text
reqHeadersL)
    relevantEq :: InsPermInfo b -> InsPermInfo b -> Bool
`relevantEq` (InsPermInfo HashSet (Column b)
colsR AnnBoolExpPartialSQL b
checkR PreSetColsPartial b
setR Bool
backendOnlyR HashSet Text
reqHeadersR) =
      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
`relevantEq` AnnBoolExpPartialSQL b
checkR
        Bool -> Bool -> Bool
&& PreSetColsPartial b
setL PreSetColsPartial b -> PreSetColsPartial b -> Bool
forall a. Eq a => a -> a -> Bool
== PreSetColsPartial 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

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 PreSetColsPartial b
setL Bool
backendOnlyL HashSet Text
reqHeadersL)
    relevantEq :: UpdPermInfo b -> UpdPermInfo b -> Bool
`relevantEq` (UpdPermInfo HashSet (Column b)
colsR TableName b
tableR AnnBoolExpPartialSQL b
filterR Maybe (AnnBoolExpPartialSQL b)
checkR PreSetColsPartial b
setR Bool
backendOnlyR HashSet Text
reqHeadersR) =
      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
`relevantEq` AnnBoolExpPartialSQL b
filterR
        Bool -> Bool -> Bool
&& Maybe (AnnBoolExpPartialSQL b)
checkL Maybe (AnnBoolExpPartialSQL b)
-> Maybe (AnnBoolExpPartialSQL b) -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
`relevantEq` Maybe (AnnBoolExpPartialSQL b)
checkR
        Bool -> Bool -> Bool
&& PreSetColsPartial b
setL PreSetColsPartial b -> PreSetColsPartial b -> Bool
forall a. Eq a => a -> a -> Bool
== PreSetColsPartial 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

instance
  ( Backend b,
    OnlyRelevantEq (AnnBoolExpPartialSQL b)
  ) =>
  OnlyRelevantEq (DelPermInfo b)
  where
  (DelPermInfo TableName b
tableL AnnBoolExpPartialSQL b
filterL Bool
backendOnlyL HashSet Text
reqHeadersL)
    relevantEq :: DelPermInfo b -> DelPermInfo b -> Bool
`relevantEq` (DelPermInfo TableName b
tableR AnnBoolExpPartialSQL b
filterR Bool
backendOnlyR HashSet Text
reqHeadersR) =
      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
`relevantEq` 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

instance OnlyRelevantEq RemoteSchemaInputValueDefinition where
  RemoteSchemaInputValueDefinition InputValueDefinition
defnL Maybe (Value RemoteSchemaVariable)
presetL
    relevantEq :: RemoteSchemaInputValueDefinition
-> RemoteSchemaInputValueDefinition -> Bool
`relevantEq` RemoteSchemaInputValueDefinition InputValueDefinition
defnR Maybe (Value RemoteSchemaVariable)
presetR =
      InputValueDefinition
defnL InputValueDefinition -> InputValueDefinition -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
`relevantEq` 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
    relevantEq :: RemoteSchemaIntrospection -> RemoteSchemaIntrospection -> Bool
`relevantEq` 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]
Map.elems HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
typeDefinitionsL) [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition] -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
`relevantEq` [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]
Map.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
    relevantEq :: IntrospectionResult -> IntrospectionResult -> Bool
`relevantEq` 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]
Map.elems HashMap
  Name (TypeDefinition [Name] RemoteSchemaInputValueDefinition)
typeDefnsL) [TypeDefinition [Name] RemoteSchemaInputValueDefinition]
-> [TypeDefinition [Name] RemoteSchemaInputValueDefinition] -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
`relevantEq` [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]
Map.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
  relevantEq :: Maybe a -> Maybe a -> Bool
relevantEq 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
`relevantEq` a
r'
      (Maybe a
Nothing, Maybe a
Nothing) -> Bool
True
      (Maybe a, Maybe a)
_ -> Bool
False

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

instance OnlyRelevantEq a => OnlyRelevantEq [a] where
  [a]
l relevantEq :: [a] -> [a] -> Bool
`relevantEq` [a]
r =
    ([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 (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
relevantEq [a]
l [a]
r))

instance OnlyRelevantEq G.ScalarTypeDefinition where
  G.ScalarTypeDefinition Maybe Description
_descL Name
nameL [Directive Void]
directivesL
    relevantEq :: ScalarTypeDefinition -> ScalarTypeDefinition -> Bool
`relevantEq` 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 ArgumentsDefinition a
argumentsL GType
typeL [Directive Void]
directivesL
    relevantEq :: FieldDefinition a -> FieldDefinition a -> Bool
`relevantEq` G.FieldDefinition Maybe Description
_descR Name
nameR ArgumentsDefinition a
argumentsR GType
typeR [Directive Void]
directivesR =
      Name
nameL Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
nameR
        Bool -> Bool -> Bool
&& ArgumentsDefinition a -> ArgumentsDefinition a
forall a. Ord a => [a] -> [a]
sort ArgumentsDefinition a
argumentsL ArgumentsDefinition a -> ArgumentsDefinition a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
`relevantEq` ArgumentsDefinition a -> ArgumentsDefinition a
forall a. Ord a => [a] -> [a]
sort ArgumentsDefinition 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
    relevantEq :: ObjectTypeDefinition a -> ObjectTypeDefinition a -> Bool
`relevantEq` 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
`relevantEq` [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
    relevantEq :: InterfaceTypeDefinition [Name] a
-> InterfaceTypeDefinition [Name] a -> Bool
`relevantEq` 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
`relevantEq` [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
    relevantEq :: UnionTypeDefinition -> UnionTypeDefinition -> Bool
`relevantEq` 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
    relevantEq :: InputObjectTypeDefinition a -> InputObjectTypeDefinition a -> Bool
`relevantEq` 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
`relevantEq` [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
    relevantEq :: EnumValueDefinition -> EnumValueDefinition -> Bool
`relevantEq` 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
    relevantEq :: EnumTypeDefinition -> EnumTypeDefinition -> Bool
`relevantEq` 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
`relevantEq` [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 relevantEq :: TypeDefinition [Name] a -> TypeDefinition [Name] a -> Bool
`relevantEq` G.TypeDefinitionScalar ScalarTypeDefinition
scalarDefnR = ScalarTypeDefinition
scalarDefnL ScalarTypeDefinition -> ScalarTypeDefinition -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
`relevantEq` ScalarTypeDefinition
scalarDefnR
  G.TypeDefinitionObject ObjectTypeDefinition a
objDefnL `relevantEq` G.TypeDefinitionObject ObjectTypeDefinition a
objDefnR = ObjectTypeDefinition a
objDefnL ObjectTypeDefinition a -> ObjectTypeDefinition a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
`relevantEq` ObjectTypeDefinition a
objDefnR
  G.TypeDefinitionInterface InterfaceTypeDefinition [Name] a
interfaceDefnL `relevantEq` G.TypeDefinitionInterface InterfaceTypeDefinition [Name] a
interfaceDefnR = InterfaceTypeDefinition [Name] a
interfaceDefnL InterfaceTypeDefinition [Name] a
-> InterfaceTypeDefinition [Name] a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
`relevantEq` InterfaceTypeDefinition [Name] a
interfaceDefnR
  G.TypeDefinitionUnion UnionTypeDefinition
unionDefnL `relevantEq` G.TypeDefinitionUnion UnionTypeDefinition
unionDefnR = UnionTypeDefinition
unionDefnL UnionTypeDefinition -> UnionTypeDefinition -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
`relevantEq` UnionTypeDefinition
unionDefnR
  G.TypeDefinitionEnum EnumTypeDefinition
enumDefnL `relevantEq` G.TypeDefinitionEnum EnumTypeDefinition
enumDefnR = EnumTypeDefinition
enumDefnL EnumTypeDefinition -> EnumTypeDefinition -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
`relevantEq` EnumTypeDefinition
enumDefnR
  G.TypeDefinitionInputObject InputObjectTypeDefinition a
inpObjDefnL `relevantEq` G.TypeDefinitionInputObject InputObjectTypeDefinition a
inpObjDefnR = InputObjectTypeDefinition a
inpObjDefnL InputObjectTypeDefinition a -> InputObjectTypeDefinition a -> Bool
forall a. OnlyRelevantEq a => a -> a -> Bool
`relevantEq` InputObjectTypeDefinition a
inpObjDefnR
  TypeDefinition [Name] a
_ `relevantEq` 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
    relevantEq :: InputValueDefinition -> InputValueDefinition -> Bool
`relevantEq` 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 :: 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