github.com/shippio/gqlgen@v0.0.0-20220912092219-633ea699ef07/graphql/introspection/introspection.go (about)

     1  // introspection implements the spec defined in https://github.com/facebook/graphql/blob/master/spec/Section%204%20--%20Introspection.md#schema-introspection
     2  package introspection
     3  
     4  import "github.com/vektah/gqlparser/v2/ast"
     5  
     6  type (
     7  	Directive struct {
     8  		Name         string
     9  		description  string
    10  		Locations    []string
    11  		Args         []InputValue
    12  		IsRepeatable bool
    13  	}
    14  
    15  	EnumValue struct {
    16  		Name        string
    17  		description string
    18  		deprecation *ast.Directive
    19  	}
    20  
    21  	Field struct {
    22  		Name        string
    23  		description string
    24  		Type        *Type
    25  		Args        []InputValue
    26  		deprecation *ast.Directive
    27  	}
    28  
    29  	InputValue struct {
    30  		Name         string
    31  		description  string
    32  		DefaultValue *string
    33  		Type         *Type
    34  	}
    35  )
    36  
    37  func WrapSchema(schema *ast.Schema) *Schema {
    38  	return &Schema{schema: schema}
    39  }
    40  
    41  func (f *EnumValue) Description() *string {
    42  	if f.description == "" {
    43  		return nil
    44  	}
    45  	return &f.description
    46  }
    47  
    48  func (f *EnumValue) IsDeprecated() bool {
    49  	return f.deprecation != nil
    50  }
    51  
    52  func (f *EnumValue) DeprecationReason() *string {
    53  	if f.deprecation == nil {
    54  		return nil
    55  	}
    56  
    57  	reason := f.deprecation.Arguments.ForName("reason")
    58  	if reason == nil {
    59  		return nil
    60  	}
    61  
    62  	return &reason.Value.Raw
    63  }
    64  
    65  func (f *Field) Description() *string {
    66  	if f.description == "" {
    67  		return nil
    68  	}
    69  	return &f.description
    70  }
    71  
    72  func (f *Field) IsDeprecated() bool {
    73  	return f.deprecation != nil
    74  }
    75  
    76  func (f *Field) DeprecationReason() *string {
    77  	if f.deprecation == nil {
    78  		return nil
    79  	}
    80  
    81  	reason := f.deprecation.Arguments.ForName("reason")
    82  	if reason == nil {
    83  		return nil
    84  	}
    85  
    86  	return &reason.Value.Raw
    87  }
    88  
    89  func (f *InputValue) Description() *string {
    90  	if f.description == "" {
    91  		return nil
    92  	}
    93  	return &f.description
    94  }
    95  
    96  func (f *Directive) Description() *string {
    97  	if f.description == "" {
    98  		return nil
    99  	}
   100  	return &f.description
   101  }