-
Notifications
You must be signed in to change notification settings - Fork 118
/
ast_enum_type_extension.go
62 lines (50 loc) · 2.58 KB
/
ast_enum_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
package ast
import (
"github.com/wundergraph/graphql-go-tools/pkg/internal/unsafebytes"
"github.com/wundergraph/graphql-go-tools/pkg/lexer/position"
)
type EnumTypeExtension struct {
ExtendLiteral position.Position
EnumTypeDefinition
}
func (d *Document) EnumTypeExtensionNameBytes(ref int) ByteSlice {
return d.Input.ByteSlice(d.EnumTypeExtensions[ref].Name)
}
func (d *Document) EnumTypeExtensionNameString(ref int) string {
return unsafebytes.BytesToString(d.Input.ByteSlice(d.EnumTypeExtensions[ref].Name))
}
func (d *Document) EnumTypeExtensionDescriptionBytes(ref int) ByteSlice {
if !d.EnumTypeExtensions[ref].Description.IsDefined {
return nil
}
return d.Input.ByteSlice(d.EnumTypeExtensions[ref].Description.Content)
}
func (d *Document) EnumTypeExtensionDescriptionString(ref int) string {
return unsafebytes.BytesToString(d.EnumTypeExtensionDescriptionBytes(ref))
}
func (d *Document) EnumTypeExtensionHasEnumValueDefinition(ref int) bool {
return d.EnumTypeExtensions[ref].HasEnumValuesDefinition
}
func (d *Document) EnumTypeExtensionHasDirectives(ref int) bool {
return d.EnumTypeExtensions[ref].HasDirectives
}
func (d *Document) ExtendEnumTypeDefinitionByEnumTypeExtension(enumTypeDefinitionRef, enumTypeExtensionRef int) {
if d.EnumTypeExtensionHasDirectives(enumTypeExtensionRef) {
d.EnumTypeDefinitions[enumTypeDefinitionRef].Directives.Refs = append(d.EnumTypeDefinitions[enumTypeDefinitionRef].Directives.Refs, d.EnumTypeExtensions[enumTypeExtensionRef].Directives.Refs...)
d.EnumTypeDefinitions[enumTypeDefinitionRef].HasDirectives = true
}
if d.EnumTypeExtensionHasEnumValueDefinition(enumTypeExtensionRef) {
d.EnumTypeDefinitions[enumTypeDefinitionRef].EnumValuesDefinition.Refs = append(d.EnumTypeDefinitions[enumTypeDefinitionRef].EnumValuesDefinition.Refs, d.EnumTypeExtensions[enumTypeExtensionRef].EnumValuesDefinition.Refs...)
d.EnumTypeDefinitions[enumTypeDefinitionRef].HasEnumValuesDefinition = true
}
d.Index.MergedTypeExtensions = append(d.Index.MergedTypeExtensions, Node{Ref: enumTypeExtensionRef, Kind: NodeKindEnumTypeExtension})
}
func (d *Document) ImportAndExtendEnumTypeDefinitionByEnumTypeExtension(enumTypeExtensionRef int) {
d.ImportEnumTypeDefinitionWithDirectives(
d.EnumTypeExtensionNameString(enumTypeExtensionRef),
d.EnumTypeExtensionDescriptionString(enumTypeExtensionRef),
d.EnumTypeExtensions[enumTypeExtensionRef].EnumValuesDefinition.Refs,
d.EnumTypeExtensions[enumTypeExtensionRef].Directives.Refs,
)
d.Index.MergedTypeExtensions = append(d.Index.MergedTypeExtensions, Node{Ref: enumTypeExtensionRef, Kind: NodeKindEnumTypeExtension})
}