Skip to content

feat(gqlerrors): support custom path per error via PathError interface#54

Merged
haru0017 merged 1 commit intomainfrom
feat/support-custom-path-per-error
Feb 24, 2026
Merged

feat(gqlerrors): support custom path per error via PathError interface#54
haru0017 merged 1 commit intomainfrom
feat/support-custom-path-per-error

Conversation

@haru0017
Copy link
Contributor

Issue

N/A

TL; DR

  • Enable errors to specify custom paths, overriding the default field path

Task summary / Change details

  • Add PathError interface in gqlerrors/formatted.go
  • Update FormatError to check for PathError and use custom path
  • Add tests for custom paths, combined with extensions, and multiple errors

Usage:

type ValidationError struct {
    Msg       string
    FieldPath []interface{}
}

func (e *ValidationError) Error() string       { return e.Msg }
func (e *ValidationError) Path() []interface{} { return e.FieldPath }

func resolve(p graphql.ResolveParams) (interface{}, error) {
    return nil, &ValidationError{
        Msg:       "Name is required",
        FieldPath: []interface{}{"createUser", "input", "name"},
    }
}

Result:

{
  "errors": [
    {"message": "Name is required", "path": ["createUser", "input", "name"]}
  ]
}

Backward compatible - errors without PathError work as before.

@haru0017 haru0017 self-assigned this Feb 24, 2026
@haru0017 haru0017 marked this pull request as ready for review February 24, 2026 01:24
@haru0017 haru0017 requested a review from a team as a code owner February 24, 2026 01:24
Copy link
Contributor

@k1LoW k1LoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@haru0017 haru0017 merged commit d0e93ef into main Feb 24, 2026
1 check passed
@haru0017 haru0017 deleted the feat/support-custom-path-per-error branch February 24, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants