status
stringclasses
1 value
repo_name
stringclasses
31 values
repo_url
stringclasses
31 values
issue_id
int64
1
104k
title
stringlengths
4
233
body
stringlengths
0
186k
βŒ€
issue_url
stringlengths
38
56
pull_url
stringlengths
37
54
before_fix_sha
stringlengths
40
40
after_fix_sha
stringlengths
40
40
report_datetime
timestamp[us, tz=UTC]
language
stringclasses
5 values
commit_datetime
timestamp[us, tz=UTC]
updated_file
stringlengths
7
188
chunk_content
stringlengths
1
1.03M
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
return err } case 1: if results.At(0).Type().String() == errorTypeName { statements = append(statements, Return( Nil(), Parens(Op("*").Id(objName)).Dot(fnName).Call(fnCallArgs...), )) cases[objName] = append(cases[objName], Case(Lit(fnName)).Block(statements...)) } else { statements = append(statements, Return( Parens(Op("*").Id(objName)).Dot(fnName).Call(fnCallArgs...), Nil(), )) cases[objName] = append(cases[objName], Case(Lit(fnName)).Block(statements...)) if err := ps.fillObjectFunctionCases(results.At(0).Type(), cases); err != nil { return err } } case 0: statements = append(statements, Parens(Op("*").Id(objName)).Dot(fnName).Call(fnCallArgs...), Return(Nil(), Nil())) cases[objName] = append(cases[objName], Case(Lit(fnName)).Block(statements...))
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
default: return fmt.Errorf("unexpected number of results from method %s: %d", fnName, results.Len()) } } cases[objName] = append(cases[objName], Default().Block( Return(Nil(), Qual("fmt", "Errorf").Call(Lit("unknown function %s"), Id(fnNameVar))), )) return nil } type parseState struct { pkg *packages.Package fset *token.FileSet methods map[string][]method } type method struct { fn *types.Func paramSpecs []paramSpec } func (ps *parseState) goTypeToAPIType(typ types.Type, named *types.Named) (*Statement, *types.Named, error) { switch t := typ.(type) { case *types.Named: typeDef, _, err := ps.goTypeToAPIType(t.Underlying(), t) if err != nil { return nil, nil, fmt.Errorf("failed to convert named type: %w", err) } return typeDef, t, nil case *types.Pointer: return ps.goTypeToAPIType(t.Elem(), named)
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
case *types.Slice: elemTypeDef, underlying, err := ps.goTypeToAPIType(t.Elem(), nil) if err != nil { return nil, nil, fmt.Errorf("failed to convert slice element type: %w", err) } return Qual("dag", "TypeDef").Call().Dot("WithListOf").Call( elemTypeDef, ), underlying, nil case *types.Basic: if t.Kind() == types.Invalid { return nil, nil, fmt.Errorf("invalid type: %+v", t) } var kind Code switch t.Info() { case types.IsString: kind = Id("Stringkind") case types.IsInteger: kind = Id("Integerkind") case types.IsBoolean: kind = Id("Booleankind") default: return nil, nil, fmt.Errorf("unsupported basic type: %+v", t) } return Qual("dag", "TypeDef").Call().Dot("WithKind").Call( kind, ), named, nil case *types.Struct: if named == nil { return nil, nil, fmt.Errorf("struct types must be named") }
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
typeName := named.Obj().Name() if typeName == "" { return nil, nil, fmt.Errorf("struct types must be named") } return Qual("dag", "TypeDef").Call().Dot("WithObject").Call( Lit(typeName), ), named, nil default: return nil, nil, fmt.Errorf("unsupported type %T", t) } } const errorTypeName = "error" func (ps *parseState) goStructToAPIType(t *types.Struct, named *types.Named) (*Statement, []types.Type, error) { if named == nil { return nil, nil, fmt.Errorf("struct types must be named") } typeName := named.Obj().Name() if typeName == "" { return nil, nil, fmt.Errorf("struct types must be named") } objectIsDaggerGenerated := ps.isDaggerGenerated(named.Obj()) methods := []*types.Func{} methodSet := types.NewMethodSet(types.NewPointer(named)) for i := 0; i < methodSet.Len(); i++ { methodObj := methodSet.At(i).Obj()
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
if ps.isDaggerGenerated(methodObj) { continue } if objectIsDaggerGenerated { return nil, nil, fmt.Errorf("cannot define methods on objects from outside this module") } method, ok := methodObj.(*types.Func) if !ok { return nil, nil, fmt.Errorf("expected method to be a func, got %T", methodObj) } if !method.Exported() { continue } methods = append(methods, method) } if objectIsDaggerGenerated { return nil, nil, nil } sort.Slice(methods, func(i, j int) bool { return methods[i].Pos() < methods[j].Pos() }) withObjectArgs := []Code{ Lit(typeName), } withObjectOpts := []Code{} typeSpec, err := ps.typeSpecForNamedType(named) if err != nil {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
return nil, nil, fmt.Errorf("failed to find decl for named type %s: %w", typeName, err) } if doc := typeSpec.Doc; doc != nil { withObjectOpts = append(withObjectOpts, Id("Description").Op(":").Lit(doc.Text())) } if len(withObjectOpts) > 0 { withObjectArgs = append(withObjectArgs, Id("TypeDefWithObjectOpts").Values(withObjectOpts...)) } typeDef := Qual("dag", "TypeDef").Call().Dot("WithObject").Call(withObjectArgs...) var subTypes []types.Type for _, method := range methods { fnTypeDef, functionSubTypes, err := ps.goMethodToAPIFunctionDef(typeName, method, named) if err != nil { return nil, nil, fmt.Errorf("failed to convert method %s to function def: %w", method.Name(), err) } subTypes = append(subTypes, functionSubTypes...) typeDef = dotLine(typeDef, "WithFunction").Call(Add(Line(), fnTypeDef)) } astStructType, ok := typeSpec.Type.(*ast.StructType) if !ok { return nil, nil, fmt.Errorf("expected type spec to be a struct, got %T", typeSpec.Type) } for i := 0; i < t.NumFields(); i++ { field := t.Field(i) if !field.Exported() { continue } fieldTypeDef, subType, err := ps.goTypeToAPIType(field.Type(), nil) if err != nil {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
return nil, nil, fmt.Errorf("failed to convert field type: %w", err) } if subType != nil { subTypes = append(subTypes, subType) } var description string if doc := astStructType.Fields.List[i].Doc; doc != nil { description = doc.Text() } withFieldArgs := []Code{ Lit(field.Name()), fieldTypeDef, } if description != "" { withFieldArgs = append(withFieldArgs, Id("TypeDefWithFieldOpts").Values( Id("Description").Op(":").Lit(description), )) } typeDef = dotLine(typeDef, "WithField").Call(withFieldArgs...) } return typeDef, subTypes, nil } var voidDef = Qual("dag", "TypeDef").Call(). Dot("WithKind").Call(Id("Voidkind")). Dot("WithOptional").Call(Lit(true)) func (ps *parseState) goMethodToAPIFunctionDef(typeName string, fn *types.Func, named *types.Named) (*Statement, []types.Type, error) { methodSig, ok := fn.Type().(*types.Signature) if !ok { return nil, nil, fmt.Errorf("expected method to be a func, got %T", fn.Type())
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
} specs, err := ps.parseParamSpecs(fn) if err != nil { return nil, nil, err } ps.methods[typeName] = append(ps.methods[typeName], method{fn: fn, paramSpecs: specs}) var fnReturnType *Statement var subTypes []types.Type methodResults := methodSig.Results() var returnSubType *types.Named switch methodResults.Len() { case 0: fnReturnType = voidDef case 1: result := methodResults.At(0).Type() if result.String() == errorTypeName { fnReturnType = voidDef } else { fnReturnType, returnSubType, err = ps.goTypeToAPIType(result, nil) if err != nil { return nil, nil, fmt.Errorf("failed to convert result type: %w", err) } } case 2: result := methodResults.At(0).Type() subTypes = append(subTypes, result) fnReturnType, returnSubType, err = ps.goTypeToAPIType(result, nil) if err != nil {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
return nil, nil, fmt.Errorf("failed to convert result type: %w", err) } default: return nil, nil, fmt.Errorf("method %s has too many return values", fn.Name()) } if returnSubType != nil { subTypes = append(subTypes, returnSubType) } fnDef := Qual("dag", "Function").Call(Lit(fn.Name()), Add(Line(), fnReturnType)) funcDecl, err := ps.declForFunc(fn) if err != nil { return nil, nil, fmt.Errorf("failed to find decl for method %s: %w", fn.Name(), err) } if doc := funcDecl.Doc; doc != nil { fnDef = dotLine(fnDef, "WithDescription").Call(Lit(doc.Text())) } for i, spec := range specs { if i == 0 && spec.paramType.String() == contextTypename { continue } typeDef, subType, err := ps.goTypeToAPIType(spec.baseType, nil) if err != nil { return nil, nil, fmt.Errorf("failed to convert param type: %w", err) } if subType != nil { subTypes = append(subTypes, subType) } if spec.optional { typeDef = typeDef.Dot("WithOptional").Call(Lit(true))
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
} args := []Code{Lit(spec.graphqlName()), typeDef} argOpts := []Code{} if spec.description != "" { argOpts = append(argOpts, Id("Description").Op(":").Lit(spec.description)) } if spec.defaultValue != "" { var jsonEnc string if spec.baseType.String() == "string" { enc, err := json.Marshal(spec.defaultValue) if err != nil { return nil, nil, fmt.Errorf("failed to marshal default value: %w", err) } jsonEnc = string(enc) } else { jsonEnc = spec.defaultValue } argOpts = append(argOpts, Id("DefaultValue").Op(":").Id("JSON").Call(Lit(jsonEnc))) } if len(argOpts) > 0 { args = append(args, Id("FunctionWithArgOpts").Values(argOpts...)) } fnDef = dotLine(fnDef, "WithArg").Call(args...) } return fnDef, subTypes, nil } func (ps *parseState) parseParamSpecs(fn *types.Func) ([]paramSpec, error) { sig := fn.Type().(*types.Signature) params := sig.Params()
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
if params.Len() == 0 { return nil, nil } specs := make([]paramSpec, 0, params.Len()) i := 0 if params.At(i).Type().String() == contextTypename { spec, err := ps.parseParamSpecVar(params.At(i)) if err != nil { return nil, err } specs = append(specs, spec) i++ } fnDecl, err := ps.declForFunc(fn) if err != nil { return nil, err } if i+1 == params.Len() { param := params.At(i) paramType, ok := asInlineStruct(param.Type()) if ok { stype, ok := asInlineStructAst(fnDecl.Type.Params.List[i].Type) if !ok { return nil, fmt.Errorf("expected struct type for %s", param.Name()) } parent := &paramSpec{ name: params.At(i).Name(), paramType: param.Type(),
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
baseType: param.Type(), } paramFields := unpackASTFields(stype.Fields) for f := 0; f < paramType.NumFields(); f++ { spec, err := ps.parseParamSpecVar(paramType.Field(f)) if err != nil { return nil, err } spec.parent = parent spec.description = paramFields[f].Doc.Text() if spec.description == "" { spec.description = paramFields[f].Comment.Text() } spec.description = strings.TrimSpace(spec.description) specs = append(specs, spec) } return specs, nil } } paramFields := unpackASTFields(fnDecl.Type.Params) for ; i < params.Len(); i++ { spec, err := ps.parseParamSpecVar(params.At(i)) if err != nil { return nil, err } if sig.Variadic() && i == params.Len()-1 { spec.variadic = true }
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
if cmt, err := ps.commentForFuncField(fnDecl, paramFields, i); err == nil { spec.description = cmt.Text() spec.description = strings.TrimSpace(spec.description) } specs = append(specs, spec) } return specs, nil } func (ps *parseState) parseParamSpecVar(field *types.Var) (paramSpec, error) { if _, ok := field.Type().(*types.Struct); ok { return paramSpec{}, fmt.Errorf("nested structs are not supported") } paramType := field.Type() baseType := paramType for { ptr, ok := baseType.(*types.Pointer) if !ok { break } baseType = ptr.Elem() } optional := false if named, ok := baseType.(*types.Named); ok { if named.Obj().Name() == "Optional" && ps.isDaggerGenerated(named.Obj()) { typeArgs := named.TypeArgs() if typeArgs.Len() != 1 { return paramSpec{}, fmt.Errorf("optional type must have exactly one type argument") } optional = true baseType = typeArgs.At(0)
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
for { ptr, ok := baseType.(*types.Pointer) if !ok { break } baseType = ptr.Elem() } } } return paramSpec{ name: field.Name(), paramType: paramType, baseType: baseType, optional: optional, }, nil } type paramSpec struct { name string description string optional bool variadic bool defaultValue string paramType types.Type baseType types.Type parent *paramSpec
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
} func (spec *paramSpec) graphqlName() string { return strcase.ToLowerCamel(spec.name) } func (ps *parseState) typeSpecForNamedType(namedType *types.Named) (*ast.TypeSpec, error) { tokenFile := ps.fset.File(namedType.Obj().Pos()) if tokenFile == nil { return nil, fmt.Errorf("no file for %s", namedType.Obj().Name()) } for _, f := range ps.pkg.Syntax { if ps.fset.File(f.Pos()) != tokenFile { continue } for _, decl := range f.Decls { genDecl, ok := decl.(*ast.GenDecl) if !ok { continue } for _, spec := range genDecl.Specs { typeSpec, ok := spec.(*ast.TypeSpec) if !ok { continue } if typeSpec.Name.Name == namedType.Obj().Name() { return typeSpec, nil } } } } return nil, fmt.Errorf("no decl for %s", namedType.Obj().Name())
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
} func (ps *parseState) declForFunc(fnType *types.Func) (*ast.FuncDecl, error) { tokenFile := ps.fset.File(fnType.Pos()) if tokenFile == nil { return nil, fmt.Errorf("no file for %s", fnType.Name()) } for _, f := range ps.pkg.Syntax { if ps.fset.File(f.Pos()) != tokenFile { continue } for _, decl := range f.Decls { fnDecl, ok := decl.(*ast.FuncDecl) if ok && fnDecl.Name.Name == fnType.Name() { return fnDecl, nil } } } return nil, fmt.Errorf("no decl for %s", fnType.Name()) } func (ps *parseState) commentForFuncField(fnDecl *ast.FuncDecl, unpackedParams []*ast.Field, i int) (*ast.CommentGroup, error) { pos := unpackedParams[i].Pos() tokenFile := ps.fset.File(pos) if tokenFile == nil { return nil, fmt.Errorf("no file for function %s", fnDecl.Name.Name) } line := tokenFile.Line(pos) allowDocComment := true allowLineComment := true if i == 0 { fieldStartLine := tokenFile.Line(fnDecl.Type.Params.Pos())
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
if fieldStartLine == line || fieldStartLine == line-1 { allowDocComment = false } } else { prevArgLine := tokenFile.Line(unpackedParams[i-1].Pos()) if prevArgLine == line || prevArgLine == line-1 { allowDocComment = false } } if i+1 < len(fnDecl.Type.Params.List) { nextArgLine := tokenFile.Line(unpackedParams[i+1].Pos()) if nextArgLine == line { allowLineComment = false } } else { fieldEndLine := tokenFile.Line(fnDecl.Type.Params.End()) if fieldEndLine == line { allowLineComment = false } } for _, f := range ps.pkg.Syntax { if ps.fset.File(f.Pos()) != tokenFile {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
continue } if allowDocComment { npos := tokenFile.LineStart(tokenFile.Line(pos)) - 1 for _, comment := range f.Comments { if comment.Pos() <= npos && npos <= comment.End() { return comment, nil } } } if allowLineComment { npos := tokenFile.LineStart(tokenFile.Line(pos)+1) - 1 for _, comment := range f.Comments { if comment.Pos() <= npos && npos <= comment.End() { return comment, nil } } } } return nil, fmt.Errorf("no comment for function %s", fnDecl.Name.Name) } func (ps *parseState) isDaggerGenerated(obj types.Object) bool { tokenFile := ps.fset.File(obj.Pos()) return filepath.Base(tokenFile.Name()) == daggerGenFilename } func findOptsAccessPattern(t types.Type, access *Statement) (types.Type, *Statement) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
switch t := t.(type) { case *types.Pointer: t2, val := findOptsAccessPattern(t.Elem(), access) return t2, Id("ptr").Call(val) default: return t, access } } func asInlineStruct(t types.Type) (*types.Struct, bool) { switch t := t.(type) { case *types.Pointer: return asInlineStruct(t.Elem()) case *types.Struct: return t, true default: return nil, false } } func asInlineStructAst(t ast.Node) (*ast.StructType, bool) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
cmd/codegen/generator/go/templates/modules.go
switch t := t.(type) { case *ast.StarExpr: return asInlineStructAst(t.X) case *ast.StructType: return t, true default: return nil, false } } func unpackASTFields(fields *ast.FieldList) []*ast.Field { var unpacked []*ast.Field for _, field := range fields.List { for i, name := range field.Names { field := *field field.Names = []*ast.Ident{name} if i != 0 { field.Doc = nil field.Comment = nil } unpacked = append(unpacked, &field) } } return unpacked }
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/function.go
package core import ( "fmt" "strings" "github.com/dagger/dagger/core/resourceid" "github.com/iancoleman/strcase" "github.com/opencontainers/go-digest" ) type Function struct {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/function.go
Name string `json:"name"` Description string `json:"description"` Args []*FunctionArg `json:"args"` ReturnType *TypeDef `json:"returnType"` ParentOriginalName string `json:"parentOriginalName,omitempty"` OriginalName string `json:"originalName,omitempty"` } func NewFunction(name string, returnType *TypeDef) *Function { return &Function{ Name: strcase.ToLowerCamel(name), ReturnType: returnType, OriginalName: name, } } func (fn *Function) ID() (FunctionID, error) { return resourceid.Encode(fn) } func (fn *Function) Digest() (digest.Digest, error) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/function.go
return stableDigest(fn) } func (fn Function) Clone() *Function { cp := fn cp.Args = make([]*FunctionArg, len(fn.Args)) for i, arg := range fn.Args { cp.Args[i] = arg.Clone() } if fn.ReturnType != nil { cp.ReturnType = fn.ReturnType.Clone() } return &cp } func (fn *Function) WithDescription(desc string) *Function { fn = fn.Clone() fn.Description = strings.TrimSpace(desc) return fn } func (fn *Function) WithArg(name string, typeDef *TypeDef, desc string, defaultValue any) *Function { fn = fn.Clone() fn.Args = append(fn.Args, &FunctionArg{ Name: strcase.ToLowerCamel(name), Description: desc, TypeDef: typeDef, DefaultValue: defaultValue, OriginalName: name, }) return fn } type FunctionArg struct {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/function.go
Name string `json:"name"` Description string `json:"description"` TypeDef *TypeDef `json:"typeDef"` DefaultValue any `json:"defaultValue"` OriginalName string `json:"originalName,omitempty"` } func (arg FunctionArg) Clone() *FunctionArg { cp := arg cp.TypeDef = arg.TypeDef.Clone() return &cp } type TypeDef struct { Kind TypeDefKind `json:"kind"` Optional bool `json:"optional"` AsList *ListTypeDef `json:"asList"` AsObject *ObjectTypeDef `json:"asObject"` } func (typeDef *TypeDef) ID() (TypeDefID, error) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/function.go
return resourceid.Encode(typeDef) } func (typeDef *TypeDef) Digest() (digest.Digest, error) { return stableDigest(typeDef) } func (typeDef TypeDef) Clone() *TypeDef { cp := typeDef if typeDef.AsList != nil { cp.AsList = typeDef.AsList.Clone() } if typeDef.AsObject != nil { cp.AsObject = typeDef.AsObject.Clone() } return &cp } func (typeDef *TypeDef) WithKind(kind TypeDefKind) *TypeDef { typeDef = typeDef.Clone() typeDef.Kind = kind return typeDef } func (typeDef *TypeDef) WithListOf(elem *TypeDef) *TypeDef { typeDef = typeDef.WithKind(TypeDefKindList) typeDef.AsList = &ListTypeDef{ ElementTypeDef: elem, } return typeDef } func (typeDef *TypeDef) WithObject(name, desc string) *TypeDef { typeDef = typeDef.WithKind(TypeDefKindObject) typeDef.AsObject = NewObjectTypeDef(name, desc)
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/function.go
return typeDef } func (typeDef *TypeDef) WithOptional(optional bool) *TypeDef { typeDef = typeDef.Clone() typeDef.Optional = optional return typeDef } func (typeDef *TypeDef) WithObjectField(name string, fieldType *TypeDef, desc string) (*TypeDef, error) { if typeDef.AsObject == nil { return nil, fmt.Errorf("cannot add function to non-object type: %s", typeDef.Kind) } typeDef = typeDef.Clone() typeDef.AsObject.Fields = append(typeDef.AsObject.Fields, &FieldTypeDef{ Name: name, Description: desc, TypeDef: fieldType, }) return typeDef, nil } func (typeDef *TypeDef) WithObjectFunction(fn *Function) (*TypeDef, error) { if typeDef.AsObject == nil { return nil, fmt.Errorf("cannot add function to non-object type: %s", typeDef.Kind) } typeDef = typeDef.Clone() fn = fn.Clone() fn.ParentOriginalName = typeDef.AsObject.OriginalName typeDef.AsObject.Functions = append(typeDef.AsObject.Functions, fn) return typeDef, nil } type ObjectTypeDef struct {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/function.go
Name string `json:"name"` Description string `json:"description"` Fields []*FieldTypeDef `json:"fields"` Functions []*Function `json:"functions"` OriginalName string `json:"originalName,omitempty"` } func NewObjectTypeDef(name, description string) *ObjectTypeDef { return &ObjectTypeDef{ Name: strcase.ToCamel(name), OriginalName: name, } } func (typeDef ObjectTypeDef) Clone() *ObjectTypeDef { cp := typeDef cp.Fields = make([]*FieldTypeDef, len(typeDef.Fields)) for i, field := range typeDef.Fields { cp.Fields[i] = field.Clone() } cp.Functions = make([]*Function, len(typeDef.Functions)) for i, fn := range typeDef.Functions { cp.Functions[i] = fn.Clone() } return &cp
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/function.go
} func (typeDef ObjectTypeDef) FieldByName(name string) (*FieldTypeDef, bool) { for _, field := range typeDef.Fields { if field.Name == name { return field, true } } return nil, false } func (typeDef ObjectTypeDef) FunctionByName(name string) (*Function, bool) { for _, fn := range typeDef.Functions { if fn.Name == name { return fn, true } } return nil, false } type FieldTypeDef struct { Name string `json:"name"` Description string `json:"description"` TypeDef *TypeDef `json:"typeDef"` } func (typeDef FieldTypeDef) Clone() *FieldTypeDef { cp := typeDef if typeDef.TypeDef != nil { cp.TypeDef = typeDef.TypeDef.Clone() } return &cp } type ListTypeDef struct {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/function.go
ElementTypeDef *TypeDef `json:"elementTypeDef"` } func (typeDef ListTypeDef) Clone() *ListTypeDef { cp := typeDef if typeDef.ElementTypeDef != nil { cp.ElementTypeDef = typeDef.ElementTypeDef.Clone() } return &cp } type TypeDefKind string func (k TypeDefKind) String() string { return string(k) } const ( TypeDefKindString TypeDefKind = "StringKind" TypeDefKindInteger TypeDefKind = "IntegerKind" TypeDefKindBoolean TypeDefKind = "BooleanKind" TypeDefKindList TypeDefKind = "ListKind" TypeDefKindObject TypeDefKind = "ObjectKind" TypeDefKindVoid TypeDefKind = "VoidKind" ) type FunctionCall struct {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/function.go
Name string `json:"name"` ParentName string `json:"parentName"` Parent any `json:"parent"` InputArgs []*CallInput `json:"inputArgs"` } func (fnCall *FunctionCall) Digest() (digest.Digest, error) { return stableDigest(fnCall) } type CallInput struct { Name string `json:"name"` Value any `json:"value"` }
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
package core import ( "context" _ "embed" "encoding/json" "errors" "fmt" "go/format" "os" "path/filepath" "strconv" "strings" "testing" "time" "dagger.io/dagger" "github.com/dagger/dagger/core/modules" "github.com/iancoleman/strcase" "github.com/moby/buildkit/identity" "github.com/stretchr/testify/require" "github.com/tidwall/gjson" "golang.org/x/sync/errgroup" ) /* TODO: add coverage for * dagger mod use * dagger mod sync * that the codegen of the testdata envs are up to date (or incorporate that into a cli command) * if a dependency changes, then checks should re-run */ func TestModuleGoInit(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Run("from scratch", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=bare", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out) }) t.Run("reserved go.mod name", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=go", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{go{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"go":{"containerEcho":{"stdout":"hello\n"}}}`, out) }) t.Run("uses expected Go module name, camel-cases Dagger module name", func(t *testing.T) { t.Parallel()
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=My-Module", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{myModule{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"myModule":{"containerEcho":{"stdout":"hello\n"}}}`, out) generated, err := modGen.File("go.mod").Contents(ctx) require.NoError(t, err) require.Contains(t, generated, "module main") }) t.Run("creates go.mod beneath an existing go.mod if root points beneath it", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("/work/go.mod", dagger.ContainerWithNewFileOpts{ Contents: "module example.com/test\n", }). WithNewFile("/work/foo.go", dagger.ContainerWithNewFileOpts{ Contents: "package foo\n", }). WithWorkdir("/work/ci"). With(daggerExec("mod", "init", "--name=beneathGoMod", "--sdk=go")) logGen(ctx, t, modGen.Directory("."))
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
out, err := modGen. With(daggerQuery(`{beneathGoMod{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"beneathGoMod":{"containerEcho":{"stdout":"hello\n"}}}`, out) t.Run("names Go module after Dagger module", func(t *testing.T) { generated, err := modGen.File("go.mod").Contents(ctx) require.NoError(t, err) require.Contains(t, generated, "module main") }) }) t.Run("respects existing go.mod", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithExec([]string{"go", "mod", "init", "example.com/test"}). With(daggerExec("mod", "init", "--name=hasGoMod", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{hasGoMod{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"hasGoMod":{"containerEcho":{"stdout":"hello\n"}}}`, out) t.Run("preserves module name", func(t *testing.T) { generated, err := modGen.File("go.mod").Contents(ctx) require.NoError(t, err) require.Contains(t, generated, "module example.com/test") })
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
}) t.Run("respects parent go.mod if root points to it", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithExec([]string{"go", "mod", "init", "example.com/test"}). WithNewFile("/work/foo.go", dagger.ContainerWithNewFileOpts{ Contents: "package foo\n", }). WithWorkdir("/work/child"). With(daggerExec("mod", "init", "--name=child", "--sdk=go", "--root=..")). WithNewFile("/work/child/main.go", dagger.ContainerWithNewFileOpts{ Contents: ` package main import "os" type Child struct{} func (m *Child) Root() *Directory { wd, err := os.Getwd() if err != nil { panic(err) } return dag.Host().Directory(wd+"/..") } `, }) generated := modGen. With(daggerExec("mod", "sync")).
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
Directory(".") logGen(ctx, t, generated) out, err := modGen. With(daggerQuery(`{child{root{entries}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"child":{"root":{"entries":["child","foo.go","go.mod","go.sum"]}}}`, out) childEntries, err := generated.Entries(ctx) require.NoError(t, err) require.NotContains(t, childEntries, "go.mod") t.Run("preserves parent module name", func(t *testing.T) { generated, err := modGen.File("/work/go.mod").Contents(ctx) require.NoError(t, err) require.Contains(t, generated, "module example.com/test") }) }) t.Run("respects existing go.mod even if root points to parent that has go.mod", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithExec([]string{"go", "mod", "init", "example.com/test"}). WithNewFile("/work/foo.go", dagger.ContainerWithNewFileOpts{ Contents: "package foo\n", }). WithWorkdir("/work/child"). WithExec([]string{"go", "mod", "init", "my-mod"}). With(daggerExec("mod", "init", "--name=child", "--sdk=go", "--root=..")). WithNewFile("/work/child/main.go", dagger.ContainerWithNewFileOpts{
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
Contents: ` package main import "os" type Child struct{} func (m *Child) Root() *Directory { wd, err := os.Getwd() if err != nil { panic(err) } return dag.Host().Directory(wd+"/..") } `, }) generated := modGen. With(daggerExec("mod", "sync")). Directory(".") logGen(ctx, t, generated) out, err := modGen. With(daggerQuery(`{child{root{entries}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"child":{"root":{"entries":["child","foo.go","go.mod"]}}}`, out) childEntries, err := generated.Entries(ctx) require.NoError(t, err) require.Contains(t, childEntries, "go.mod") require.Contains(t, childEntries, "go.sum") }) t.Run("respects existing main.go", func(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: ` package main type HasMainGo struct {} func (m *HasMainGo) Hello() string { return "Hello, world!" } `, }). With(daggerExec("mod", "init", "--name=hasMainGo", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{hasMainGo{hello}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"hasMainGo":{"hello":"Hello, world!"}}`, out) }) t.Run("respects existing main.go even if it uses types not generated yet", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: ` package main type HasDaggerTypes struct {}
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
func (m *HasDaggerTypes) Hello() *Container { return dag.Container(). From("` + alpineImage + `"). WithExec([]string{"echo", "Hello, world!"}) } `, }). With(daggerExec("mod", "init", "--name=hasDaggerTypes", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen. With(daggerQuery(`{hasDaggerTypes{hello{stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"hasDaggerTypes":{"hello":{"stdout":"Hello, world!\n"}}}`, out) }) t.Run("respects existing package without creating main.go", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("/work/notmain.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type HasNotMainGo struct {} func (m *HasNotMainGo) Hello() string { return "Hello, world!" } `, }). With(daggerExec("mod", "init", "--name=hasNotMainGo", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
With(daggerQuery(`{hasNotMainGo{hello}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"hasNotMainGo":{"hello":"Hello, world!"}}`, out) }) } func TestModuleInitLICENSE(t *testing.T) { t.Run("bootstraps Apache-2.0 LICENSE file if none found", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=licensed-to-ill", "--sdk=go")) content, err := modGen.File("LICENSE").Contents(ctx) require.NoError(t, err) require.Contains(t, content, "Apache License, Version 2.0") }) t.Run("creates LICENSE file in the directory specified by -m", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "-m", "./mymod", "--name=licensed-to-ill", "--sdk=go")) content, err := modGen.File("mymod/LICENSE").Contents(ctx) require.NoError(t, err) require.Contains(t, content, "Apache License, Version 2.0") }) t.Run("does not bootstrap LICENSE file if it exists in the parent dir", func(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("/work/LICENSE", dagger.ContainerWithNewFileOpts{ Contents: "doesnt matter", }). WithWorkdir("/work/sub"). With(daggerExec("mod", "init", "--name=licensed-to-ill", "--sdk=go")) _, err := modGen.File("LICENSE").Contents(ctx) require.Error(t, err) }) t.Run("bootstraps a LICENSE file when requested, even if it exists in the parent dir", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("/work/LICENSE", dagger.ContainerWithNewFileOpts{ Contents: "doesnt matter", }). WithWorkdir("/work/sub"). With(daggerExec("mod", "init", "--name=licensed-to-ill", "--sdk=go", "--license=MIT")) content, err := modGen.File("LICENSE").Contents(ctx) require.NoError(t, err) require.Contains(t, content, "MIT License") }) } func TestModuleGit(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() type testCase struct { sdk string gitignores []string } for _, tc := range []testCase{ { sdk: "go", gitignores: []string{ "/dagger.gen.go\n", "/querybuilder/\n", }, }, { sdk: "python",
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
gitignores: []string{ "/sdk\n", }, }, } { tc := tc t.Run(fmt.Sprintf("module %s git", tc.sdk), func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := goGitBase(t, c). With(daggerExec("mod", "init", "--name=bare", "--sdk="+tc.sdk)) if tc.sdk == "go" { logGen(ctx, t, modGen.Directory(".")) } out, err := modGen. With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out) t.Run("configures .gitignore", func(t *testing.T) { ignore, err := modGen.File(".gitignore").Contents(ctx) require.NoError(t, err) for _, gitignore := range tc.gitignores { require.Contains(t, ignore, gitignore) } }) }) } } func TestModuleGoGitRemovesIgnored(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) committedModGen := goGitBase(t, c). With(daggerExec("mod", "init", "--name=bare", "--sdk=go")). WithExec([]string{"rm", ".gitignore"}). WithExec([]string{"mkdir", "./internal"}). WithExec([]string{"cp", "-a", "./querybuilder", "./internal/querybuilder"}). WithExec([]string{"git", "add", "."}). WithExec([]string{"git", "commit", "-m", "init with generated files"}) changedAfterSync, err := committedModGen. With(daggerExec("mod", "sync")). WithExec([]string{"git", "diff"}). WithExec([]string{"git", "status", "--short"}). Stdout(ctx) require.NoError(t, err) t.Logf("changed after sync:\n%s", changedAfterSync) require.Contains(t, changedAfterSync, "D dagger.gen.go\n") require.Contains(t, changedAfterSync, "D querybuilder/marshal.go\n") require.Contains(t, changedAfterSync, "D querybuilder/querybuilder.go\n") require.Contains(t, changedAfterSync, "D internal/querybuilder/marshal.go\n") require.Contains(t, changedAfterSync, "D internal/querybuilder/querybuilder.go\n") } func TestModulePythonGitRemovesIgnored(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) committedModGen := goGitBase(t, c). With(daggerExec("mod", "init", "--name=bare", "--sdk=python")). WithExec([]string{"rm", ".gitignore"}). WithExec([]string{"git", "add", "."}). WithExec([]string{"git", "commit", "-m", "init with generated files"}) changedAfterSync, err := committedModGen. With(daggerExec("mod", "sync")). WithExec([]string{"git", "diff"}). WithExec([]string{"git", "status", "--short"}). Stdout(ctx) require.NoError(t, err) t.Logf("changed after sync:\n%s", changedAfterSync) require.Contains(t, changedAfterSync, "D sdk/pyproject.toml\n") require.Contains(t, changedAfterSync, "D sdk/src/dagger/__init__.py\n") } var goSignatures string func TestModuleGoSignatures(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: goSignatures, }) logGen(ctx, t, modGen.Directory(".")) t.Run("func Hello() string", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{hello}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"hello":"hello"}}`, out) }) t.Run("func Echo(string) string", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echo(msg: "hello")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echo":"hello...hello...hello..."}}`, out) }) t.Run("func EchoPointer(*string) string", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoPointer(msg: "hello")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoPointer":"hello...hello...hello..."}}`, out) }) t.Run("func EchoPointerPointer(**string) string", func(t *testing.T) { t.Parallel()
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
out, err := modGen.With(daggerQuery(`{minimal{echoPointerPointer(msg: "hello")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoPointerPointer":"hello...hello...hello..."}}`, out) }) t.Run("func EchoOptional(string) string", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoOptional(msg: "hello")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptional":"hello...hello...hello..."}}`, out) out, err = modGen.With(daggerQuery(`{minimal{echoOptional}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptional":"default...default...default..."}}`, out) }) t.Run("func EchoOptionalPointer(string) string", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoOptionalPointer(msg: "hello")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptionalPointer":"hello...hello...hello..."}}`, out) out, err = modGen.With(daggerQuery(`{minimal{echoOptionalPointer}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptionalPointer":"default...default...default..."}}`, out) }) t.Run("func EchoOptionalSlice([]string) string", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoOptionalSlice(msg: ["hello", "there"])}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptionalSlice":"hello+there...hello+there...hello+there..."}}`, out) out, err = modGen.With(daggerQuery(`{minimal{echoOptionalSlice}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptionalSlice":"foobar...foobar...foobar..."}}`, out)
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
}) t.Run("func Echoes([]string) []string", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoes(msgs: "hello")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoes":["hello...hello...hello..."]}}`, out) }) t.Run("func EchoesVariadic(...string) string", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoesVariadic(msgs: "hello")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoesVariadic":"hello...hello...hello..."}}`, out) }) t.Run("func HelloContext(context.Context) string", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{helloContext}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"helloContext":"hello context"}}`, out) }) t.Run("func EchoContext(context.Context, string) string", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoContext(msg: "hello")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoContext":"ctx.hello...ctx.hello...ctx.hello..."}}`, out) }) t.Run("func HelloStringError() (string, error)", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{helloStringError}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"helloStringError":"hello i worked"}}`, out)
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
}) t.Run("func HelloVoid()", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{helloVoid}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"helloVoid":null}}`, out) }) t.Run("func HelloVoidError() error", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{helloVoidError}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"helloVoidError":null}}`, out) }) t.Run("func EchoOpts(string, string, int) error", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoOpts(msg: "hi")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOpts":"hi"}}`, out) out, err = modGen.With(daggerQuery(`{minimal{echoOpts(msg: "hi", suffix: "!", times: 2)}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOpts":"hi!hi!"}}`, out) }) t.Run("func EchoOptsInline(struct{string, string, int}) error", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoOptsInline(msg: "hi")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptsInline":"hi"}}`, out) out, err = modGen.With(daggerQuery(`{minimal{echoOptsInline(msg: "hi", suffix: "!", times: 2)}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptsInline":"hi!hi!"}}`, out)
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
}) t.Run("func EchoOptsInlinePointer(*struct{string, string, int}) error", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoOptsInlinePointer(msg: "hi")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptsInlinePointer":"hi"}}`, out) out, err = modGen.With(daggerQuery(`{minimal{echoOptsInlinePointer(msg: "hi", suffix: "!", times: 2)}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptsInlinePointer":"hi!hi!"}}`, out) }) t.Run("func EchoOptsInlineCtx(ctx, struct{string, string, int}) error", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoOptsInlineCtx(msg: "hi")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptsInlineCtx":"hi"}}`, out) out, err = modGen.With(daggerQuery(`{minimal{echoOptsInlineCtx(msg: "hi", suffix: "!", times: 2)}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptsInlineCtx":"hi!hi!"}}`, out) }) t.Run("func EchoOptsInlineTags(struct{string, string, int}) error", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(`{minimal{echoOptsInlineTags(msg: "hi")}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptsInlineTags":"hi"}}`, out) out, err = modGen.With(daggerQuery(`{minimal{echoOptsInlineTags(msg: "hi", suffix: "!", times: 2)}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"echoOptsInlineTags":"hi!hi!"}}`, out) }) } func TestModuleGoSignaturesBuiltinTypes(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main import "context" type Minimal struct {}
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
func (m *Minimal) Read(ctx context.Context, dir Directory) (string, error) { return dir.File("foo").Contents(ctx) } func (m *Minimal) ReadPointer(ctx context.Context, dir *Directory) (string, error) { return dir.File("foo").Contents(ctx) } func (m *Minimal) ReadSlice(ctx context.Context, dir []Directory) (string, error) { return dir[0].File("foo").Contents(ctx) } func (m *Minimal) ReadVariadic(ctx context.Context, dir ...Directory) (string, error) { return dir[0].File("foo").Contents(ctx) } func (m *Minimal) ReadOptional(ctx context.Context, dir Optional[Directory]) (string, error) { d, ok := dir.Get() if ok { return d.File("foo").Contents(ctx) } return "", nil } `, }) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(daggerQuery(`{directory{withNewFile(path: "foo", contents: "bar"){id}}}`)).Stdout(ctx) require.NoError(t, err) dirID := gjson.Get(out, "directory.withNewFile.id").String() t.Run("func Read(ctx, Directory) (string, error)", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(fmt.Sprintf(`{minimal{read(dir: "%s")}}`, dirID))).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"read":"bar"}}`, out)
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
}) t.Run("func ReadPointer(ctx, *Directory) (string, error)", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(fmt.Sprintf(`{minimal{readPointer(dir: "%s")}}`, dirID))).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"readPointer":"bar"}}`, out) }) t.Run("func ReadSlice(ctx, []Directory) (string, error)", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(fmt.Sprintf(`{minimal{readSlice(dir: ["%s"])}}`, dirID))).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"readSlice":"bar"}}`, out) }) t.Run("func ReadVariadic(ctx, ...Directory) (string, error)", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(fmt.Sprintf(`{minimal{readVariadic(dir: ["%s"])}}`, dirID))).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"readVariadic":"bar"}}`, out) }) t.Run("func ReadOptional(ctx, Optional[Directory]) (string, error)", func(t *testing.T) { t.Parallel() out, err := modGen.With(daggerQuery(fmt.Sprintf(`{minimal{readOptional(dir: "%s")}}`, dirID))).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"readOptional":"bar"}}`, out) out, err = modGen.With(daggerQuery(`{minimal{readOptional}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"minimal":{"readOptional":""}}`, out) }) } func TestModuleGoSignaturesUnexported(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Minimal struct {} type Foo struct {} type bar struct {} func (m *Minimal) Hello(name string) string { return name } func (f *Foo) Hello(name string) string { return name } func (b *bar) Hello(name string) string { return name } `, }) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(inspectModule).Stdout(ctx) require.NoError(t, err) objs := gjson.Get(out, "host.directory.asModule.objects") require.Equal(t, 2, len(objs.Array())) minimal := objs.Get(`0.asObject`)
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
require.Equal(t, "Minimal", minimal.Get("name").String()) foo := objs.Get(`1.asObject`) require.Equal(t, "MinimalFoo", foo.Get("name").String()) modGen = c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Minimal struct {} type Foo struct { Bar bar } type bar struct {} func (m *Minimal) Hello(name string) string { return name } func (f *Foo) Hello(name string) string { return name } func (b *bar) Hello(name string) string { return name } `, }) logGen(ctx, t, modGen.Directory(".")) _, err = modGen.With(inspectModule).Stderr(ctx) require.Error(t, err) } func TestModuleGoSignaturesMixMatch(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Minimal struct {} func (m *Minimal) Hello(name string, opts struct{}, opts2 struct{}) string { return name } `, }) logGen(ctx, t, modGen.Directory(".")) _, err := modGen.With(daggerQuery(`{minimal{hello}}`)).Stdout(ctx) require.Error(t, err) } func TestModuleGoSignaturesIDable(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Minimal struct {} type Custom struct { Data string } func (m *Minimal) Hello() string { return "hello" } func (m *Minimal) UseCustom(custom *Custom) string { return custom.Data } `, }) logGen(ctx, t, modGen.Directory("."))
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
_, err := modGen.With(daggerQuery(`{minimal{hello}}`)).Stdout(ctx) require.Error(t, err) require.Contains(t, err.Error(), "Undefined type MinimalCustomID") } var inspectModule = daggerQuery(` query { host { directory(path: ".") { asModule { objects { asObject { name functions { name description args { name description } } } } } } } } `) func TestModuleGoDocs(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: goSignatures, }) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(inspectModule).Stdout(ctx) require.NoError(t, err)
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
obj := gjson.Get(out, "host.directory.asModule.objects.0.asObject") require.Equal(t, "Minimal", obj.Get("name").String()) hello := obj.Get(`functions.#(name="hello")`) require.Equal(t, "hello", hello.Get("name").String()) require.Empty(t, hello.Get("description").String()) require.Empty(t, hello.Get("args").Array()) echoOpts := obj.Get(`functions.#(name="echoOpts")`) require.Equal(t, "echoOpts", echoOpts.Get("name").String()) require.Equal(t, "EchoOpts does some opts things", echoOpts.Get("description").String()) require.Len(t, echoOpts.Get("args").Array(), 3) require.Equal(t, "msg", echoOpts.Get("args.0.name").String()) require.Equal(t, "the message to echo", echoOpts.Get("args.0.description").String()) require.Equal(t, "suffix", echoOpts.Get("args.1.name").String()) require.Equal(t, "String to append to the echoed message", echoOpts.Get("args.1.description").String()) require.Equal(t, "times", echoOpts.Get("args.2.name").String()) require.Equal(t, "Number of times to repeat the message", echoOpts.Get("args.2.description").String()) echoOpts = obj.Get(`functions.#(name="echoOptsInline")`) require.Equal(t, "echoOptsInline", echoOpts.Get("name").String()) require.Equal(t, "EchoOptsInline does some opts things", echoOpts.Get("description").String()) require.Len(t, echoOpts.Get("args").Array(), 3) require.Equal(t, "msg", echoOpts.Get("args.0.name").String()) require.Equal(t, "the message to echo", echoOpts.Get("args.0.description").String()) require.Equal(t, "suffix", echoOpts.Get("args.1.name").String()) require.Equal(t, "String to append to the echoed message", echoOpts.Get("args.1.description").String()) require.Equal(t, "times", echoOpts.Get("args.2.name").String()) require.Equal(t, "Number of times to repeat the message", echoOpts.Get("args.2.description").String()) } func TestModuleGoDocsEdgeCases(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Minimal struct {} // some docs func (m *Minimal) Hello(foo string, bar string, // hello baz string, qux string, x string, // lol ) string { return foo + bar } func (m *Minimal) HelloMore( // foo here foo, // bar here bar string, ) string { return foo + bar
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
} func (m *Minimal) HelloMoreInline(opts struct{ // foo here foo, bar string }) string { return opts.foo + opts.bar } func (m *Minimal) HelloAgain( // docs for helloagain foo string, bar string, // docs for bar baz string, ) string { return foo + bar } func (m *Minimal) HelloFinal( foo string) string { // woops return foo } `, }) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(inspectModule).Stdout(ctx) require.NoError(t, err) obj := gjson.Get(out, "host.directory.asModule.objects.0.asObject") require.Equal(t, "Minimal", obj.Get("name").String()) hello := obj.Get(`functions.#(name="hello")`) require.Equal(t, "hello", hello.Get("name").String()) require.Len(t, hello.Get("args").Array(), 5) require.Equal(t, "foo", hello.Get("args.0.name").String()) require.Equal(t, "", hello.Get("args.0.description").String())
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
require.Equal(t, "bar", hello.Get("args.1.name").String()) require.Equal(t, "", hello.Get("args.1.description").String()) require.Equal(t, "baz", hello.Get("args.2.name").String()) require.Equal(t, "hello", hello.Get("args.2.description").String()) require.Equal(t, "qux", hello.Get("args.3.name").String()) require.Equal(t, "", hello.Get("args.3.description").String()) require.Equal(t, "x", hello.Get("args.4.name").String()) require.Equal(t, "lol", hello.Get("args.4.description").String()) hello = obj.Get(`functions.#(name="helloMore")`) require.Equal(t, "helloMore", hello.Get("name").String()) require.Len(t, hello.Get("args").Array(), 2) require.Equal(t, "foo", hello.Get("args.0.name").String()) require.Equal(t, "foo here", hello.Get("args.0.description").String()) require.Equal(t, "bar", hello.Get("args.1.name").String()) require.Equal(t, "bar here", hello.Get("args.1.description").String()) hello = obj.Get(`functions.#(name="helloMoreInline")`) require.Equal(t, "helloMoreInline", hello.Get("name").String()) require.Len(t, hello.Get("args").Array(), 2) require.Equal(t, "foo", hello.Get("args.0.name").String()) require.Equal(t, "foo here", hello.Get("args.0.description").String()) require.Equal(t, "bar", hello.Get("args.1.name").String()) require.Equal(t, "", hello.Get("args.1.description").String()) hello = obj.Get(`functions.#(name="helloAgain")`) require.Equal(t, "helloAgain", hello.Get("name").String()) require.Len(t, hello.Get("args").Array(), 3) require.Equal(t, "foo", hello.Get("args.0.name").String()) require.Equal(t, "", hello.Get("args.0.description").String()) require.Equal(t, "bar", hello.Get("args.1.name").String()) require.Equal(t, "docs for bar", hello.Get("args.1.description").String()) require.Equal(t, "baz", hello.Get("args.2.name").String())
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
require.Equal(t, "", hello.Get("args.2.description").String()) hello = obj.Get(`functions.#(name="helloFinal")`) require.Equal(t, "helloFinal", hello.Get("name").String()) require.Len(t, hello.Get("args").Array(), 1) require.Equal(t, "foo", hello.Get("args.0.name").String()) require.Equal(t, "", hello.Get("args.0.description").String()) } var goExtend string func TestModuleGoExtendCore(t *testing.T) { t.Parallel() var logs safeBuffer c, ctx := connect(t, dagger.WithLogOutput(&logs)) _, err := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: goExtend, }). With(daggerExec("mod", "sync")). Sync(ctx) require.Error(t, err) require.NoError(t, c.Close()) require.Contains(t, logs.String(), "cannot define methods on objects from outside this module") } var goCustomTypes string var pythonCustomTypes string func TestModuleCustomTypes(t *testing.T) { t.Parallel() type testCase struct {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
sdk string sourcePath string sourceContent string } for _, tc := range []testCase{ { sdk: "go", sourcePath: "main.go", sourceContent: goCustomTypes, }, { sdk: "python", sourcePath: "src/main.py", sourceContent: pythonCustomTypes, }, } { t.Run(fmt.Sprintf("custom %s types", tc.sdk), func(t *testing.T) { c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk="+tc.sdk)). WithNewFile(tc.sourcePath, dagger.ContainerWithNewFileOpts{ Contents: tc.sourceContent, }) if tc.sdk == "go" { logGen(ctx, t, modGen.Directory(".")) }
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
out, err := modGen.With(daggerQuery(`{test{repeater(msg:"echo!", times: 3){render}}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"test":{"repeater":{"render":"echo!echo!echo!"}}}`, out) }) } } func TestModuleGoReturnTypeDetection(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=foo", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Foo struct {} type X struct { Message string ` + "`json:\"message\"`" + ` } func (m *Foo) MyFunction() X { return X{Message: "foo"} } `, }) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(daggerQuery(`{foo{myFunction{message}}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"foo":{"myFunction":{"message":"foo"}}}`, out) } func TestModuleGoGlobalVarDAG(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=foo", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main import "context" type Foo struct {} var someDefault = dag.Container().From("alpine:latest") func (m *Foo) Fn(ctx context.Context) (string, error) { return someDefault.WithExec([]string{"echo", "foo"}).Stdout(ctx) } `, }) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(daggerQuery(`{foo{fn}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"foo":{"fn":"foo\n"}}`, out) } var useInner string var useOuter string func TestModuleUseLocal(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) t.Run("go uses go", func(t *testing.T) { t.Parallel() modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work/dep"). With(daggerExec("mod", "init", "--name=dep", "--sdk=go")). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=use", "--sdk=go")). WithNewFile("/work/dep/main.go", dagger.ContainerWithNewFileOpts{ Contents: useInner, }). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: useOuter, }). With(daggerExec("mod", "install", "./dep")). WithEnvVariable("BUST", identity.NewID()) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(daggerQuery(`{use{useHello}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"use":{"useHello":"hello"}}`, out) _, err = modGen.With(daggerQuery(`{dep{hello}}`)).Stdout(ctx) require.Error(t, err) require.ErrorContains(t, err, `Cannot query field "dep" on type "Query".`) })
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Run("python uses go", func(t *testing.T) { t.Parallel() modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work/dep"). With(daggerExec("mod", "init", "--name=dep", "--sdk=go")). WithNewFile("/work/dep/main.go", dagger.ContainerWithNewFileOpts{ Contents: useInner, }). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=use", "--sdk=python")). With(daggerExec("mod", "install", "./dep")). WithNewFile("/work/src/main.py", dagger.ContainerWithNewFileOpts{ Contents: `from dagger.mod import function import dagger @function def use_hello() -> str: return dagger.dep().hello() `, }) out, err := modGen.With(daggerQuery(`{use{useHello}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"use":{"useHello":"hello"}}`, out) _, err = modGen.With(daggerQuery(`{dep{hello}}`)).Stdout(ctx) require.Error(t, err) require.ErrorContains(t, err, `Cannot query field "dep" on type "Query".`) }) } func TestModuleCodegenonDepChange(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) t.Run("go uses go", func(t *testing.T) { t.Parallel() modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work/dep"). With(daggerExec("mod", "init", "--name=dep", "--sdk=go")). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=use", "--sdk=go")). WithNewFile("/work/dep/main.go", dagger.ContainerWithNewFileOpts{ Contents: useInner, }). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: useOuter, }). With(daggerExec("mod", "install", "./dep")) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(daggerQuery(`{use{useHello}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"use":{"useHello":"hello"}}`, out)
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
newInner := strings.ReplaceAll(useInner, `Hello()`, `Hellov2()`) modGen = modGen. WithNewFile("/work/dep/main.go", dagger.ContainerWithNewFileOpts{ Contents: newInner, }). WithExec([]string{"sh", "-c", "dagger mod sync"}, dagger.ContainerWithExecOpts{ ExperimentalPrivilegedNesting: true, }) codegenContents, err := modGen.File("/work/dagger.gen.go").Contents(ctx) require.NoError(t, err) require.Contains(t, codegenContents, "Hellov2") newOuter := strings.ReplaceAll(useOuter, `Hello(ctx)`, `Hellov2(ctx)`) modGen = modGen. WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: newOuter, }) out, err = modGen.With(daggerQuery(`{use{useHello}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"use":{"useHello":"hello"}}`, out) }) t.Run("python uses go", func(t *testing.T) { t.Parallel() modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work/dep"). With(daggerExec("mod", "init", "--name=dep", "--sdk=go")). WithNewFile("/work/dep/main.go", dagger.ContainerWithNewFileOpts{ Contents: useInner, }). WithWorkdir("/work").
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
With(daggerExec("mod", "init", "--name=use", "--sdk=python")). With(daggerExec("mod", "install", "./dep")). WithNewFile("/work/src/main.py", dagger.ContainerWithNewFileOpts{ Contents: `from dagger.mod import function import dagger @function def use_hello() -> str: return dagger.dep().hello() `, }) out, err := modGen.With(daggerQuery(`{use{useHello}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"use":{"useHello":"hello"}}`, out) newInner := strings.ReplaceAll(useInner, `Hello()`, `Hellov2()`) modGen = modGen. WithNewFile("/work/dep/main.go", dagger.ContainerWithNewFileOpts{ Contents: newInner, }). WithExec([]string{"sh", "-c", "dagger mod sync"}, dagger.ContainerWithExecOpts{ ExperimentalPrivilegedNesting: true, }) codegenContents, err := modGen.File("/work/sdk/src/dagger/client/gen.py").Contents(ctx) require.NoError(t, err) require.Contains(t, codegenContents, "hellov2") modGen = modGen. WithNewFile("/work/src/main.py", dagger.ContainerWithNewFileOpts{ Contents: `from dagger.mod import function import dagger @function
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
def use_hello() -> str: return dagger.dep().hellov2() `, }) out, err = modGen.With(daggerQuery(`{use{useHello}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"use":{"useHello":"hello"}}`, out) }) } func TestModuleGoUseLocalMulti(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work/foo"). WithNewFile("/work/foo/main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Foo struct {} func (m *Foo) Name() string { return "foo" } `, }). With(daggerExec("mod", "init", "--name=foo", "--sdk=go")). WithWorkdir("/work/bar"). WithNewFile("/work/bar/main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Bar struct {} func (m *Bar) Name() string { return "bar" } `, }). With(daggerExec("mod", "init", "--name=bar", "--sdk=go")).
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=use", "--sdk=go")). With(daggerExec("mod", "install", "./foo")). With(daggerExec("mod", "install", "./bar")). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main import "context" import "fmt" type Use struct {} func (m *Use) Names(ctx context.Context) ([]string, error) { fooName, err := dag.Foo().Name(ctx) if err != nil { return nil, fmt.Errorf("foo.name: %w", err) } barName, err := dag.Bar().Name(ctx) if err != nil { return nil, fmt.Errorf("bar.name: %w", err) } return []string{fooName, barName}, nil } `, }). WithEnvVariable("BUST", identity.NewID()) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(daggerQuery(`{use{names}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"use":{"names":["foo", "bar"]}}`, out) } var wrapper string func TestModuleGoWrapping(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=wrapper", "--sdk=go")). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: wrapper, }) logGen(ctx, t, modGen.Directory(".")) id := identity.NewID() out, err := modGen.With(daggerQuery( fmt.Sprintf(`{wrapper{container{echo(msg:%q){unwrap{stdout}}}}}`, id), )).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, fmt.Sprintf(`{"wrapper":{"container":{"echo":{"unwrap":{"stdout":%q}}}}}`, id), out) } func TestModuleConfigAPI(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) moduleDir := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work/subdir"). With(daggerExec("mod", "init", "--name=test", "--sdk=go", "--root=..")). Directory("/work") cfg := c.ModuleConfig(moduleDir, dagger.ModuleConfigOpts{Subpath: "subdir"}) name, err := cfg.Name(ctx) require.NoError(t, err) require.Equal(t, "test", name) sdk, err := cfg.SDK(ctx) require.NoError(t, err) require.Equal(t, "go", sdk) root, err := cfg.Root(ctx) require.NoError(t, err) require.Equal(t, "..", root) } func TestModulePythonInit(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Run("from scratch", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=bare", "--sdk=python")) out, err := modGen. With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out) }) t.Run("with different root", func(t *testing.T) { t.Parallel()
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work/child"). With(daggerExec("mod", "init", "--name=bare", "--sdk=python", "--root=..")) out, err := modGen. With(daggerQuery(`{bare{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"bare":{"containerEcho":{"stdout":"hello\n"}}}`, out) }) t.Run("respects existing pyproject.toml", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("pyproject.toml", dagger.ContainerWithNewFileOpts{ Contents: `[project] name = "has-pyproject" version = "0.0.0" `, }). With(daggerExec("mod", "init", "--name=hasPyproject", "--sdk=python")) out, err := modGen. With(daggerQuery(`{hasPyproject{containerEcho(stringArg:"hello"){stdout}}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"hasPyproject":{"containerEcho":{"stdout":"hello\n"}}}`, out) t.Run("preserves module name", func(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
generated, err := modGen.File("pyproject.toml").Contents(ctx) require.NoError(t, err) require.Contains(t, generated, `name = "has-pyproject"`) }) }) t.Run("respects existing main.py", func(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("/work/src/main/__init__.py", dagger.ContainerWithNewFileOpts{ Contents: "from . import notmain\n", }). WithNewFile("/work/src/main/notmain.py", dagger.ContainerWithNewFileOpts{ Contents: `from dagger.mod import function @function def hello() -> str: return "Hello, world!" `, }). With(daggerExec("mod", "init", "--name=hasMainPy", "--sdk=python")) out, err := modGen. With(daggerQuery(`{hasMainPy{hello}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"hasMainPy":{"hello":"Hello, world!"}}`, out) }) } func TestModuleLotsOfFunctions(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() const funcCount = 100 t.Run("go sdk", func(t *testing.T) { t.Parallel() c, ctx := connect(t) mainSrc := ` package main type PotatoSack struct {} ` for i := 0; i < funcCount; i++ { mainSrc += fmt.Sprintf(` func (m *PotatoSack) Potato%d() string { return "potato #%d" } `, i, i) } modGen := c.Container().From(golangImage).
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: mainSrc, }). With(daggerExec("mod", "init", "--name=potatoSack", "--sdk=go")) logGen(ctx, t, modGen.Directory(".")) var eg errgroup.Group for i := 0; i < funcCount; i++ { i := i if i%10 != 0 { continue } eg.Go(func() error { _, err := modGen. With(daggerCall(fmt.Sprintf("potato%d", i))). Sync(ctx) return err }) } require.NoError(t, eg.Wait()) }) t.Run("python sdk", func(t *testing.T) { t.Parallel() c, ctx := connect(t) mainSrc := `from dagger.mod import function ` for i := 0; i < funcCount; i++ { mainSrc += fmt.Sprintf(`
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
@function def potato_%d() -> str: return "potato #%d" `, i, i) } modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). WithNewFile("./src/main.py", dagger.ContainerWithNewFileOpts{ Contents: mainSrc, }). With(daggerExec("mod", "init", "--name=potatoSack", "--sdk=python")) var eg errgroup.Group for i := 0; i < funcCount; i++ { i := i if i%10 != 0 { continue } eg.Go(func() error { _, err := modGen. With(daggerCall(fmt.Sprintf("potato%d", i))). Sync(ctx) return err }) } require.NoError(t, eg.Wait()) }) } func TestModuleLotsOfDeps(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work") modCount := 0 getModMainSrc := func(name string, depNames []string) string { t.Helper() mainSrc := fmt.Sprintf(`package main import "context" type %s struct {} func (m *%s) Fn(ctx context.Context) (string, error) { s := "%s" var depS string _ = depS var err error _ = err `, strcase.ToCamel(name), strcase.ToCamel(name), name) for _, depName := range depNames { mainSrc += fmt.Sprintf(` depS, err = dag.%s().Fn(ctx) if err != nil { return "", err
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
} s += depS `, strcase.ToCamel(depName)) } mainSrc += "return s, nil\n}\n" fmted, err := format.Source([]byte(mainSrc)) require.NoError(t, err) return string(fmted) } getModDaggerConfig := func(name string, depNames []string) string { t.Helper() var depVals []string for _, depName := range depNames { depVals = append(depVals, "../"+depName) } cfg := modules.Config{ Name: name, Root: "..", SDK: "go", Dependencies: depVals, } bs, err := json.Marshal(cfg) require.NoError(t, err) return string(bs) } addModulesWithDeps := func(newMods int, depNames []string) []string { t.Helper() var newModNames []string
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
for i := 0; i < newMods; i++ { name := fmt.Sprintf("mod%d", modCount) modCount++ newModNames = append(newModNames, name) modGen = modGen. WithWorkdir("/work/"+name). WithNewFile("./main.go", dagger.ContainerWithNewFileOpts{ Contents: getModMainSrc(name, depNames), }). WithNewFile("./dagger.json", dagger.ContainerWithNewFileOpts{ Contents: getModDaggerConfig(name, depNames), }) } return newModNames } curDeps := addModulesWithDeps(1, nil) for i := 0; i < 6; i++ { curDeps = addModulesWithDeps(len(curDeps)+1, curDeps) } addModulesWithDeps(1, curDeps) _, err := modGen.With(daggerCall("fn")).Stdout(ctx) require.NoError(t, err) } func TestModuleNamespacing(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) moduleSrcPath, err := filepath.Abs("./testdata/modules/go/namespacing") require.NoError(t, err) ctr := c.Container().From(alpineImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithMountedDirectory("/work", c.Host().Directory(moduleSrcPath)). WithWorkdir("/work") out, err := ctr. With(daggerQuery(`{test{fn(s:"yo")}}`)). Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"test":{"fn":"1:yo 2:yo"}}`, out) } func TestModuleRoots(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) moduleSrcPath, err := filepath.Abs("./testdata/modules/go/roots") require.NoError(t, err) entries, err := os.ReadDir(moduleSrcPath) require.NoError(t, err) ctr := c.Container().From(alpineImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithMountedDirectory("/work", c.Host().Directory(moduleSrcPath)) for _, entry := range entries { entry := entry t.Run(entry.Name(), func(t *testing.T) { t.Parallel() ctr := ctr.WithWorkdir("/work/" + entry.Name()) out, err := ctr. With(daggerQuery(fmt.Sprintf(`{%s{hello}}`, strcase.ToLowerCamel(entry.Name())))). Stdout(ctx) if strings.HasPrefix(entry.Name(), "good-") { require.NoError(t, err) require.JSONEq(t, fmt.Sprintf(`{"%s":{"hello": "hello"}}`, strcase.ToLowerCamel(entry.Name())), out) } else if strings.HasPrefix(entry.Name(), "bad-") { require.Error(t, err) require.Regexp(t, "is not under( module)? root", err.Error()) } }) } } func TestModuleDaggerCall(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) t.Run("service args", func(t *testing.T) { t.Parallel() modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main import ( "context" ) type Test struct {} func (m *Test) Fn(ctx context.Context, svc *Service) (string, error) { return dag.Container().From("alpine:3.18").WithExec([]string{"apk", "add", "curl"}). WithServiceBinding("daserver", svc). WithExec([]string{"curl", "http://daserver:8000"}). Stdout(ctx) } `, })
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
logGen(ctx, t, modGen.Directory(".")) httpServer, _ := httpService(ctx, t, c, "im up") endpoint, err := httpServer.Endpoint(ctx) require.NoError(t, err) out, err := modGen. WithServiceBinding("testserver", httpServer). With(daggerCall("fn", "--svc", "tcp://"+endpoint)).Stdout(ctx) require.NoError(t, err) require.Equal(t, strings.TrimSpace(out), "im up") }) t.Run("list args", func(t *testing.T) { t.Parallel() modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("foo.txt", dagger.ContainerWithNewFileOpts{ Contents: "bar", }). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main import ( "context" "strings" ) type Minimal struct {} func (m *Minimal) Hello(msgs []string) string { return strings.Join(msgs, "+") } func (m *Minimal) Reads(ctx context.Context, files []File) (string, error) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
var contents []string for _, f := range files { content, err := f.Contents(ctx) if err != nil { return "", err } contents = append(contents, content) } return strings.Join(contents, "+"), nil } `, }) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(daggerCall("hello", "--msgs", "yo", "--msgs", "my", "--msgs", "friend")).Stdout(ctx) require.NoError(t, err) require.Equal(t, strings.TrimSpace(out), "yo+my+friend") out, err = modGen.With(daggerCall("reads", "--files=foo.txt", "--files=foo.txt")).Stdout(ctx) require.NoError(t, err) require.Equal(t, strings.TrimSpace(out), "bar+bar") }) t.Run("return list objects", func(t *testing.T) { t.Parallel() modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=minimal", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Minimal struct {} type Foo struct {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
Bar int ` + "`" + `json:"bar"` + "`" + ` } func (m *Minimal) Fn() []*Foo { var foos []*Foo for i := 0; i < 3; i++ { foos = append(foos, &Foo{Bar: i}) } return foos } `, }) logGen(ctx, t, modGen.Directory(".")) out, err := modGen.With(daggerCall("fn", "bar")).Stdout(ctx) require.NoError(t, err) require.Equal(t, strings.TrimSpace(out), "0\n1\n2") }) t.Run("directory arg inputs", func(t *testing.T) { t.Parallel() t.Run("local dir", func(t *testing.T) { t.Parallel() modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("/dir/subdir/foo.txt", dagger.ContainerWithNewFileOpts{ Contents: "foo", }). WithNewFile("/dir/subdir/bar.txt", dagger.ContainerWithNewFileOpts{ Contents: "bar", }).
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Test struct {} func (m *Test) Fn(dir *Directory) *Directory { return dir } `, }) out, err := modGen.With(daggerCall("fn", "--dir", "/dir/subdir")).Stdout(ctx) require.NoError(t, err) require.Equal(t, strings.TrimSpace(out), "bar.txt\nfoo.txt") out, err = modGen.With(daggerCall("fn", "--dir", "file:///dir/subdir")).Stdout(ctx) require.NoError(t, err) require.Equal(t, strings.TrimSpace(out), "bar.txt\nfoo.txt") }) t.Run("git dir", func(t *testing.T) { t.Parallel() modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("main.go", dagger.ContainerWithNewFileOpts{ Contents: `package main type Test struct {} func (m *Test) Fn(dir *Directory, subpath Optional[string]) *Directory { return dir.Directory(subpath.GetOr(".")) } `, }) for _, tc := range []struct {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
baseURL string subpath string }{ { baseURL: "https://github.com/dagger/dagger", }, { baseURL: "https://github.com/dagger/dagger", subpath: ".changes", }, { baseURL: "https://github.com/dagger/dagger.git", }, { baseURL: "https://github.com/dagger/dagger.git", subpath: ".changes", },
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
} { tc := tc t.Run(fmt.Sprintf("%s:%s", tc.baseURL, tc.subpath), func(t *testing.T) { t.Parallel() url := tc.baseURL + "#v0.9.1" if tc.subpath != "" { url += ":" + tc.subpath } args := []string{"fn", "--dir", url} if tc.subpath == "" { args = append(args, "--subpath", ".changes") } out, err := modGen.With(daggerCall(args...)).Stdout(ctx) require.NoError(t, err) require.Contains(t, out, "v0.9.1.md") require.NotContains(t, out, "v0.9.2.md") }) } }) }) } func TestModuleGoSyncDeps(t *testing.T) { t.Parallel() c, ctx := connect(t) modGen := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work/dep"). With(daggerExec("mod", "init", "--name=dep", "--sdk=go")). WithWorkdir("/work").
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
With(daggerExec("mod", "init", "--name=use", "--sdk=go")). WithNewFile("/work/dep/main.go", dagger.ContainerWithNewFileOpts{ Contents: useInner, }). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: useOuter, }). With(daggerExec("mod", "install", "./dep")) logGen(ctx, t, modGen.Directory(".")) modGen = modGen.With(daggerQuery(`{use{useHello}}`)) out, err := modGen.Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"use":{"useHello":"hello"}}`, out) newInner := strings.ReplaceAll(useInner, `"hello"`, `"goodbye"`) modGen = modGen. WithNewFile("/work/dep/main.go", dagger.ContainerWithNewFileOpts{ Contents: newInner, }). With(daggerExec("mod", "sync")) logGen(ctx, t, modGen.Directory(".")) out, err = modGen.With(daggerQuery(`{use{useHello}}`)).Stdout(ctx) require.NoError(t, err) require.JSONEq(t, `{"use":{"useHello":"goodbye"}}`, out) } var badIDArgGoSrc string var badIDArgPySrc string var badIDFieldGoSrc string var badIDFnGoSrc string var badIDFnPySrc string func TestModuleReservedWords(t *testing.T) {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
t.Parallel() c, ctx := connect(t) t.Run("id", func(t *testing.T) { t.Parallel() t.Run("arg", func(t *testing.T) { t.Parallel() t.Run("go", func(t *testing.T) { t.Parallel() _, err := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: badIDArgGoSrc, }). With(daggerQuery(`{test{fn(id:"no")}}`)). Sync(ctx) require.ErrorContains(t, err, "cannot define argument with reserved name \"id\"") }) t.Run("python", func(t *testing.T) { t.Parallel() _, err := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work").
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
With(daggerExec("mod", "init", "--name=test", "--sdk=python")). WithNewFile("/work/src/main.py", dagger.ContainerWithNewFileOpts{ Contents: badIDArgPySrc, }). With(daggerQuery(`{test{fn(id:"no")}}`)). Sync(ctx) require.ErrorContains(t, err, "cannot define argument with reserved name \"id\"") }) }) t.Run("field", func(t *testing.T) { t.Parallel() t.Run("go", func(t *testing.T) { t.Parallel() _, err := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: badIDFieldGoSrc, }). With(daggerQuery(`{test{fn{id}}}`)). Sync(ctx) require.ErrorContains(t, err, "cannot define field with reserved name \"ID\"") }) }) t.Run("fn", func(t *testing.T) { t.Parallel() t.Run("go", func(t *testing.T) { t.Parallel() _, err := c.Container().From(golangImage).
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=go")). WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{ Contents: badIDFnGoSrc, }). With(daggerQuery(`{test{id}}`)). Sync(ctx) require.ErrorContains(t, err, "cannot define function with reserved name \"id\"") }) t.Run("python", func(t *testing.T) { t.Parallel() _, err := c.Container().From(golangImage). WithMountedFile(testCLIBinPath, daggerCliFile(t, c)). WithWorkdir("/work"). With(daggerExec("mod", "init", "--name=test", "--sdk=python")). WithNewFile("/work/src/main.py", dagger.ContainerWithNewFileOpts{ Contents: badIDFnPySrc, }). With(daggerQuery(`{test{fn(id:"no")}}`)). Sync(ctx) require.ErrorContains(t, err, "cannot define function with reserved name \"id\"") }) }) }) } func TestEnvCmd(t *testing.T) { t.Skip("pending conversion to modules") t.Parallel() type testCase struct {
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
environmentPath string expectedSDK string expectedName string expectedRoot string } for _, tc := range []testCase{ { environmentPath: "core/integration/testdata/environments/go/basic", expectedSDK: "go", expectedName: "basic", expectedRoot: "../../../../../../", }, } { tc := tc for _, testGitEnv := range []bool{false, true} { testGitEnv := testGitEnv testName := "local environment" if testGitEnv { testName = "git environment"
closed
dagger/dagger
https://github.com/dagger/dagger
5,860
Zenith: fix Go struct field json serialization
https://github.com/dagger/dagger/pull/5757#issuecomment-1744739721 Right now if you have something like: ```go type Foo struct { Bar `json:"blahblah"` } ``` The graphql schema for `Foo` will be populated with a field called `Bar`, but when we do json serialization we use `blahblah`, which means that if you try to query for the value of the `Bar` field, our gql server hits the trivial resolver codepath and looks for `bar` in the json object and doesn't find it (since it's been serialized to `blahblah`). My first thought was that if a json struct tag is present, we should use that as the graphql field name rather than the go name. That would fix this problem I think, but it's more debatable whether it's surprising behavior (or honestly if anyone will really care about this). --- Possibly related issue from https://github.com/dagger/dagger/pull/5757#issuecomment-1752775608 ```golang package main import ( "context" ) type Foo struct{} type Test struct { X string Y int } func (t *Test) Void() {} func (m *Foo) MyFunction(ctx context.Context) Test { return Test{X: "hello", Y: 1337} } ``` ```bash $ echo '{foo{myFunction{x}}}' | dagger query -m "" ... β§— 1.17s βœ” 22 βˆ… 20 ✘ 2 Error: make request: input:1: foo.myFunction.x Cannot return null for non-nullable field Test.x. ``` If I modify the struct with JSON field names, the above works: ```golang type Test struct { X string `json:"x"` Y int `json:"y"` } ``` --- cc @vito @jedevc
https://github.com/dagger/dagger/issues/5860
https://github.com/dagger/dagger/pull/6057
2c554b2ac26c4c6863893bac94d85108cecb48d9
e1d69edbfd0f94c93489edac4d9d6050c36fc3b7
2023-10-10T22:50:32Z
go
2023-11-14T23:56:25Z
core/integration/module_test.go
} testName += "/" + tc.environmentPath t.Run(testName, func(t *testing.T) { t.Parallel() c, ctx := connect(t) stderr, err := CLITestContainer(ctx, t, c). WithLoadedEnv(tc.environmentPath, testGitEnv). CallEnv(). Stderr(ctx) require.NoError(t, err) require.Contains(t, stderr, fmt.Sprintf(`"root": %q`, tc.expectedRoot)) require.Contains(t, stderr, fmt.Sprintf(`"name": %q`, tc.expectedName)) require.Contains(t, stderr, fmt.Sprintf(`"sdk": %q`, tc.expectedSDK)) }) } } } func TestEnvCmdHelps(t *testing.T) { t.Skip("pending conversion to modules") t.Parallel() c, ctx := connect(t) baseCtr := CLITestContainer(ctx, t, c).WithHelpArg(true) noEnvCtr := baseCtr validLocalEnvCtr := baseCtr.WithLoadedEnv("core/integration/testdata/environments/go/basic", false) brokenLocalEnvCtr := baseCtr.WithLoadedEnv("core/integration/testdata/environments/go/broken", false) for _, ctr := range []*DaggerCLIContainer{noEnvCtr, validLocalEnvCtr, brokenLocalEnvCtr} { type testCase struct {