2020-09-18 16:34:49 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
// Arguments to format are:
|
|
|
|
// [1]: type name
|
|
|
|
const gqlgenMethods = `
|
|
|
|
// MarshalGQL implements the graphql.Marshaler interface for %[1]s
|
|
|
|
func (i %[1]s) MarshalGQL(w io.Writer) {
|
2022-11-17 19:20:30 +03:00
|
|
|
fmt.Fprint(w, strconv.Quote(i.String()))
|
2020-09-18 16:34:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalGQL implements the graphql.Unmarshaler interface for %[1]s
|
|
|
|
func (i *%[1]s) UnmarshalGQL(value interface{}) error {
|
2022-11-17 19:20:30 +03:00
|
|
|
str, ok := value.(string)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("%[1]s should be a string, got %%T", value)
|
|
|
|
}
|
2020-09-18 16:34:49 +03:00
|
|
|
|
2022-11-17 19:20:30 +03:00
|
|
|
var err error
|
|
|
|
*i, err = %[1]sString(str)
|
|
|
|
return err
|
2020-09-18 16:34:49 +03:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
func (g *Generator) buildGQLGenMethods(runs [][]Value, typeName string) {
|
|
|
|
g.Printf(gqlgenMethods, typeName)
|
|
|
|
}
|