Compare commits
11 Commits
4063d48a37
...
v1.3.0.0
Author | SHA1 | Date | |
---|---|---|---|
1c4584abdd
|
|||
e071553e75
|
|||
e731c7db07
|
|||
303cf18d77
|
|||
6b8346e527
|
|||
303f84ed41
|
|||
d2ea9fb467
|
|||
809f446ff1
|
|||
b1b6bfcdb9
|
|||
59aa010f0b | |||
b1c5a568dd
|
@ -2,67 +2,51 @@ name: Build
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
branches:
|
||||||
|
- '**'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [master]
|
branches: [master]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
audit:
|
audit:
|
||||||
runs-on: alpine
|
runs-on: haskell
|
||||||
steps:
|
steps:
|
||||||
- name: Set up environment
|
- name: Set up environment
|
||||||
shell: ash {0}
|
|
||||||
run: |
|
run: |
|
||||||
apk add --no-cache git bash curl build-base readline-dev openssl-dev zlib-dev libpq-dev gmp-dev
|
apt-get update -y
|
||||||
- name: Prepare system
|
apt-get upgrade -y
|
||||||
run: |
|
apt-get install -y nodejs pkg-config
|
||||||
curl --create-dirs --output-dir \
|
|
||||||
~/.ghcup/bin https://downloads.haskell.org/~ghcup/0.1.19.5/x86_64-linux-ghcup-0.1.19.5 -o ghcup
|
|
||||||
chmod +x ~/.ghcup/bin/ghcup
|
|
||||||
~/.ghcup/bin/ghcup install ghc 9.4.8
|
|
||||||
~/.ghcup/bin/ghcup install cabal 3.6.2.0
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
~/.ghcup/bin/ghcup run --ghc 9.4.8 --cabal 3.6.2.0 -- cabal update
|
cabal update
|
||||||
~/.ghcup/bin/ghcup run --ghc 9.4.8 --cabal 3.6.2.0 -- cabal install hlint --constraint="hlint ==3.6.1"
|
cabal install hlint "--constraint=hlint ==3.8"
|
||||||
- run: ~/.cabal/bin/hlint -- src tests
|
- run: cabal exec hlint -- src tests
|
||||||
|
|
||||||
test:
|
test:
|
||||||
runs-on: alpine
|
runs-on: haskell
|
||||||
steps:
|
steps:
|
||||||
- name: Set up environment
|
- name: Set up environment
|
||||||
shell: ash {0}
|
|
||||||
run: |
|
run: |
|
||||||
apk add --no-cache git bash curl build-base readline-dev openssl-dev zlib-dev libpq-dev gmp-dev
|
apt-get update -y
|
||||||
- name: Prepare system
|
apt-get upgrade -y
|
||||||
run: |
|
apt-get install -y nodejs pkg-config
|
||||||
curl --create-dirs --output-dir \
|
|
||||||
~/.ghcup/bin https://downloads.haskell.org/~ghcup/0.1.19.5/x86_64-linux-ghcup-0.1.19.5 -o ghcup
|
|
||||||
chmod +x ~/.ghcup/bin/ghcup
|
|
||||||
~/.ghcup/bin/ghcup install ghc 9.4.8
|
|
||||||
~/.ghcup/bin/ghcup install cabal 3.6.2.0
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: cabal update
|
||||||
~/.ghcup/bin/ghcup run --ghc 9.4.8 --cabal 3.6.2.0 -- cabal update
|
- name: Prepare system
|
||||||
~/.ghcup/bin/ghcup run --ghc 9.4.8 --cabal 3.6.2.0 -- cabal build graphql-test
|
run: cabal build graphql-test
|
||||||
- run: ~/.ghcup/bin/ghcup run --ghc 9.4.8 --cabal 3.6.2.0 -- cabal test --test-show-details=direct
|
- run: cabal test --test-show-details=streaming
|
||||||
|
|
||||||
doc:
|
doc:
|
||||||
runs-on: alpine
|
runs-on: haskell
|
||||||
steps:
|
steps:
|
||||||
- name: Set up environment
|
- name: Set up environment
|
||||||
shell: ash {0}
|
|
||||||
run: |
|
run: |
|
||||||
apk add --no-cache git bash curl build-base readline-dev openssl-dev zlib-dev libpq-dev gmp-dev
|
apt-get update -y
|
||||||
- name: Prepare system
|
apt-get upgrade -y
|
||||||
run: |
|
apt-get install -y nodejs pkg-config
|
||||||
curl --create-dirs --output-dir \
|
|
||||||
~/.ghcup/bin https://downloads.haskell.org/~ghcup/0.1.19.5/x86_64-linux-ghcup-0.1.19.5 -o ghcup
|
|
||||||
chmod +x ~/.ghcup/bin/ghcup
|
|
||||||
~/.ghcup/bin/ghcup install ghc 9.4.8
|
|
||||||
~/.ghcup/bin/ghcup install cabal 3.6.2.0
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: ~/.ghcup/bin/ghcup run --ghc 9.4.8 --cabal 3.6.2.0 -- cabal update
|
run: cabal update
|
||||||
- run: ~/.ghcup/bin/ghcup run --ghc 9.4.8 --cabal 3.6.2.0 -- cabal haddock --enable-documentation
|
- run: cabal haddock --enable-documentation
|
||||||
|
23
.gitea/workflows/release.yml
Normal file
23
.gitea/workflows/release.yml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: haskell
|
||||||
|
steps:
|
||||||
|
- name: Set up environment
|
||||||
|
run: |
|
||||||
|
apt-get update -y
|
||||||
|
apt-get upgrade -y
|
||||||
|
apt-get install -y nodejs pkg-config
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Upload a candidate
|
||||||
|
env:
|
||||||
|
HACKAGE_PASSWORD: ${{ secrets.HACKAGE_PASSWORD }}
|
||||||
|
run: |
|
||||||
|
cabal sdist
|
||||||
|
cabal upload --username belka --password ${HACKAGE_PASSWORD}
|
16
CHANGELOG.md
16
CHANGELOG.md
@ -6,11 +6,21 @@ The format is based on
|
|||||||
and this project adheres to
|
and this project adheres to
|
||||||
[Haskell Package Versioning Policy](https://pvp.haskell.org/).
|
[Haskell Package Versioning Policy](https://pvp.haskell.org/).
|
||||||
|
|
||||||
## [Unreleased]
|
## [1.3.0.0] - 2024-05-01
|
||||||
|
### Changed
|
||||||
|
- Remove deprecated `runCollectErrs`, `Resolution`, `CollectErrsT` from the
|
||||||
|
`Error` module.
|
||||||
|
|
||||||
|
## [1.2.0.3] - 2024-01-09
|
||||||
|
### Fixed
|
||||||
|
- Fix corrupted source distribution.
|
||||||
|
|
||||||
|
## [1.2.0.2] - 2024-01-09
|
||||||
### Fixed
|
### Fixed
|
||||||
- `gql` removes not only leading `\n` but also `\r`.
|
- `gql` removes not only leading `\n` but also `\r`.
|
||||||
- Fix non nullable type string representation in executor error messages.
|
- Fix non nullable type string representation in executor error messages.
|
||||||
- Fix input objects not being coerced to lists.
|
- Fix input objects not being coerced to lists.
|
||||||
|
- Fix used variables are not found in the properties of input objects.
|
||||||
|
|
||||||
## [1.2.0.1] - 2023-04-25
|
## [1.2.0.1] - 2023-04-25
|
||||||
### Fixed
|
### Fixed
|
||||||
@ -514,7 +524,9 @@ and this project adheres to
|
|||||||
### Added
|
### Added
|
||||||
- Data types for the GraphQL language.
|
- Data types for the GraphQL language.
|
||||||
|
|
||||||
[Unreleased]: https://git.caraus.tech/OSS/graphql/compare/v1.2.0.1...master
|
[1.3.0.0]: https://git.caraus.tech/OSS/graphql/compare/v1.2.0.3...v1.3.0.0
|
||||||
|
[1.2.0.3]: https://git.caraus.tech/OSS/graphql/compare/v1.2.0.2...v1.2.0.3
|
||||||
|
[1.2.0.2]: https://git.caraus.tech/OSS/graphql/compare/v1.2.0.1...v1.2.0.2
|
||||||
[1.2.0.1]: https://git.caraus.tech/OSS/graphql/compare/v1.2.0.0...v1.2.0.1
|
[1.2.0.1]: https://git.caraus.tech/OSS/graphql/compare/v1.2.0.0...v1.2.0.1
|
||||||
[1.2.0.0]: https://git.caraus.tech/OSS/graphql/compare/v1.1.0.0...v1.2.0.0
|
[1.2.0.0]: https://git.caraus.tech/OSS/graphql/compare/v1.1.0.0...v1.2.0.0
|
||||||
[1.1.0.0]: https://git.caraus.tech/OSS/graphql/compare/v1.0.3.0...v1.1.0.0
|
[1.1.0.0]: https://git.caraus.tech/OSS/graphql/compare/v1.0.3.0...v1.1.0.0
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
cabal-version: 2.4
|
cabal-version: 2.4
|
||||||
|
|
||||||
name: graphql
|
name: graphql
|
||||||
version: 1.2.0.1
|
version: 1.3.0.0
|
||||||
synopsis: Haskell GraphQL implementation
|
synopsis: Haskell GraphQL implementation
|
||||||
description: Haskell <https://spec.graphql.org/June2018/ GraphQL> implementation.
|
description: Haskell <https://spec.graphql.org/June2018/ GraphQL> implementation.
|
||||||
category: Language
|
category: Language
|
||||||
@ -11,7 +11,7 @@ author: Danny Navarro <j@dannynavarro.net>,
|
|||||||
Matthías Páll Gissurarson <mpg@mpg.is>,
|
Matthías Páll Gissurarson <mpg@mpg.is>,
|
||||||
Sólrún Halla Einarsdóttir <she@mpg.is>
|
Sólrún Halla Einarsdóttir <she@mpg.is>
|
||||||
maintainer: belka@caraus.de
|
maintainer: belka@caraus.de
|
||||||
copyright: (c) 2019-2023 Eugen Wissner,
|
copyright: (c) 2019-2024 Eugen Wissner,
|
||||||
(c) 2015-2017 J. Daniel Navarro
|
(c) 2015-2017 J. Daniel Navarro
|
||||||
license: MPL-2.0 AND BSD-3-Clause
|
license: MPL-2.0 AND BSD-3-Clause
|
||||||
license-files: LICENSE,
|
license-files: LICENSE,
|
||||||
@ -60,7 +60,7 @@ library
|
|||||||
build-depends:
|
build-depends:
|
||||||
base >= 4.7 && < 5,
|
base >= 4.7 && < 5,
|
||||||
conduit ^>= 1.3.4,
|
conduit ^>= 1.3.4,
|
||||||
containers ^>= 0.6.2,
|
containers >= 0.6 && < 0.8,
|
||||||
exceptions ^>= 0.10.4,
|
exceptions ^>= 0.10.4,
|
||||||
megaparsec >= 9.0 && < 10,
|
megaparsec >= 9.0 && < 10,
|
||||||
parser-combinators >= 1.3 && < 2,
|
parser-combinators >= 1.3 && < 2,
|
||||||
@ -93,7 +93,7 @@ test-suite graphql-test
|
|||||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
||||||
|
|
||||||
build-depends:
|
build-depends:
|
||||||
QuickCheck ^>= 2.14.1,
|
QuickCheck >= 2.14 && < 2.16,
|
||||||
base,
|
base,
|
||||||
conduit,
|
conduit,
|
||||||
exceptions,
|
exceptions,
|
||||||
|
@ -8,28 +8,22 @@
|
|||||||
|
|
||||||
-- | Error handling.
|
-- | Error handling.
|
||||||
module Language.GraphQL.Error
|
module Language.GraphQL.Error
|
||||||
( CollectErrsT
|
( Error(..)
|
||||||
, Error(..)
|
|
||||||
, Path(..)
|
, Path(..)
|
||||||
, Resolution(..)
|
|
||||||
, ResolverException(..)
|
, ResolverException(..)
|
||||||
, Response(..)
|
, Response(..)
|
||||||
, ResponseEventStream
|
, ResponseEventStream
|
||||||
, parseError
|
, parseError
|
||||||
, runCollectErrs
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Conduit
|
import Conduit
|
||||||
import Control.Exception (Exception(..))
|
import Control.Exception (Exception(..))
|
||||||
import Control.Monad.Trans.State (StateT, runStateT)
|
|
||||||
import Data.HashMap.Strict (HashMap)
|
|
||||||
import Data.Sequence (Seq(..), (|>))
|
import Data.Sequence (Seq(..), (|>))
|
||||||
import qualified Data.Sequence as Seq
|
import qualified Data.Sequence as Seq
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
import Language.GraphQL.AST (Location(..), Name)
|
import Language.GraphQL.AST (Location(..))
|
||||||
import Language.GraphQL.Execute.Coerce
|
import Language.GraphQL.Execute.Coerce
|
||||||
import qualified Language.GraphQL.Type.Schema as Schema
|
|
||||||
import Prelude hiding (null)
|
import Prelude hiding (null)
|
||||||
import Text.Megaparsec
|
import Text.Megaparsec
|
||||||
( ParseErrorBundle(..)
|
( ParseErrorBundle(..)
|
||||||
@ -97,28 +91,3 @@ instance Show ResolverException where
|
|||||||
show (ResolverException e) = show e
|
show (ResolverException e) = show e
|
||||||
|
|
||||||
instance Exception ResolverException
|
instance Exception ResolverException
|
||||||
|
|
||||||
-- * Deprecated
|
|
||||||
|
|
||||||
{-# DEPRECATED runCollectErrs "runCollectErrs was part of the old executor and isn't used anymore" #-}
|
|
||||||
-- | Runs the given query computation, but collects the errors into an error
|
|
||||||
-- list, which is then sent back with the data.
|
|
||||||
runCollectErrs :: (Monad m, Serialize a)
|
|
||||||
=> HashMap Name (Schema.Type m)
|
|
||||||
-> CollectErrsT m a
|
|
||||||
-> m (Response a)
|
|
||||||
runCollectErrs types' res = do
|
|
||||||
(dat, Resolution{..}) <- runStateT res
|
|
||||||
$ Resolution{ errors = Seq.empty, types = types' }
|
|
||||||
pure $ Response dat errors
|
|
||||||
|
|
||||||
{-# DEPRECATED Resolution "Resolution was part of the old executor and isn't used anymore" #-}
|
|
||||||
-- | Executor context.
|
|
||||||
data Resolution m = Resolution
|
|
||||||
{ errors :: Seq Error
|
|
||||||
, types :: HashMap Name (Schema.Type m)
|
|
||||||
}
|
|
||||||
|
|
||||||
{-# DEPRECATED CollectErrsT "CollectErrsT was part of the old executor and isn't used anymore" #-}
|
|
||||||
-- | A wrapper to pass error messages around.
|
|
||||||
type CollectErrsT m = StateT (Resolution m) m
|
|
||||||
|
@ -2,11 +2,13 @@
|
|||||||
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||||
obtain one at https://mozilla.org/MPL/2.0/. -}
|
obtain one at https://mozilla.org/MPL/2.0/. -}
|
||||||
|
|
||||||
|
{-# LANGUAGE DataKinds #-}
|
||||||
{-# LANGUAGE LambdaCase #-}
|
{-# LANGUAGE LambdaCase #-}
|
||||||
{-# LANGUAGE NamedFieldPuns #-}
|
{-# LANGUAGE NamedFieldPuns #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
|
{-# LANGUAGE TypeApplications #-}
|
||||||
{-# LANGUAGE ViewPatterns #-}
|
{-# LANGUAGE ViewPatterns #-}
|
||||||
|
|
||||||
-- | This module contains default rules defined in the GraphQL specification.
|
-- | This module contains default rules defined in the GraphQL specification.
|
||||||
@ -61,6 +63,7 @@ import Data.Sequence (Seq(..), (|>))
|
|||||||
import qualified Data.Sequence as Seq
|
import qualified Data.Sequence as Seq
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
|
import GHC.Records (HasField(..))
|
||||||
import qualified Language.GraphQL.AST.Document as Full
|
import qualified Language.GraphQL.AST.Document as Full
|
||||||
import qualified Language.GraphQL.Type.Definition as Definition
|
import qualified Language.GraphQL.Type.Definition as Definition
|
||||||
import qualified Language.GraphQL.Type.Internal as Type
|
import qualified Language.GraphQL.Type.Internal as Type
|
||||||
@ -618,6 +621,10 @@ noUndefinedVariablesRule =
|
|||||||
, "\"."
|
, "\"."
|
||||||
]
|
]
|
||||||
|
|
||||||
|
-- Used to find the difference between defined and used variables. The first
|
||||||
|
-- argument are variables defined in the operation, the second argument are
|
||||||
|
-- variables used in the query. It should return the difference between these
|
||||||
|
-- 2 sets.
|
||||||
type UsageDifference
|
type UsageDifference
|
||||||
= HashMap Full.Name [Full.Location]
|
= HashMap Full.Name [Full.Location]
|
||||||
-> HashMap Full.Name [Full.Location]
|
-> HashMap Full.Name [Full.Location]
|
||||||
@ -664,25 +671,16 @@ variableUsageDifference difference errorMessage = OperationDefinitionRule $ \cas
|
|||||||
= filterSelections' selections
|
= filterSelections' selections
|
||||||
>>= lift . mapReaderT (<> mapDirectives directives') . pure
|
>>= lift . mapReaderT (<> mapDirectives directives') . pure
|
||||||
findDirectiveVariables (Full.Directive _ arguments _) = mapArguments arguments
|
findDirectiveVariables (Full.Directive _ arguments _) = mapArguments arguments
|
||||||
|
|
||||||
mapArguments = Seq.fromList . (>>= findArgumentVariables)
|
mapArguments = Seq.fromList . (>>= findArgumentVariables)
|
||||||
mapDirectives = foldMap findDirectiveVariables
|
mapDirectives = foldMap findDirectiveVariables
|
||||||
|
|
||||||
findArgumentVariables (Full.Argument _ Full.Node{node = value, ..} _) =
|
findArgumentVariables (Full.Argument _ value _) = findNodeVariables value
|
||||||
findValueVariables location value
|
findNodeVariables Full.Node{ node = value, ..} = findValueVariables location value
|
||||||
|
|
||||||
findValueVariables location (Full.Variable value') = [(value', [location])]
|
findValueVariables location (Full.Variable value') = [(value', [location])]
|
||||||
findValueVariables location (Full.List values) =
|
findValueVariables _ (Full.List values) = values >>= findNodeVariables
|
||||||
values
|
findValueVariables _ (Full.Object fields) = fields
|
||||||
>>= (\(Full.Node{node = value}) -> findValueVariables location value)
|
>>= findNodeVariables . getField @"value"
|
||||||
findValueVariables _ (Full.Object fields) =
|
|
||||||
fields
|
|
||||||
>>= ( \( Full.ObjectField
|
|
||||||
{ location = location
|
|
||||||
, value = Full.Node{node = value}
|
|
||||||
}
|
|
||||||
) -> findValueVariables location value
|
|
||||||
)
|
|
||||||
findValueVariables _ _ = []
|
findValueVariables _ _ = []
|
||||||
makeError operationName (variableName, locations') = Error
|
makeError operationName (variableName, locations') = Error
|
||||||
{ message = errorMessage operationName variableName
|
{ message = errorMessage operationName variableName
|
||||||
|
@ -7,6 +7,7 @@ import Test.QuickCheck.Arbitrary (Arbitrary (arbitrary))
|
|||||||
import Test.QuickCheck (oneof, elements, listOf, resize, NonEmptyList (..))
|
import Test.QuickCheck (oneof, elements, listOf, resize, NonEmptyList (..))
|
||||||
import Test.QuickCheck.Gen (Gen (..))
|
import Test.QuickCheck.Gen (Gen (..))
|
||||||
import Data.Text (Text, pack)
|
import Data.Text (Text, pack)
|
||||||
|
import Data.Functor ((<&>))
|
||||||
|
|
||||||
newtype AnyPrintableChar = AnyPrintableChar { getAnyPrintableChar :: Char } deriving (Eq, Show)
|
newtype AnyPrintableChar = AnyPrintableChar { getAnyPrintableChar :: Char } deriving (Eq, Show)
|
||||||
|
|
||||||
@ -59,34 +60,36 @@ instance Arbitrary a => Arbitrary (AnyObjectField a) where
|
|||||||
location' <- getAnyLocation <$> arbitrary
|
location' <- getAnyLocation <$> arbitrary
|
||||||
pure $ AnyObjectField $ Doc.ObjectField name' value' location'
|
pure $ AnyObjectField $ Doc.ObjectField name' value' location'
|
||||||
|
|
||||||
newtype AnyValue = AnyValue { getAnyValue :: Doc.Value } deriving (Eq, Show)
|
newtype AnyValue = AnyValue { getAnyValue :: Doc.Value }
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
instance Arbitrary AnyValue where
|
instance Arbitrary AnyValue
|
||||||
arbitrary = AnyValue <$> oneof
|
where
|
||||||
[ variableGen
|
arbitrary =
|
||||||
, Doc.Int <$> arbitrary
|
let variableGen :: Gen Doc.Value
|
||||||
, Doc.Float <$> arbitrary
|
variableGen = Doc.Variable . getAnyName <$> arbitrary
|
||||||
, Doc.String <$> (getAnyPrintableText <$> arbitrary)
|
listGen :: Gen [Doc.Node Doc.Value]
|
||||||
, Doc.Boolean <$> arbitrary
|
listGen = (resize 5 . listOf) nodeGen
|
||||||
, MkGen $ \_ _ -> Doc.Null
|
nodeGen :: Gen (Doc.Node Doc.Value)
|
||||||
, Doc.Enum <$> (getAnyName <$> arbitrary)
|
nodeGen = fmap getAnyNode arbitrary <&> fmap getAnyValue
|
||||||
, Doc.List <$> listGen
|
objectGen :: Gen [Doc.ObjectField Doc.Value]
|
||||||
, Doc.Object <$> objectGen
|
objectGen = resize 1
|
||||||
]
|
$ fmap getNonEmpty arbitrary
|
||||||
where
|
<&> map (fmap getAnyValue . getAnyObjectField)
|
||||||
variableGen :: Gen Doc.Value
|
in AnyValue <$> oneof
|
||||||
variableGen = Doc.Variable <$> (getAnyName <$> arbitrary)
|
[ variableGen
|
||||||
listGen :: Gen [Doc.Node Doc.Value]
|
, Doc.Int <$> arbitrary
|
||||||
listGen = (resize 5 . listOf) nodeGen
|
, Doc.Float <$> arbitrary
|
||||||
nodeGen = do
|
, Doc.String . getAnyPrintableText <$> arbitrary
|
||||||
node' <- getAnyNode <$> (arbitrary :: Gen (AnyNode AnyValue))
|
, Doc.Boolean <$> arbitrary
|
||||||
pure (getAnyValue <$> node')
|
, MkGen $ \_ _ -> Doc.Null
|
||||||
objectGen :: Gen [Doc.ObjectField Doc.Value]
|
, Doc.Enum . getAnyName <$> arbitrary
|
||||||
objectGen = resize 1 $ do
|
, Doc.List <$> listGen
|
||||||
list <- getNonEmpty <$> (arbitrary :: Gen (NonEmptyList (AnyObjectField AnyValue)))
|
, Doc.Object <$> objectGen
|
||||||
pure $ map (fmap getAnyValue . getAnyObjectField) list
|
]
|
||||||
|
|
||||||
newtype AnyArgument a = AnyArgument { getAnyArgument :: Doc.Argument } deriving (Eq, Show)
|
newtype AnyArgument a = AnyArgument { getAnyArgument :: Doc.Argument }
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
instance Arbitrary a => Arbitrary (AnyArgument a) where
|
instance Arbitrary a => Arbitrary (AnyArgument a) where
|
||||||
arbitrary = do
|
arbitrary = do
|
||||||
|
@ -29,6 +29,7 @@ queryType = ObjectType "Query" Nothing [] $ HashMap.fromList
|
|||||||
[ ("dog", dogResolver)
|
[ ("dog", dogResolver)
|
||||||
, ("cat", catResolver)
|
, ("cat", catResolver)
|
||||||
, ("findDog", findDogResolver)
|
, ("findDog", findDogResolver)
|
||||||
|
, ("findCats", findCatsResolver)
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
dogField = Field Nothing (Out.NamedObjectType dogType) mempty
|
dogField = Field Nothing (Out.NamedObjectType dogType) mempty
|
||||||
@ -39,6 +40,11 @@ queryType = ObjectType "Query" Nothing [] $ HashMap.fromList
|
|||||||
findDogResolver = ValueResolver findDogField $ pure Null
|
findDogResolver = ValueResolver findDogField $ pure Null
|
||||||
catField = Field Nothing (Out.NamedObjectType catType) mempty
|
catField = Field Nothing (Out.NamedObjectType catType) mempty
|
||||||
catResolver = ValueResolver catField $ pure Null
|
catResolver = ValueResolver catField $ pure Null
|
||||||
|
findCatsArguments = HashMap.singleton "commands"
|
||||||
|
$ In.Argument Nothing (In.NonNullListType $ In.NonNullEnumType catCommandType)
|
||||||
|
$ Just $ List []
|
||||||
|
findCatsField = Field Nothing (Out.NonNullListType $ Out.NonNullObjectType catType) findCatsArguments
|
||||||
|
findCatsResolver = ValueResolver findCatsField $ pure $ List []
|
||||||
|
|
||||||
catCommandType :: EnumType
|
catCommandType :: EnumType
|
||||||
catCommandType = EnumType "CatCommand" Nothing $ HashMap.fromList
|
catCommandType = EnumType "CatCommand" Nothing $ HashMap.fromList
|
||||||
@ -538,7 +544,7 @@ spec =
|
|||||||
}
|
}
|
||||||
in validate queryString `shouldContain` [expected]
|
in validate queryString `shouldContain` [expected]
|
||||||
|
|
||||||
context "noUndefinedVariablesRule" $
|
context "noUndefinedVariablesRule" $ do
|
||||||
it "rejects undefined variables" $
|
it "rejects undefined variables" $
|
||||||
let queryString = [gql|
|
let queryString = [gql|
|
||||||
query variableIsNotDefinedUsedInSingleFragment {
|
query variableIsNotDefinedUsedInSingleFragment {
|
||||||
@ -560,7 +566,35 @@ spec =
|
|||||||
}
|
}
|
||||||
in validate queryString `shouldBe` [expected]
|
in validate queryString `shouldBe` [expected]
|
||||||
|
|
||||||
context "noUnusedVariablesRule" $
|
it "gets variable location inside an input object" $
|
||||||
|
let queryString = [gql|
|
||||||
|
query {
|
||||||
|
findDog (complex: { name: $name }) {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
expected = Error
|
||||||
|
{ message = "Variable \"$name\" is not defined."
|
||||||
|
, locations = [AST.Location 2 29]
|
||||||
|
}
|
||||||
|
in validate queryString `shouldBe` [expected]
|
||||||
|
|
||||||
|
it "gets variable location inside an array" $
|
||||||
|
let queryString = [gql|
|
||||||
|
query {
|
||||||
|
findCats (commands: [JUMP, $command]) {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
expected = Error
|
||||||
|
{ message = "Variable \"$command\" is not defined."
|
||||||
|
, locations = [AST.Location 2 30]
|
||||||
|
}
|
||||||
|
in validate queryString `shouldBe` [expected]
|
||||||
|
|
||||||
|
context "noUnusedVariablesRule" $ do
|
||||||
it "rejects unused variables" $
|
it "rejects unused variables" $
|
||||||
let queryString = [gql|
|
let queryString = [gql|
|
||||||
query variableUnused($atOtherHomes: Boolean) {
|
query variableUnused($atOtherHomes: Boolean) {
|
||||||
@ -577,6 +611,16 @@ spec =
|
|||||||
}
|
}
|
||||||
in validate queryString `shouldBe` [expected]
|
in validate queryString `shouldBe` [expected]
|
||||||
|
|
||||||
|
it "detects variables in properties of input objects" $
|
||||||
|
let queryString = [gql|
|
||||||
|
query withVar ($name: String!) {
|
||||||
|
findDog (complex: { name: $name }) {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
in validate queryString `shouldBe` []
|
||||||
|
|
||||||
context "uniqueInputFieldNamesRule" $
|
context "uniqueInputFieldNamesRule" $
|
||||||
it "rejects duplicate fields in input objects" $
|
it "rejects duplicate fields in input objects" $
|
||||||
let queryString = [gql|
|
let queryString = [gql|
|
||||||
|
Reference in New Issue
Block a user