Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 5c8e89e

Browse files
author
Josh Price
committed
Parse strings or char lists
1 parent ce5d3d9 commit 5c8e89e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/graphql.ex

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ defmodule Graphql do
55
tokens
66
end
77

8+
def parse(input_string) when is_binary(input_string) do
9+
input_string |> to_char_list |> parse
10+
end
11+
812
def parse(input_string) do
9-
{:ok, parse_result} = :graphql_parser.parse tokenize(input_string)
13+
{:ok, parse_result} = input_string
14+
|> tokenize
15+
|> :graphql_parser.parse
1016
parse_result
1117
end
1218

test/graphql_test.exs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule GraphqlTest do
2+
use ExUnit.Case
3+
4+
def assert_parse(input_string, expected_output) do
5+
assert Graphql.parse(input_string) == expected_output
6+
end
7+
8+
test "parse char list" do
9+
assert_parse '{ hero }', [ {[ 'hero' ]} ]
10+
end
11+
12+
test "parse string" do
13+
assert_parse "{ hero }", [ {[ 'hero' ]} ]
14+
end
15+
end

0 commit comments

Comments
 (0)