Skip to content

Commit

Permalink
Merge pull request #257 from Yamashou/any
Browse files Browse the repository at this point in the history
interface{} to any and update dependencies
  • Loading branch information
Yamashou authored Dec 20, 2024
2 parents 27dbd21 + 7d02fed commit 10e03ee
Show file tree
Hide file tree
Showing 22 changed files with 325 additions and 327 deletions.
6 changes: 3 additions & 3 deletions clientgenv2/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func RenderTemplate(cfg *config.Config, fragments []*Fragment, operations []*Ope
PackageName: client.Package,
Filename: client.Filename,
Template: template,
Data: map[string]interface{}{
Data: map[string]any{
"Fragment": fragments,
"Operation": operations,
"OperationResponse": operationResponses,
Expand All @@ -33,7 +33,7 @@ func RenderTemplate(cfg *config.Config, fragments []*Fragment, operations []*Ope
},
Packages: cfg.Packages,
PackageDoc: "// Code generated by github.com/Yamashou/gqlgenc, DO NOT EDIT.\n",
Funcs: map[string]interface{}{
Funcs: map[string]any{
"genGetters": genGettersGenerator.GenFunc(),
},
}); err != nil {
Expand Down Expand Up @@ -70,7 +70,7 @@ func (g *GenGettersGenerator) returnTypeName(t types.Type, nested bool) string {

return "*" + name
case *types.Interface:
return "interface{}"
return "any"
case *types.Map:
return "map[" + g.returnTypeName(it.Key(), true) + "]" + g.returnTypeName(it.Elem(), true)
default:
Expand Down
2 changes: 1 addition & 1 deletion clientgenv2/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestReturnTypeName(t *testing.T) {
name: "Interface",
input: types.NewInterfaceType(nil, nil).Complete(),
nested: false,
expected: "interface{}",
expected: "any",
},
{
name: "Map",
Expand Down
6 changes: 3 additions & 3 deletions clientv2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func TestMarshalJSON(t *testing.T) {
{
name: "marshal NumberOne",
args: args{
v: map[string]interface{}{"input": NumberOne},
v: map[string]any{"input": NumberOne},
},
want: []byte(`{"input":"ONE"}`),
},
Expand Down Expand Up @@ -898,7 +898,7 @@ func TestUnsafeChainInterceptor(t *testing.T) {

t.Run("should properly propagate errors", func(t *testing.T) {
expectedError := errors.New("test error")

// Interceptor that returns an error
errorInterceptor := func(ctx context.Context, req *http.Request, gqlInfo *GQLRequestInfo, res any, next RequestInterceptorFunc) error {
return expectedError
Expand All @@ -925,7 +925,7 @@ func TestUnsafeChainInterceptor(t *testing.T) {

t.Run("should execute interceptors in correct order", func(t *testing.T) {
var order []int

// Create interceptors that record execution order
makeInterceptor := func(id int) RequestInterceptor {
return func(ctx context.Context, req *http.Request, gqlInfo *GQLRequestInfo, res any, next RequestInterceptorFunc) error {
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (c *Config) LoadSchema(ctx context.Context) error {
}

func (c *Config) loadRemoteSchema(ctx context.Context) (*ast.Schema, error) {
addHeaderInterceptor := func(ctx context.Context, req *http.Request, gqlInfo *clientv2.GQLRequestInfo, res interface{}, next clientv2.RequestInterceptorFunc) error {
addHeaderInterceptor := func(ctx context.Context, req *http.Request, gqlInfo *clientv2.GQLRequestInfo, res any, next clientv2.RequestInterceptorFunc) error {
for key, value := range c.Endpoint.Headers {
req.Header.Set(key, value)
}
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ type mockRemoteServer struct {
body []byte
}

func newMockRemoteServer(t *testing.T, response interface{}) (mock *mockRemoteServer, closeServer func()) {
func newMockRemoteServer(t *testing.T, response any) (mock *mockRemoteServer, closeServer func()) {
t.Helper()

mock = &mockRemoteServer{
Expand Down
18 changes: 9 additions & 9 deletions example/annictV2/gen/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions example/annictV2/gen/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/annictV2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
key := os.Getenv("ANNICT_KEY")

annictClient := NewAnnictClient(clientv2.NewClient(http.DefaultClient, "https://api.annict.com/graphql", nil,
func(ctx context.Context, req *http.Request, gqlInfo *clientv2.GQLRequestInfo, res interface{}, next clientv2.RequestInterceptorFunc) error {
func(ctx context.Context, req *http.Request, gqlInfo *clientv2.GQLRequestInfo, res any, next clientv2.RequestInterceptorFunc) error {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", key))

return next(ctx, req, gqlInfo, res)
Expand Down
2 changes: 1 addition & 1 deletion example/autobind/gen/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/autobind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {

githubClient := &gen.Client{
Client: clientv2.NewClient(http.DefaultClient, "https://api.github.com/graphql", nil,
func(ctx context.Context, req *http.Request, gqlInfo *clientv2.GQLRequestInfo, res interface{}, next clientv2.RequestInterceptorFunc) error {
func(ctx context.Context, req *http.Request, gqlInfo *clientv2.GQLRequestInfo, res any, next clientv2.RequestInterceptorFunc) error {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))

return next(ctx, req, gqlInfo, res)
Expand Down
Loading

0 comments on commit 10e03ee

Please sign in to comment.