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

     1  // Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
     2  
     3  package todo
     4  
     5  import (
     6  	"fmt"
     7  	"io"
     8  	"strconv"
     9  )
    10  
    11  // Passed to createTodo to create a new todo
    12  type TodoInput struct {
    13  	Text string `json:"text"`
    14  	Done *bool  `json:"done"`
    15  }
    16  
    17  type Role string
    18  
    19  const (
    20  	RoleAdmin Role = "ADMIN"
    21  	RoleOwner Role = "OWNER"
    22  )
    23  
    24  func (e Role) IsValid() bool {
    25  	switch e {
    26  	case RoleAdmin, RoleOwner:
    27  		return true
    28  	}
    29  	return false
    30  }
    31  
    32  func (e Role) String() string {
    33  	return string(e)
    34  }
    35  
    36  func (e *Role) UnmarshalGQL(v interface{}) error {
    37  	str, ok := v.(string)
    38  	if !ok {
    39  		return fmt.Errorf("enums must be strings")
    40  	}
    41  
    42  	*e = Role(str)
    43  	if !e.IsValid() {
    44  		return fmt.Errorf("%s is not a valid Role", str)
    45  	}
    46  	return nil
    47  }
    48  
    49  func (e Role) MarshalGQL(w io.Writer) {
    50  	fmt.Fprint(w, strconv.Quote(e.String()))
    51  }