github.com/deliveroo/gqlgen@v0.7.2/example/starwars/models_gen.go (about)

     1  // Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
     2  
     3  package starwars
     4  
     5  import (
     6  	"fmt"
     7  	"io"
     8  	"strconv"
     9  )
    10  
    11  type Character interface {
    12  	IsCharacter()
    13  }
    14  
    15  type FriendsEdge struct {
    16  	Cursor string    `json:"cursor"`
    17  	Node   Character `json:"node"`
    18  }
    19  
    20  type PageInfo struct {
    21  	StartCursor string `json:"startCursor"`
    22  	EndCursor   string `json:"endCursor"`
    23  	HasNextPage bool   `json:"hasNextPage"`
    24  }
    25  
    26  type SearchResult interface {
    27  	IsSearchResult()
    28  }
    29  
    30  type Starship struct {
    31  	ID      string  `json:"id"`
    32  	Name    string  `json:"name"`
    33  	Length  float64 `json:"length"`
    34  	History [][]int `json:"history"`
    35  }
    36  
    37  func (Starship) IsSearchResult() {}
    38  
    39  type Episode string
    40  
    41  const (
    42  	EpisodeNewhope Episode = "NEWHOPE"
    43  	EpisodeEmpire  Episode = "EMPIRE"
    44  	EpisodeJedi    Episode = "JEDI"
    45  )
    46  
    47  func (e Episode) IsValid() bool {
    48  	switch e {
    49  	case EpisodeNewhope, EpisodeEmpire, EpisodeJedi:
    50  		return true
    51  	}
    52  	return false
    53  }
    54  
    55  func (e Episode) String() string {
    56  	return string(e)
    57  }
    58  
    59  func (e *Episode) UnmarshalGQL(v interface{}) error {
    60  	str, ok := v.(string)
    61  	if !ok {
    62  		return fmt.Errorf("enums must be strings")
    63  	}
    64  
    65  	*e = Episode(str)
    66  	if !e.IsValid() {
    67  		return fmt.Errorf("%s is not a valid Episode", str)
    68  	}
    69  	return nil
    70  }
    71  
    72  func (e Episode) MarshalGQL(w io.Writer) {
    73  	fmt.Fprint(w, strconv.Quote(e.String()))
    74  }
    75  
    76  type LengthUnit string
    77  
    78  const (
    79  	LengthUnitMeter LengthUnit = "METER"
    80  	LengthUnitFoot  LengthUnit = "FOOT"
    81  )
    82  
    83  func (e LengthUnit) IsValid() bool {
    84  	switch e {
    85  	case LengthUnitMeter, LengthUnitFoot:
    86  		return true
    87  	}
    88  	return false
    89  }
    90  
    91  func (e LengthUnit) String() string {
    92  	return string(e)
    93  }
    94  
    95  func (e *LengthUnit) UnmarshalGQL(v interface{}) error {
    96  	str, ok := v.(string)
    97  	if !ok {
    98  		return fmt.Errorf("enums must be strings")
    99  	}
   100  
   101  	*e = LengthUnit(str)
   102  	if !e.IsValid() {
   103  		return fmt.Errorf("%s is not a valid LengthUnit", str)
   104  	}
   105  	return nil
   106  }
   107  
   108  func (e LengthUnit) MarshalGQL(w io.Writer) {
   109  	fmt.Fprint(w, strconv.Quote(e.String()))
   110  }