Skip to content

Commit

Permalink
Merge pull request #109 from andreas/parser-number-value-fix
Browse files Browse the repository at this point in the history
Fix parsing of enums with E
  • Loading branch information
rrosenzweig authored Aug 9, 2018
2 parents 13de5de + 008fad7 commit 995d266
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions graphql_parser/src/graphql_parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,14 @@ let string_value = lift (fun s -> `String s) (quote *> string_chars <* quote)
let boolean_value = string "true" *> return (`Bool true) <|>
string "false" *> return (`Bool false)

let number_value = lift (fun n ->
let number_value = number_chars >>= fun n ->
try
`Int (int_of_string n)
return (`Int (int_of_string n))
with Failure _ ->
`Float (float_of_string n)) number_chars
try
return (`Float (float_of_string n))
with Failure _ ->
fail (Format.sprintf "Invalid number value: %s" n)

let enum_value = name >>= function
| "true"
Expand Down
4 changes: 2 additions & 2 deletions graphql_parser/test/data/kitchen_sink.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ fragment frag on Friend {
}

{
unnamed(truthy: true, falsey: false, nullish: null),
unnamed(truthy: true, falsey: false, nullish: null, enum: ECHO),
query
}
}
3 changes: 2 additions & 1 deletion graphql_parser/test/data/kitchen_sink.sexp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
((Field
((alias ()) (name unnamed)
(arguments
((truthy (Bool true)) (falsey (Bool false)) (nullish Null)))
((truthy (Bool true)) (falsey (Bool false)) (nullish Null)
(enum (Enum ECHO))))
(directives ()) (selection_set ())))
(Field
((alias ()) (name query) (arguments ()) (directives ())
Expand Down

0 comments on commit 995d266

Please sign in to comment.