-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.go
More file actions
107 lines (101 loc) · 4.09 KB
/
module.go
File metadata and controls
107 lines (101 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package graphql
import (
"github.com/99designs/gqlgen/graphql"
mHttp "github.com/go-modulus/modulus/http"
"github.com/go-modulus/modulus/logger"
"github.com/go-modulus/modulus/module"
)
func NewModule(options ...module.Option) *module.Module {
return module.NewModule("modulus/graphql").
AddDependencies(
mHttp.NewModule(),
logger.NewModule(),
).
AddProviders(
NewGraphqlServer,
NewLoadersInitializer,
NewHandlerRoute,
NewPlaygroundHandlerRoute,
).
SetOverriddenProvider("modulus/graphql.ErrorPresenter", NewErrorPresenter).
InitConfig(Config{}).
WithOptions(options...)
}
// OverrideErrorPresenter overrides the error presenter provider.
func OverrideErrorPresenter[T ErrorPresenterFactory](gqlModule *module.Module) *module.Module {
return gqlModule.SetOverriddenProvider(
"modulus/graphql.ErrorPresenter", func(factory T) graphql.ErrorPresenterFunc {
return factory.NewErrorPresenter()
},
)
}
// NewManifestModule creates a new graphql module with the manifest module.
func NewManifesto() module.Manifesto {
graphqlModule := module.NewManifesto(
NewModule(),
"github.com/go-modulus/graphql",
"Graphql server and generator. It is based on the gqlgen library. It also provides a playground for the graphql server. You need to install the `chi http` module to use this module.",
"1.0.0",
)
graphqlModule.Install.AppendFiles(
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/schema.graphql",
DestFile: "internal/graphql/schema.graphql",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/gqlgen.yaml",
DestFile: "gqlgen.yaml",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/types/time.go",
DestFile: "internal/graphql/types/time.go",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/types/time.graphql",
DestFile: "internal/graphql/types/time.graphql",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/types/uuid.go",
DestFile: "internal/graphql/types/uuid.go",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/types/uuid.graphql",
DestFile: "internal/graphql/types/uuid.graphql",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/types/void.go",
DestFile: "internal/graphql/types/void.go",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/types/void.graphql",
DestFile: "internal/graphql/types/void.graphql",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/gqlgen.mk",
DestFile: "mk/gqlgen.mk",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/module.go.tmpl",
DestFile: "internal/graphql/module.go",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/model/tools.go",
DestFile: "internal/graphql/model/tools.go",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/resolver/resolver.go.tmpl",
DestFile: "internal/graphql/resolver/resolver.go",
},
module.InstalledFile{
SourceUrl: "https://raw.githubusercontent.com/go-modulus/modulus/refs/heads/main/graphql/install/resolver/schema.resolvers.go.tmpl",
DestFile: "internal/graphql/resolver/schema.resolvers.go",
},
).AppendPostInstallCommands(
module.PostInstallCommand{
CmdPackage: "github.com/99designs/gqlgen@latest",
Params: []string{"generate", "--config", "gqlgen.yaml"},
},
)
graphqlModule.LocalPath = "internal/graphql"
return graphqlModule
}