-
Notifications
You must be signed in to change notification settings - Fork 121
/
ast_scalar_type_definition.go
65 lines (53 loc) · 2.06 KB
/
ast_scalar_type_definition.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
package ast
import (
"github.com/wundergraph/graphql-go-tools/pkg/internal/unsafebytes"
"github.com/wundergraph/graphql-go-tools/pkg/lexer/position"
)
// ScalarTypeDefinition
// example:
// scalar JSON
type ScalarTypeDefinition struct {
Description Description // optional, describes the scalar
ScalarLiteral position.Position // scalar
Name ByteSliceReference // e.g. JSON
HasDirectives bool
Directives DirectiveList // optional, e.g. @foo
}
func (d *Document) ScalarTypeDefinitionNameBytes(ref int) ByteSlice {
return d.Input.ByteSlice(d.ScalarTypeDefinitions[ref].Name)
}
func (d *Document) ScalarTypeDefinitionNameString(ref int) string {
return unsafebytes.BytesToString(d.Input.ByteSlice(d.ScalarTypeDefinitions[ref].Name))
}
func (d *Document) ScalarTypeDefinitionDescriptionBytes(ref int) ByteSlice {
if !d.ScalarTypeDefinitions[ref].Description.IsDefined {
return nil
}
return d.Input.ByteSlice(d.ScalarTypeDefinitions[ref].Description.Content)
}
func (d *Document) ScalarTypeDefinitionDescriptionString(ref int) string {
return unsafebytes.BytesToString(d.ScalarTypeDefinitionDescriptionBytes(ref))
}
func (d *Document) ScalarTypeDefinitionHasDirectives(ref int) bool {
return d.ScalarTypeDefinitions[ref].HasDirectives
}
func (d *Document) AddScalarTypeDefinition(definition ScalarTypeDefinition) (ref int) {
d.ScalarTypeDefinitions = append(d.ScalarTypeDefinitions, definition)
return len(d.ScalarTypeDefinitions) - 1
}
func (d *Document) ImportScalarTypeDefinition(name, description string) (ref int) {
return d.ImportScalarTypeDefinitionWithDirectives(name, description, nil)
}
func (d *Document) ImportScalarTypeDefinitionWithDirectives(name, description string, directiveRefs []int) (ref int) {
definition := ScalarTypeDefinition{
Description: d.ImportDescription(description),
Name: d.Input.AppendInputString(name),
HasDirectives: len(directiveRefs) > 0,
Directives: DirectiveList{
Refs: directiveRefs,
},
}
ref = d.AddScalarTypeDefinition(definition)
d.ImportRootNode(ref, NodeKindScalarTypeDefinition)
return
}