aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/graphql-go/graphql/language/ast/selections.go
blob: 0dc0ea12144885ca0210cfb63a57eb5a9e4c60d6 (plain) (blame)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package ast

import (
	"github.com/graphql-go/graphql/language/kinds"
)

type Selection interface {
	GetSelectionSet() *SelectionSet
}

// Ensure that all definition types implements Selection interface
var _ Selection = (*Field)(nil)
var _ Selection = (*FragmentSpread)(nil)
var _ Selection = (*InlineFragment)(nil)

// Field implements Node, Selection
type Field struct {
	Kind         string
	Loc          *Location
	Alias        *Name
	Name         *Name
	Arguments    []*Argument
	Directives   []*Directive
	SelectionSet *SelectionSet
}

func NewField(f *Field) *Field {
	if f == nil {
		f = &Field{}
	}
	return &Field{
		Kind:         kinds.Field,
		Loc:          f.Loc,
		Alias:        f.Alias,
		Name:         f.Name,
		Arguments:    f.Arguments,
		Directives:   f.Directives,
		SelectionSet: f.SelectionSet,
	}
}

func (f *Field) GetKind() string {
	return f.Kind
}

func (f *Field) GetLoc() *Location {
	return f.Loc
}

func (f *Field) GetSelectionSet() *SelectionSet {
	return f.SelectionSet
}

// FragmentSpread implements Node, Selection
type FragmentSpread struct {
	Kind       string
	Loc        *Location
	Name       *Name
	Directives []*Directive
}

func NewFragmentSpread(fs *FragmentSpread) *FragmentSpread {
	if fs == nil {
		fs = &FragmentSpread{}
	}
	return &FragmentSpread{
		Kind:       kinds.FragmentSpread,
		Loc:        fs.Loc,
		Name:       fs.Name,
		Directives: fs.Directives,
	}
}

func (fs *FragmentSpread) GetKind() string {
	return fs.Kind
}

func (fs *FragmentSpread) GetLoc() *Location {
	return fs.Loc
}

func (fs *FragmentSpread) GetSelectionSet() *SelectionSet {
	return nil
}

// InlineFragment implements Node, Selection
type InlineFragment struct {
	Kind          string
	Loc           *Location
	TypeCondition *Named
	Directives    []*Directive
	SelectionSet  *SelectionSet
}

func NewInlineFragment(f *InlineFragment) *InlineFragment {
	if f == nil {
		f = &InlineFragment{}
	}
	return &InlineFragment{
		Kind:          kinds.InlineFragment,
		Loc:           f.Loc,
		TypeCondition: f.TypeCondition,
		Directives:    f.Directives,
		SelectionSet:  f.SelectionSet,
	}
}

func (f *InlineFragment) GetKind() string {
	return f.Kind
}

func (f *InlineFragment) GetLoc() *Location {
	return f.Loc
}

func (f *InlineFragment) GetSelectionSet() *SelectionSet {
	return f.SelectionSet
}

// SelectionSet implements Node
type SelectionSet struct {
	Kind       string
	Loc        *Location
	Selections []Selection
}

func NewSelectionSet(ss *SelectionSet) *SelectionSet {
	if ss == nil {
		ss = &SelectionSet{}
	}
	return &SelectionSet{
		Kind:       kinds.SelectionSet,
		Loc:        ss.Loc,
		Selections: ss.Selections,
	}
}

func (ss *SelectionSet) GetKind() string {
	return ss.Kind
}

func (ss *SelectionSet) GetLoc() *Location {
	return ss.Loc
}