github.com/fortexxx/gqlgen@v0.10.3-0.20191216030626-ca5ea8b21ead/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/ast"
     5  
     6  type (
     7  	Directive struct {
     8  		Name        string
     9  		Description string
    10  		Locations   []string
    11  		Args        []InputValue
    12  	}
    13  
    14  	EnumValue struct {
    15  		Name        string
    16  		Description string
    17  		deprecation *ast.Directive
    18  	}
    19  
    20  	Field struct {
    21  		Name        string
    22  		Description string
    23  		Type        *Type
    24  		Args        []InputValue
    25  		deprecation *ast.Directive
    26  	}
    27  
    28  	InputValue struct {
    29  		Name         string
    30  		Description  string
    31  		DefaultValue *string
    32  		Type         *Type
    33  	}
    34  
    35  	Service struct {
    36  		SDL string `json:"sdl"`
    37  	}
    38  )
    39  
    40  func WrapSchema(schema *ast.Schema) *Schema {
    41  	return &Schema{schema: schema}
    42  }
    43  
    44  func (f *EnumValue) IsDeprecated() bool {
    45  	return f.deprecation != nil
    46  }
    47  
    48  func (f *EnumValue) DeprecationReason() *string {
    49  	if f.deprecation == nil {
    50  		return nil
    51  	}
    52  
    53  	reason := f.deprecation.Arguments.ForName("reason")
    54  	if reason == nil {
    55  		return nil
    56  	}
    57  
    58  	return &reason.Value.Raw
    59  }
    60  
    61  func (f *Field) IsDeprecated() bool {
    62  	return f.deprecation != nil
    63  }
    64  
    65  func (f *Field) DeprecationReason() *string {
    66  	if f.deprecation == nil {
    67  		return nil
    68  	}
    69  
    70  	reason := f.deprecation.Arguments.ForName("reason")
    71  	if reason == nil {
    72  		return nil
    73  	}
    74  
    75  	return &reason.Value.Raw
    76  }