From 1cf21c335d20ed286942c62ac9d4715924c70708 Mon Sep 17 00:00:00 2001 From: Ganesha Danu Date: Wed, 18 Sep 2019 00:04:54 +0700 Subject: [PATCH] fix string variable --- gqlyzer.go | 4 +--- gqlyzer_test.go | 6 ++---- parse_operation.go | 5 +---- parse_value.go | 1 + 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/gqlyzer.go b/gqlyzer.go index 7f46d52..ac7d839 100644 --- a/gqlyzer.go +++ b/gqlyzer.go @@ -44,13 +44,12 @@ func (l *Lexer) ParseWithVariables(variables string) (token.Operation, error) { if err != nil { return token.Operation{}, err } - fmt.Println(variableMap) for key, content := range variableMap { var s string switch content.(type) { case string: - s = content.(string) + s = fmt.Sprintf("\"%s\"", content.(string)) case int: s = string(content.(int)) default: @@ -60,7 +59,6 @@ func (l *Lexer) ParseWithVariables(variables string) (token.Operation, error) { } s = string(jsonStr) } - fmt.Println(s) l.input = strings.ReplaceAll(l.input, "$"+key, s) } diff --git a/gqlyzer_test.go b/gqlyzer_test.go index 35b546a..a153d73 100644 --- a/gqlyzer_test.go +++ b/gqlyzer_test.go @@ -16,17 +16,15 @@ func TestParseWithVariable(t *testing.T) { l.Reset() s, err := l.ParseWithVariables(` { - "id": 123 + "id": "danu" } `) - l.push('\\') - assert.NoError(t, err) assert.Equal(t, operation.Query, s.Type) assert.Equal(t, "SomeOperation", s.Name) assert.Equal(t, "SomeQuery", s.Selections["SomeQuery"].Name) assert.Equal(t, "id", s.Selections["SomeQuery"].Arguments["id"].Key) - assert.Equal(t, "123", s.Selections["SomeQuery"].Arguments["id"].Value) + assert.Equal(t, `"danu"`, s.Selections["SomeQuery"].Arguments["id"].Value) assert.Equal(t, "subQuery", s.Selections["SomeQuery"].InnerSelection["subQuery"].Name) } diff --git a/parse_operation.go b/parse_operation.go index 355cb43..aba0071 100644 --- a/parse_operation.go +++ b/parse_operation.go @@ -2,7 +2,6 @@ package gqlyzer import ( "errors" - "fmt" "github.com/kumparan/gqlyzer/token" "github.com/kumparan/gqlyzer/token/operation" @@ -60,7 +59,6 @@ func (l *Lexer) parseOperation() (op token.Operation, err error) { l.consumeWhitespace() c, err = l.read() - fmt.Println(">>", string(c)) if err != nil { return } @@ -79,14 +77,13 @@ func (l *Lexer) parseOperation() (op token.Operation, err error) { } l.cursor++ + l.consumeWhitespace() } - fmt.Println("masih jalan") op.Selections, err = l.parseSelectionSet() if err != nil { return } - fmt.Println("masih jalan 2", op, err) return } diff --git a/parse_value.go b/parse_value.go index 77870fe..5b0f1a9 100644 --- a/parse_value.go +++ b/parse_value.go @@ -51,5 +51,6 @@ func (l *Lexer) parseString() (value string, err error) { return } + l.cursor++ return `"` + content + `"`, nil }