mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
* Upgrade gqlgen to v0.17.2 This enables builds on Go 1.18. github.com/vektah/gqlparser is upgraded to the newest version too. Getting this to work is a bit of a hazzle. I had to first remove vendoring from the repository, perform the upgrade and then re-introduce the vendor directory. I think gqlgens analysis went wrong for some reason on the upgrade. It would seem a clean-room installation fixed it. * Bump project to 1.18 * Update all packages, address gqlgenc breaking changes * Let `go mod tidy` handle the go.mod file * Upgrade linter to 1.45.2 * Introduce v1.45.2 of the linter The linter now correctly warns on `strings.Title` because it isn't unicode-aware. Fix this by using the suggested fix from x/text/cases to produce unicode-aware strings. The mapping isn't entirely 1-1 as this new approach has a larger iface: it spans all of unicode rather than just ASCII. It coincides for ASCII however, so things should be largely the same. * Ready ourselves for errchkjson and contextcheck. * Revert dockerfile golang version changes for now Co-authored-by: Kermie <kermie@isinthe.house> Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
86 lines
2.3 KiB
Go
86 lines
2.3 KiB
Go
package clientgen
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/99designs/gqlgen/codegen/config"
|
|
"github.com/99designs/gqlgen/plugin"
|
|
gqlgencConfig "github.com/Yamashou/gqlgenc/config"
|
|
)
|
|
|
|
var _ plugin.ConfigMutator = &Plugin{}
|
|
|
|
type Plugin struct {
|
|
queryFilePaths []string
|
|
Client config.PackageConfig
|
|
GenerateConfig *gqlgencConfig.GenerateConfig
|
|
}
|
|
|
|
func New(queryFilePaths []string, client config.PackageConfig, generateConfig *gqlgencConfig.GenerateConfig) *Plugin {
|
|
return &Plugin{
|
|
queryFilePaths: queryFilePaths,
|
|
Client: client,
|
|
GenerateConfig: generateConfig,
|
|
}
|
|
}
|
|
|
|
func (p *Plugin) Name() string {
|
|
return "clientgen"
|
|
}
|
|
|
|
func (p *Plugin) MutateConfig(cfg *config.Config) error {
|
|
querySources, err := LoadQuerySources(p.queryFilePaths)
|
|
if err != nil {
|
|
return fmt.Errorf("load query sources failed: %w", err)
|
|
}
|
|
|
|
// 1. 全体のqueryDocumentを1度にparse
|
|
// 1. Parse document from source of query
|
|
queryDocument, err := ParseQueryDocuments(cfg.Schema, querySources, p.GenerateConfig)
|
|
if err != nil {
|
|
return fmt.Errorf(": %w", err)
|
|
}
|
|
|
|
// 2. OperationごとのqueryDocumentを作成
|
|
// 2. Separate documents for each operation
|
|
queryDocuments, err := QueryDocumentsByOperations(cfg.Schema, queryDocument.Operations)
|
|
if err != nil {
|
|
return fmt.Errorf("parse query document failed: %w", err)
|
|
}
|
|
|
|
// 3. テンプレートと情報ソースを元にコード生成
|
|
// 3. Generate code from template and document source
|
|
sourceGenerator := NewSourceGenerator(cfg, p.Client)
|
|
source := NewSource(cfg.Schema, queryDocument, sourceGenerator, p.GenerateConfig)
|
|
query, err := source.Query()
|
|
if err != nil {
|
|
return fmt.Errorf("generating query object: %w", err)
|
|
}
|
|
|
|
mutation, err := source.Mutation()
|
|
if err != nil {
|
|
return fmt.Errorf("generating mutation object: %w", err)
|
|
}
|
|
|
|
fragments, err := source.Fragments()
|
|
if err != nil {
|
|
return fmt.Errorf("generating fragment failed: %w", err)
|
|
}
|
|
|
|
operationResponses, err := source.OperationResponses()
|
|
if err != nil {
|
|
return fmt.Errorf("generating operation response failed: %w", err)
|
|
}
|
|
|
|
operations, err := source.Operations(queryDocuments)
|
|
if err != nil {
|
|
return fmt.Errorf("generating operation failed: %w", err)
|
|
}
|
|
|
|
if err := RenderTemplate(cfg, query, mutation, fragments, operations, operationResponses, p.GenerateConfig, p.Client); err != nil {
|
|
return fmt.Errorf("template failed: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|