Skip to content

Commit

Permalink
[breaking change] snake case graphql status enum if snaking case form…
Browse files Browse the repository at this point in the history
…at is on (#1459)
  • Loading branch information
lolopinto committed May 25, 2023
1 parent 873c99d commit 021972e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 14 deletions.
14 changes: 7 additions & 7 deletions examples/ent-rsvp/backend/package-lock.json

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

2 changes: 1 addition & 1 deletion examples/ent-rsvp/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"@sentry/node": "^6.3.0",
"@sentry/tracing": "^6.3.0",
"@snowtop/ent": "^0.1.0-alpha139",
"@snowtop/ent": "^0.1.0-alpha141",
"@snowtop/ent-email": "^0.1.0-alpha1",
"@snowtop/ent-passport": "^0.1.0-alpha3",
"@snowtop/ent-password": "^0.1.0-alpha1",
Expand Down

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

2 changes: 1 addition & 1 deletion examples/todo-sqlite/src/graphql/generated/schema.gql

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

4 changes: 4 additions & 0 deletions internal/edge/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,10 @@ func (edgeGroup *AssociationEdgeGroup) GetStatusMethod() string {
return strcase.ToLowerCamel(edgeGroup.GroupStatusName) + "For"
}

func (edgeGroup *AssociationEdgeGroup) GetGraphQLNameForStatusMethod(cfg codegenapi.Config) string {
return codegenapi.GraphQLName(cfg, edgeGroup.GetStatusMethod())
}

func (edgeGroup *AssociationEdgeGroup) GetStatusMapMethod() string {
return fmt.Sprintf("get%sMap", strcase.ToCamel(edgeGroup.ConstType))
}
Expand Down
18 changes: 15 additions & 3 deletions internal/graphql/generate_ts_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,7 @@ func buildNodeForObject(processor *codegen.Processor, nodeMap schema.NodeMapInfo

for _, group := range nodeData.EdgeInfo.AssocGroups {
method := group.GetStatusMethod()
gqlName := group.GetGraphQLNameForStatusMethod(processor.Config)
var imps []*tsimport.ImportPath
if !group.IsNullable() {
imps = append(imps, tsimport.NewGQLClassImportPath("GraphQLNonNull"))
Expand All @@ -2008,15 +2009,26 @@ func buildNodeForObject(processor *codegen.Processor, nodeMap schema.NodeMapInfo
imps = getGQLFileImports(imps, false)

if group.ViewerBased {
hasResolve := method != gqlName
var contents []string
if hasResolve {
contents = []string{
fmt.Sprintf("return %s.%s();", instance, method),
}
}

if err := result.addField(&fieldType{
Name: method,
FieldImports: imps,
Name: gqlName,
FieldImports: imps,
HasResolveFunction: hasResolve,
HasAsyncModifier: true,
FunctionContents: contents,
}); err != nil {
return nil, err
}
} else {
if err := result.addField(&fieldType{
Name: method,
Name: gqlName,
FieldImports: imps,
ExtraImports: []*tsimport.ImportPath{
tsimport.NewLocalEntImportPath(group.DestNodeInfo.Node),
Expand Down
2 changes: 1 addition & 1 deletion internal/schema/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ type AssocEdgeGroup struct {
TableName string `json:"tableName,omitempty"`
AssocEdges []*AssocEdge `json:"assocEdges,omitempty"`
EdgeActions []*EdgeAction `json:"edgeActions,omitempty"`
ViewerBased bool `json:"viewerBased"`
ViewerBased bool `json:"viewerBased,omitempty"`
StatusEnums []string `json:"statusEnums,omitempty"`
NullStateFn string `json:"nullStateFn,omitempty"`
NullStates []string `json:"nullStates,omitempty"`
Expand Down

0 comments on commit 021972e

Please sign in to comment.