forked from wundergraph/graphql-go-tools
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ast_interface_type_extension.go
75 lines (61 loc) · 3.48 KB
/
ast_interface_type_extension.go
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
64
65
66
67
68
69
70
71
72
73
74
75
package ast
import (
"github.com/TykTechnologies/graphql-go-tools/v2/internal/pkg/unsafebytes"
"github.com/TykTechnologies/graphql-go-tools/v2/pkg/lexer/position"
)
type InterfaceTypeExtension struct {
ExtendLiteral position.Position
InterfaceTypeDefinition
}
func (d *Document) InterfaceTypeExtensionNameBytes(ref int) ByteSlice {
return d.Input.ByteSlice(d.InterfaceTypeExtensions[ref].Name)
}
func (d *Document) InterfaceTypeExtensionNameString(ref int) string {
return unsafebytes.BytesToString(d.Input.ByteSlice(d.InterfaceTypeExtensions[ref].Name))
}
func (d *Document) InterfaceTypeExtensionDescriptionBytes(ref int) ByteSlice {
if !d.InterfaceTypeExtensions[ref].Description.IsDefined {
return nil
}
return d.Input.ByteSlice(d.InterfaceTypeExtensions[ref].Description.Content)
}
func (d *Document) InterfaceTypeExtensionDescriptionString(ref int) string {
return unsafebytes.BytesToString(d.InterfaceTypeExtensionDescriptionBytes(ref))
}
func (d *Document) InterfaceTypeExtensionHasFieldDefinitions(ref int) bool {
return d.InterfaceTypeExtensions[ref].HasFieldDefinitions
}
func (d *Document) InterfaceTypeExtensionHasDirectives(ref int) bool {
return d.InterfaceTypeExtensions[ref].HasDirectives
}
func (d *Document) ExtendInterfaceTypeDefinitionByInterfaceTypeExtension(interfaceTypeDefinitionRef, interfaceTypeExtensionRef int) {
if d.InterfaceTypeExtensionHasFieldDefinitions(interfaceTypeExtensionRef) {
d.InterfaceTypeDefinitions[interfaceTypeDefinitionRef].FieldsDefinition.Refs = append(d.InterfaceTypeDefinitions[interfaceTypeDefinitionRef].FieldsDefinition.Refs, d.InterfaceTypeExtensions[interfaceTypeExtensionRef].FieldsDefinition.Refs...)
d.InterfaceTypeDefinitions[interfaceTypeDefinitionRef].HasFieldDefinitions = true
}
if d.InterfaceTypeExtensionHasDirectives(interfaceTypeExtensionRef) {
d.InterfaceTypeDefinitions[interfaceTypeDefinitionRef].Directives.Refs = append(d.InterfaceTypeDefinitions[interfaceTypeDefinitionRef].Directives.Refs, d.InterfaceTypeExtensions[interfaceTypeExtensionRef].Directives.Refs...)
d.InterfaceTypeDefinitions[interfaceTypeDefinitionRef].HasDirectives = true
}
if len(d.InterfaceTypeExtensions[interfaceTypeExtensionRef].ImplementsInterfaces.Refs) > 0 {
d.InterfaceTypeDefinitions[interfaceTypeDefinitionRef].ImplementsInterfaces.Refs = append(
d.InterfaceTypeDefinitions[interfaceTypeDefinitionRef].ImplementsInterfaces.Refs,
d.InterfaceTypeExtensions[interfaceTypeExtensionRef].ImplementsInterfaces.Refs...,
)
}
d.Index.MergedTypeExtensions = append(d.Index.MergedTypeExtensions, Node{Ref: interfaceTypeExtensionRef, Kind: NodeKindInterfaceTypeExtension})
}
func (d *Document) ImportAndExtendInterfaceTypeDefinitionByInterfaceTypeExtension(interfaceTypeExtensionRef int) {
d.ImportInterfaceTypeDefinitionWithDirectives(
d.InterfaceTypeExtensionNameString(interfaceTypeExtensionRef),
d.InterfaceTypeExtensionDescriptionString(interfaceTypeExtensionRef),
d.InterfaceTypeExtensions[interfaceTypeExtensionRef].FieldsDefinition.Refs,
d.InterfaceTypeExtensions[interfaceTypeExtensionRef].ImplementsInterfaces.Refs,
d.InterfaceTypeExtensions[interfaceTypeExtensionRef].Directives.Refs,
)
d.Index.MergedTypeExtensions = append(d.Index.MergedTypeExtensions, Node{Ref: interfaceTypeExtensionRef, Kind: NodeKindInterfaceTypeExtension})
}
func (d *Document) AddInterfaceTypeExtension(extension InterfaceTypeExtension) (ref int) {
d.InterfaceTypeExtensions = append(d.InterfaceTypeExtensions, extension)
return len(d.InterfaceTypeExtensions) - 1
}