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 BuiltIn bool `dump:"-"`
34}
35
36func (d *Definition) IsLeafType() bool {
37 return d.Kind == Enum || d.Kind == Scalar
38}
39
40func (d *Definition) IsAbstractType() bool {
41 return d.Kind == Interface || d.Kind == Union
42}
43
44func (d *Definition) IsCompositeType() bool {
45 return d.Kind == Object || d.Kind == Interface || d.Kind == Union
46}
47
48func (d *Definition) IsInputType() bool {
49 return d.Kind == Scalar || d.Kind == Enum || d.Kind == InputObject
50}
51
52func (d *Definition) OneOf(types ...string) bool {
53 for _, t := range types {
54 if d.Name == t {
55 return true
56 }
57 }
58 return false
59}
60
61type FieldDefinition struct {
62 Description string
63 Name string
64 Arguments ArgumentDefinitionList // only for objects
65 DefaultValue *Value // only for input objects
66 Type *Type
67 Directives DirectiveList
68 Position *Position `dump:"-"`
69}
70
71type ArgumentDefinition struct {
72 Description string
73 Name string
74 DefaultValue *Value
75 Type *Type
76 Directives DirectiveList
77 Position *Position `dump:"-"`
78}
79
80type EnumValueDefinition struct {
81 Description string
82 Name string
83 Directives DirectiveList
84 Position *Position `dump:"-"`
85}
86
87type DirectiveDefinition struct {
88 Description string
89 Name string
90 Arguments ArgumentDefinitionList
91 Locations []DirectiveLocation
92 Position *Position `dump:"-"`
93}