Fix strings not consuming spaces

Fixes #28
This commit is contained in:
Sam Nolan 2019-11-27 19:18:20 +11:00
parent 3497784984
commit def52ddc20
3 changed files with 20 additions and 2 deletions

View File

@ -1,6 +1,12 @@
# Change Log # Change Log
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## Unreleased
### Fixed
- Parsing multiple string arguments, such as
`login(username: "username", password: "password")` would fail on the comma
due to strings not having a space consumer.
## [0.6.0.0] - 2019-11-27 ## [0.6.0.0] - 2019-11-27
### Changed ### Changed
- `Language.GraphQL.Encoder` moved to `Language.GraphQL.AST.Encoder`. - `Language.GraphQL.Encoder` moved to `Language.GraphQL.AST.Encoder`.

View File

@ -134,7 +134,7 @@ braces = between (symbol "{") (symbol "}")
-- | Parser for strings. -- | Parser for strings.
string :: Parser T.Text string :: Parser T.Text
string = between "\"" "\"" stringValue string = between "\"" "\"" stringValue <* spaceConsumer
where where
stringValue = T.pack <$> many stringCharacter stringValue = T.pack <$> many stringCharacter
stringCharacter = satisfy isStringCharacter1 stringCharacter = satisfy isStringCharacter1
@ -143,7 +143,7 @@ string = between "\"" "\"" stringValue
-- | Parser for block strings. -- | Parser for block strings.
blockString :: Parser T.Text blockString :: Parser T.Text
blockString = between "\"\"\"" "\"\"\"" stringValue blockString = between "\"\"\"" "\"\"\"" stringValue <* spaceConsumer
where where
stringValue = do stringValue = do
byLine <- sepBy (many blockStringCharacter) lineTerminator byLine <- sepBy (many blockStringCharacter) lineTerminator

View File

@ -30,3 +30,15 @@ spec = describe "Parser" $ do
mutation auth($username: String!, $password: String!){ mutation auth($username: String!, $password: String!){
test test
}|] }|]
it "accepts two string arguments" $
parse document "" `shouldSucceedOn` [r|
mutation auth{
test(username: "username", password: "password")
}|]
it "accepts two block string arguments" $
parse document "" `shouldSucceedOn` [r|
mutation auth{
test(username: """username""", password: """password""")
}|]