cli / go-gh

A Go module for interacting with gh and the GitHub API from the command line.
https://pkg.go.dev/github.com/cli/go-gh/v2
MIT License
322 stars 45 forks source link

Export GraphQL error types #35

Closed heaths closed 2 years ago

heaths commented 2 years ago

Similar to HTTPError and HTTPErrorItem already (which was actually HttpErrorItem), export GQLError (was GQLErrorREsponse) and GQLErrorItem (was GQLError). This makes it possible for callers to check the errors and react accordingly, as in cli/cli#5588 where certain GraphQL errors could be filtered out.

heaths commented 2 years ago

A specific use case is a work around for https://github.com/github/feedback/discussions/16168. A ProjectNext object can exist in either an Organization or a User if not already linked to a Repository. But to minimize the number of requests I would ideally query both the root organization and user to figure out a ProjectNext.id. In fact, given both an owner and repo name, I could query all three root objects and use whichever ProjectNext I can, but I need to ignore the other 2 errors.

Technically, the current implementation still populates the response interface{} despite returning an error, but this may not always be the case since its atypical. Relying solely on the error message is also fragile and again relies on implementation details. Instead, just like RESTClent, export the GQLError so they can be used by the caller.

heaths commented 2 years ago

I did rename it in another commit but realized I forgot to push it. 😣