fix empty list argument parsing

This commit is contained in:
Dmitrii Skurikhin 2022-01-06 16:49:54 +03:00 committed by Eugen Wissner
parent 73585dde85
commit 0c8edae90a
3 changed files with 59 additions and 27 deletions

View File

@ -8,7 +8,9 @@ and this project adheres to
## [Unreleased] ## [Unreleased]
### Fixed ### Fixed
- Index position in error path. (Index and Segment paths of a field have been swapped) - Index position in error path. (Index and Segment paths of a field have been
swapped).
- Parsing empty list as an argument.
## [1.0.2.0] - 2021-12-26 ## [1.0.2.0] - 2021-12-26
### Added ### Added

View File

@ -450,8 +450,8 @@ value = Full.Variable <$> variable
<|> Full.Null <$ nullValue <|> Full.Null <$ nullValue
<|> Full.String <$> stringValue <|> Full.String <$> stringValue
<|> Full.Enum <$> try enumValue <|> Full.Enum <$> try enumValue
<|> Full.List <$> brackets (some $ valueNode value) <|> Full.List <$> brackets (many $ valueNode value)
<|> Full.Object <$> braces (some $ objectField $ valueNode value) <|> Full.Object <$> braces (many $ objectField $ valueNode value)
<?> "Value" <?> "Value"
constValue :: Parser Full.ConstValue constValue :: Parser Full.ConstValue

View File

@ -9,7 +9,7 @@ import Language.GraphQL.AST.Document
import qualified Language.GraphQL.AST.DirectiveLocation as DirLoc import qualified Language.GraphQL.AST.DirectiveLocation as DirLoc
import Language.GraphQL.AST.Parser import Language.GraphQL.AST.Parser
import Language.GraphQL.TH import Language.GraphQL.TH
import Test.Hspec (Spec, describe, it) import Test.Hspec (Spec, describe, it, context)
import Test.Hspec.Megaparsec (shouldParse, shouldFailOn, shouldSucceedOn) import Test.Hspec.Megaparsec (shouldParse, shouldFailOn, shouldSucceedOn)
import Text.Megaparsec (parse) import Text.Megaparsec (parse)
@ -18,33 +18,56 @@ spec = describe "Parser" $ do
it "accepts BOM header" $ it "accepts BOM header" $
parse document "" `shouldSucceedOn` "\xfeff{foo}" parse document "" `shouldSucceedOn` "\xfeff{foo}"
it "accepts block strings as argument" $ context "Arguments" $ do
parse document "" `shouldSucceedOn` [gql|{ it "accepts block strings as argument" $
hello(text: """Argument""") parse document "" `shouldSucceedOn` [gql|{
}|] hello(text: """Argument""")
}|]
it "accepts strings as argument" $ it "accepts strings as argument" $
parse document "" `shouldSucceedOn` [gql|{ parse document "" `shouldSucceedOn` [gql|{
hello(text: "Argument") hello(text: "Argument")
}|] }|]
it "accepts two required arguments" $ it "accepts int as argument" $
parse document "" `shouldSucceedOn` [gql| parse document "" `shouldSucceedOn` [gql|{
mutation auth($username: String!, $password: String!){ user(id: 4)
test }|]
}|]
it "accepts boolean as argument" $
parse document "" `shouldSucceedOn` [gql|{
hello(flag: true) { field1 }
}|]
it "accepts float as argument" $
parse document "" `shouldSucceedOn` [gql|{
body(height: 172.5) { height }
}|]
it "accepts empty list as argument" $
parse document "" `shouldSucceedOn` [gql|{
query(list: []) { field1 }
}|]
it "accepts two required arguments" $
parse document "" `shouldSucceedOn` [gql|
mutation auth($username: String!, $password: String!){
test
}|]
it "accepts two string arguments" $
parse document "" `shouldSucceedOn` [gql|
mutation auth{
test(username: "username", password: "password")
}|]
it "accepts two block string arguments" $
parse document "" `shouldSucceedOn` [gql|
mutation auth{
test(username: """username""", password: """password""")
}|]
it "accepts two string arguments" $
parse document "" `shouldSucceedOn` [gql|
mutation auth{
test(username: "username", password: "password")
}|]
it "accepts two block string arguments" $
parse document "" `shouldSucceedOn` [gql|
mutation auth{
test(username: """username""", password: """password""")
}|]
it "parses minimal schema definition" $ it "parses minimal schema definition" $
parse document "" `shouldSucceedOn` [gql|schema { query: Query }|] parse document "" `shouldSucceedOn` [gql|schema { query: Query }|]
@ -202,6 +225,13 @@ spec = describe "Parser" $ do
} }
|] |]
it "rejects empty selection set" $
parse document "" `shouldFailOn` [gql|
query {
innerField {}
}
|]
it "parses documents beginning with a comment" $ it "parses documents beginning with a comment" $
parse document "" `shouldSucceedOn` [gql| parse document "" `shouldSucceedOn` [gql|
""" """