...

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

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

     1  package ast
     2  
     3  type FieldList []*FieldDefinition
     4  
     5  func (l FieldList) ForName(name string) *FieldDefinition {
     6  	for _, it := range l {
     7  		if it.Name == name {
     8  			return it
     9  		}
    10  	}
    11  	return nil
    12  }
    13  
    14  type EnumValueList []*EnumValueDefinition
    15  
    16  func (l EnumValueList) ForName(name string) *EnumValueDefinition {
    17  	for _, it := range l {
    18  		if it.Name == name {
    19  			return it
    20  		}
    21  	}
    22  	return nil
    23  }
    24  
    25  type DirectiveList []*Directive
    26  
    27  func (l DirectiveList) ForName(name string) *Directive {
    28  	for _, it := range l {
    29  		if it.Name == name {
    30  			return it
    31  		}
    32  	}
    33  	return nil
    34  }
    35  
    36  func (l DirectiveList) ForNames(name string) []*Directive {
    37  	resp := []*Directive{}
    38  	for _, it := range l {
    39  		if it.Name == name {
    40  			resp = append(resp, it)
    41  		}
    42  	}
    43  	return resp
    44  }
    45  
    46  type OperationList []*OperationDefinition
    47  
    48  func (l OperationList) ForName(name string) *OperationDefinition {
    49  	if name == "" && len(l) == 1 {
    50  		return l[0]
    51  	}
    52  	for _, it := range l {
    53  		if it.Name == name {
    54  			return it
    55  		}
    56  	}
    57  	return nil
    58  }
    59  
    60  type FragmentDefinitionList []*FragmentDefinition
    61  
    62  func (l FragmentDefinitionList) ForName(name string) *FragmentDefinition {
    63  	for _, it := range l {
    64  		if it.Name == name {
    65  			return it
    66  		}
    67  	}
    68  	return nil
    69  }
    70  
    71  type VariableDefinitionList []*VariableDefinition
    72  
    73  func (l VariableDefinitionList) ForName(name string) *VariableDefinition {
    74  	for _, it := range l {
    75  		if it.Variable == name {
    76  			return it
    77  		}
    78  	}
    79  	return nil
    80  }
    81  
    82  type ArgumentList []*Argument
    83  
    84  func (l ArgumentList) ForName(name string) *Argument {
    85  	for _, it := range l {
    86  		if it.Name == name {
    87  			return it
    88  		}
    89  	}
    90  	return nil
    91  }
    92  
    93  type ArgumentDefinitionList []*ArgumentDefinition
    94  
    95  func (l ArgumentDefinitionList) ForName(name string) *ArgumentDefinition {
    96  	for _, it := range l {
    97  		if it.Name == name {
    98  			return it
    99  		}
   100  	}
   101  	return nil
   102  }
   103  
   104  type SchemaDefinitionList []*SchemaDefinition
   105  
   106  type DirectiveDefinitionList []*DirectiveDefinition
   107  
   108  func (l DirectiveDefinitionList) ForName(name string) *DirectiveDefinition {
   109  	for _, it := range l {
   110  		if it.Name == name {
   111  			return it
   112  		}
   113  	}
   114  	return nil
   115  }
   116  
   117  type DefinitionList []*Definition
   118  
   119  func (l DefinitionList) ForName(name string) *Definition {
   120  	for _, it := range l {
   121  		if it.Name == name {
   122  			return it
   123  		}
   124  	}
   125  	return nil
   126  }
   127  
   128  type OperationTypeDefinitionList []*OperationTypeDefinition
   129  
   130  func (l OperationTypeDefinitionList) ForType(name string) *OperationTypeDefinition {
   131  	for _, it := range l {
   132  		if it.Type == name {
   133  			return it
   134  		}
   135  	}
   136  	return nil
   137  }
   138  
   139  type ChildValueList []*ChildValue
   140  
   141  func (v ChildValueList) ForName(name string) *Value {
   142  	for _, f := range v {
   143  		if f.Name == name {
   144  			return f.Value
   145  		}
   146  	}
   147  	return nil
   148  }
   149  

View as plain text