cubefs
235 строк · 5.4 Кб
1package ast2
3import (4"github.com/graphql-go/graphql/language/kinds"5)
6
7type Definition interface {8GetOperation() string9GetVariableDefinitions() []*VariableDefinition10GetSelectionSet() *SelectionSet11GetKind() string12GetLoc() *Location13}
14
15// Ensure that all definition types implements Definition interface
16var _ Definition = (*OperationDefinition)(nil)17var _ Definition = (*FragmentDefinition)(nil)18var _ Definition = (TypeSystemDefinition)(nil) // experimental non-spec addition.19
20// Note: subscription is an experimental non-spec addition.
21const (22OperationTypeQuery = "query"23OperationTypeMutation = "mutation"24OperationTypeSubscription = "subscription"25)
26
27// OperationDefinition implements Node, Definition
28type OperationDefinition struct {29Kind string30Loc *Location31Operation string32Name *Name33VariableDefinitions []*VariableDefinition34Directives []*Directive35SelectionSet *SelectionSet36}
37
38func NewOperationDefinition(op *OperationDefinition) *OperationDefinition {39if op == nil {40op = &OperationDefinition{}41}42op.Kind = kinds.OperationDefinition43return op44}
45
46func (op *OperationDefinition) GetKind() string {47return op.Kind48}
49
50func (op *OperationDefinition) GetLoc() *Location {51return op.Loc52}
53
54func (op *OperationDefinition) GetOperation() string {55return op.Operation56}
57
58func (op *OperationDefinition) GetName() *Name {59return op.Name60}
61
62func (op *OperationDefinition) GetVariableDefinitions() []*VariableDefinition {63return op.VariableDefinitions64}
65
66func (op *OperationDefinition) GetDirectives() []*Directive {67return op.Directives68}
69
70func (op *OperationDefinition) GetSelectionSet() *SelectionSet {71return op.SelectionSet72}
73
74// FragmentDefinition implements Node, Definition
75type FragmentDefinition struct {76Kind string77Loc *Location78Operation string79Name *Name80VariableDefinitions []*VariableDefinition81TypeCondition *Named82Directives []*Directive83SelectionSet *SelectionSet84}
85
86func NewFragmentDefinition(fd *FragmentDefinition) *FragmentDefinition {87if fd == nil {88fd = &FragmentDefinition{}89}90return &FragmentDefinition{91Kind: kinds.FragmentDefinition,92Loc: fd.Loc,93Operation: fd.Operation,94Name: fd.Name,95VariableDefinitions: fd.VariableDefinitions,96TypeCondition: fd.TypeCondition,97Directives: fd.Directives,98SelectionSet: fd.SelectionSet,99}100}
101
102func (fd *FragmentDefinition) GetKind() string {103return fd.Kind104}
105
106func (fd *FragmentDefinition) GetLoc() *Location {107return fd.Loc108}
109
110func (fd *FragmentDefinition) GetOperation() string {111return fd.Operation112}
113
114func (fd *FragmentDefinition) GetName() *Name {115return fd.Name116}
117
118func (fd *FragmentDefinition) GetVariableDefinitions() []*VariableDefinition {119return fd.VariableDefinitions120}
121
122func (fd *FragmentDefinition) GetSelectionSet() *SelectionSet {123return fd.SelectionSet124}
125
126// VariableDefinition implements Node
127type VariableDefinition struct {128Kind string129Loc *Location130Variable *Variable131Type Type
132DefaultValue Value
133}
134
135func NewVariableDefinition(vd *VariableDefinition) *VariableDefinition {136if vd == nil {137vd = &VariableDefinition{}138}139vd.Kind = kinds.VariableDefinition140return vd141}
142
143func (vd *VariableDefinition) GetKind() string {144return vd.Kind145}
146
147func (vd *VariableDefinition) GetLoc() *Location {148return vd.Loc149}
150
151// TypeExtensionDefinition implements Node, Definition
152type TypeExtensionDefinition struct {153Kind string154Loc *Location155Definition *ObjectDefinition156}
157
158func NewTypeExtensionDefinition(def *TypeExtensionDefinition) *TypeExtensionDefinition {159if def == nil {160def = &TypeExtensionDefinition{}161}162return &TypeExtensionDefinition{163Kind: kinds.TypeExtensionDefinition,164Loc: def.Loc,165Definition: def.Definition,166}167}
168
169func (def *TypeExtensionDefinition) GetKind() string {170return def.Kind171}
172
173func (def *TypeExtensionDefinition) GetLoc() *Location {174return def.Loc175}
176
177func (def *TypeExtensionDefinition) GetVariableDefinitions() []*VariableDefinition {178return []*VariableDefinition{}179}
180
181func (def *TypeExtensionDefinition) GetSelectionSet() *SelectionSet {182return &SelectionSet{}183}
184
185func (def *TypeExtensionDefinition) GetOperation() string {186return ""187}
188
189// DirectiveDefinition implements Node, Definition
190type DirectiveDefinition struct {191Kind string192Loc *Location193Name *Name194Description *StringValue195Arguments []*InputValueDefinition196Locations []*Name197}
198
199func NewDirectiveDefinition(def *DirectiveDefinition) *DirectiveDefinition {200if def == nil {201def = &DirectiveDefinition{}202}203return &DirectiveDefinition{204Kind: kinds.DirectiveDefinition,205Loc: def.Loc,206Name: def.Name,207Description: def.Description,208Arguments: def.Arguments,209Locations: def.Locations,210}211}
212
213func (def *DirectiveDefinition) GetKind() string {214return def.Kind215}
216
217func (def *DirectiveDefinition) GetLoc() *Location {218return def.Loc219}
220
221func (def *DirectiveDefinition) GetVariableDefinitions() []*VariableDefinition {222return []*VariableDefinition{}223}
224
225func (def *DirectiveDefinition) GetSelectionSet() *SelectionSet {226return &SelectionSet{}227}
228
229func (def *DirectiveDefinition) GetOperation() string {230return ""231}
232
233func (def *DirectiveDefinition) GetDescription() *StringValue {234return def.Description235}
236