Skip to content

Commit

Permalink
fix string variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Ganesha Danu committed Sep 17, 2019
1 parent 39f26be commit 1cf21c3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
4 changes: 1 addition & 3 deletions gqlyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
}

Expand Down
6 changes: 2 additions & 4 deletions gqlyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 1 addition & 4 deletions parse_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gqlyzer

import (
"errors"
"fmt"

"github.com/kumparan/gqlyzer/token"
"github.com/kumparan/gqlyzer/token/operation"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
1 change: 1 addition & 0 deletions parse_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ func (l *Lexer) parseString() (value string, err error) {
return
}

l.cursor++
return `"` + content + `"`, nil
}

0 comments on commit 1cf21c3

Please sign in to comment.