forked from wundergraph/graphql-go-tools
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ast_union_type_extension.go
62 lines (50 loc) · 2.62 KB
/
ast_union_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/TykTechnologies/graphql-go-tools/v2/internal/pkg/unsafebytes"
"github.com/TykTechnologies/graphql-go-tools/v2/pkg/lexer/position"
)
type UnionTypeExtension struct {
ExtendLiteral position.Position
UnionTypeDefinition
}
func (d *Document) UnionTypeExtensionNameBytes(ref int) ByteSlice {
return d.Input.ByteSlice(d.UnionTypeExtensions[ref].Name)
}
func (d *Document) UnionTypeExtensionNameString(ref int) string {
return unsafebytes.BytesToString(d.Input.ByteSlice(d.UnionTypeExtensions[ref].Name))
}
func (d *Document) UnionTypeExtensionDescriptionBytes(ref int) ByteSlice {
if !d.UnionTypeExtensions[ref].Description.IsDefined {
return nil
}
return d.Input.ByteSlice(d.UnionTypeExtensions[ref].Description.Content)
}
func (d *Document) UnionTypeExtensionDescriptionString(ref int) string {
return unsafebytes.BytesToString(d.UnionTypeExtensionDescriptionBytes(ref))
}
func (d *Document) UnionTypeExtensionHasUnionMemberTypes(ref int) bool {
return d.UnionTypeExtensions[ref].HasUnionMemberTypes
}
func (d *Document) UnionTypeExtensionHasDirectives(ref int) bool {
return d.UnionTypeExtensions[ref].HasDirectives
}
func (d *Document) ExtendUnionTypeDefinitionByUnionTypeExtension(unionTypeDefinitionRef, unionTypeExtensionRef int) {
if d.UnionTypeExtensionHasDirectives(unionTypeExtensionRef) {
d.UnionTypeDefinitions[unionTypeDefinitionRef].Directives.Refs = append(d.UnionTypeDefinitions[unionTypeDefinitionRef].Directives.Refs, d.UnionTypeExtensions[unionTypeExtensionRef].Directives.Refs...)
d.UnionTypeDefinitions[unionTypeDefinitionRef].HasDirectives = true
}
if d.UnionTypeExtensionHasUnionMemberTypes(unionTypeExtensionRef) {
d.UnionTypeDefinitions[unionTypeDefinitionRef].UnionMemberTypes.Refs = append(d.UnionTypeDefinitions[unionTypeDefinitionRef].UnionMemberTypes.Refs, d.UnionTypeExtensions[unionTypeExtensionRef].UnionMemberTypes.Refs...)
d.UnionTypeDefinitions[unionTypeDefinitionRef].HasUnionMemberTypes = true
}
d.Index.MergedTypeExtensions = append(d.Index.MergedTypeExtensions, Node{Ref: unionTypeExtensionRef, Kind: NodeKindUnionTypeExtension})
}
func (d *Document) ImportAndExtendUnionTypeDefinitionByUnionTypeExtension(unionTypeExtensionRef int) {
d.ImportUnionTypeDefinitionWithDirectives(
d.UnionTypeExtensionNameString(unionTypeExtensionRef),
d.UnionTypeExtensionDescriptionString(unionTypeExtensionRef),
d.UnionTypeExtensions[unionTypeExtensionRef].UnionMemberTypes.Refs,
d.UnionTypeExtensions[unionTypeExtensionRef].Directives.Refs,
)
d.Index.MergedTypeExtensions = append(d.Index.MergedTypeExtensions, Node{Ref: unionTypeExtensionRef, Kind: NodeKindUnionTypeExtension})
}