Skip to content

Commit

Permalink
COSMOS-3252: Nexus annotation nexus-graphql-ts-type not working as ex…
Browse files Browse the repository at this point in the history
…pected for array of customType (#201)

* Support graphql array types

* Don't add @jsonencoded if field don't have type-name annotation

* Revert "Don't add @jsonencoded if field don't have type-name annotation"

This reverts commit f76d400.

* Fix Makefile
  • Loading branch information
kacpersaw authored Jun 16, 2023
1 parent 5786530 commit b65bca7
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 7 deletions.
3 changes: 2 additions & 1 deletion compiler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ test_generate_code_in_container: ${BUILDER_NAME}\:${BUILDER_TAG}.image.exists in
CRD_MODULE_PATH="github.com/vmware-tanzu/graph-framework-for-microservices/compiler/example/output/generated/" \
LOG_LEVEL=trace \
GENERATED_OUTPUT_DIRECTORY=example/output/generated && \
cd example/output/generated && go vet -structtag=FALSE ./... && golangci-lint run ./...)
cd example/output/generated && [ ! -f model/model.go ] || mv model/model.go model/model.tmp && \
go vet -structtag=FALSE ./... && golangci-lint run ./... && [ ! -f model/model.tmp ] || mv model/model.tmp model/model.go)
@if [ -n "$$(git ls-files --modified --exclude-standard)" ]; then\
echo "The following changes should be committed:";\
git status;\
Expand Down
1 change: 1 addition & 0 deletions compiler/example/datamodel/config/gns/gns.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ type Gns struct {
IgnoreChild IgnoreChild `nexus:"child" nexus-graphql:"ignore:true"`
Foo Foo `nexus:"child"`
Meta string
IntOrString []intstr.IntOrString `nexus-graphql-type-name:"IntOrString" json:"intOrString,omitempty" mapstructure:"intOrString,omitempty"`

Port *int // pointer test
OtherDescription *Description // pointer test - struct
Expand Down

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

3 changes: 3 additions & 0 deletions compiler/example/output/_rendered_templates/model/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type IntOrString []intstr.IntOrString


21 changes: 21 additions & 0 deletions compiler/example/output/_rendered_templates/nexus-client/client.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ TargetPortData := string(TargetPort)
Description, _ := json.Marshal(vGns.Spec.Description)
DescriptionData := string(Description)
vMeta := string(vGns.Spec.Meta)
IntOrString, _ := json.Marshal(vGns.Spec.IntOrString)
IntOrStringData := string(IntOrString)
OtherDescription, _ := json.Marshal(vGns.Spec.OtherDescription)
OtherDescriptionData := string(OtherDescription)
MapPointer, _ := json.Marshal(vGns.Spec.MapPointer)
Expand Down Expand Up @@ -441,6 +443,7 @@ ServiceSegmentRefMapData := string(ServiceSegmentRefMap)
TargetPort: &TargetPortData,
Description: &DescriptionData,
Meta: &vMeta,
IntOrString: &IntOrStringData,
OtherDescription: &OtherDescriptionData,
MapPointer: &MapPointerData,
SlicePointer: &SlicePointerData,
Expand Down Expand Up @@ -477,6 +480,8 @@ TargetPortData := string(TargetPort)
Description, _ := json.Marshal(vGns.Spec.Description)
DescriptionData := string(Description)
vMeta := string(vGns.Spec.Meta)
IntOrString, _ := json.Marshal(vGns.Spec.IntOrString)
IntOrStringData := string(IntOrString)
OtherDescription, _ := json.Marshal(vGns.Spec.OtherDescription)
OtherDescriptionData := string(OtherDescription)
MapPointer, _ := json.Marshal(vGns.Spec.MapPointer)
Expand Down Expand Up @@ -508,6 +513,7 @@ ServiceSegmentRefMapData := string(ServiceSegmentRefMap)
TargetPort: &TargetPortData,
Description: &DescriptionData,
Meta: &vMeta,
IntOrString: &IntOrStringData,
OtherDescription: &OtherDescriptionData,
MapPointer: &MapPointerData,
SlicePointer: &SlicePointerData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type gns_Gns {
TargetPort: String
Description: String
Meta: String
IntOrString: String
Port: Int
OtherDescription: String
MapPointer: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ type Config_Config @nexus(group:"config.tsm.tanzu.vmware.com",version:"v1",kind:
fooExample(id: ID): [Config_FooTypeABC!]
svcGrpInfo: Servicegroup_SvcGroupLinkInfo
myStr0: String
myStr1: String
myStr1: String @jsonencoded(gofile:"model.go", name:"MyStr", goname:"nexus_gns.MyStr")
myStr2: String
xYZPort: String @jsonencoded(gofile:"model.go", name:"Port", goname:"nexus_gns.Port")
aBCHost: String
aBCHost: String @jsonencoded(gofile:"model.go", name:"Host", goname:"nexus_gns.Host")
clusterNamespaces: String
testValMarkers: String @jsonencoded(gofile:"model.go", name:"TestValMarkers", goname:"nexus_config.TestValMarkers")
instance: Float
Expand Down Expand Up @@ -79,6 +79,7 @@ type Gns_Gns @nexus(group:"gns.tsm.tanzu.vmware.com",version:"v1",kind:"Gns",res
targetPort: String @jsonencoded(gofile:"model.go", name:"IntOrString")
description: String @jsonencoded(gofile:"model.go", name:"Description", goname:"nexus_gns.Description")
meta: String
intOrString: String @jsonencoded(gofile:"model.go", name:"IntOrString")
port: Int
otherDescription: String
mapPointer: String
Expand Down

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

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

7 changes: 7 additions & 0 deletions compiler/example/output/generated/crds/gns_gns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ spec:
- kind
- name
type: object
intOrString:
items:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
type: array
mapPointer:
additionalProperties:
type: string
Expand Down
3 changes: 3 additions & 0 deletions compiler/example/output/generated/model/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type IntOrString []intstr.IntOrString


21 changes: 21 additions & 0 deletions compiler/example/output/generated/nexus-client/client.go

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ func getConfigConfigGNSResolver(obj *model.ConfigConfig, id *string) (*model.Gns
Description, _ := json.Marshal(vGns.Spec.Description)
DescriptionData := string(Description)
vMeta := string(vGns.Spec.Meta)
IntOrString, _ := json.Marshal(vGns.Spec.IntOrString)
IntOrStringData := string(IntOrString)
OtherDescription, _ := json.Marshal(vGns.Spec.OtherDescription)
OtherDescriptionData := string(OtherDescription)
MapPointer, _ := json.Marshal(vGns.Spec.MapPointer)
Expand Down Expand Up @@ -454,6 +456,7 @@ func getConfigConfigGNSResolver(obj *model.ConfigConfig, id *string) (*model.Gns
TargetPort: &TargetPortData,
Description: &DescriptionData,
Meta: &vMeta,
IntOrString: &IntOrStringData,
OtherDescription: &OtherDescriptionData,
MapPointer: &MapPointerData,
SlicePointer: &SlicePointerData,
Expand Down Expand Up @@ -490,6 +493,8 @@ func getConfigConfigGNSResolver(obj *model.ConfigConfig, id *string) (*model.Gns
Description, _ := json.Marshal(vGns.Spec.Description)
DescriptionData := string(Description)
vMeta := string(vGns.Spec.Meta)
IntOrString, _ := json.Marshal(vGns.Spec.IntOrString)
IntOrStringData := string(IntOrString)
OtherDescription, _ := json.Marshal(vGns.Spec.OtherDescription)
OtherDescriptionData := string(OtherDescription)
MapPointer, _ := json.Marshal(vGns.Spec.MapPointer)
Expand Down Expand Up @@ -521,6 +526,7 @@ func getConfigConfigGNSResolver(obj *model.ConfigConfig, id *string) (*model.Gns
TargetPort: &TargetPortData,
Description: &DescriptionData,
Meta: &vMeta,
IntOrString: &IntOrStringData,
OtherDescription: &OtherDescriptionData,
MapPointer: &MapPointerData,
SlicePointer: &SlicePointerData,
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type gns_Gns {
TargetPort: String
Description: String
Meta: String
IntOrString: String
Port: Int
OtherDescription: String
MapPointer: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ type Config_Config @nexus(group:"config.tsm.tanzu.vmware.com",version:"v1",kind:
fooExample(id: ID): [Config_FooTypeABC!]
svcGrpInfo: Servicegroup_SvcGroupLinkInfo
myStr0: String
myStr1: String
myStr1: String @jsonencoded(gofile:"model.go", name:"MyStr", goname:"nexus_gns.MyStr")
myStr2: String
xYZPort: String @jsonencoded(gofile:"model.go", name:"Port", goname:"nexus_gns.Port")
aBCHost: String
aBCHost: String @jsonencoded(gofile:"model.go", name:"Host", goname:"nexus_gns.Host")
clusterNamespaces: String
testValMarkers: String @jsonencoded(gofile:"model.go", name:"TestValMarkers", goname:"nexus_config.TestValMarkers")
instance: Float
Expand Down Expand Up @@ -79,6 +79,7 @@ type Gns_Gns @nexus(group:"gns.tsm.tanzu.vmware.com",version:"v1",kind:"Gns",res
targetPort: String @jsonencoded(gofile:"model.go", name:"IntOrString")
description: String @jsonencoded(gofile:"model.go", name:"Description", goname:"nexus_gns.Description")
meta: String
intOrString: String @jsonencoded(gofile:"model.go", name:"IntOrString")
port: Int
otherDescription: String
mapPointer: String
Expand Down
Loading

0 comments on commit b65bca7

Please sign in to comment.