mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 21:04:37 +03:00
Stash box client interface (#751)
* Add gql client generation files * Update dependencies * Add stash-box client generation to the makefile * Move scraped scene object matchers to models * Add stash-box to scrape with dropdown * Add scrape scene from fingerprint in UI
This commit is contained in:
183
vendor/github.com/99designs/gqlgen/cmd/init.go
generated
vendored
183
vendor/github.com/99designs/gqlgen/cmd/init.go
generated
vendored
@@ -3,28 +3,79 @@ package cmd
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/99designs/gqlgen/api"
|
||||
"github.com/99designs/gqlgen/plugin/servergen"
|
||||
|
||||
"github.com/99designs/gqlgen/codegen/config"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
"github.com/99designs/gqlgen/internal/code"
|
||||
"github.com/99designs/gqlgen/plugin/servergen"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var configComment = `
|
||||
# .gqlgen.yml example
|
||||
#
|
||||
# Refer to https://gqlgen.com/config/
|
||||
# for detailed .gqlgen.yml documentation.
|
||||
`
|
||||
var configTemplate = template.Must(template.New("name").Parse(
|
||||
`# Where are all the schema files located? globs are supported eg src/**/*.graphqls
|
||||
schema:
|
||||
- graph/*.graphqls
|
||||
|
||||
var schemaDefault = `
|
||||
# GraphQL schema example
|
||||
# Where should the generated server code go?
|
||||
exec:
|
||||
filename: graph/generated/generated.go
|
||||
package: generated
|
||||
|
||||
# Uncomment to enable federation
|
||||
# federation:
|
||||
# filename: graph/generated/federation.go
|
||||
# package: generated
|
||||
|
||||
# Where should any generated models go?
|
||||
model:
|
||||
filename: graph/model/models_gen.go
|
||||
package: model
|
||||
|
||||
# Where should the resolver implementations go?
|
||||
resolver:
|
||||
layout: follow-schema
|
||||
dir: graph
|
||||
package: graph
|
||||
|
||||
# Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models
|
||||
# struct_tag: json
|
||||
|
||||
# Optional: turn on to use []Thing instead of []*Thing
|
||||
# omit_slice_element_pointers: false
|
||||
|
||||
# Optional: set to speed up generation time by not performing a final validation pass.
|
||||
# skip_validation: true
|
||||
|
||||
# gqlgen will search for any type names in the schema in these go packages
|
||||
# if they match it will use them, otherwise it will generate them.
|
||||
autobind:
|
||||
- "{{.}}/graph/model"
|
||||
|
||||
# This section declares type mapping between the GraphQL and go type systems
|
||||
#
|
||||
# The first line in each type will be used as defaults for resolver arguments and
|
||||
# modelgen, the others will be allowed when binding to fields. Configure them to
|
||||
# your liking
|
||||
models:
|
||||
ID:
|
||||
model:
|
||||
- github.com/99designs/gqlgen/graphql.ID
|
||||
- github.com/99designs/gqlgen/graphql.Int
|
||||
- github.com/99designs/gqlgen/graphql.Int64
|
||||
- github.com/99designs/gqlgen/graphql.Int32
|
||||
Int:
|
||||
model:
|
||||
- github.com/99designs/gqlgen/graphql.Int
|
||||
- github.com/99designs/gqlgen/graphql.Int64
|
||||
- github.com/99designs/gqlgen/graphql.Int32
|
||||
`))
|
||||
|
||||
var schemaDefault = `# GraphQL schema example
|
||||
#
|
||||
# https://gqlgen.com/getting-started/
|
||||
|
||||
@@ -54,91 +105,95 @@ type Mutation {
|
||||
}
|
||||
`
|
||||
|
||||
var initCmd = cli.Command{
|
||||
var initCmd = &cli.Command{
|
||||
Name: "init",
|
||||
Usage: "create a new gqlgen project",
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{Name: "verbose, v", Usage: "show logs"},
|
||||
cli.StringFlag{Name: "config, c", Usage: "the config filename"},
|
||||
cli.StringFlag{Name: "server", Usage: "where to write the server stub to", Value: "server/server.go"},
|
||||
cli.StringFlag{Name: "schema", Usage: "where to write the schema stub to", Value: "schema.graphql"},
|
||||
&cli.BoolFlag{Name: "verbose, v", Usage: "show logs"},
|
||||
&cli.StringFlag{Name: "config, c", Usage: "the config filename"},
|
||||
&cli.StringFlag{Name: "server", Usage: "where to write the server stub to", Value: "server.go"},
|
||||
&cli.StringFlag{Name: "schema", Usage: "where to write the schema stub to", Value: "graph/schema.graphqls"},
|
||||
},
|
||||
Action: func(ctx *cli.Context) {
|
||||
initSchema(ctx.String("schema"))
|
||||
config := initConfig(ctx)
|
||||
Action: func(ctx *cli.Context) error {
|
||||
configFilename := ctx.String("config")
|
||||
serverFilename := ctx.String("server")
|
||||
|
||||
GenerateGraphServer(config, ctx.String("server"))
|
||||
pkgName := code.ImportPathForDir(".")
|
||||
if pkgName == "" {
|
||||
return fmt.Errorf("unable to determine import path for current directory, you probably need to run go mod init first")
|
||||
}
|
||||
|
||||
if err := initSchema(ctx.String("schema")); err != nil {
|
||||
return err
|
||||
}
|
||||
if !configExists(configFilename) {
|
||||
if err := initConfig(configFilename, pkgName); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
GenerateGraphServer(serverFilename)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func GenerateGraphServer(cfg *config.Config, serverFilename string) {
|
||||
err := api.Generate(cfg, api.AddPlugin(servergen.New(serverFilename)))
|
||||
func GenerateGraphServer(serverFilename string) {
|
||||
cfg, err := config.LoadConfigFromDefaultLocations()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
}
|
||||
|
||||
if err := api.Generate(cfg, api.AddPlugin(servergen.New(serverFilename))); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stdout, "Exec \"go run ./%s\" to start GraphQL server\n", serverFilename)
|
||||
}
|
||||
|
||||
func initConfig(ctx *cli.Context) *config.Config {
|
||||
func configExists(configFilename string) bool {
|
||||
var cfg *config.Config
|
||||
var err error
|
||||
configFilename := ctx.String("config")
|
||||
|
||||
if configFilename != "" {
|
||||
cfg, err = config.LoadConfig(configFilename)
|
||||
cfg, _ = config.LoadConfig(configFilename)
|
||||
} else {
|
||||
cfg, err = config.LoadConfigFromDefaultLocations()
|
||||
}
|
||||
|
||||
if cfg != nil {
|
||||
fmt.Fprintf(os.Stderr, "init failed: a configuration file already exists\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if !os.IsNotExist(errors.Cause(err)) {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
cfg, _ = config.LoadConfigFromDefaultLocations()
|
||||
}
|
||||
return cfg != nil
|
||||
}
|
||||
|
||||
func initConfig(configFilename string, pkgName string) error {
|
||||
if configFilename == "" {
|
||||
configFilename = "gqlgen.yml"
|
||||
}
|
||||
cfg = config.DefaultConfig()
|
||||
|
||||
cfg.Resolver = config.PackageConfig{
|
||||
Filename: "resolver.go",
|
||||
Type: "Resolver",
|
||||
if err := os.MkdirAll(filepath.Dir(configFilename), 0755); err != nil {
|
||||
return fmt.Errorf("unable to create config dir: " + err.Error())
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString(strings.TrimSpace(configComment))
|
||||
buf.WriteString("\n\n")
|
||||
var b []byte
|
||||
b, err = yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "unable to marshal yaml: "+err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
buf.Write(b)
|
||||
|
||||
err = ioutil.WriteFile(configFilename, buf.Bytes(), 0644)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "unable to write cfg file: "+err.Error())
|
||||
os.Exit(1)
|
||||
if err := configTemplate.Execute(&buf, pkgName); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return cfg
|
||||
if err := ioutil.WriteFile(configFilename, buf.Bytes(), 0644); err != nil {
|
||||
return fmt.Errorf("unable to write cfg file: " + err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initSchema(schemaFilename string) {
|
||||
func initSchema(schemaFilename string) error {
|
||||
_, err := os.Stat(schemaFilename)
|
||||
if !os.IsNotExist(err) {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(schemaFilename, []byte(strings.TrimSpace(schemaDefault)), 0644)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "unable to write schema file: "+err.Error())
|
||||
os.Exit(1)
|
||||
if err := os.MkdirAll(filepath.Dir(schemaFilename), 0755); err != nil {
|
||||
return fmt.Errorf("unable to create schema dir: " + err.Error())
|
||||
}
|
||||
|
||||
if err = ioutil.WriteFile(schemaFilename, []byte(strings.TrimSpace(schemaDefault)), 0644); err != nil {
|
||||
return fmt.Errorf("unable to write schema file: " + err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user