github.com/HaswinVidanage/gqlgen@v0.8.1-0.20220609041233-69528c1bf712/example/starwars/models/generated.go (about)

     1  // Code generated by github.com/HaswinVidanage/gqlgen, DO NOT EDIT.
     2  
     3  package models
     4  
     5  import (
     6  	"fmt"
     7  	"io"
     8  	"strconv"
     9  )
    10  
    11  type Character interface {
    12  	IsCharacter()
    13  }
    14  
    15  type SearchResult interface {
    16  	IsSearchResult()
    17  }
    18  
    19  type FriendsEdge struct {
    20  	Cursor string    `json:"cursor"`
    21  	Node   Character `json:"node"`
    22  }
    23  
    24  type PageInfo struct {
    25  	StartCursor string `json:"startCursor"`
    26  	EndCursor   string `json:"endCursor"`
    27  	HasNextPage bool   `json:"hasNextPage"`
    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  var AllEpisode = []Episode{
    48  	EpisodeNewhope,
    49  	EpisodeEmpire,
    50  	EpisodeJedi,
    51  }
    52  
    53  func (e Episode) IsValid() bool {
    54  	switch e {
    55  	case EpisodeNewhope, EpisodeEmpire, EpisodeJedi:
    56  		return true
    57  	}
    58  	return false
    59  }
    60  
    61  func (e Episode) String() string {
    62  	return string(e)
    63  }
    64  
    65  func (e *Episode) UnmarshalGQL(v interface{}) error {
    66  	str, ok := v.(string)
    67  	if !ok {
    68  		return fmt.Errorf("enums must be strings")
    69  	}
    70  
    71  	*e = Episode(str)
    72  	if !e.IsValid() {
    73  		return fmt.Errorf("%s is not a valid Episode", str)
    74  	}
    75  	return nil
    76  }
    77  
    78  func (e Episode) MarshalGQL(w io.Writer) {
    79  	fmt.Fprint(w, strconv.Quote(e.String()))
    80  }
    81  
    82  type LengthUnit string
    83  
    84  const (
    85  	LengthUnitMeter LengthUnit = "METER"
    86  	LengthUnitFoot  LengthUnit = "FOOT"
    87  )
    88  
    89  var AllLengthUnit = []LengthUnit{
    90  	LengthUnitMeter,
    91  	LengthUnitFoot,
    92  }
    93  
    94  func (e LengthUnit) IsValid() bool {
    95  	switch e {
    96  	case LengthUnitMeter, LengthUnitFoot:
    97  		return true
    98  	}
    99  	return false
   100  }
   101  
   102  func (e LengthUnit) String() string {
   103  	return string(e)
   104  }
   105  
   106  func (e *LengthUnit) UnmarshalGQL(v interface{}) error {
   107  	str, ok := v.(string)
   108  	if !ok {
   109  		return fmt.Errorf("enums must be strings")
   110  	}
   111  
   112  	*e = LengthUnit(str)
   113  	if !e.IsValid() {
   114  		return fmt.Errorf("%s is not a valid LengthUnit", str)
   115  	}
   116  	return nil
   117  }
   118  
   119  func (e LengthUnit) MarshalGQL(w io.Writer) {
   120  	fmt.Fprint(w, strconv.Quote(e.String()))
   121  }