1package ast
2
3type DefinitionKind string
4
5const (
6 Scalar DefinitionKind = "SCALAR"
7 Object DefinitionKind = "OBJECT"
8 Interface DefinitionKind = "INTERFACE"
9 Union DefinitionKind = "UNION"
10 Enum DefinitionKind = "ENUM"
11 InputObject DefinitionKind = "INPUT_OBJECT"
12)
13
14// ObjectDefinition is the core type definition object, it includes all of the definable types
15// but does *not* cover schema or directives.
16//
17// @vektah: Javascript implementation has different types for all of these, but they are
18// more similar than different and don't define any behaviour. I think this style of
19// "some hot" struct works better, at least for go.
20//
21// Type extensions are also represented by this same struct.
22type Definition struct {
23 Kind DefinitionKind
24 Description string
25 Name string
26 Directives DirectiveList
27 Interfaces []string // object and input object
28 Fields FieldList // object and input object
29 Types []string // union
30 EnumValues EnumValueList // enum
31
32 Position *Position `dump:"-"`
33}
34
35func (d *Definition) IsLeafType() bool {
36 return d.Kind == Enum || d.Kind == Scalar
37}
38
39func (d *Definition) IsAbstractType() bool {
40 return d.Kind == Interface || d.Kind == Union
41}
42
43func (d *Definition) IsCompositeType() bool {
44 return d.Kind == Object || d.Kind == Interface || d.Kind == Union
45}
46
47func (d *Definition) IsInputType() bool {
48 return d.Kind == Scalar || d.Kind == Enum || d.Kind == InputObject
49}
50
51func (d *Definition) OneOf(types ...string) bool {
52 for _, t := range types {
53 if d.Name == t {
54 return true
55 }
56 }
57 return false
58}
59
60type FieldDefinition struct {
61 Description string
62 Name string
63 Arguments ArgumentDefinitionList // only for objects
64 DefaultValue *Value // only for input objects
65 Type *Type
66 Directives DirectiveList
67 Position *Position `dump:"-"`
68}
69
70type ArgumentDefinition struct {
71 Description string
72 Name string
73 DefaultValue *Value
74 Type *Type
75 Directives DirectiveList
76 Position *Position `dump:"-"`
77}
78
79type EnumValueDefinition struct {
80 Description string
81 Name string
82 Directives DirectiveList
83 Position *Position `dump:"-"`
84}
85
86type DirectiveDefinition struct {
87 Description string
88 Name string
89 Arguments ArgumentDefinitionList
90 Locations []DirectiveLocation
91 Position *Position `dump:"-"`
92}