aboutsummaryrefslogtreecommitdiffstats
path: root/bug/label.go
blob: ccfa15f4333b792e80c3cda01bc8ff88bde5c266 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package bug

import (
	"fmt"
	"io"
)

type Label string

func (l Label) String() string {
	return string(l)
}

// UnmarshalGQL implements the graphql.Marshaler interface
func (l *Label) UnmarshalGQL(v interface{}) error {
	_, ok := v.(string)
	if !ok {
		return fmt.Errorf("labels must be strings")
	}

	*l = v.(Label)

	return nil
}

// MarshalGQL implements the graphql.Marshaler interface
func (l Label) MarshalGQL(w io.Writer) {
	w.Write([]byte(`"` + l.String() + `"`))
}