Files
buildx/vendor/github.com/vektah/gqlparser/v2/ast/path.go
Sebastiaan van Stijn 3bcb873b04 vendor: github.com/vektah/gqlparser/v2 v2.5.32
- Add formatter.WithNonIntrospectionBuiltin
- Add a nil check in ArgumentMap
- fix(validator): allow nullable variables for nonnull args with default
- lint and format

full diff: https://github.com/vektah/gqlparser/compare/v2.5.30...v2.5.32

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-07-01 15:31:34 +02:00

73 lines
1.2 KiB
Go

package ast
import (
"bytes"
"encoding/json"
"fmt"
)
var _ json.Unmarshaler = (*Path)(nil)
type Path []PathElement
type PathElement interface {
isPathElement()
}
var (
_ PathElement = PathIndex(0)
_ PathElement = PathName("")
)
func (path Path) String() string {
if path == nil {
return ""
}
var str bytes.Buffer
for i, v := range path {
switch v := v.(type) {
case PathIndex:
fmt.Fprintf(&str, "[%d]", v)
case PathName:
if i != 0 {
str.WriteByte('.')
}
str.WriteString(string(v))
default:
panic(fmt.Sprintf("unknown type: %T", v))
}
}
return str.String()
}
func (path *Path) UnmarshalJSON(b []byte) error {
var vs []any
err := json.Unmarshal(b, &vs)
if err != nil {
return err
}
*path = make([]PathElement, 0, len(vs))
for _, v := range vs {
switch v := v.(type) {
case string:
*path = append(*path, PathName(v))
case int:
*path = append(*path, PathIndex(v))
case float64:
*path = append(*path, PathIndex(int(v)))
default:
return fmt.Errorf("unknown path element type: %T", v)
}
}
return nil
}
type PathIndex int
func (PathIndex) isPathElement() {}
type PathName string
func (PathName) isPathElement() {}