haskell-graphql / graphql-api

Write type-safe GraphQL services in Haskell
BSD 3-Clause "New" or "Revised" License
406 stars 35 forks source link

Issue with parsing non-nullable types #221

Open fredefox opened 5 years ago

fredefox commented 5 years ago

There is a bug that prevents a document such as

input B {
  b: [B!]!
}

from parsing.

Note the difference between:

λ length <$> parseOnly (many1 inputValueDefinition) "b: [B!]! x: B"
Right 1
λ length <$> parseOnly (many1 inputValueDefinition) "b: [B!] x: B"
Right 2

And similarly for

λ length <$> parseOnly (many1 fieldDefinition) "b: [B!] b: B"
Right 2
λ length <$> parseOnly (many1 fieldDefinition) "b: [B!]! b: B"
Right 1

Related to this I want to ask about the definition of NonNullType. Wouldn't it make more sense to define NonNullType to be:

newtype NonNullType = NonNullType GType

Of course this will permit parsing something like A!!! - but I believe it would simplify some of the code and help fix the bug in the parser. One challenge with that approach, though, is that parsing a type declaration will then require a look-ahead. Does the declaration end with an exclamation mark or not.