Skip to content

Commit f51a3a2

Browse files
authored
Merge branch 'master' into subscription-execution
2 parents 4ce4c9a + 8a92e97 commit f51a3a2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

language/printer/printer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package printer
22

33
import (
44
"fmt"
5+
"strconv"
56
"strings"
67

78
"reflect"
@@ -372,7 +373,7 @@ var printDocASTReducer = map[string]visitor.VisitFunc{
372373
"StringValue": func(p visitor.VisitFuncParams) (string, interface{}) {
373374
switch node := p.Node.(type) {
374375
case *ast.StringValue:
375-
return visitor.ActionUpdate, `"` + fmt.Sprintf("%v", node.Value) + `"`
376+
return visitor.ActionUpdate, strconv.Quote(node.Value)
376377
case map[string]interface{}:
377378
return visitor.ActionUpdate, `"` + getMapValueString(node, "Value") + `"`
378379
}

language/printer/printer_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,17 @@ fragment frag on Follower {
186186
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, results))
187187
}
188188
}
189+
190+
func TestPrinter_CorrectlyPrintsStringArgumentsWithProperQuoting(t *testing.T) {
191+
queryAst := `query { foo(jsonStr: "{\"foo\": \"bar\"}") }`
192+
expected := `{
193+
foo(jsonStr: "{\"foo\": \"bar\"}")
194+
}
195+
`
196+
astDoc := parse(t, queryAst)
197+
results := printer.Print(astDoc)
198+
199+
if !reflect.DeepEqual(expected, results) {
200+
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, results))
201+
}
202+
}

0 commit comments

Comments
 (0)