Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging #10

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions command/cli/generate/initialize/two/tpl/resolver.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func init() {

}
36 changes: 36 additions & 0 deletions command/cli/generate/initialize/two/two.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package two

import (
"embed"
"fmt"
"path/filepath"

"github.com/light-speak/lighthouse/template"
Expand All @@ -20,6 +21,10 @@ func Run(module string) error {
if err != nil {
return err
}
err = initResolver()
if err != nil {
return err
}
err = initService()
if err != nil {
return err
Expand Down Expand Up @@ -56,6 +61,23 @@ func initRepo() error {
return template.Render(options)
}

func initResolver() error {
resolverTemplate, err := twoFs.ReadFile("tpl/resolver.tpl")
if err != nil {
return err
}
options := &template.Options{
Path: filepath.Join(projectName, "resolver"),
Template: string(resolverTemplate),
FileName: "resolver",
FileExt: "go",
Package: "resolver",
Editable: true,
SkipIfExists: true,
}
return template.Render(options)
}

func initService() error {
serviceTemplate, err := twoFs.ReadFile("tpl/service.tpl")
if err != nil {
Expand All @@ -69,6 +91,20 @@ func initService() error {
Package: "service",
Editable: true,
SkipIfExists: true,
Imports: []*template.Import{
{
Path: fmt.Sprintf("%s/resolver", projectModule),
Alias: "_",
},
{
Path: fmt.Sprintf("%s/repo", projectModule),
Alias: "_",
},
{
Path: fmt.Sprintf("%s/models", projectModule),
Alias: "_",
},
},
}
return template.Render(options)
}
Expand Down
30 changes: 15 additions & 15 deletions example/user/models/model.go

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

66 changes: 33 additions & 33 deletions example/user/repo/repo.go

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

53 changes: 43 additions & 10 deletions example/user/resolver/operation_gen.go

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

45 changes: 30 additions & 15 deletions example/user/resolver/query.go

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

2 changes: 2 additions & 0 deletions example/user/schema/post.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ extend type Query {
posts(id: [ID!]! @in, user_id: ID! @neq): [Post!]! @find
post(id: ID! @eq): Post! @first
getPost(fuck: String!): Post!
getPosts(fuck: String!): [Post!]!
getPostIds: [ID!]!
testPostEnum(enum: TestEnum!): String!
testPostInput(input: TestInput!): String!
}
Expand Down
Loading
Loading