mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 21:04:37 +03:00
Support Go 1.18: Upgrade gqlgen to v0.17.2 (#2443)
* 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>
This commit is contained in:
86
vendor/github.com/99designs/gqlgen/codegen/config/config.go
generated
vendored
86
vendor/github.com/99designs/gqlgen/codegen/config/config.go
generated
vendored
@@ -10,7 +10,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/99designs/gqlgen/internal/code"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/vektah/gqlparser/v2"
|
||||
"github.com/vektah/gqlparser/v2/ast"
|
||||
"gopkg.in/yaml.v2"
|
||||
@@ -18,7 +17,7 @@ import (
|
||||
|
||||
type Config struct {
|
||||
SchemaFilename StringList `yaml:"schema,omitempty"`
|
||||
Exec PackageConfig `yaml:"exec"`
|
||||
Exec ExecConfig `yaml:"exec"`
|
||||
Model PackageConfig `yaml:"model,omitempty"`
|
||||
Federation PackageConfig `yaml:"federation,omitempty"`
|
||||
Resolver ResolverConfig `yaml:"resolver,omitempty"`
|
||||
@@ -28,11 +27,12 @@ type Config struct {
|
||||
Directives map[string]DirectiveConfig `yaml:"directives,omitempty"`
|
||||
OmitSliceElementPointers bool `yaml:"omit_slice_element_pointers,omitempty"`
|
||||
SkipValidation bool `yaml:"skip_validation,omitempty"`
|
||||
SkipModTidy bool `yaml:"skip_mod_tidy,omitempty"`
|
||||
Sources []*ast.Source `yaml:"-"`
|
||||
Packages *code.Packages `yaml:"-"`
|
||||
Schema *ast.Schema `yaml:"-"`
|
||||
|
||||
// Deprecated use Federation instead. Will be removed next release
|
||||
// Deprecated: use Federation instead. Will be removed next release
|
||||
Federated bool `yaml:"federated,omitempty"`
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
SchemaFilename: StringList{"schema.graphql"},
|
||||
Model: PackageConfig{Filename: "models_gen.go"},
|
||||
Exec: PackageConfig{Filename: "generated.go"},
|
||||
Exec: ExecConfig{Filename: "generated.go"},
|
||||
Directives: map[string]DirectiveConfig{},
|
||||
Models: TypeMap{},
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func LoadDefaultConfig() (*Config, error) {
|
||||
var schemaRaw []byte
|
||||
schemaRaw, err = ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to open schema")
|
||||
return nil, fmt.Errorf("unable to open schema: %w", err)
|
||||
}
|
||||
|
||||
config.Sources = append(config.Sources, &ast.Source{Name: filename, Input: string(schemaRaw)})
|
||||
@@ -78,7 +78,7 @@ func LoadConfigFromDefaultLocations() (*Config, error) {
|
||||
|
||||
err = os.Chdir(filepath.Dir(cfgFile))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to enter config dir")
|
||||
return nil, fmt.Errorf("unable to enter config dir: %w", err)
|
||||
}
|
||||
return LoadConfig(cfgFile)
|
||||
}
|
||||
@@ -96,17 +96,28 @@ func LoadConfig(filename string) (*Config, error) {
|
||||
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to read config")
|
||||
return nil, fmt.Errorf("unable to read config: %w", err)
|
||||
}
|
||||
|
||||
if err := yaml.UnmarshalStrict(b, config); err != nil {
|
||||
return nil, errors.Wrap(err, "unable to parse config")
|
||||
return nil, fmt.Errorf("unable to parse config: %w", err)
|
||||
}
|
||||
|
||||
if err := CompleteConfig(config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// CompleteConfig fills in the schema and other values to a config loaded from
|
||||
// YAML.
|
||||
func CompleteConfig(config *Config) error {
|
||||
defaultDirectives := map[string]DirectiveConfig{
|
||||
"skip": {SkipRuntime: true},
|
||||
"include": {SkipRuntime: true},
|
||||
"deprecated": {SkipRuntime: true},
|
||||
"skip": {SkipRuntime: true},
|
||||
"include": {SkipRuntime: true},
|
||||
"deprecated": {SkipRuntime: true},
|
||||
"specifiedBy": {SkipRuntime: true},
|
||||
}
|
||||
|
||||
for key, value := range defaultDirectives {
|
||||
@@ -140,12 +151,13 @@ func LoadConfig(filename string) (*Config, error) {
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to walk schema at root %s", pathParts[0])
|
||||
return fmt.Errorf("failed to walk schema at root %s: %w", pathParts[0], err)
|
||||
}
|
||||
} else {
|
||||
var err error
|
||||
matches, err = filepath.Glob(f)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to glob schema filename %s", f)
|
||||
return fmt.Errorf("failed to glob schema filename %s: %w", f, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,13 +175,12 @@ func LoadConfig(filename string) (*Config, error) {
|
||||
var schemaRaw []byte
|
||||
schemaRaw, err = ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to open schema")
|
||||
return fmt.Errorf("unable to open schema: %w", err)
|
||||
}
|
||||
|
||||
config.Sources = append(config.Sources, &ast.Source{Name: filename, Input: string(schemaRaw)})
|
||||
}
|
||||
|
||||
return config, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) Init() error {
|
||||
@@ -194,15 +205,8 @@ func (c *Config) Init() error {
|
||||
}
|
||||
|
||||
c.injectBuiltins()
|
||||
|
||||
// prefetch all packages in one big packages.Load call
|
||||
pkgs := []string{
|
||||
"github.com/99designs/gqlgen/graphql",
|
||||
"github.com/99designs/gqlgen/graphql/introspection",
|
||||
}
|
||||
pkgs = append(pkgs, c.Models.ReferencedPackages()...)
|
||||
pkgs = append(pkgs, c.AutoBind...)
|
||||
c.Packages.LoadAll(pkgs...)
|
||||
c.Packages.LoadAll(c.packageList()...)
|
||||
|
||||
// check everything is valid on the way out
|
||||
err = c.check()
|
||||
@@ -213,6 +217,20 @@ func (c *Config) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) packageList() []string {
|
||||
pkgs := []string{
|
||||
"github.com/99designs/gqlgen/graphql",
|
||||
"github.com/99designs/gqlgen/graphql/introspection",
|
||||
}
|
||||
pkgs = append(pkgs, c.Models.ReferencedPackages()...)
|
||||
pkgs = append(pkgs, c.AutoBind...)
|
||||
return pkgs
|
||||
}
|
||||
|
||||
func (c *Config) ReloadAllPackages() {
|
||||
c.Packages.ReloadAll(c.packageList()...)
|
||||
}
|
||||
|
||||
func (c *Config) injectTypesFromSchema() error {
|
||||
c.Directives["goModel"] = DirectiveConfig{
|
||||
SkipRuntime: true,
|
||||
@@ -222,6 +240,10 @@ func (c *Config) injectTypesFromSchema() error {
|
||||
SkipRuntime: true,
|
||||
}
|
||||
|
||||
c.Directives["goTag"] = DirectiveConfig{
|
||||
SkipRuntime: true,
|
||||
}
|
||||
|
||||
for _, schemaType := range c.Schema.Types {
|
||||
if schemaType == c.Schema.Query || schemaType == c.Schema.Mutation || schemaType == c.Schema.Subscription {
|
||||
continue
|
||||
@@ -333,10 +355,10 @@ func (c *Config) check() error {
|
||||
fileList := map[string][]FilenamePackage{}
|
||||
|
||||
if err := c.Models.Check(); err != nil {
|
||||
return errors.Wrap(err, "config.models")
|
||||
return fmt.Errorf("config.models: %w", err)
|
||||
}
|
||||
if err := c.Exec.Check(); err != nil {
|
||||
return errors.Wrap(err, "config.exec")
|
||||
return fmt.Errorf("config.exec: %w", err)
|
||||
}
|
||||
fileList[c.Exec.ImportPath()] = append(fileList[c.Exec.ImportPath()], FilenamePackage{
|
||||
Filename: c.Exec.Filename,
|
||||
@@ -346,7 +368,7 @@ func (c *Config) check() error {
|
||||
|
||||
if c.Model.IsDefined() {
|
||||
if err := c.Model.Check(); err != nil {
|
||||
return errors.Wrap(err, "config.model")
|
||||
return fmt.Errorf("config.model: %w", err)
|
||||
}
|
||||
fileList[c.Model.ImportPath()] = append(fileList[c.Model.ImportPath()], FilenamePackage{
|
||||
Filename: c.Model.Filename,
|
||||
@@ -356,7 +378,7 @@ func (c *Config) check() error {
|
||||
}
|
||||
if c.Resolver.IsDefined() {
|
||||
if err := c.Resolver.Check(); err != nil {
|
||||
return errors.Wrap(err, "config.resolver")
|
||||
return fmt.Errorf("config.resolver: %w", err)
|
||||
}
|
||||
fileList[c.Resolver.ImportPath()] = append(fileList[c.Resolver.ImportPath()], FilenamePackage{
|
||||
Filename: c.Resolver.Filename,
|
||||
@@ -366,7 +388,7 @@ func (c *Config) check() error {
|
||||
}
|
||||
if c.Federation.IsDefined() {
|
||||
if err := c.Federation.Check(); err != nil {
|
||||
return errors.Wrap(err, "config.federation")
|
||||
return fmt.Errorf("config.federation: %w", err)
|
||||
}
|
||||
fileList[c.Federation.ImportPath()] = append(fileList[c.Federation.ImportPath()], FilenamePackage{
|
||||
Filename: c.Federation.Filename,
|
||||
@@ -470,7 +492,7 @@ func inStrSlice(haystack []string, needle string) bool {
|
||||
func findCfg() (string, error) {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "unable to get working dir to findCfg")
|
||||
return "", fmt.Errorf("unable to get working dir to findCfg: %w", err)
|
||||
}
|
||||
|
||||
cfg := findCfgInDir(dir)
|
||||
@@ -510,7 +532,7 @@ func (c *Config) autobind() error {
|
||||
}
|
||||
|
||||
for i, p := range ps {
|
||||
if p == nil {
|
||||
if p == nil || p.Module == nil {
|
||||
return fmt.Errorf("unable to load %s - make sure you're using an import path to a package that exists", c.AutoBind[i])
|
||||
}
|
||||
if t := p.Types.Scope().Lookup(t.Name); t != nil {
|
||||
@@ -554,7 +576,7 @@ func (c *Config) injectBuiltins() {
|
||||
"__EnumValue": {Model: StringList{"github.com/99designs/gqlgen/graphql/introspection.EnumValue"}},
|
||||
"__InputValue": {Model: StringList{"github.com/99designs/gqlgen/graphql/introspection.InputValue"}},
|
||||
"__Schema": {Model: StringList{"github.com/99designs/gqlgen/graphql/introspection.Schema"}},
|
||||
"Float": {Model: StringList{"github.com/99designs/gqlgen/graphql.Float"}},
|
||||
"Float": {Model: StringList{"github.com/99designs/gqlgen/graphql.FloatContext"}},
|
||||
"String": {Model: StringList{"github.com/99designs/gqlgen/graphql.String"}},
|
||||
"Boolean": {Model: StringList{"github.com/99designs/gqlgen/graphql.Boolean"}},
|
||||
"Int": {Model: StringList{
|
||||
|
||||
Reference in New Issue
Block a user