...

Source file src/github.com/vektah/gqlparser/v2/ast/definition.go

Documentation: github.com/vektah/gqlparser/v2/ast

     1  package ast
     2  
     3  type DefinitionKind string
     4  
     5  const (
     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  // Definition 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.
    22  type 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  	BeforeDescriptionComment *CommentGroup
    36  	AfterDescriptionComment  *CommentGroup
    37  	EndOfDefinitionComment   *CommentGroup
    38  }
    39  
    40  func (d *Definition) IsLeafType() bool {
    41  	return d.Kind == Enum || d.Kind == Scalar
    42  }
    43  
    44  func (d *Definition) IsAbstractType() bool {
    45  	return d.Kind == Interface || d.Kind == Union
    46  }
    47  
    48  func (d *Definition) IsCompositeType() bool {
    49  	return d.Kind == Object || d.Kind == Interface || d.Kind == Union
    50  }
    51  
    52  func (d *Definition) IsInputType() bool {
    53  	return d.Kind == Scalar || d.Kind == Enum || d.Kind == InputObject
    54  }
    55  
    56  func (d *Definition) OneOf(types ...string) bool {
    57  	for _, t := range types {
    58  		if d.Name == t {
    59  			return true
    60  		}
    61  	}
    62  	return false
    63  }
    64  
    65  type FieldDefinition struct {
    66  	Description  string
    67  	Name         string
    68  	Arguments    ArgumentDefinitionList // only for objects
    69  	DefaultValue *Value                 // only for input objects
    70  	Type         *Type
    71  	Directives   DirectiveList
    72  	Position     *Position `dump:"-"`
    73  
    74  	BeforeDescriptionComment *CommentGroup
    75  	AfterDescriptionComment  *CommentGroup
    76  }
    77  
    78  type ArgumentDefinition struct {
    79  	Description  string
    80  	Name         string
    81  	DefaultValue *Value
    82  	Type         *Type
    83  	Directives   DirectiveList
    84  	Position     *Position `dump:"-"`
    85  
    86  	BeforeDescriptionComment *CommentGroup
    87  	AfterDescriptionComment  *CommentGroup
    88  }
    89  
    90  type EnumValueDefinition struct {
    91  	Description string
    92  	Name        string
    93  	Directives  DirectiveList
    94  	Position    *Position `dump:"-"`
    95  
    96  	BeforeDescriptionComment *CommentGroup
    97  	AfterDescriptionComment  *CommentGroup
    98  }
    99  
   100  type DirectiveDefinition struct {
   101  	Description  string
   102  	Name         string
   103  	Arguments    ArgumentDefinitionList
   104  	Locations    []DirectiveLocation
   105  	IsRepeatable bool
   106  	Position     *Position `dump:"-"`
   107  
   108  	BeforeDescriptionComment *CommentGroup
   109  	AfterDescriptionComment  *CommentGroup
   110  }
   111  

View as plain text