1
0
mirror of https://github.com/hasura/graphql-engine.git synced 2024-12-21 06:21:39 +03:00
graphql-engine/server/src-lib/Hasura/GraphQL/Schema/Options.hs
Antoine Leblanc a3e23adac5 Remove remote schema permissions from schema options.
### Description

A trivial PR, extracted out of , that removes remote schema permissions from the schema context, as they are only ever used at the top level: whether or not we need to use remote schema permissions is not something that impacts _how_ we build the schema, but whether some parts of the schema should be built at all, and therefore doesn't need to be accessible throughout the build process.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5050
GitOrigin-RevId: 734673370393d5640ad753222982baf2698f6d8f
2022-07-18 13:09:40 +00:00

87 lines
3.0 KiB
Haskell

-- |
-- Definitions for schema building configuration.
module Hasura.GraphQL.Schema.Options
( SchemaOptions (..),
StringifyNumbers (..),
DangerouslyCollapseBooleans (..),
InferFunctionPermissions (..),
RemoteSchemaPermissions (..),
OptimizePermissionFilters (..),
)
where
import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), withBool)
import Hasura.Prelude
-- | The record of options required to build the schema. This includes options
-- that can be enabled with 'Hasura.Server.Types.ExperimentalFeature' flags.
data SchemaOptions = SchemaOptions
{ soStringifyNumbers :: StringifyNumbers,
soDangerousBooleanCollapse :: DangerouslyCollapseBooleans,
soInferFunctionPermissions :: InferFunctionPermissions,
soOptimizePermissionFilters :: OptimizePermissionFilters
}
-- | Should we represent numbers in our responses as numbers, or strings?
-- Some backends can return numbers that exceed the bounds of JSON's own
-- number type. In these cases, we can use stringified versions of these
-- numbers to avoid this problem.
data StringifyNumbers
= StringifyNumbers
| Don'tStringifyNumbers
deriving (Eq, Show)
-- | Should Boolean fields be collapsed to 'True' when a null value is
-- given? This was the behaviour of Hasura V1, and is now discouraged.
data DangerouslyCollapseBooleans
= DangerouslyCollapseBooleans
| Don'tDangerouslyCollapseBooleans
deriving (Eq, Show)
-- | Should we infer function permissions? If this flag is set to
-- 'InferFunctionPermissions', we may fail to build expression parsers
-- in 'buildQueryAndSubscriptionFields' for users with unrecognised roles.
data InferFunctionPermissions
= InferFunctionPermissions
| Don'tInferFunctionPermissions
deriving (Eq, Show)
instance FromJSON InferFunctionPermissions where
parseJSON =
withBool "InferFunctionPermissions" $
pure . \case
True -> InferFunctionPermissions
False -> Don'tInferFunctionPermissions
instance ToJSON InferFunctionPermissions where
toJSON = \case
InferFunctionPermissions -> Bool True
Don'tInferFunctionPermissions -> Bool False
-- | Should we enable remote schema permissions? If so, these permissions will
-- influence 'Hasura.GraphQL.Schema.buildGQLContext'.
data RemoteSchemaPermissions
= EnableRemoteSchemaPermissions
| DisableRemoteSchemaPermissions
deriving (Eq, Show)
instance FromJSON RemoteSchemaPermissions where
parseJSON =
withBool "RemoteSchemaPermissions" $
pure . \case
True -> EnableRemoteSchemaPermissions
False -> DisableRemoteSchemaPermissions
instance ToJSON RemoteSchemaPermissions where
toJSON = \case
EnableRemoteSchemaPermissions -> Bool True
DisableRemoteSchemaPermissions -> Bool False
-- | Should we attempt to deduplicate permission filters? This flag is used in
-- 'Hasura.GraphQL.Schema.Select.relationshipField' to determine whether
-- certain row-level permission filters can be dropped in certain cases.
data OptimizePermissionFilters
= OptimizePermissionFilters
| Don'tOptimizePermissionFilters
deriving (Eq, Show)