...

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

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

     1  package ast
     2  
     3  type QueryDocument struct {
     4  	Operations OperationList
     5  	Fragments  FragmentDefinitionList
     6  	Position   *Position `dump:"-"`
     7  	Comment    *CommentGroup
     8  }
     9  
    10  type SchemaDocument struct {
    11  	Schema          SchemaDefinitionList
    12  	SchemaExtension SchemaDefinitionList
    13  	Directives      DirectiveDefinitionList
    14  	Definitions     DefinitionList
    15  	Extensions      DefinitionList
    16  	Position        *Position `dump:"-"`
    17  	Comment         *CommentGroup
    18  }
    19  
    20  func (d *SchemaDocument) Merge(other *SchemaDocument) {
    21  	d.Schema = append(d.Schema, other.Schema...)
    22  	d.SchemaExtension = append(d.SchemaExtension, other.SchemaExtension...)
    23  	d.Directives = append(d.Directives, other.Directives...)
    24  	d.Definitions = append(d.Definitions, other.Definitions...)
    25  	d.Extensions = append(d.Extensions, other.Extensions...)
    26  }
    27  
    28  type Schema struct {
    29  	Query        *Definition
    30  	Mutation     *Definition
    31  	Subscription *Definition
    32  
    33  	Types      map[string]*Definition
    34  	Directives map[string]*DirectiveDefinition
    35  
    36  	PossibleTypes map[string][]*Definition
    37  	Implements    map[string][]*Definition
    38  
    39  	Description string
    40  
    41  	Comment *CommentGroup
    42  }
    43  
    44  // AddTypes is the helper to add types definition to the schema
    45  func (s *Schema) AddTypes(defs ...*Definition) {
    46  	if s.Types == nil {
    47  		s.Types = make(map[string]*Definition)
    48  	}
    49  	for _, def := range defs {
    50  		s.Types[def.Name] = def
    51  	}
    52  }
    53  
    54  func (s *Schema) AddPossibleType(name string, def *Definition) {
    55  	s.PossibleTypes[name] = append(s.PossibleTypes[name], def)
    56  }
    57  
    58  // GetPossibleTypes will enumerate all the definitions for a given interface or union
    59  func (s *Schema) GetPossibleTypes(def *Definition) []*Definition {
    60  	return s.PossibleTypes[def.Name]
    61  }
    62  
    63  func (s *Schema) AddImplements(name string, iface *Definition) {
    64  	s.Implements[name] = append(s.Implements[name], iface)
    65  }
    66  
    67  // GetImplements returns all the interface and union definitions that the given definition satisfies
    68  func (s *Schema) GetImplements(def *Definition) []*Definition {
    69  	return s.Implements[def.Name]
    70  }
    71  
    72  type SchemaDefinition struct {
    73  	Description    string
    74  	Directives     DirectiveList
    75  	OperationTypes OperationTypeDefinitionList
    76  	Position       *Position `dump:"-"`
    77  
    78  	BeforeDescriptionComment *CommentGroup
    79  	AfterDescriptionComment  *CommentGroup
    80  	EndOfDefinitionComment   *CommentGroup
    81  }
    82  
    83  type OperationTypeDefinition struct {
    84  	Operation Operation
    85  	Type      string
    86  	Position  *Position `dump:"-"`
    87  	Comment   *CommentGroup
    88  }
    89  

View as plain text