github.com/humans-group/gqlgen@v0.7.2/example/type-system-extension/models_gen.go (about)

     1  // Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
     2  
     3  package type_system_extension
     4  
     5  import (
     6  	"fmt"
     7  	"io"
     8  	"strconv"
     9  )
    10  
    11  type Data interface {
    12  	IsData()
    13  }
    14  
    15  type Node interface {
    16  	IsNode()
    17  }
    18  
    19  type Todo struct {
    20  	ID       string `json:"id"`
    21  	Text     string `json:"text"`
    22  	State    State  `json:"state"`
    23  	Verified bool   `json:"verified"`
    24  }
    25  
    26  func (Todo) IsNode() {}
    27  func (Todo) IsData() {}
    28  
    29  type TodoInput struct {
    30  	Text string `json:"text"`
    31  }
    32  
    33  type State string
    34  
    35  const (
    36  	StateNotYet State = "NOT_YET"
    37  	StateDone   State = "DONE"
    38  )
    39  
    40  func (e State) IsValid() bool {
    41  	switch e {
    42  	case StateNotYet, StateDone:
    43  		return true
    44  	}
    45  	return false
    46  }
    47  
    48  func (e State) String() string {
    49  	return string(e)
    50  }
    51  
    52  func (e *State) UnmarshalGQL(v interface{}) error {
    53  	str, ok := v.(string)
    54  	if !ok {
    55  		return fmt.Errorf("enums must be strings")
    56  	}
    57  
    58  	*e = State(str)
    59  	if !e.IsValid() {
    60  		return fmt.Errorf("%s is not a valid State", str)
    61  	}
    62  	return nil
    63  }
    64  
    65  func (e State) MarshalGQL(w io.Writer) {
    66  	fmt.Fprint(w, strconv.Quote(e.String()))
    67  }