From 02879757b0b1cf54dda2ab0bb6c0748ba9e0aac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kosiec?= Date: Sat, 8 May 2021 22:23:09 +0200 Subject: [PATCH] Fix invalid escaping of quote in string argument (#18) * Add test case for input JSON string argument * Use latest graphql-go/graphql with the JSON input arguments fix --- go.mod | 3 +-- go.sum | 6 ++---- printer.go | 2 +- printer_test.go | 27 +++++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 8770f6f..35eb220 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,8 @@ module github.com/nautilus/graphql require ( - github.com/carted/graphql v0.7.6 github.com/graph-gophers/dataloader v5.0.0+incompatible - github.com/graphql-go/graphql v0.7.7 + github.com/graphql-go/graphql v0.7.10-0.20210411022516-8a92e977c10b github.com/mitchellh/mapstructure v1.1.2 github.com/opentracing/opentracing-go v1.0.2 // indirect github.com/stretchr/testify v1.4.0 diff --git a/go.sum b/go.sum index 2c40228..0409abe 100644 --- a/go.sum +++ b/go.sum @@ -2,15 +2,13 @@ github.com/agnivade/levenshtein v1.0.1 h1:3oJU7J3FGFmyhn8KHjmVaZCN5hxTr7GxgRue+s github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= -github.com/carted/graphql v0.7.6 h1:1DAom3l7Irln/hHlPMBR6w/RirCXjopsCY9WCZc7WUc= -github.com/carted/graphql v0.7.6/go.mod h1:aIVByVaa4avHzEnahcnHbP48OrkT/+gTtxBT+dPV2R0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/graph-gophers/dataloader v5.0.0+incompatible h1:R+yjsbrNq1Mo3aPG+Z/EKYrXrXXUNJHOgbRt+U6jOug= github.com/graph-gophers/dataloader v5.0.0+incompatible/go.mod h1:jk4jk0c5ZISbKaMe8WsVopGB5/15GvGHMdMdPtwlRp4= -github.com/graphql-go/graphql v0.7.7 h1:nwEsJGwPq9N6cElOO+NYyoWuELAQZ4GuJks0Rlco5og= -github.com/graphql-go/graphql v0.7.7/go.mod h1:k6yrAYQaSP59DC5UVxbgxESlmVyojThKdORUqGDGmrI= +github.com/graphql-go/graphql v0.7.10-0.20210411022516-8a92e977c10b h1:pFOI7cDz2wI+MwaoDqqrhFCXkwvpvkWpYQCXvQVAlfs= +github.com/graphql-go/graphql v0.7.10-0.20210411022516-8a92e977c10b/go.mod h1:k6yrAYQaSP59DC5UVxbgxESlmVyojThKdORUqGDGmrI= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= diff --git a/printer.go b/printer.go index 905c112..7b02153 100644 --- a/printer.go +++ b/printer.go @@ -5,8 +5,8 @@ import ( "strconv" "strings" - "github.com/carted/graphql/language/printer" gAst "github.com/graphql-go/graphql/language/ast" + "github.com/graphql-go/graphql/language/printer" "github.com/vektah/gqlparser/v2/ast" ) diff --git a/printer_test.go b/printer_test.go index c17ff1a..3db149a 100644 --- a/printer_test.go +++ b/printer_test.go @@ -278,6 +278,33 @@ fragment Foo on User { }, }, }, + // json string arguments + { + `{ + hello(json: "{\"foo\": \"bar\"}") +} +`, + &ast.QueryDocument{ + Operations: ast.OperationList{&ast.OperationDefinition{ + Operation: ast.Query, + SelectionSet: ast.SelectionSet{ + &ast.Field{ + Name: "hello", + Arguments: ast.ArgumentList{ + { + Name: "json", + Value: &ast.Value{ + Kind: ast.StringValue, + Raw: "{\"foo\": \"bar\"}", + }, + }, + }, + }, + }, + }, + }, + }, + }, // int arguments { `{