1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
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)
}
|