-
Notifications
You must be signed in to change notification settings - Fork 121
/
ast_field_alias.go
48 lines (39 loc) · 1.2 KB
/
ast_field_alias.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
package ast
import (
"github.com/wundergraph/graphql-go-tools/pkg/internal/unsafebytes"
"github.com/wundergraph/graphql-go-tools/pkg/lexer/position"
)
type Alias struct {
IsDefined bool
Name ByteSliceReference // optional, e.g. renamedField
Colon position.Position // :
}
func (d *Document) CopyAlias(alias Alias) Alias {
return Alias{
IsDefined: alias.IsDefined,
Name: d.copyByteSliceReference(alias.Name),
}
}
func (d *Document) FieldAliasOrNameBytes(ref int) ByteSlice {
if d.FieldAliasIsDefined(ref) {
return d.FieldAliasBytes(ref)
}
return d.FieldNameBytes(ref)
}
func (d *Document) FieldAliasOrNameString(ref int) string {
return unsafebytes.BytesToString(d.FieldAliasOrNameBytes(ref))
}
func (d *Document) FieldAliasBytes(ref int) ByteSlice {
return d.Input.ByteSlice(d.Fields[ref].Alias.Name)
}
func (d *Document) FieldAliasString(ref int) string {
return unsafebytes.BytesToString(d.Input.ByteSlice(d.Fields[ref].Alias.Name))
}
func (d *Document) FieldAliasIsDefined(ref int) bool {
return d.Fields[ref].Alias.IsDefined
}
func (d *Document) RemoveFieldAlias(ref int) {
d.Fields[ref].Alias.IsDefined = false
d.Fields[ref].Alias.Name.Start = 0
d.Fields[ref].Alias.Name.End = 0
}