github.com/deliveroo/gqlgen@v0.7.2/graphql/introspection/schema.go (about)

     1  package introspection
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/vektah/gqlparser/ast"
     7  )
     8  
     9  type Schema struct {
    10  	schema *ast.Schema
    11  }
    12  
    13  func (s *Schema) Types() []Type {
    14  	var types []Type
    15  	for _, typ := range s.schema.Types {
    16  		if strings.HasPrefix(typ.Name, "__") {
    17  			continue
    18  		}
    19  		types = append(types, *WrapTypeFromDef(s.schema, typ))
    20  	}
    21  	return types
    22  }
    23  
    24  func (s *Schema) QueryType() *Type {
    25  	return WrapTypeFromDef(s.schema, s.schema.Query)
    26  }
    27  
    28  func (s *Schema) MutationType() *Type {
    29  	return WrapTypeFromDef(s.schema, s.schema.Mutation)
    30  }
    31  
    32  func (s *Schema) SubscriptionType() *Type {
    33  	return WrapTypeFromDef(s.schema, s.schema.Subscription)
    34  }
    35  
    36  func (s *Schema) Directives() []Directive {
    37  	var res []Directive
    38  
    39  	for _, d := range s.schema.Directives {
    40  		res = append(res, s.directiveFromDef(d))
    41  	}
    42  
    43  	return res
    44  }
    45  
    46  func (s *Schema) directiveFromDef(d *ast.DirectiveDefinition) Directive {
    47  	var locs []string
    48  	for _, loc := range d.Locations {
    49  		locs = append(locs, string(loc))
    50  	}
    51  
    52  	var args []InputValue
    53  	for _, arg := range d.Arguments {
    54  		args = append(args, InputValue{
    55  			Name:         arg.Name,
    56  			Description:  arg.Description,
    57  			DefaultValue: defaultValue(arg.DefaultValue),
    58  			Type:         WrapTypeFromType(s.schema, arg.Type),
    59  		})
    60  	}
    61  
    62  	return Directive{
    63  		Name:        d.Name,
    64  		Description: d.Description,
    65  		Locations:   locs,
    66  		Args:        args,
    67  	}
    68  }