mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
* Use vendor code for all go calls * Add missing vendor dependencies * Add travis_retry to yarn install * Fix go test call
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package codegen
|
|
|
|
import (
|
|
"go/types"
|
|
|
|
"github.com/vektah/gqlparser/ast"
|
|
)
|
|
|
|
type Interface struct {
|
|
*ast.Definition
|
|
Type types.Type
|
|
Implementors []InterfaceImplementor
|
|
InTypemap bool
|
|
}
|
|
|
|
type InterfaceImplementor struct {
|
|
*ast.Definition
|
|
|
|
Interface *Interface
|
|
Type types.Type
|
|
}
|
|
|
|
func (b *builder) buildInterface(typ *ast.Definition) *Interface {
|
|
obj, err := b.Binder.DefaultUserObject(typ.Name)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
i := &Interface{
|
|
Definition: typ,
|
|
Type: obj,
|
|
InTypemap: b.Config.Models.UserDefined(typ.Name),
|
|
}
|
|
|
|
for _, implementor := range b.Schema.GetPossibleTypes(typ) {
|
|
obj, err := b.Binder.DefaultUserObject(implementor.Name)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
i.Implementors = append(i.Implementors, InterfaceImplementor{
|
|
Definition: implementor,
|
|
Type: obj,
|
|
Interface: i,
|
|
})
|
|
}
|
|
|
|
return i
|
|
}
|
|
|
|
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)
|
|
}
|