mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44: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:
71
vendor/github.com/99designs/gqlgen/codegen/interface.go
generated
vendored
71
vendor/github.com/99designs/gqlgen/codegen/interface.go
generated
vendored
@@ -1,9 +1,13 @@
|
||||
package codegen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/types"
|
||||
|
||||
"github.com/vektah/gqlparser/ast"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/vektah/gqlparser/v2/ast"
|
||||
|
||||
"github.com/99designs/gqlgen/codegen/config"
|
||||
)
|
||||
|
||||
type Interface struct {
|
||||
@@ -16,11 +20,11 @@ type Interface struct {
|
||||
type InterfaceImplementor struct {
|
||||
*ast.Definition
|
||||
|
||||
Interface *Interface
|
||||
Type types.Type
|
||||
Type types.Type
|
||||
TakeRef bool
|
||||
}
|
||||
|
||||
func (b *builder) buildInterface(typ *ast.Definition) *Interface {
|
||||
func (b *builder) buildInterface(typ *ast.Definition) (*Interface, error) {
|
||||
obj, err := b.Binder.DefaultUserObject(typ.Name)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -32,32 +36,53 @@ func (b *builder) buildInterface(typ *ast.Definition) *Interface {
|
||||
InTypemap: b.Config.Models.UserDefined(typ.Name),
|
||||
}
|
||||
|
||||
interfaceType, err := findGoInterface(i.Type)
|
||||
if interfaceType == nil || err != nil {
|
||||
return nil, fmt.Errorf("%s is not an interface", i.Type)
|
||||
}
|
||||
|
||||
for _, implementor := range b.Schema.GetPossibleTypes(typ) {
|
||||
obj, err := b.Binder.DefaultUserObject(implementor.Name)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, fmt.Errorf("%s has no backing go type", implementor.Name)
|
||||
}
|
||||
|
||||
i.Implementors = append(i.Implementors, InterfaceImplementor{
|
||||
Definition: implementor,
|
||||
Type: obj,
|
||||
Interface: i,
|
||||
})
|
||||
implementorType, err := findGoNamedType(obj)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "can not find backing go type %s", obj.String())
|
||||
} else if implementorType == nil {
|
||||
return nil, fmt.Errorf("can not find backing go type %s", obj.String())
|
||||
}
|
||||
|
||||
anyValid := false
|
||||
|
||||
// first check if the value receiver can be nil, eg can we type switch on case Thing:
|
||||
if types.Implements(implementorType, interfaceType) {
|
||||
i.Implementors = append(i.Implementors, InterfaceImplementor{
|
||||
Definition: implementor,
|
||||
Type: obj,
|
||||
TakeRef: !types.IsInterface(obj),
|
||||
})
|
||||
anyValid = true
|
||||
}
|
||||
|
||||
// then check if the pointer receiver can be nil, eg can we type switch on case *Thing:
|
||||
if types.Implements(types.NewPointer(implementorType), interfaceType) {
|
||||
i.Implementors = append(i.Implementors, InterfaceImplementor{
|
||||
Definition: implementor,
|
||||
Type: types.NewPointer(obj),
|
||||
})
|
||||
anyValid = true
|
||||
}
|
||||
|
||||
if !anyValid {
|
||||
return nil, fmt.Errorf("%s does not satisfy the interface %s", implementorType.String(), i.Type.String())
|
||||
}
|
||||
}
|
||||
|
||||
return i
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (i *InterfaceImplementor) ValueReceiver() bool {
|
||||
interfaceType, err := findGoInterface(i.Interface.Type)
|
||||
if interfaceType == nil || err != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
implementorType, err := findGoNamedType(i.Type)
|
||||
if implementorType == nil || err != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return types.Implements(implementorType, interfaceType)
|
||||
func (i *InterfaceImplementor) CanBeNil() bool {
|
||||
return config.IsNilable(i.Type)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user