{{/* (the blank lines at the start are intentional, to separate the helper from the function it follows) */}} func __unmarshal{{.GoName}}(b []byte, v *{{.GoName}}) error { if string(b) == "null" { return nil } var tn struct { TypeName string `json:"__typename"` } err := {{ref "encoding/json.Unmarshal"}}(b, &tn) if err != nil { return err } switch tn.TypeName { {{range .Implementations -}} case "{{.GraphQLName}}": *v = new({{.GoName}}) return {{ref "encoding/json.Unmarshal"}}(b, *v) {{end -}} case "": {{/* Likely if we're making a request to a mock server and the author of the mock didn't know to add __typename, so give a special error. */ -}} return {{ref "fmt.Errorf"}}( "Response was missing {{.GraphQLName}}.__typename") default: return {{ref "fmt.Errorf"}}( `Unexpected concrete type for {{.GoName}}: "%v"`, tn.TypeName) } }