server: Move the schema parsers to their own library.

It's about time.

To do this I had to check a few more boxes.

* I copied the flags from `graphql-engine.cabal` to the libraries in `server/lib`.
* I moved `Cacheable` instances of schema parser types beside the typeclass declaration.
* I removed imports of `Hasura.Prelude` from the tests, and rewrote them accordingly.
* I copied the `TestMonad` parse monad into `server/src-test/Hasura/GraphQL/Schema/RemoteTest.hs`, which was using it. I think this could be done with the real thing, but I tried replacing it with constraints and it messed with my head somewhat.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5311
GitOrigin-RevId: ebebcc50a16f2d517b7f730fe72410827ca3e86c
This commit is contained in:
Samir Talwar 2022-08-05 15:52:33 +02:00 committed by hasura-bot
parent a61741fbf5
commit aa18f65217
38 changed files with 422 additions and 102 deletions

View File

@ -28,3 +28,8 @@ cradle:
- path: "server/lib/error-message/test"
component: "hasura-error-message:test:tests"
- path: "server/lib/schema-parsers/src"
component: "hasura-schema-parsers:lib:hasura-schema-parsers"
- path: "server/lib/schema-parsers/test"
component: "hasura-schema-parsers:test:tests"

View File

@ -56,6 +56,6 @@ build-multitenant-integration-tests: $(GENERATED_CABAL_FILES)
# See the documentation for more information:
# https://www.gnu.org/software/make/manual/html_node/Static-Pattern.html
# https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
$(GENERATED_CABAL_FILES): %.cabal: $$(dir %)/package.yaml
$(GENERATED_CABAL_FILES): %.cabal: $$(dir %)/package.yaml server/lib/common.yaml $$(shell find $$(dir %) -name '*.hs')
./scripts/hpack.sh $@
@ touch $@ # Required because `hpack` will not change the modified timestamp if the file is up-to-date.

View File

@ -159,6 +159,7 @@ common lib-depends
, free
, hashable
, hasura-error-message
, hasura-schema-parsers
, http-client-tls
, http-conduit
, http-media
@ -796,26 +797,6 @@ library
, Hasura.GraphQL.Explain
, Hasura.GraphQL.Namespace
, Hasura.GraphQL.ParameterizedQueryHash
, Hasura.GraphQL.Parser
, Hasura.GraphQL.Parser.Class
, Hasura.GraphQL.Parser.Collect
, Hasura.GraphQL.Parser.DirectiveName
, Hasura.GraphQL.Parser.Directives
, Hasura.GraphQL.Parser.ErrorCode
, Hasura.GraphQL.Parser.Internal.Convert
, Hasura.GraphQL.Parser.Internal.Input
, Hasura.GraphQL.Parser.Internal.Parser
, Hasura.GraphQL.Parser.Internal.Scalars
, Hasura.GraphQL.Parser.Internal.TypeChecking
, Hasura.GraphQL.Parser.Internal.Types
, Hasura.GraphQL.Parser.Monad
, Hasura.GraphQL.Parser.Name
, Hasura.GraphQL.Parser.Name.Introspection
, Hasura.GraphQL.Parser.Name.TypeSystem
, Hasura.GraphQL.Parser.Names
, Hasura.GraphQL.Parser.Schema
, Hasura.GraphQL.Parser.Schema.Convert
, Hasura.GraphQL.Parser.Variable
, Hasura.GraphQL.RemoteServer
, Hasura.GraphQL.Schema
, Hasura.GraphQL.Schema.Action
@ -864,7 +845,6 @@ library
, Hasura.Eventing.ScheduledTrigger
, Hasura.Eventing.ScheduledTrigger.Types
, Hasura.Name
, Data.GADT.Compare.Extended
, Hasura.SQL.AnyBackend
, Hasura.SQL.Backend
, Hasura.SQL.BackendMap
@ -1058,10 +1038,6 @@ test-suite graphql-engine-tests
Hasura.EventingSpec
Hasura.Generator.Common
Hasura.GraphQL.NamespaceSpec
Hasura.GraphQL.Parser.DirectivesTest
Hasura.GraphQL.Parser.MonadParseTest
Hasura.GraphQL.Parser.TestInstances
Hasura.GraphQL.Parser.TestUtils
Hasura.GraphQL.Schema.Build.UpdateSpec
Hasura.GraphQL.Schema.RemoteTest
Hasura.IncrementalSpec

43
server/lib/common.yaml Normal file
View File

@ -0,0 +1,43 @@
common-boilerplate: &common-boilerplate
version: 1.0.0
author:
- Hasura, Inc.
github: hasura/github-engine
extra-source-files:
- ../../../LICENSE
common-lib: &common-lib
flags:
optimize-hasura:
description: Compile hasura code with appropriate optimizations
default: true
manual: false
profiling:
description: Configures the project to be profiling-compatible
default: false
manual: true
ghc-options:
- "-foptimal-applicative-do"
- "-Wall"
- "-Werror"
- "-Wcompat"
- "-Wincomplete-record-updates"
- "-Wincomplete-uni-patterns"
- "-Wredundant-constraints"
- "-Wmissing-export-lists"
when:
- condition: flag(profiling)
cpp-options: -DPROFILING
- condition: flag(optimize-hasura)
then:
ghc-options:
- "-fexpose-all-unfoldings"
- "-O2"
else:
# we just want to build fast
ghc-options:
- "-O0"

View File

@ -23,6 +23,16 @@ source-repository head
type: git
location: https://github.com/hasura/github-engine
flag optimize-hasura
description: Compile hasura code with appropriate optimizations
manual: False
default: True
flag profiling
description: Configures the project to be profiling-compatible
manual: True
default: False
library
exposed-modules:
Hasura.Base.ErrorMessage
@ -39,13 +49,19 @@ library
ImportQualifiedPost
OverloadedStrings
ScopedTypeVariables
ghc-options: -Wall -Werror
ghc-options: -foptimal-applicative-do -Wall -Werror -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -Wmissing-export-lists
build-depends:
aeson
, base
, graphql-parser
, text
, unordered-containers
if flag(profiling)
cpp-options: -DPROFILING
if flag(optimize-hasura)
ghc-options: -fexpose-all-unfoldings -O2
else
ghc-options: -O0
default-language: Haskell2010
test-suite tests
@ -63,7 +79,7 @@ test-suite tests
ImportQualifiedPost
OverloadedStrings
ScopedTypeVariables
ghc-options: -Wall -Werror -main-is Main
ghc-options: -foptimal-applicative-do -Wall -Werror -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -Wmissing-export-lists -main-is Main
build-depends:
aeson
, base
@ -74,4 +90,10 @@ test-suite tests
, text
, unordered-containers
, vector
if flag(profiling)
cpp-options: -DPROFILING
if flag(optimize-hasura)
ghc-options: -fexpose-all-unfoldings -O2
else
ghc-options: -O0
default-language: Haskell2010

View File

@ -3,17 +3,10 @@ spec-version: 0.34.7
name: hasura-error-message
description: >
An error message type that makes it difficult to convert back to text.
version: 1.0.0
author:
- Hasura, Inc.
github: hasura/github-engine
extra-source-files:
- ../../../LICENSE
ghc-options:
- "-Wall"
- "-Werror"
_common: !include "../common.yaml"
<<: *common-boilerplate
<<: *common-lib
default-extensions:
- BlockArguments

View File

@ -1 +1,2 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
{-# OPTIONS_GHC -Wno-missing-export-lists #-}

View File

@ -0,0 +1,202 @@
cabal-version: 1.12
-- This file is generated using hpack.
-- Do not modify it directly. Instead, edit package.yaml and then run:
-- make server/lib/schema-parsers/hasura-schema-parsers.cabal
-- This file has been generated from package.yaml by hpack version 0.34.7.
--
-- see: https://github.com/sol/hpack
name: hasura-schema-parsers
version: 1.0.0
description: Parsers built from GraphQL schemas.
homepage: https://github.com/hasura/github-engine#readme
bug-reports: https://github.com/hasura/github-engine/issues
author: Hasura, Inc.
maintainer: Hasura, Inc.
build-type: Simple
extra-source-files:
../../../LICENSE
source-repository head
type: git
location: https://github.com/hasura/github-engine
flag optimize-hasura
description: Compile hasura code with appropriate optimizations
manual: False
default: True
flag profiling
description: Configures the project to be profiling-compatible
manual: True
default: False
library
exposed-modules:
Data.GADT.Compare.Extended
Hasura.GraphQL.Parser
Hasura.GraphQL.Parser.Class
Hasura.GraphQL.Parser.Collect
Hasura.GraphQL.Parser.DirectiveName
Hasura.GraphQL.Parser.Directives
Hasura.GraphQL.Parser.ErrorCode
Hasura.GraphQL.Parser.Internal.Convert
Hasura.GraphQL.Parser.Internal.Input
Hasura.GraphQL.Parser.Internal.Parser
Hasura.GraphQL.Parser.Internal.Scalars
Hasura.GraphQL.Parser.Internal.TypeChecking
Hasura.GraphQL.Parser.Internal.Types
Hasura.GraphQL.Parser.Monad
Hasura.GraphQL.Parser.Name
Hasura.GraphQL.Parser.Name.Introspection
Hasura.GraphQL.Parser.Name.TypeSystem
Hasura.GraphQL.Parser.Names
Hasura.GraphQL.Parser.Schema
Hasura.GraphQL.Parser.Schema.Convert
Hasura.GraphQL.Parser.Variable
other-modules:
Paths_hasura_schema_parsers
hs-source-dirs:
src
default-extensions:
AllowAmbiguousTypes
ApplicativeDo
BangPatterns
BlockArguments
DataKinds
DeriveFoldable
DeriveFunctor
DeriveLift
DeriveGeneric
DeriveTraversable
DerivingStrategies
ExplicitNamespaces
FlexibleContexts
FlexibleInstances
FunctionalDependencies
GADTs
GeneralizedNewtypeDeriving
ImportQualifiedPost
KindSignatures
LambdaCase
MultiWayIf
MultiParamTypeClasses
NamedFieldPuns
OverloadedStrings
RankNTypes
RecordWildCards
ScopedTypeVariables
StandaloneDeriving
StrictData
TupleSections
TypeApplications
TypeFamilies
TypeOperators
ghc-options: -foptimal-applicative-do -Wall -Werror -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -Wmissing-export-lists
build-depends:
aeson
, base
, dependent-map
, dependent-sum
, graphql-parser
, hashable
, hasura-error-message
, insert-ordered-containers
, lens
, mtl
, scientific
, some
, template-haskell
, text
, th-lift
, unordered-containers
, uuid
, vector
, witherable
if flag(profiling)
cpp-options: -DPROFILING
if flag(optimize-hasura)
ghc-options: -fexpose-all-unfoldings -O2
else
ghc-options: -O0
default-language: Haskell2010
test-suite tests
type: exitcode-stdio-1.0
main-is: Main.hs
other-modules:
Hasura.GraphQL.Parser.DirectivesTest
Hasura.GraphQL.Parser.MonadParseTest
Hasura.GraphQL.Parser.TestInstances
Hasura.GraphQL.Parser.TestUtils
Paths_hasura_schema_parsers
hs-source-dirs:
test
default-extensions:
AllowAmbiguousTypes
ApplicativeDo
BangPatterns
BlockArguments
DataKinds
DeriveFoldable
DeriveFunctor
DeriveLift
DeriveGeneric
DeriveTraversable
DerivingStrategies
ExplicitNamespaces
FlexibleContexts
FlexibleInstances
FunctionalDependencies
GADTs
GeneralizedNewtypeDeriving
ImportQualifiedPost
KindSignatures
LambdaCase
MultiWayIf
MultiParamTypeClasses
NamedFieldPuns
OverloadedStrings
RankNTypes
RecordWildCards
ScopedTypeVariables
StandaloneDeriving
StrictData
TupleSections
TypeApplications
TypeFamilies
TypeOperators
ghc-options: -foptimal-applicative-do -Wall -Werror -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -Wmissing-export-lists -main-is Main
build-depends:
hasura-schema-parsers
, hspec
if flag(profiling)
cpp-options: -DPROFILING
if flag(optimize-hasura)
ghc-options: -fexpose-all-unfoldings -O2
else
ghc-options: -O0
if true
build-depends:
aeson
, base
, dependent-map
, dependent-sum
, graphql-parser
, hashable
, hasura-error-message
, insert-ordered-containers
, lens
, mtl
, scientific
, some
, template-haskell
, text
, th-lift
, unordered-containers
, uuid
, vector
, witherable
default-language: Haskell2010

View File

@ -0,0 +1,83 @@
spec-version: 0.34.7
name: hasura-schema-parsers
description: >
Parsers built from GraphQL schemas.
_common: !include "../common.yaml"
<<: *common-boilerplate
<<: *common-lib
default-extensions:
- AllowAmbiguousTypes
- ApplicativeDo
- BangPatterns
- BlockArguments
- DataKinds
- DeriveFoldable
- DeriveFunctor
- DeriveLift
- DeriveGeneric
- DeriveTraversable
- DerivingStrategies
- ExplicitNamespaces
- FlexibleContexts
- FlexibleInstances
- FunctionalDependencies
- GADTs
- GeneralizedNewtypeDeriving
- ImportQualifiedPost
- KindSignatures
- LambdaCase
- MultiWayIf
- MultiParamTypeClasses
- NamedFieldPuns
- OverloadedStrings
- RankNTypes
- RecordWildCards
- ScopedTypeVariables
- StandaloneDeriving
- StrictData
- TupleSections
- TypeApplications
- TypeFamilies
- TypeOperators
library:
source-dirs:
- src
dependencies: &library-dependencies
- base
- aeson
- dependent-map
- dependent-sum
- graphql-parser
- hashable
- hasura-error-message
- insert-ordered-containers
- lens
- mtl
- scientific
- some
- template-haskell
- text
- th-lift
- unordered-containers
- uuid
- vector
- witherable
tests:
tests:
source-dirs:
- test
main: Main
dependencies:
- hasura-schema-parsers
- hspec
when:
# Merges the library dependencies with the above list, using `when:` to cheat.
- condition: true
dependencies: *library-dependencies

View File

@ -7,8 +7,7 @@ module Data.GADT.Compare.Extended
)
where
import "some" Data.GADT.Compare
import Prelude
import Data.GADT.Compare
strengthenOrdering :: Ordering -> GOrdering a a
strengthenOrdering LT = GLT

View File

@ -20,7 +20,6 @@ import Hasura.GraphQL.Parser.Class
import Hasura.GraphQL.Parser.Directives
import Hasura.GraphQL.Parser.Variable
import Language.GraphQL.Draft.Syntax
import Prelude
-- | Collects the effective set of fields queried by a selection set by
-- flattening fragments and merging duplicate fields.

View File

@ -48,7 +48,6 @@ import Hasura.GraphQL.Parser.Variable
import Language.GraphQL.Draft.Syntax qualified as G
import Type.Reflection (Typeable, typeRep, (:~:) (..))
import Witherable (catMaybes)
import Prelude
-- Disable custom prelude warnings in preparation for extracting this module into a separate package.
{-# ANN module ("HLint: ignore Use onNothing" :: String) #-}

View File

@ -1,7 +1,5 @@
module Hasura.GraphQL.Parser.ErrorCode (ParseErrorCode (..)) where
import Prelude
data ParseErrorCode
= ValidationFailed
| ParseFailed

View File

@ -23,7 +23,6 @@ import Hasura.GraphQL.Parser.Class
import Hasura.GraphQL.Parser.Internal.TypeChecking
import Hasura.GraphQL.Parser.Variable
import Language.GraphQL.Draft.Syntax qualified as G
import Prelude
-- Disable custom prelude warnings in preparation for extracting this module into a separate package.
{-# ANN module ("HLint: ignore Use onNothing" :: String) #-}

View File

@ -40,7 +40,6 @@ import Hasura.GraphQL.Parser.Internal.Types
import Hasura.GraphQL.Parser.Schema
import Hasura.GraphQL.Parser.Variable
import Language.GraphQL.Draft.Syntax hiding (Definition)
import Prelude
-- Disable custom prelude warnings in preparation for extracting this module into a separate package.
{-# ANN module ("HLint: ignore Use onNothing" :: String) #-}

View File

@ -45,7 +45,6 @@ import Hasura.GraphQL.Parser.Variable
import Language.GraphQL.Draft.Syntax hiding (Definition)
import Language.GraphQL.Draft.Syntax qualified as G
import Witherable (catMaybes, mapMaybe)
import Prelude
infixl 1 `bind`

View File

@ -42,7 +42,6 @@ import Hasura.GraphQL.Parser.Name qualified as GName
import Hasura.GraphQL.Parser.Schema
import Hasura.GraphQL.Parser.Variable
import Language.GraphQL.Draft.Syntax hiding (Definition)
import Prelude
-- Disable custom prelude warnings in preparation for extracting this module into a separate package.
{-# ANN module ("HLint: ignore Use onLeft" :: String) #-}

View File

@ -20,7 +20,6 @@ import Hasura.GraphQL.Parser.Class
import Hasura.GraphQL.Parser.Names
import Hasura.GraphQL.Parser.Variable
import Language.GraphQL.Draft.Syntax hiding (Definition)
import Prelude
-- | Peeling a variable.
--

View File

@ -11,7 +11,6 @@ import Hasura.GraphQL.Parser.Names
import Hasura.GraphQL.Parser.Schema
import Hasura.GraphQL.Parser.Variable
import Language.GraphQL.Draft.Syntax hiding (Definition)
import Prelude
-- -----------------------------------------------------------------------------
-- type definitions

View File

@ -14,16 +14,13 @@ import Hasura.GraphQL.Parser.Class
import Hasura.GraphQL.Parser.ErrorCode
import Prelude
-- Disable custom prelude warnings in preparation for extracting this module into a separate package.
{-# ANN module ("HLint: ignore Use onLeft" :: String) #-}
-- -------------------------------------------------------------------------------------------------
-- query parsing
newtype Parse a = Parse
{ unParse :: Except ParseError a
}
deriving (Functor, Applicative, Monad)
deriving newtype (Functor, Applicative, Monad)
runParse ::
MonadError ParseError m =>

View File

@ -1,7 +1,6 @@
module Hasura.GraphQL.Parser.Names (HasName (..)) where
import Language.GraphQL.Draft.Syntax (Name)
import Prelude
class HasName a where
getName :: a -> Name

View File

@ -72,7 +72,6 @@ import Language.GraphQL.Draft.Syntax
Value (..),
)
import Language.GraphQL.Draft.Syntax qualified as G
import Prelude
-- | GraphQL types are divided into two classes: input types and output types.
-- The GraphQL spec does not use the word “kind” to describe these classes, but

View File

@ -8,7 +8,6 @@ where
import Data.List.NonEmpty qualified as NonEmpty
import Hasura.GraphQL.Parser.Schema
import Language.GraphQL.Draft.Syntax qualified as G
import Prelude
-------------------------------------------------------------------------------

View File

@ -10,14 +10,12 @@ import Data.Hashable (Hashable)
import Data.Void (Void)
import GHC.Generics (Generic)
import Hasura.GraphQL.Parser.Names
import Hasura.Incremental (Cacheable)
import Language.GraphQL.Draft.Syntax
( GType (..),
Name (..),
Value (..),
)
import Language.Haskell.TH.Lift qualified as TH
import Prelude
{- Note [Parsing variable values]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -81,8 +79,6 @@ data InputValue v
instance (Hashable v) => Hashable (InputValue v)
instance (Cacheable v) => Cacheable (InputValue v)
data Variable = Variable
{ vInfo :: VariableInfo,
vType :: GType,
@ -94,8 +90,6 @@ data Variable = Variable
instance Hashable Variable
instance Cacheable Variable
instance HasName Variable where
getName = getName . vInfo
@ -109,8 +103,6 @@ data VariableInfo
instance Hashable VariableInfo
instance Cacheable VariableInfo
instance HasName VariableInfo where
getName (VIRequired name) = name
getName (VIOptional name _) = name

View File

@ -1,11 +1,13 @@
module Hasura.GraphQL.Parser.DirectivesTest (spec) where
import Control.Monad.Identity (Identity (..))
import Data.Dependent.Map qualified as DM
import Data.Maybe (isJust)
import Data.Text qualified as T
import Hasura.GraphQL.Parser.Directives hiding (Directive)
import Hasura.GraphQL.Parser.Directives
import Hasura.GraphQL.Parser.Schema
import Hasura.GraphQL.Parser.TestInstances ()
import Hasura.GraphQL.Parser.TestUtils
import Hasura.GraphQL.Schema.Parser
import Hasura.Prelude
import Language.GraphQL.Draft.Syntax qualified as G
import Test.Hspec
@ -16,7 +18,7 @@ spec = do
testDirective cachedDirective cached
testDirective multipleRootFieldsDirective multipleRootFields
testDirective :: Directive TestMonad -> DirectiveKey a -> Spec
testDirective :: Directive origin TestMonad -> DirectiveKey a -> Spec
testDirective dir key = do
let name = diName $ dDefinition dir
location = head $ diLocations $ dDefinition dir

View File

@ -6,7 +6,6 @@ import Hasura.GraphQL.Parser.Class
import Hasura.GraphQL.Parser.ErrorCode
import Hasura.GraphQL.Parser.Monad
import Hasura.GraphQL.Parser.TestInstances ()
import Hasura.Prelude
import Test.Hspec
runParse' :: Parse () -> Either ParseError ()

View File

@ -0,0 +1,16 @@
{-# OPTIONS_GHC -Wno-orphans #-}
module Hasura.GraphQL.Parser.TestInstances () where
import Data.Text qualified as Text
import Hasura.Base.ErrorMessage (ErrorMessage, fromErrorMessage)
import Hasura.GraphQL.Parser.Monad (ParseError (..))
-- Orphan instances so that we can write assertions over 'Either ErrorMessage a'.
instance Show ErrorMessage where
show = Text.unpack . fromErrorMessage
-- Orphan instances so that we can write assertions over 'Either ParseError a'.
deriving stock instance Eq ParseError
deriving stock instance Show ParseError

View File

@ -6,36 +6,36 @@ module Hasura.GraphQL.Parser.TestUtils
)
where
import Data.Functor ((<&>))
import Data.HashMap.Strict qualified as M
import Data.List.NonEmpty qualified as NE
import Data.Text qualified as T
import Hasura.Base.ErrorMessage (fromErrorMessage)
import Hasura.GraphQL.Schema.Parser
import Hasura.Prelude
import Hasura.Base.ErrorMessage (ErrorMessage)
import Hasura.GraphQL.Parser
import Hasura.GraphQL.Parser.Name qualified as GName
import Language.GraphQL.Draft.Syntax qualified as G
-- test monad
newtype TestMonad a = TestMonad {runTest :: Either Text a}
deriving (Functor, Applicative, Monad)
newtype TestMonad a = TestMonad {runTest :: Either ErrorMessage a}
deriving newtype (Functor, Applicative, Monad)
instance MonadParse TestMonad where
withKey = const id
parseErrorWith = const $ TestMonad . Left . fromErrorMessage
parseErrorWith = const $ TestMonad . Left
-- values generation
fakeScalar :: G.Name -> G.Value Variable
fakeScalar =
G.unName >>> \case
"Int" -> G.VInt 4242
"Boolean" -> G.VBoolean False
name -> error $ "no test value implemented for scalar " <> T.unpack name
fakeScalar name =
if
| name == GName._Int -> G.VInt 4242
| name == GName._Boolean -> G.VBoolean False
| otherwise -> error $ "no test value implemented for scalar " <> show name
fakeInputFieldValue :: InputFieldInfo -> G.Value Variable
fakeInputFieldValue :: forall origin. InputFieldInfo origin -> G.Value Variable
fakeInputFieldValue (InputFieldInfo t _) = go t
where
go :: forall k. ('Input <: k) => Type k -> G.Value Variable
go :: forall k. ('Input <: k) => Type origin k -> G.Value Variable
go = \case
TList _ t' -> G.VList [go t', go t']
TNamed _ (Definition name _ _ _ info) -> case (info, subKind @'Input @k) of
@ -47,7 +47,7 @@ fakeInputFieldValue (InputFieldInfo t _) = go t
pure (fieldName, fakeInputFieldValue fieldInfo)
_ -> error "fakeInputFieldValue: non-exhaustive. FIXME"
fakeDirective :: DirectiveInfo -> G.Directive Variable
fakeDirective :: DirectiveInfo origin -> G.Directive Variable
fakeDirective DirectiveInfo {..} =
G.Directive diName $
M.fromList $

View File

@ -0,0 +1,2 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
{-# OPTIONS_GHC -Wno-missing-export-lists #-}

View File

@ -45,6 +45,7 @@ import GHC.Generics
(:*:) (..),
(:+:) (..),
)
import Hasura.GraphQL.Parser qualified as P
import Hasura.Incremental.Select
import Hasura.Prelude
import Language.GraphQL.Draft.Syntax qualified as G
@ -403,6 +404,12 @@ instance Cacheable Scheme
instance Cacheable BaseUrl
instance (Cacheable v) => Cacheable (P.InputValue v)
instance Cacheable P.Variable
instance Cacheable P.VariableInfo
class GCacheable f where
gunchanged :: f p -> f p -> Accesses -> Bool

View File

@ -1,15 +0,0 @@
{-# OPTIONS_GHC -Wno-orphans #-}
module Hasura.GraphQL.Parser.TestInstances () where
import Hasura.Base.ErrorMessage (fromErrorMessage)
import Hasura.GraphQL.Parser.Monad (ParseError (..))
import Hasura.Prelude
-- Orphan instances so that we can write assertions over 'Either ParseError a'.
deriving stock instance Eq ParseError
-- This cannot be automatically derived because 'ErrorMessage' doesn't have a 'Show' instance.
instance Show ParseError where
show ParseError {pePath, peMessage, peCode} =
"ParseError { pePath = " <> show pePath <> ", peMessage = " <> show (fromErrorMessage peMessage) <> ", peCode = " <> show peCode <> "}"

View File

@ -14,13 +14,13 @@ import Data.Text qualified as T
import Data.Text.Extended
import Data.Text.RawString
import Hasura.Base.Error
import Hasura.Base.ErrorMessage (ErrorMessage, fromErrorMessage)
import Hasura.GraphQL.Execute.Inline
import Hasura.GraphQL.Execute.Remote (resolveRemoteVariable, runVariableCache)
import Hasura.GraphQL.Execute.Resolve
import Hasura.GraphQL.Namespace
import Hasura.GraphQL.Parser.Name qualified as GName
import Hasura.GraphQL.Parser.Names
import Hasura.GraphQL.Parser.TestUtils
import Hasura.GraphQL.Parser.Variable
import Hasura.GraphQL.Schema.Common
import Hasura.GraphQL.Schema.NamingCase
@ -44,6 +44,15 @@ import Language.GraphQL.Draft.Syntax.QQ qualified as G
import Network.URI qualified as N
import Test.Hspec
-- test monad
newtype TestMonad a = TestMonad {runTest :: Either ErrorMessage a}
deriving newtype (Functor, Applicative, Monad)
instance P.MonadParse TestMonad where
withKey = const id
parseErrorWith = const $ TestMonad . Left
-- test tools
runError :: Monad m => ExceptT QErr m a -> m a
@ -159,7 +168,7 @@ runQueryParser parser (varDefs, selSet) vars = runIdentity . runError $ do
field <- case resolvedSelSet of
[G.SelectionField f] -> pure f
_ -> error "expecting only one field in the query"
runTest (P.fParser parser field) `onLeft` throw500
runTest (P.fParser parser field) `onLeft` (throw500 . fromErrorMessage)
run ::
-- | schema