-
Notifications
You must be signed in to change notification settings - Fork 32
Fix error on anonymous query #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jml
merged 6 commits into
haskell-graphql:master
from
sunwukonga:fix/error_on_anonymous_query
Jan 14, 2018
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
05fc62b
Make Node instance of HasName. Implement getName
sunwukonga d27f591
Add Data.Text import and clean up unused imports.
sunwukonga a8cd01f
Fix error when single query is anonymous.
sunwukonga 0a96e00
Cut commented out code. Comment monoid instance.
sunwukonga 2bf5c01
Remove deriving Monoid from Name.
sunwukonga 693d0b3
Revert Node as instance of HasName to getNodeName
sunwukonga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,17 +4,11 @@ | |
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module GraphQL.Internal.Syntax.AST | ||
( Name(unName) | ||
, nameParser | ||
, NameError(..) | ||
, unsafeMakeName | ||
, makeName | ||
, QueryDocument(..) | ||
( QueryDocument(..) | ||
, SchemaDocument(..) | ||
, Definition(..) | ||
, OperationDefinition(..) | ||
, Node(..) | ||
, getNodeName | ||
, VariableDefinition(..) | ||
, Variable(..) | ||
, SelectionSet | ||
|
@@ -54,72 +48,11 @@ module GraphQL.Internal.Syntax.AST | |
|
||
import Protolude | ||
|
||
import qualified Data.Aeson as Aeson | ||
import qualified Data.Attoparsec.Text as A | ||
import Data.Char (isDigit) | ||
import Data.String (IsString(..)) | ||
--import Data.String (IsString(..)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please just delete, rather than comment out. |
||
import Test.QuickCheck (Arbitrary(..), elements, listOf, oneof) | ||
|
||
import GraphQL.Internal.Arbitrary (arbitraryText) | ||
import GraphQL.Internal.Syntax.Tokens (tok) | ||
|
||
-- * Name | ||
|
||
-- | A name in GraphQL. | ||
-- | ||
-- https://facebook.github.io/graphql/#sec-Names | ||
newtype Name = Name { unName :: Text } deriving (Eq, Ord, Show) | ||
|
||
-- | Create a 'Name', panicking if the given text is invalid. | ||
-- | ||
-- Prefer 'makeName' to this in all cases. | ||
-- | ||
-- >>> unsafeMakeName "foo" | ||
-- Name {unName = "foo"} | ||
unsafeMakeName :: HasCallStack => Text -> Name | ||
unsafeMakeName name = | ||
case makeName name of | ||
Left e -> panic (show e) | ||
Right n -> n | ||
|
||
-- | Create a 'Name'. | ||
-- | ||
-- Names must match the regex @[_A-Za-z][_0-9A-Za-z]*@. If the given text does | ||
-- not match, return Nothing. | ||
-- | ||
-- >>> makeName "foo" | ||
-- Right (Name {unName = "foo"}) | ||
-- >>> makeName "9-bar" | ||
-- Left (NameError "9-bar") | ||
makeName :: Text -> Either NameError Name | ||
makeName name = first (const (NameError name)) (A.parseOnly nameParser name) | ||
|
||
-- | An invalid name. | ||
newtype NameError = NameError Text deriving (Eq, Show) | ||
|
||
|
||
instance IsString Name where | ||
fromString = unsafeMakeName . toS | ||
|
||
instance Aeson.ToJSON Name where | ||
toJSON = Aeson.toJSON . unName | ||
|
||
instance Arbitrary Name where | ||
arbitrary = do | ||
initial <- elements alpha | ||
rest <- listOf (elements (alpha <> numeric)) | ||
pure (Name (toS (initial:rest))) | ||
where | ||
alpha = ['A'..'Z'] <> ['a'..'z'] <> ['_'] | ||
numeric = ['0'..'9'] | ||
|
||
-- | Parser for 'Name'. | ||
nameParser :: A.Parser Name | ||
nameParser = Name <$> tok ((<>) <$> A.takeWhile1 isA_z | ||
<*> A.takeWhile ((||) <$> isDigit <*> isA_z)) | ||
where | ||
-- `isAlpha` handles many more Unicode Chars | ||
isA_z = A.inClass $ '_' : ['A'..'Z'] <> ['a'..'z'] | ||
import GraphQL.Internal.Name (HasName(getName), Name(unName, Name), unsafeMakeName) | ||
|
||
-- * Documents | ||
|
||
|
@@ -146,9 +79,8 @@ data OperationDefinition | |
data Node = Node Name [VariableDefinition] [Directive] SelectionSet | ||
deriving (Eq,Show) | ||
|
||
-- TODO: Just make Node implement HasName. | ||
getNodeName :: Node -> Name | ||
getNodeName (Node name _ _ _) = name | ||
instance HasName Node where | ||
getName (Node name _ _ _) = name | ||
|
||
data VariableDefinition = VariableDefinition Variable Type (Maybe DefaultValue) | ||
deriving (Eq,Show) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you do this? The
Protolude
import gets us exactly thisText
.