func hasGraphQLName(f reflect.StructField, name string) bool {
	value, ok := f.Tag.Lookup("graphql")
	if !ok {
		return strings.EqualFold(f.Name, name)
	}
	value = strings.TrimSpace(value)  
	if strings.HasPrefix(value, "...") {
		return false
	}
	if i := strings.Index(value, "("); i != -1 {
		value = value[:i]
	}
	if i := strings.Index(value, ":"); i != -1 {
		value = value[:i]
	}
	return strings.TrimSpace(value) == name
}
hasGraphQLName reports whether struct field f has GraphQL name.
package graphqljson
import (
	"bytes"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"reflect"
	"strings"
)
func UnmarshalData(data json.RawMessage, v interface{}) error {
	d := newDecoder(bytes.NewBuffer(data))
	if err := d.Decode(v); err != nil {
		return fmt.Errorf(": %w", err)
	}
	tok, err := d.jsonDecoder.Token()
	switch err {
	case io.EOF:
		return nil
	case nil:
		return fmt.Errorf("invalid token '%v' after top-level value", tok)
	}
	return fmt.Errorf("invalid token '%v' after top-level value", tok)
}
type Decoder struct {
	jsonDecoder *json.Decoder
	parseState []json.Delim
	vs [][]reflect.Value
}
func newDecoder(r io.Reader) *Decoder {
	jsonDecoder := json.NewDecoder(r)
	jsonDecoder.UseNumber()
	return &Decoder{
		jsonDecoder: jsonDecoder,
	}
}
func (d *Decoder) Decode(v interface{}) error {
	rv := reflect.ValueOf(v)
	if rv.Kind() != reflect.Ptr {
		return fmt.Errorf("cannot decode into non-pointer %T", v)
	}
	d.vs = [][]reflect.Value{{rv.Elem()}}
	if err := d.decode(); err != nil {
		return fmt.Errorf(": %w", err)
	}
	return nil
}
func (d *Decoder) decode() error {
	for len(d.vs) > 0 {
		tok, err := d.jsonDecoder.Token()
		if err == io.EOF {
			return errors.New("unexpected end of JSON input")
		} else if err != nil {
			return fmt.Errorf(": %w", err)
		}
		switch {
		case d.state() == '{' && tok != json.Delim('}'):
			key, ok := tok.(string)
			if !ok {
				return errors.New("unexpected non-key in JSON input")
			}
			var matchingFieldValue *reflect.Value
			for i := range d.vs {
				v := d.vs[i][len(d.vs[i])-1]
				if v.Kind() == reflect.Ptr {
					v = v.Elem()
				}
				var f reflect.Value
				if v.Kind() == reflect.Struct {
					f = fieldByGraphQLName(v, key)
					if f.IsValid() {
						matchingFieldValue = &f
					}
				}
				d.vs[i] = append(d.vs[i], f)
			}
			if matchingFieldValue == nil {
				return fmt.Errorf("struct field for %q doesn't exist in any of %v places to unmarshal", key, len(d.vs))
			}
			if matchingFieldValue.Type() == reflect.TypeOf(json.RawMessage{}) {
				var data json.RawMessage
				err = d.jsonDecoder.Decode(&data)
				tok = data
			} else {
				tok, err = d.jsonDecoder.Token()
			}
			if err == io.EOF {
				return errors.New("unexpected end of JSON input")
			} else if err != nil {
				return fmt.Errorf(": %w", err)
			}
		case d.state() == '[' && tok != json.Delim(']'):
			someSliceExist := false
			for i := range d.vs {
				v := d.vs[i][len(d.vs[i])-1]
				if v.Kind() == reflect.Ptr {
					v = v.Elem()
				}
				var f reflect.Value
				if v.Kind() == reflect.Slice {
					v.Set(reflect.Append(v, reflect.Zero(v.Type().Elem())))  
					f = v.Index(v.Len() - 1)
					someSliceExist = true
				}
				d.vs[i] = append(d.vs[i], f)
			}
			if !someSliceExist {
				return fmt.Errorf("slice doesn't exist in any of %v places to unmarshal", len(d.vs))
			}
		}
		switch tok := tok.(type) {
		case string, json.Number, bool, nil, json.RawMessage:
			for i := range d.vs {
				v := d.vs[i][len(d.vs[i])-1]
				if !v.IsValid() {
					continue
				}
				err := unmarshalValue(tok, v)
				if err != nil {
					return fmt.Errorf(": %w", err)
				}
			}
			d.popAllVs()
		case json.Delim:
			switch tok {
			case '{':
				d.pushState(tok)
				frontier := make([]reflect.Value, len(d.vs))  
				for i := range d.vs {
					v := d.vs[i][len(d.vs[i])-1]
					frontier[i] = v
					if v.Kind() == reflect.Ptr && v.IsNil() {
						v.Set(reflect.New(v.Type().Elem()))  
					}
				}
				for len(frontier) > 0 {
					v := frontier[0]
					frontier = frontier[1:]
					if v.Kind() == reflect.Ptr {
						v = v.Elem()
					}
					if v.Kind() != reflect.Struct {
						continue
					}
					for i := 0; i < v.NumField(); i++ {
						if isGraphQLFragment(v.Type().Field(i)) || v.Type().Field(i).Anonymous {
							d.vs = append(d.vs, []reflect.Value{v.Field(i)})
							frontier = append(frontier, v.Field(i))
						}
					}
				}
			case '[':
				d.pushState(tok)
				for i := range d.vs {
					v := d.vs[i][len(d.vs[i])-1]
					if v.Kind() == reflect.Ptr {
						v = v.Elem()
					}
					if v.Kind() != reflect.Slice {
						continue
					}
					v.Set(reflect.MakeSlice(v.Type(), 0, 0))  
				}
			case '}', ']':
				d.popAllVs()
				d.popState()
			default:
				return errors.New("unexpected delimiter in JSON input")
			}
		default:
			return errors.New("unexpected token in JSON input")
		}
	}
	return nil
}
func (d *Decoder) pushState(s json.Delim) {
	d.parseState = append(d.parseState, s)
}
func (d *Decoder) popState() {
	d.parseState = d.parseState[:len(d.parseState)-1]
}
func (d *Decoder) state() json.Delim {
	if len(d.parseState) == 0 {
		return 0
	}
	return d.parseState[len(d.parseState)-1]
}
func (d *Decoder) popAllVs() {
	var nonEmpty [][]reflect.Value
	for i := range d.vs {
		d.vs[i] = d.vs[i][:len(d.vs[i])-1]
		if len(d.vs[i]) > 0 {
			nonEmpty = append(nonEmpty, d.vs[i])
		}
	}
	d.vs = nonEmpty
}
func fieldByGraphQLName(v reflect.Value, name string) reflect.Value {
	for i := 0; i < v.NumField(); i++ {
		if v.Type().Field(i).PkgPath != "" {
			continue
		}
		if hasGraphQLName(v.Type().Field(i), name) {
			return v.Field(i)
		}
	}
	return reflect.Value{}
}