diff --git a/_examples/go.mod b/_examples/go.mod index 0127b4cd7c..239fe9b259 100644 --- a/_examples/go.mod +++ b/_examples/go.mod @@ -19,6 +19,7 @@ require ( require ( github.com/agnivade/levenshtein v1.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/goccy/go-json v0.10.3 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/logrusorgru/aurora/v4 v4.0.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect diff --git a/_examples/go.sum b/_examples/go.sum index 8c005fd183..d536f81217 100644 --- a/_examples/go.sum +++ b/_examples/go.sum @@ -15,6 +15,8 @@ github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7c github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= +github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= diff --git a/client/client.go b/client/client.go index ea3b4a3d20..0321a5a876 100644 --- a/client/client.go +++ b/client/client.go @@ -4,7 +4,7 @@ package client import ( "bytes" - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" "net/http" diff --git a/client/client_test.go b/client/client_test.go index ed0a78ac3d..7f3ab4bf4c 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -2,7 +2,7 @@ package client_test import ( "bytes" - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" "mime/multipart" diff --git a/client/errors.go b/client/errors.go index 7bbdd41735..229a3b1837 100644 --- a/client/errors.go +++ b/client/errors.go @@ -1,6 +1,6 @@ package client -import "encoding/json" +import "github.com/goccy/go-json" // RawJsonError is a json formatted error from a GraphQL server. type RawJsonError struct { diff --git a/client/sse.go b/client/sse.go index d173a27f84..8a40f2408f 100644 --- a/client/sse.go +++ b/client/sse.go @@ -3,7 +3,7 @@ package client import ( "bufio" "context" - "encoding/json" + "github.com/goccy/go-json" "fmt" "net/http/httptest" "net/textproto" diff --git a/client/websocket.go b/client/websocket.go index 6a14f7fead..ce8b956f55 100644 --- a/client/websocket.go +++ b/client/websocket.go @@ -1,7 +1,7 @@ package client import ( - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "io" diff --git a/client/withfilesoption.go b/client/withfilesoption.go index 86bdbeeb90..21719c70a3 100644 --- a/client/withfilesoption.go +++ b/client/withfilesoption.go @@ -2,7 +2,7 @@ package client import ( "bytes" - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" "mime/multipart" diff --git a/codegen/testserver/followschema/mutation_with_custom_scalar.go b/codegen/testserver/followschema/mutation_with_custom_scalar.go index 5683ad3d03..c59d1f3296 100644 --- a/codegen/testserver/followschema/mutation_with_custom_scalar.go +++ b/codegen/testserver/followschema/mutation_with_custom_scalar.go @@ -1,7 +1,7 @@ package followschema import ( - "encoding/json" + "github.com/goccy/go-json" "errors" "io" "regexp" diff --git a/codegen/testserver/singlefile/defer_test.go b/codegen/testserver/singlefile/defer_test.go index b0c56e8605..8d6399f0dc 100644 --- a/codegen/testserver/singlefile/defer_test.go +++ b/codegen/testserver/singlefile/defer_test.go @@ -3,7 +3,7 @@ package singlefile import ( "cmp" "context" - "encoding/json" + "github.com/goccy/go-json" "math/rand" "reflect" "slices" diff --git a/codegen/testserver/singlefile/mutation_with_custom_scalar.go b/codegen/testserver/singlefile/mutation_with_custom_scalar.go index ee5ea57817..01955f34d6 100644 --- a/codegen/testserver/singlefile/mutation_with_custom_scalar.go +++ b/codegen/testserver/singlefile/mutation_with_custom_scalar.go @@ -1,7 +1,7 @@ package singlefile import ( - "encoding/json" + "github.com/goccy/go-json" "errors" "io" "regexp" diff --git a/docs/content/recipes/federation.md b/docs/content/recipes/federation.md index 291cd73a0a..f173befc51 100644 --- a/docs/content/recipes/federation.md +++ b/docs/content/recipes/federation.md @@ -227,7 +227,7 @@ genrated resolver functions that include a new argument, `federationRequires`, t fields you requested in your `@requires.fields` selection set. > Note: currently it's represented as a map[string]any where the contained values are encoded with -`encoding/json`. Eventually we will generate a typesafe model that represents these models, +`github.com/goccy/go-json`. Eventually we will generate a typesafe model that represents these models, however that is a large lift. This typesafe support will be added in the future. ### Example diff --git a/docs/content/reference/model-generation.md b/docs/content/reference/model-generation.md index 1ec40deb1a..e42f4a42c3 100644 --- a/docs/content/reference/model-generation.md +++ b/docs/content/reference/model-generation.md @@ -11,7 +11,7 @@ advantageous, or even necessary, to have control over some aspects of this outpu ## json ",omitempty" By default, fields that are marked as nullable in the GraphQL schema, e.g. `field: String` rather than `field: String!`, -have the [json ",omitempty"](https://pkg.go.dev/encoding/json#Marshal) field tag applied to them. This is probably fine +have the [json ",omitempty"](https://pkg.go.dev/github.com/goccy/go-json#Marshal) field tag applied to them. This is probably fine if the downstream consumers of json serialized representations of this model are all written in Go, but obviously this is not always true. diff --git a/go.mod b/go.mod index 65ee358052..ac9c133d49 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,7 @@ require ( github.com/andybalholm/cascadia v1.3.2 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/goccy/go-json v0.10.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect diff --git a/go.sum b/go.sum index 5656462f87..24c320b8dc 100644 --- a/go.sum +++ b/go.sum @@ -16,6 +16,8 @@ github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7c github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= +github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= diff --git a/graphql/any.go b/graphql/any.go index be600b2f42..cb5a27de39 100644 --- a/graphql/any.go +++ b/graphql/any.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" "io" ) diff --git a/graphql/coercion.go b/graphql/coercion.go index 533ab82149..e378381cf4 100644 --- a/graphql/coercion.go +++ b/graphql/coercion.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" ) // CoerceList applies coercion from a single value to a list. diff --git a/graphql/coercion_test.go b/graphql/coercion_test.go index 7402899f17..d5dda09102 100644 --- a/graphql/coercion_test.go +++ b/graphql/coercion_test.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" "testing" "github.com/stretchr/testify/assert" diff --git a/graphql/executor/testexecutor/testexecutor.go b/graphql/executor/testexecutor/testexecutor.go index e086a4876a..e02e22d783 100644 --- a/graphql/executor/testexecutor/testexecutor.go +++ b/graphql/executor/testexecutor/testexecutor.go @@ -3,7 +3,7 @@ package testexecutor import ( "bytes" "context" - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "io" diff --git a/graphql/float.go b/graphql/float.go index b140d5bc74..c49bd8a9e4 100644 --- a/graphql/float.go +++ b/graphql/float.go @@ -2,7 +2,7 @@ package graphql import ( "context" - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "io" diff --git a/graphql/handler/apollofederatedtracingv1/tracing_test.go b/graphql/handler/apollofederatedtracingv1/tracing_test.go index 8baf6d2a23..e718f47b6e 100644 --- a/graphql/handler/apollofederatedtracingv1/tracing_test.go +++ b/graphql/handler/apollofederatedtracingv1/tracing_test.go @@ -3,7 +3,7 @@ package apollofederatedtracingv1_test import ( "context" "encoding/base64" - "encoding/json" + "github.com/goccy/go-json" "io" "net/http" "net/http/httptest" diff --git a/graphql/handler/apollotracing/tracer_test.go b/graphql/handler/apollotracing/tracer_test.go index fca76d2cee..655780d124 100644 --- a/graphql/handler/apollotracing/tracer_test.go +++ b/graphql/handler/apollotracing/tracer_test.go @@ -1,7 +1,7 @@ package apollotracing_test import ( - "encoding/json" + "github.com/goccy/go-json" "io" "net/http" "net/http/httptest" diff --git a/graphql/handler/debug/tracer.go b/graphql/handler/debug/tracer.go index 5c75565c66..1cd43a0932 100644 --- a/graphql/handler/debug/tracer.go +++ b/graphql/handler/debug/tracer.go @@ -2,7 +2,7 @@ package debug import ( "context" - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" "os" diff --git a/graphql/handler/server.go b/graphql/handler/server.go index 644bad8d99..be15cd63e2 100644 --- a/graphql/handler/server.go +++ b/graphql/handler/server.go @@ -2,7 +2,7 @@ package handler import ( "context" - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "net/http" diff --git a/graphql/handler/transport/error.go b/graphql/handler/transport/error.go index 1fefb5738c..2ada15e8a7 100644 --- a/graphql/handler/transport/error.go +++ b/graphql/handler/transport/error.go @@ -1,7 +1,7 @@ package transport import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "net/http" diff --git a/graphql/handler/transport/http_form_multipart.go b/graphql/handler/transport/http_form_multipart.go index b9eb5f8f43..ecf6251f0b 100644 --- a/graphql/handler/transport/http_form_multipart.go +++ b/graphql/handler/transport/http_form_multipart.go @@ -1,7 +1,7 @@ package transport import ( - "encoding/json" + "github.com/goccy/go-json" "io" "mime" "net/http" diff --git a/graphql/handler/transport/http_get.go b/graphql/handler/transport/http_get.go index 09f1020d03..62d4b6a0b2 100644 --- a/graphql/handler/transport/http_get.go +++ b/graphql/handler/transport/http_get.go @@ -1,7 +1,7 @@ package transport import ( - "encoding/json" + "github.com/goccy/go-json" "io" "net/http" "net/url" diff --git a/graphql/handler/transport/http_multipart_mixed.go b/graphql/handler/transport/http_multipart_mixed.go index 9cf1b53393..0b3e593559 100644 --- a/graphql/handler/transport/http_multipart_mixed.go +++ b/graphql/handler/transport/http_multipart_mixed.go @@ -1,7 +1,7 @@ package transport import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" "log" diff --git a/graphql/handler/transport/sse.go b/graphql/handler/transport/sse.go index 1d59fdffe5..7620da28b7 100644 --- a/graphql/handler/transport/sse.go +++ b/graphql/handler/transport/sse.go @@ -1,7 +1,7 @@ package transport import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" "log" diff --git a/graphql/handler/transport/util.go b/graphql/handler/transport/util.go index f2a0d357af..81927c52aa 100644 --- a/graphql/handler/transport/util.go +++ b/graphql/handler/transport/util.go @@ -1,7 +1,7 @@ package transport import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" diff --git a/graphql/handler/transport/websocket.go b/graphql/handler/transport/websocket.go index d6c174cd1f..137060bcac 100644 --- a/graphql/handler/transport/websocket.go +++ b/graphql/handler/transport/websocket.go @@ -3,7 +3,7 @@ package transport import ( "bytes" "context" - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "log" diff --git a/graphql/handler/transport/websocket_graphql_transport_ws.go b/graphql/handler/transport/websocket_graphql_transport_ws.go index bfb12541a5..15da941205 100644 --- a/graphql/handler/transport/websocket_graphql_transport_ws.go +++ b/graphql/handler/transport/websocket_graphql_transport_ws.go @@ -1,7 +1,7 @@ package transport import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "github.com/gorilla/websocket" diff --git a/graphql/handler/transport/websocket_graphqlws.go b/graphql/handler/transport/websocket_graphqlws.go index d690cec464..e35565642b 100644 --- a/graphql/handler/transport/websocket_graphqlws.go +++ b/graphql/handler/transport/websocket_graphqlws.go @@ -1,7 +1,7 @@ package transport import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "github.com/gorilla/websocket" diff --git a/graphql/handler/transport/websocket_subprotocol.go b/graphql/handler/transport/websocket_subprotocol.go index c02098a88e..9f6e917093 100644 --- a/graphql/handler/transport/websocket_subprotocol.go +++ b/graphql/handler/transport/websocket_subprotocol.go @@ -1,7 +1,7 @@ package transport import ( - "encoding/json" + "github.com/goccy/go-json" "errors" "github.com/gorilla/websocket" diff --git a/graphql/handler/transport/websocket_test.go b/graphql/handler/transport/websocket_test.go index cc02018053..e55bd8cbc2 100644 --- a/graphql/handler/transport/websocket_test.go +++ b/graphql/handler/transport/websocket_test.go @@ -2,7 +2,7 @@ package transport_test import ( "context" - "encoding/json" + "github.com/goccy/go-json" "errors" "net/http" "net/http/httptest" diff --git a/graphql/id.go b/graphql/id.go index 2a946dfa74..d516e0328e 100644 --- a/graphql/id.go +++ b/graphql/id.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" "strconv" diff --git a/graphql/id_test.go b/graphql/id_test.go index 41e4be86e0..171a718ba1 100644 --- a/graphql/id_test.go +++ b/graphql/id_test.go @@ -2,7 +2,7 @@ package graphql import ( "bytes" - "encoding/json" + "github.com/goccy/go-json" "math" "testing" diff --git a/graphql/int.go b/graphql/int.go index 41cad3f1f3..ff24964785 100644 --- a/graphql/int.go +++ b/graphql/int.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" "strconv" diff --git a/graphql/int_test.go b/graphql/int_test.go index 7cb812a4ea..07c2eed15a 100644 --- a/graphql/int_test.go +++ b/graphql/int_test.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" "testing" "github.com/stretchr/testify/assert" diff --git a/graphql/map.go b/graphql/map.go index 1e91d1d98c..931061ecb5 100644 --- a/graphql/map.go +++ b/graphql/map.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" ) diff --git a/graphql/omittable.go b/graphql/omittable.go index 89716400b6..809695bd73 100644 --- a/graphql/omittable.go +++ b/graphql/omittable.go @@ -1,6 +1,6 @@ package graphql -import "encoding/json" +import "github.com/goccy/go-json" // Omittable is a wrapper around a value that also stores whether it is set // or not. diff --git a/graphql/omittable_test.go b/graphql/omittable_test.go index 5081197eb5..b1bbb8af9b 100644 --- a/graphql/omittable_test.go +++ b/graphql/omittable_test.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" "testing" "github.com/stretchr/testify/assert" diff --git a/graphql/playground/apollo_sandbox_playground.go b/graphql/playground/apollo_sandbox_playground.go index f998b4d8c3..5fdb7acc91 100644 --- a/graphql/playground/apollo_sandbox_playground.go +++ b/graphql/playground/apollo_sandbox_playground.go @@ -1,7 +1,7 @@ package playground import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "html/template" "net/http" diff --git a/graphql/response.go b/graphql/response.go index e37b5cfc1e..c43e3ecd5c 100644 --- a/graphql/response.go +++ b/graphql/response.go @@ -2,7 +2,7 @@ package graphql import ( "context" - "encoding/json" + "github.com/goccy/go-json" "fmt" "github.com/vektah/gqlparser/v2/ast" diff --git a/graphql/string.go b/graphql/string.go index 6622734e3e..93be3196bd 100644 --- a/graphql/string.go +++ b/graphql/string.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" "strconv" diff --git a/graphql/string_test.go b/graphql/string_test.go index 5ca1c36a4d..445e086330 100644 --- a/graphql/string_test.go +++ b/graphql/string_test.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" "testing" "github.com/stretchr/testify/assert" diff --git a/graphql/uint.go b/graphql/uint.go index cd5d235503..af66c13de0 100644 --- a/graphql/uint.go +++ b/graphql/uint.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "io" diff --git a/graphql/uint_test.go b/graphql/uint_test.go index 4d7ad1796a..e2b7450ded 100644 --- a/graphql/uint_test.go +++ b/graphql/uint_test.go @@ -1,7 +1,7 @@ package graphql import ( - "encoding/json" + "github.com/goccy/go-json" "math" "testing" diff --git a/plugin/federation/federation_entityresolver_test.go b/plugin/federation/federation_entityresolver_test.go index e4b3949d43..80fe0f4314 100644 --- a/plugin/federation/federation_entityresolver_test.go +++ b/plugin/federation/federation_entityresolver_test.go @@ -2,7 +2,7 @@ package federation import ( - "encoding/json" + "github.com/goccy/go-json" "strconv" "strings" "testing" diff --git a/plugin/federation/testdata/computedrequires/schema.resolvers.go b/plugin/federation/testdata/computedrequires/schema.resolvers.go index a482f30768..b194b52f5a 100644 --- a/plugin/federation/testdata/computedrequires/schema.resolvers.go +++ b/plugin/federation/testdata/computedrequires/schema.resolvers.go @@ -6,7 +6,7 @@ package computedrequires import ( "context" - "encoding/json" + "github.com/goccy/go-json" "fmt" explicitrequires "github.com/99designs/gqlgen/plugin/federation/testdata/computedrequires/generated" diff --git a/plugin/federation/testdata/explicitrequires/generated/federation.requires.go b/plugin/federation/testdata/explicitrequires/generated/federation.requires.go index 1a3a933511..61e0960d91 100644 --- a/plugin/federation/testdata/explicitrequires/generated/federation.requires.go +++ b/plugin/federation/testdata/explicitrequires/generated/federation.requires.go @@ -2,7 +2,7 @@ package generated import ( "context" - "encoding/json" + "github.com/goccy/go-json" "fmt" ) diff --git a/plugin/resolvergen/testdata/resolvertemplate/customResolverTemplate.gotpl b/plugin/resolvergen/testdata/resolvertemplate/customResolverTemplate.gotpl index ff652f0148..63339a008b 100644 --- a/plugin/resolvergen/testdata/resolvertemplate/customResolverTemplate.gotpl +++ b/plugin/resolvergen/testdata/resolvertemplate/customResolverTemplate.gotpl @@ -6,7 +6,7 @@ {{ reserveImport "sync" }} {{ reserveImport "errors" }} {{ reserveImport "bytes" }} -{{ reserveImport "encoding/json" }} +{{ reserveImport "github.com/goccy/go-json" }} {{ reserveImport "github.com/vektah/gqlparser/v2" }} {{ reserveImport "github.com/vektah/gqlparser/v2/ast" }}