mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 21:04:37 +03:00
This reverts commit bba7c23957.
This commit is contained in:
5
vendor/github.com/Yamashou/gqlgenc/.golangci.yml
generated
vendored
5
vendor/github.com/Yamashou/gqlgenc/.golangci.yml
generated
vendored
@@ -44,13 +44,9 @@ linters:
|
||||
- varnamelen
|
||||
- nilnil
|
||||
- structcheck
|
||||
- exhaustruct
|
||||
- nonamedreturns
|
||||
fast: false
|
||||
|
||||
issues:
|
||||
max-issues-per-linter: 0
|
||||
max-same-issues: 0
|
||||
exclude-rules:
|
||||
# Test
|
||||
- path: _test\.go
|
||||
@@ -61,7 +57,6 @@ issues:
|
||||
linters:
|
||||
- unused
|
||||
- structcheck
|
||||
- forcetypeassert
|
||||
- path: introspection/type.go
|
||||
linters:
|
||||
- structcheck # These types fits IntrospectionQuery
|
||||
|
||||
6
vendor/github.com/Yamashou/gqlgenc/README.md
generated
vendored
6
vendor/github.com/Yamashou/gqlgenc/README.md
generated
vendored
@@ -48,9 +48,6 @@ endpoint:
|
||||
Authorization: "Bearer ${ANNICT_KEY}" # support environment variables
|
||||
query:
|
||||
- "./query/*.graphql" # Where are all the query files located?
|
||||
generate:
|
||||
clientV2: true # Generate a Client that provides a new signature
|
||||
clientInterfaceName: "GithubGraphQLClient" # Determine the name of the generated client interface
|
||||
```
|
||||
|
||||
Load a schema from a local file:
|
||||
@@ -71,9 +68,6 @@ schema:
|
||||
- "schema/**/*.graphql" # Where are all the schema files located?
|
||||
query:
|
||||
- "./query/*.graphql" # Where are all the query files located?
|
||||
generate:
|
||||
clientV2: true # Generate a Client that provides a new signature
|
||||
clientInterfaceName: "GithubGraphQLClient" # Determine the name of the generated client interface
|
||||
```
|
||||
|
||||
Execute the following command on same directory for .gqlgenc.yml
|
||||
|
||||
9
vendor/github.com/Yamashou/gqlgenc/client/client.go
generated
vendored
9
vendor/github.com/Yamashou/gqlgenc/client/client.go
generated
vendored
@@ -5,7 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/Yamashou/gqlgenc/graphqljson"
|
||||
@@ -55,9 +55,6 @@ func (c *Client) newRequest(ctx context.Context, operationName, query string, va
|
||||
return nil, fmt.Errorf("create request struct failed: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||
req.Header.Set("Accept", "application/json; charset=utf-8")
|
||||
|
||||
for _, httpRequestOption := range c.HTTPRequestOptions {
|
||||
httpRequestOption(req)
|
||||
}
|
||||
@@ -112,6 +109,8 @@ func (c *Client) Post(ctx context.Context, operationName, query string, respData
|
||||
if err != nil {
|
||||
return fmt.Errorf("don't create request: %w", err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||
req.Header.Set("Accept", "application/json; charset=utf-8")
|
||||
|
||||
resp, err := c.Client.Do(req)
|
||||
if err != nil {
|
||||
@@ -119,7 +118,7 @@ func (c *Client) Post(ctx context.Context, operationName, query string, respData
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read response body: %w", err)
|
||||
}
|
||||
|
||||
3
vendor/github.com/Yamashou/gqlgenc/clientgen/query_source.go
generated
vendored
3
vendor/github.com/Yamashou/gqlgenc/clientgen/query_source.go
generated
vendored
@@ -24,6 +24,7 @@ package clientgen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@@ -93,7 +94,7 @@ func LoadQuerySources(queryFileNames []string) ([]*ast.Source, error) {
|
||||
filename = filepath.ToSlash(filename)
|
||||
var err error
|
||||
var schemaRaw []byte
|
||||
schemaRaw, err = os.ReadFile(filename)
|
||||
schemaRaw, err = ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to open schema: %w", err)
|
||||
}
|
||||
|
||||
2
vendor/github.com/Yamashou/gqlgenc/clientgen/template.go
generated
vendored
2
vendor/github.com/Yamashou/gqlgenc/clientgen/template.go
generated
vendored
@@ -19,7 +19,7 @@ func RenderTemplate(cfg *config.Config, query *Query, mutation *Mutation, fragme
|
||||
"Operation": operations,
|
||||
"OperationResponse": operationResponses,
|
||||
"GenerateClient": generateCfg.ShouldGenerateClient(),
|
||||
"ClientInterfaceName": generateCfg.GetClientInterfaceName(),
|
||||
"ClientInterfaceName": generateCfg.ClientInterfaceName,
|
||||
},
|
||||
Packages: cfg.Packages,
|
||||
PackageDoc: "// Code generated by github.com/Yamashou/gqlgenc, DO NOT EDIT.\n",
|
||||
|
||||
1
vendor/github.com/Yamashou/gqlgenc/clientgen/template.gotpl
generated
vendored
1
vendor/github.com/Yamashou/gqlgenc/clientgen/template.gotpl
generated
vendored
@@ -4,6 +4,7 @@
|
||||
{{ reserveImport "encoding/json" }}
|
||||
{{ reserveImport "fmt" }}
|
||||
{{ reserveImport "io" }}
|
||||
{{ reserveImport "io/ioutil" }}
|
||||
{{ reserveImport "net/http" }}
|
||||
{{ reserveImport "net/url" }}
|
||||
{{ reserveImport "path" }}
|
||||
|
||||
3
vendor/github.com/Yamashou/gqlgenc/clientgenv2/query_source.go
generated
vendored
3
vendor/github.com/Yamashou/gqlgenc/clientgenv2/query_source.go
generated
vendored
@@ -24,6 +24,7 @@ package clientgenv2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@@ -93,7 +94,7 @@ func LoadQuerySources(queryFileNames []string) ([]*ast.Source, error) {
|
||||
filename = filepath.ToSlash(filename)
|
||||
var err error
|
||||
var schemaRaw []byte
|
||||
schemaRaw, err = os.ReadFile(filename)
|
||||
schemaRaw, err = ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to open schema: %w", err)
|
||||
}
|
||||
|
||||
1
vendor/github.com/Yamashou/gqlgenc/clientgenv2/template.gotpl
generated
vendored
1
vendor/github.com/Yamashou/gqlgenc/clientgenv2/template.gotpl
generated
vendored
@@ -4,6 +4,7 @@
|
||||
{{ reserveImport "encoding/json" }}
|
||||
{{ reserveImport "fmt" }}
|
||||
{{ reserveImport "io" }}
|
||||
{{ reserveImport "io/ioutil" }}
|
||||
{{ reserveImport "net/http" }}
|
||||
{{ reserveImport "net/url" }}
|
||||
{{ reserveImport "path" }}
|
||||
|
||||
7
vendor/github.com/Yamashou/gqlgenc/config/config.go
generated
vendored
7
vendor/github.com/Yamashou/gqlgenc/config/config.go
generated
vendored
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -115,7 +116,7 @@ var path2regex = strings.NewReplacer(
|
||||
// LoadConfig loads and parses the config gqlgenc config
|
||||
func LoadConfig(filename string) (*Config, error) {
|
||||
var cfg Config
|
||||
b, err := os.ReadFile(filename)
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read config: %w", err)
|
||||
}
|
||||
@@ -187,7 +188,7 @@ func LoadConfig(filename string) (*Config, error) {
|
||||
filename = filepath.ToSlash(filename)
|
||||
var err error
|
||||
var schemaRaw []byte
|
||||
schemaRaw, err = os.ReadFile(filename)
|
||||
schemaRaw, err = ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to open schema: %w", err)
|
||||
}
|
||||
@@ -268,7 +269,7 @@ func (c *Config) loadRemoteSchema(ctx context.Context) (*ast.Schema, error) {
|
||||
func (c *Config) loadLocalSchema() (*ast.Schema, error) {
|
||||
schema, err := gqlparser.LoadSchema(c.GQLConfig.Sources...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("loadLocalSchema: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return schema, nil
|
||||
|
||||
34
vendor/github.com/Yamashou/gqlgenc/generator/generater.go
generated
vendored
34
vendor/github.com/Yamashou/gqlgenc/generator/generater.go
generated
vendored
@@ -5,43 +5,33 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/99designs/gqlgen/api"
|
||||
codegenconfig "github.com/99designs/gqlgen/codegen/config"
|
||||
"github.com/99designs/gqlgen/plugin"
|
||||
"github.com/99designs/gqlgen/plugin/modelgen"
|
||||
"github.com/Yamashou/gqlgenc/config"
|
||||
)
|
||||
|
||||
// mutateHook adds the "omitempty" option to optional field from input type model as defined in graphql schema
|
||||
// mutateHook adds the "omitempty" option to nilable fields.
|
||||
// For more info see https://github.com/99designs/gqlgen/blob/master/docs/content/recipes/modelgen-hook.md
|
||||
func mutateHook(cfg *config.Config) func(b *modelgen.ModelBuild) *modelgen.ModelBuild {
|
||||
return func(build *modelgen.ModelBuild) *modelgen.ModelBuild {
|
||||
for _, model := range build.Models {
|
||||
// only handle input type model
|
||||
if schemaModel, ok := cfg.GQLConfig.Schema.Types[model.Name]; ok && schemaModel.IsInputType() {
|
||||
for _, field := range model.Fields {
|
||||
// find field in graphql schema
|
||||
for _, def := range schemaModel.Fields {
|
||||
if def.Name == field.Name {
|
||||
// only add 'omitempty' on optional field as defined in graphql schema
|
||||
if !def.Type.NonNull {
|
||||
field.Tag = `json:"` + field.Name + `,omitempty"`
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
func mutateHook(build *modelgen.ModelBuild) *modelgen.ModelBuild {
|
||||
for _, model := range build.Models {
|
||||
for _, field := range model.Fields {
|
||||
field.Tag = `json:"` + field.Name
|
||||
if codegenconfig.IsNilable(field.Type) {
|
||||
field.Tag += ",omitempty"
|
||||
}
|
||||
field.Tag += `"`
|
||||
}
|
||||
|
||||
return build
|
||||
}
|
||||
|
||||
return build
|
||||
}
|
||||
|
||||
func Generate(ctx context.Context, cfg *config.Config, option ...api.Option) error {
|
||||
var plugins []plugin.Plugin
|
||||
if cfg.Model.IsDefined() {
|
||||
p := modelgen.Plugin{
|
||||
MutateHook: mutateHook(cfg),
|
||||
MutateHook: mutateHook,
|
||||
}
|
||||
plugins = append(plugins, &p)
|
||||
}
|
||||
|
||||
13
vendor/github.com/Yamashou/gqlgenc/graphqljson/graphql.go
generated
vendored
13
vendor/github.com/Yamashou/gqlgenc/graphqljson/graphql.go
generated
vendored
@@ -146,17 +146,12 @@ func (d *Decoder) decode() error {
|
||||
|
||||
// We've just consumed the current token, which was the key.
|
||||
// Read the next token, which should be the value.
|
||||
// If it's of json.RawMessage or map type, decode the value.
|
||||
switch matchingFieldValue.Type() {
|
||||
case reflect.TypeOf(json.RawMessage{}):
|
||||
// If it's of json.RawMessage type, decode the value.
|
||||
if matchingFieldValue.Type() == reflect.TypeOf(json.RawMessage{}) {
|
||||
var data json.RawMessage
|
||||
err = d.jsonDecoder.Decode(&data)
|
||||
tok = data
|
||||
case reflect.TypeOf(map[string]interface{}{}):
|
||||
var data map[string]interface{}
|
||||
err = d.jsonDecoder.Decode(&data)
|
||||
tok = data
|
||||
default:
|
||||
} else {
|
||||
tok, err = d.jsonDecoder.Token()
|
||||
}
|
||||
|
||||
@@ -188,7 +183,7 @@ func (d *Decoder) decode() error {
|
||||
}
|
||||
|
||||
switch tok := tok.(type) {
|
||||
case string, json.Number, bool, nil, json.RawMessage, map[string]interface{}:
|
||||
case string, json.Number, bool, nil, json.RawMessage:
|
||||
// Value.
|
||||
|
||||
for i := range d.vs {
|
||||
|
||||
121
vendor/github.com/Yamashou/gqlgenc/introspection/parse.go
generated
vendored
121
vendor/github.com/Yamashou/gqlgenc/introspection/parse.go
generated
vendored
@@ -2,7 +2,6 @@ package introspection
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/vektah/gqlparser/v2/ast"
|
||||
)
|
||||
@@ -13,7 +12,6 @@ func ParseIntrospectionQuery(url string, query Query) *ast.SchemaDocument {
|
||||
Name: "remote",
|
||||
BuiltIn: false,
|
||||
}},
|
||||
typeMap: query.Schema.Types.NameMap(),
|
||||
}
|
||||
|
||||
if url != "" {
|
||||
@@ -24,27 +22,23 @@ func ParseIntrospectionQuery(url string, query Query) *ast.SchemaDocument {
|
||||
}
|
||||
|
||||
type parser struct {
|
||||
sharedPosition *ast.Position
|
||||
typeMap map[string]*FullType
|
||||
deprecatedDirectiveDefinition *ast.DirectiveDefinition
|
||||
sharedPosition *ast.Position
|
||||
}
|
||||
|
||||
func (p parser) parseIntrospectionQuery(query Query) *ast.SchemaDocument {
|
||||
var doc ast.SchemaDocument
|
||||
typeMap := query.Schema.Types.NameMap()
|
||||
|
||||
doc.Schema = append(doc.Schema, p.parseSchemaDefinition(query, p.typeMap))
|
||||
doc.Schema = append(doc.Schema, p.parseSchemaDefinition(query, typeMap))
|
||||
doc.Position = p.sharedPosition
|
||||
|
||||
// parseDirectiveDefinition before parseTypeSystemDefinition
|
||||
// Because SystemDefinition depends on DirectiveDefinition
|
||||
for _, typeVale := range typeMap {
|
||||
doc.Definitions = append(doc.Definitions, p.parseTypeSystemDefinition(typeVale))
|
||||
}
|
||||
|
||||
for _, directiveValue := range query.Schema.Directives {
|
||||
doc.Directives = append(doc.Directives, p.parseDirectiveDefinition(directiveValue))
|
||||
}
|
||||
p.deprecatedDirectiveDefinition = doc.Directives.ForName("deprecated")
|
||||
|
||||
for _, typeVale := range p.typeMap {
|
||||
doc.Definitions = append(doc.Definitions, p.parseTypeSystemDefinition(typeVale))
|
||||
}
|
||||
|
||||
return &doc
|
||||
}
|
||||
@@ -122,7 +116,6 @@ func (p parser) parseObjectFields(typeVale *FullType) ast.FieldList {
|
||||
Arguments: args,
|
||||
Type: typ,
|
||||
Position: p.sharedPosition,
|
||||
Directives: p.buildDeprecatedDirective(field),
|
||||
}
|
||||
fieldList = append(fieldList, fieldDefinition)
|
||||
}
|
||||
@@ -171,7 +164,7 @@ func (p parser) parseObjectTypeDefinition(typeVale *FullType) *ast.Definition {
|
||||
Fields: fieldList,
|
||||
EnumValues: enums,
|
||||
Position: p.sharedPosition,
|
||||
BuiltIn: builtInObject(typeVale),
|
||||
BuiltIn: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +182,7 @@ func (p parser) parseInterfaceTypeDefinition(typeVale *FullType) *ast.Definition
|
||||
Interfaces: interfaces,
|
||||
Fields: fieldList,
|
||||
Position: p.sharedPosition,
|
||||
BuiltIn: false,
|
||||
BuiltIn: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +200,7 @@ func (p parser) parseInputObjectTypeDefinition(typeVale *FullType) *ast.Definiti
|
||||
Interfaces: interfaces,
|
||||
Fields: fieldList,
|
||||
Position: p.sharedPosition,
|
||||
BuiltIn: false,
|
||||
BuiltIn: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +216,7 @@ func (p parser) parseUnionTypeDefinition(typeVale *FullType) *ast.Definition {
|
||||
Name: pointerString(typeVale.Name),
|
||||
Types: unions,
|
||||
Position: p.sharedPosition,
|
||||
BuiltIn: false,
|
||||
BuiltIn: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +237,7 @@ func (p parser) parseEnumTypeDefinition(typeVale *FullType) *ast.Definition {
|
||||
Name: pointerString(typeVale.Name),
|
||||
EnumValues: enums,
|
||||
Position: p.sharedPosition,
|
||||
BuiltIn: builtInEnum(typeVale),
|
||||
BuiltIn: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +247,7 @@ func (p parser) parseScalarTypeExtension(typeVale *FullType) *ast.Definition {
|
||||
Description: pointerString(typeVale.Description),
|
||||
Name: pointerString(typeVale.Name),
|
||||
Position: p.sharedPosition,
|
||||
BuiltIn: builtInScalar(typeVale),
|
||||
BuiltIn: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +279,7 @@ func (p parser) buildInputValue(input *InputValue) *ast.ArgumentDefinition {
|
||||
if input.DefaultValue != nil {
|
||||
defaultValue = &ast.Value{
|
||||
Raw: pointerString(input.DefaultValue),
|
||||
Kind: p.parseValueKind(typ),
|
||||
Kind: ast.Variable,
|
||||
Position: p.sharedPosition,
|
||||
}
|
||||
}
|
||||
@@ -324,67 +317,6 @@ func (p parser) getType(typeRef *TypeRef) *ast.Type {
|
||||
return ast.NamedType(pointerString(typeRef.Name), p.sharedPosition)
|
||||
}
|
||||
|
||||
func (p parser) buildDeprecatedDirective(field *FieldValue) ast.DirectiveList {
|
||||
var directives ast.DirectiveList
|
||||
if field.IsDeprecated {
|
||||
var arguments ast.ArgumentList
|
||||
if field.DeprecationReason != nil {
|
||||
arguments = append(arguments, &ast.Argument{
|
||||
Name: "reason",
|
||||
Value: &ast.Value{
|
||||
Raw: *field.DeprecationReason,
|
||||
Kind: ast.StringValue,
|
||||
Position: p.sharedPosition,
|
||||
},
|
||||
Position: p.sharedPosition,
|
||||
})
|
||||
}
|
||||
deprecatedDirective := &ast.Directive{
|
||||
Name: "deprecated",
|
||||
Arguments: arguments,
|
||||
Position: p.sharedPosition,
|
||||
ParentDefinition: nil,
|
||||
Definition: p.deprecatedDirectiveDefinition,
|
||||
Location: ast.LocationVariableDefinition,
|
||||
}
|
||||
directives = append(directives, deprecatedDirective)
|
||||
}
|
||||
|
||||
return directives
|
||||
}
|
||||
|
||||
func (p parser) parseValueKind(typ *ast.Type) ast.ValueKind {
|
||||
typName := typ.Name()
|
||||
|
||||
if fullType, ok := p.typeMap[typName]; ok {
|
||||
switch fullType.Kind {
|
||||
case TypeKindEnum:
|
||||
return ast.EnumValue
|
||||
case TypeKindInputObject, TypeKindObject, TypeKindUnion, TypeKindInterface:
|
||||
return ast.ObjectValue
|
||||
case TypeKindList:
|
||||
return ast.ListValue
|
||||
case TypeKindNonNull:
|
||||
panic(fmt.Sprintf("parseValueKind not match Type Name: %s", typ.Name()))
|
||||
case TypeKindScalar:
|
||||
switch typName {
|
||||
case "Int":
|
||||
return ast.IntValue
|
||||
case "Float":
|
||||
return ast.FloatValue
|
||||
case "Boolean":
|
||||
return ast.BooleanValue
|
||||
case "String", "ID":
|
||||
return ast.StringValue
|
||||
default:
|
||||
return ast.StringValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("parseValueKind not match Type Name: %s", typ.Name()))
|
||||
}
|
||||
|
||||
func pointerString(s *string) string {
|
||||
if s == nil {
|
||||
return ""
|
||||
@@ -392,28 +324,3 @@ func pointerString(s *string) string {
|
||||
|
||||
return *s
|
||||
}
|
||||
|
||||
func builtInScalar(fullType *FullType) bool {
|
||||
name := pointerString(fullType.Name)
|
||||
if strings.HasPrefix(name, "__") {
|
||||
return true
|
||||
}
|
||||
switch name {
|
||||
case "String", "Int", "Float", "Boolean", "ID":
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func builtInEnum(fullType *FullType) bool {
|
||||
name := pointerString(fullType.Name)
|
||||
|
||||
return strings.HasPrefix(name, "__")
|
||||
}
|
||||
|
||||
func builtInObject(fullType *FullType) bool {
|
||||
name := pointerString(fullType.Name)
|
||||
|
||||
return strings.HasPrefix(name, "__")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user