Documentation ¶
Overview ¶
Package gqldecode provides a decoder that unmarshals GraphQL input arguments into a struct. The struct for the input arguments is annotated with tags similar to the stdlib json parser, but instead of "json" the key "gql" is used. The options "nonzero" and "plane0" can be used to signify that the field should not be the zero value and that a string field must be plan0 utf8 (i.e. no emoji).
Example ¶
type Artist struct { Name string `gql:"name,nonzero,plane0"` Age int `gql:"age"` Albums []string `gql:"albums"` } args := map[string]any{ "name": "Jimi Hendrix", "age": 75, "albums": []any{ "Are You Experienced", "Axis: Bold as Love", "Electric Ladyland", }, } var artist Artist err := Decode(args, &artist) if err != nil { fmt.Println("error:", err) } fmt.Printf("%+v", artist)
Output: {Name:Jimi Hendrix Age:75 Albums:[Are You Experienced Axis: Bold as Love Electric Ladyland]}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode parses a map of strings to interfaces, as provided by the graphql library, into the provided out interface.
func IsValidPlane0Unicode ¶
IsValidPlane0Unicode returns true iff the provided string only has valid plane 0 unicode (no emoji)
Types ¶
type ValidationFailedError ¶
ValidationFailedError is returned if the input doesn't match the expected output format.
func (*ValidationFailedError) Error ¶
func (e *ValidationFailedError) Error() string