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
|
package ast
type DefinitionKind string
const (
Scalar DefinitionKind = "SCALAR"
Object DefinitionKind = "OBJECT"
Interface DefinitionKind = "INTERFACE"
Union DefinitionKind = "UNION"
Enum DefinitionKind = "ENUM"
InputObject DefinitionKind = "INPUT_OBJECT"
)
// Definition is the core type definition object, it includes all of the definable types
// but does *not* cover schema or directives.
//
// @vektah: Javascript implementation has different types for all of these, but they are
// more similar than different and don't define any behaviour. I think this style of
// "some hot" struct works better, at least for go.
//
// Type extensions are also represented by this same struct.
type Definition struct {
Kind DefinitionKind
Description string
Name string
Directives DirectiveList
Interfaces []string // object and input object
Fields FieldList // object and input object
Types []string // union
EnumValues EnumValueList // enum
Position *Position `dump:"-"`
BuiltIn bool `dump:"-"`
BeforeDescriptionComment *CommentGroup
AfterDescriptionComment *CommentGroup
EndOfDefinitionComment *CommentGroup
}
func (d *Definition) IsLeafType() bool {
return d.Kind == Enum || d.Kind == Scalar
}
func (d *Definition) IsAbstractType() bool {
return d.Kind == Interface || d.Kind == Union
}
func (d *Definition) IsCompositeType() bool {
return d.Kind == Object || d.Kind == Interface || d.Kind == Union
}
func (d *Definition) IsInputType() bool {
return d.Kind == Scalar || d.Kind == Enum || d.Kind == InputObject
}
func (d *Definition) OneOf(types ...string) bool {
for _, t := range types {
if d.Name == t {
return true
}
}
return false
}
type FieldDefinition struct {
Description string
Name string
Arguments ArgumentDefinitionList // only for objects
DefaultValue *Value // only for input objects
Type *Type
Directives DirectiveList
Position *Position `dump:"-"`
BeforeDescriptionComment *CommentGroup
AfterDescriptionComment *CommentGroup
}
type ArgumentDefinition struct {
Description string
Name string
DefaultValue *Value
Type *Type
Directives DirectiveList
Position *Position `dump:"-"`
BeforeDescriptionComment *CommentGroup
AfterDescriptionComment *CommentGroup
}
type EnumValueDefinition struct {
Description string
Name string
Directives DirectiveList
Position *Position `dump:"-"`
BeforeDescriptionComment *CommentGroup
AfterDescriptionComment *CommentGroup
}
type DirectiveDefinition struct {
Description string
Name string
Arguments ArgumentDefinitionList
Locations []DirectiveLocation
IsRepeatable bool
Position *Position `dump:"-"`
BeforeDescriptionComment *CommentGroup
AfterDescriptionComment *CommentGroup
}
|