Skip to content

Commit a578647

Browse files
committed
upgrade go v1.26
1 parent 52a6e99 commit a578647

18 files changed

Lines changed: 229 additions & 164 deletions

File tree

cmd/hasura-ndc-go/command/internal/connector.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (ctb connectorTypeBuilder) String() string {
6464
alias += " "
6565
}
6666

67-
bs.WriteString(fmt.Sprintf(" %s\"%s\"\n", alias, pkg))
67+
fmt.Fprintf(&bs, " %s\"%s\"\n", alias, pkg)
6868
}
6969

7070
bs.WriteString(")\n")
@@ -102,6 +102,7 @@ func ParseAndGenerateConnector(args ConnectorGenerationArguments, moduleName str
102102
if err = trace.Start(w); err != nil {
103103
return fmt.Errorf("failed to start trace: %w", err)
104104
}
105+
105106
defer trace.Stop()
106107
}
107108

@@ -226,7 +227,7 @@ func (cg *connectorGenerator) generateConnector(name string) error {
226227
func (cg *connectorGenerator) genConnectorCodeFromTemplate(w io.Writer, packageName string) error {
227228
sortedImports := utils.GetSortedKeys(cg.rawSchema.Imports)
228229

229-
importLines := []string{}
230+
importLines := make([]string, 0, len(sortedImports))
230231
for _, importPath := range sortedImports {
231232
importLines = append(importLines, fmt.Sprintf(`"%s"`, importPath))
232233
}
@@ -969,7 +970,8 @@ func (cg *connectorGenerator) writeGetTypeValueDecoder( //nolint:gocyclo,cyclop,
969970
sb.builder.WriteString("DecodeObjectValue")
970971

971972
if len(objectField.Type) > 0 {
972-
if typeEnum, err := objectField.Type.Type(); err == nil && typeEnum == schema.TypeNullable {
973+
if typeEnum, err := objectField.Type.Type(); err == nil &&
974+
typeEnum == schema.TypeNullable {
973975
sb.builder.WriteString("Default")
974976
}
975977
}
@@ -1027,31 +1029,37 @@ func (cg *connectorGenerator) getAnonymousObjectTypeName(
10271029
result += "*"
10281030
}
10291031

1030-
underlyingName, packagePaths := cg.getAnonymousObjectTypeName(sb, inferredType.Elem(), false)
1032+
underlyingName, packagePaths := cg.getAnonymousObjectTypeName(
1033+
sb,
1034+
inferredType.Elem(),
1035+
false,
1036+
)
10311037

10321038
return result + underlyingName, packagePaths
10331039
case *types.Struct:
10341040
packagePaths := []string{}
10351041
result := "struct{"
10361042

1043+
var resultSb1037 strings.Builder
10371044
for i := range inferredType.NumFields() {
10381045
fieldVar := inferredType.Field(i)
10391046
fieldTag := inferredType.Tag(i)
10401047

10411048
if i > 0 {
1042-
result += "; "
1049+
resultSb1037.WriteString("; ")
10431050
}
10441051

1045-
result += fieldVar.Name() + " "
1052+
resultSb1037.WriteString(fieldVar.Name() + " ")
10461053
underlyingName, pkgPaths := cg.getAnonymousObjectTypeName(sb, fieldVar.Type(), false)
1047-
result += underlyingName
1054+
resultSb1037.WriteString(underlyingName)
10481055

10491056
packagePaths = append(packagePaths, pkgPaths...)
10501057

10511058
if fieldTag != "" {
1052-
result += " `" + fieldTag + "`"
1059+
resultSb1037.WriteString(" `" + fieldTag + "`")
10531060
}
10541061
}
1062+
result += resultSb1037.String()
10551063

10561064
result += "}"
10571065

@@ -1086,14 +1094,18 @@ func (cg *connectorGenerator) getAnonymousObjectTypeName(
10861094
if err := parseTypeParameters(typeInfo, inferredType.String()); err == nil {
10871095
result += "["
10881096

1097+
var resultSb1089 strings.Builder
10891098
for i, typeParam := range typeInfo.TypeParameters {
10901099
if i > 0 {
1091-
result += ", "
1100+
resultSb1089.WriteString(", ")
10921101
}
10931102

1094-
packagePaths = append(packagePaths, getTypePackagePaths(typeParam, sb.packagePath)...)
1095-
result += getTypeArgumentName(typeParam, sb.packagePath, false)
1103+
packagePaths = append(
1104+
packagePaths,
1105+
getTypePackagePaths(typeParam, sb.packagePath)...)
1106+
resultSb1089.WriteString(getTypeArgumentName(typeParam, sb.packagePath, false))
10961107
}
1108+
result += resultSb1089.String()
10971109

10981110
result += "]"
10991111
}

cmd/hasura-ndc-go/command/internal/connector_handler.go

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,29 @@ func (dch DataConnectorHandler) execQuery(ctx context.Context, state *`,
190190

191191
switch resultType.(type) {
192192
case *ArrayType:
193-
chb.writeOperationResult(sb, fn.OriginName, OperationFunction, argumentParamStr, isNullable)
194-
sb.WriteString("\n result, err := utils.EvalNestedColumnArrayIntoSlice(selection, rawResult)")
193+
chb.writeOperationResult(
194+
sb,
195+
fn.OriginName,
196+
OperationFunction,
197+
argumentParamStr,
198+
isNullable,
199+
)
200+
sb.WriteString(
201+
"\n result, err := utils.EvalNestedColumnArrayIntoSlice(selection, rawResult)",
202+
)
195203
writeErrorCheck(sb, 2, 4)
196204
sb.WriteString(" return result, nil\n")
197205
case *NamedType:
198-
chb.writeOperationResult(sb, fn.OriginName, OperationFunction, argumentParamStr, isNullable)
199-
sb.WriteString("\n result, err := utils.EvalNestedColumnObject(selection, rawResult)")
206+
chb.writeOperationResult(
207+
sb,
208+
fn.OriginName,
209+
OperationFunction,
210+
argumentParamStr,
211+
isNullable,
212+
)
213+
sb.WriteString(
214+
"\n result, err := utils.EvalNestedColumnObject(selection, rawResult)",
215+
)
200216
writeErrorCheck(sb, 2, 4)
201217
sb.WriteString(" return result, nil\n")
202218
}
@@ -281,12 +297,28 @@ func (dch DataConnectorHandler) Mutation(ctx context.Context, state *`)
281297
} else {
282298
switch resultType.(type) {
283299
case *ArrayType:
284-
chb.writeOperationResult(sb, fn.OriginName, OperationProcedure, argumentParamStr, isNullable)
285-
sb.WriteString("\n result, err := utils.EvalNestedColumnArrayIntoSlice(selection, rawResult)\n")
300+
chb.writeOperationResult(
301+
sb,
302+
fn.OriginName,
303+
OperationProcedure,
304+
argumentParamStr,
305+
isNullable,
306+
)
307+
sb.WriteString(
308+
"\n result, err := utils.EvalNestedColumnArrayIntoSlice(selection, rawResult)\n",
309+
)
286310
writeErrorCheck(sb, 2, 4)
287311
case *NamedType:
288-
chb.writeOperationResult(sb, fn.OriginName, OperationProcedure, argumentParamStr, isNullable)
289-
sb.WriteString("\n result, err := utils.EvalNestedColumnObject(selection, rawResult)\n")
312+
chb.writeOperationResult(
313+
sb,
314+
fn.OriginName,
315+
OperationProcedure,
316+
argumentParamStr,
317+
isNullable,
318+
)
319+
sb.WriteString(
320+
"\n result, err := utils.EvalNestedColumnObject(selection, rawResult)\n",
321+
)
290322
writeErrorCheck(sb, 2, 4)
291323
}
292324
}

cmd/hasura-ndc-go/command/internal/rand.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func GenRandomScalarValue(random *rand.Rand, name string, scalar *schema.ScalarT
4848
case *schema.TypeRepresentationDate:
4949
return baseTime.Add(time.Duration(random.Intn(math.MaxInt32))).Format("2006-01-02")
5050
case *schema.TypeRepresentationTimestamp:
51-
return baseTime.Add(time.Duration(random.Intn(math.MaxInt32))).Format("2006-01-02T15:04:05Z")
51+
return baseTime.Add(time.Duration(random.Intn(math.MaxInt32))).
52+
Format("2006-01-02T15:04:05Z")
5253
case *schema.TypeRepresentationTimestampTZ:
5354
return baseTime.Add(time.Duration(random.Intn(math.MaxInt32))).Format(time.RFC3339)
5455
case *schema.TypeRepresentationUUID:

cmd/hasura-ndc-go/command/internal/schema.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package internal
33
import (
44
"fmt"
55
"go/types"
6+
"strings"
67

78
"github.com/hasura/ndc-sdk-go/v2/schema"
89
"github.com/hasura/ndc-sdk-go/v2/utils"
@@ -252,12 +253,14 @@ func (ti *TypeInfo) getArgumentName(packagePath string, isAbsolute bool) string
252253
paramLen := len(ti.TypeParameters)
253254
if paramLen > 0 {
254255
name += "["
256+
var nameSb255 strings.Builder
255257
for i, param := range ti.TypeParameters {
256-
name += getTypeArgumentName(param, packagePath, isAbsolute)
258+
nameSb255.WriteString(getTypeArgumentName(param, packagePath, isAbsolute))
257259
if i < paramLen-1 {
258-
name += ", "
260+
nameSb255.WriteString(", ")
259261
}
260262
}
263+
name += nameSb255.String()
261264

262265
name += "]"
263266
}

cmd/hasura-ndc-go/command/internal/schema_parser.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ func (sp *SchemaParser) parsePackageScope(pkg *types.Package, name string) error
221221
var resultTuple *types.Tuple
222222

223223
var params *types.Tuple
224+
224225
switch sig := obj.Type().(type) {
225226
case *types.Signature:
226227
params = sig.Params()
@@ -230,11 +231,19 @@ func (sp *SchemaParser) parsePackageScope(pkg *types.Package, name string) error
230231
}
231232

232233
if params == nil || (params.Len() < 2 || params.Len() > 3) {
233-
return fmt.Errorf("%s: expect 2 or 3 parameters only (ctx context.Context, state *types.State, arguments *[ArgumentType]), got %s", opInfo.OriginName, params)
234+
return fmt.Errorf(
235+
"%s: expect 2 or 3 parameters only (ctx context.Context, state *types.State, arguments *[ArgumentType]), got %s",
236+
opInfo.OriginName,
237+
params,
238+
)
234239
}
235240

236241
if resultTuple == nil || resultTuple.Len() != 2 {
237-
return fmt.Errorf("%s: expect result tuple ([type], error), got %s", opInfo.OriginName, resultTuple)
242+
return fmt.Errorf(
243+
"%s: expect result tuple ([type], error), got %s",
244+
opInfo.OriginName,
245+
resultTuple,
246+
)
238247
}
239248

240249
if sp.rawSchema.StateType == nil {

cmd/hasura-ndc-go/command/internal/schema_type_parser.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"go/types"
7+
"maps"
78
"strings"
89

910
"github.com/hasura/ndc-sdk-go/v2/schema"
@@ -97,7 +98,10 @@ func (tp *TypeParser) parseArgumentTypes(ty types.Type, fieldPaths []string) (*O
9798
typeInfo.TypeAST = inferredType.Underlying()
9899
}
99100

100-
arguments, err := tp.parseArgumentTypes(typeInfo.TypeAST, append(fieldPaths, typeObj.Name()))
101+
arguments, err := tp.parseArgumentTypes(
102+
typeInfo.TypeAST,
103+
append(fieldPaths, typeObj.Name()),
104+
)
101105
if err != nil {
102106
return nil, err
103107
}
@@ -186,7 +190,11 @@ func (tp *TypeParser) parseType(ty types.Type, fieldPaths []string) (Type, error
186190
case types.String:
187191
typeInfo.SchemaName = string(ScalarString)
188192
default:
189-
return nil, fmt.Errorf("%s: unsupported scalar type <%s>", strings.Join(fieldPaths, "."), inferredType.String())
193+
return nil, fmt.Errorf(
194+
"%s: unsupported scalar type <%s>",
195+
strings.Join(fieldPaths, "."),
196+
inferredType.String(),
197+
)
190198
}
191199

192200
tp.schemaParser.rawSchema.SetScalar(typeInfo.SchemaName, Scalar{
@@ -225,7 +233,11 @@ func (tp *TypeParser) parseType(ty types.Type, fieldPaths []string) (Type, error
225233
case *types.Chan, *types.Signature, *types.Tuple, *types.Union:
226234
return nil, nil
227235
default:
228-
return nil, fmt.Errorf("%s: unsupported type: %s", strings.Join(fieldPaths, "."), ty.String())
236+
return nil, fmt.Errorf(
237+
"%s: unsupported type: %s",
238+
strings.Join(fieldPaths, "."),
239+
ty.String(),
240+
)
229241
}
230242
}
231243

@@ -444,9 +456,7 @@ func (tp *TypeParser) parseStructType(
444456
embeddedObject, ok := tp.schemaParser.rawSchema.Objects[field.Type.SchemaName(false)]
445457
if field.Embedded && ok {
446458
// flatten embedded object fields to the parent object
447-
for k, of := range embeddedObject.SchemaFields {
448-
objectInfo.SchemaFields[k] = of
449-
}
459+
maps.Copy(objectInfo.SchemaFields, embeddedObject.SchemaFields)
450460
} else {
451461
fieldSchema := field.Type.Schema()
452462
if tagInfo.OmitEmpty && field.Type.Kind() != schema.TypeNullable {
@@ -501,9 +511,9 @@ func (tp *TypeParser) parseTypeInfoFromComments(
501511
if len(enumMatches) == 2 {
502512
var enums []string
503513

504-
rawEnumItems := strings.Split(enumMatches[1], ",")
514+
rawEnumItems := strings.SplitSeq(enumMatches[1], ",")
505515

506-
for _, item := range rawEnumItems {
516+
for item := range rawEnumItems {
507517
trimmed := strings.TrimSpace(item)
508518
if trimmed != "" {
509519
enums = append(enums, trimmed)
@@ -610,9 +620,9 @@ func parseTypeParameters(rootType *TypeInfo, input string) error {
610620
paramsString = paramsString[:len(paramsString)-1]
611621
}
612622

613-
rawParams := strings.Split(paramsString, ",")
623+
rawParams := strings.SplitSeq(paramsString, ",")
614624

615-
for _, param := range rawParams {
625+
for param := range rawParams {
616626
param = strings.TrimSpace(param)
617627
if param == "" {
618628
continue

cmd/hasura-ndc-go/command/internal/templates/new/.hasura-connector/Dockerfile.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# build context at repo root: docker build -f Dockerfile .
2-
FROM golang:1.25 AS builder
2+
FROM golang:1.26 AS builder
33

44
WORKDIR /app
55
COPY go.mod go.sum ./

cmd/hasura-ndc-go/command/internal/templates/new/go.mod.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module {{.Module}}
22

3-
go 1.24.12
3+
go 1.26.1
44

55
require (
66
github.com/hasura/ndc-sdk-go/v2 {{.Version}}

cmd/hasura-ndc-go/command/snapshots_gen.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,10 @@ func (cmd *genTestSnapshotsCommand) genNestFieldAndValueInternal(
376376
return nil, nil, false, nil
377377
}
378378

379-
innerType, data, isScalar, err := cmd.genNestFieldAndValueInternal(ty.ElementType, currentDepth+1)
379+
innerType, data, isScalar, err := cmd.genNestFieldAndValueInternal(
380+
ty.ElementType,
381+
currentDepth+1,
382+
)
380383
if err != nil {
381384
return nil, nil, false, err
382385
}

cmd/hasura-ndc-go/command/update.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ func UpdateConnectorSchema(args UpdateArguments, start time.Time) {
3030
log.Fatal().Err(err).Msg("")
3131
}
3232

33-
if err = internal.ParseAndGenerateConnector(internal.ConnectorGenerationArguments(args), moduleName); err != nil {
33+
if err = internal.ParseAndGenerateConnector(
34+
internal.ConnectorGenerationArguments(args),
35+
moduleName,
36+
); err != nil {
3437
log.Fatal().Err(err).Msg("failed to generate connector schema")
3538
}
3639

0 commit comments

Comments
 (0)