From fcdeb81b34579b3379ef239470f15c55982fcafd Mon Sep 17 00:00:00 2001 From: Ben Kraft Date: Sat, 30 Nov 2024 11:52:38 -0800 Subject: [PATCH] add docs --- docs/CHANGELOG.md | 1 + docs/client_config.md | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index dd69c6f8..f7ae81fc 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -31,6 +31,7 @@ When releasing a new version: See the [documentation](FAQ.md) for how to `subscribe to an API 'subscription' endpoint`. - genqlient now supports double-star globs for schema and query files; see [`genqlient.yaml` docs](genqlient.yaml) for more. - genqlient now generates slices containing all enum values for each enum type. +- genqlient now returns `Is`/`As`-able errors when the HTTP request returns a non-200 status. ### Bug fixes: diff --git a/docs/client_config.md b/docs/client_config.md index b980e53d..80b62410 100644 --- a/docs/client_config.md +++ b/docs/client_config.md @@ -119,7 +119,18 @@ For more on accessing response objects for interfaces and fragments, see the [op ### Handling errors -In addition to the response-struct, each genqlient-generated helper function returns an error. The response-struct will always be initialized (never nil), even on error. If the request returns a valid GraphQL response containing errors, the returned error will be [`As`-able](https://pkg.go.dev/errors#As) as [`gqlerror.List`](https://pkg.go.dev/github.com/vektah/gqlparser/v2/gqlerror#List), and the struct may be partly-populated (if one field failed but another was computed successfully). If the request fails entirely, the error will be another error (e.g. a [`*url.Error`](https://pkg.go.dev/net/url#Error)), and the response will be blank (but still non-nil). +In addition to the response-struct, each genqlient-generated helper function returns an error. The error may be [`As`-able][As] to one of the following: + +- [`gqlerror.List`][gqlerror], if the request returns a valid GraphQL response containing errors; in this case the struct may be partly-populated +- [`graphql.HTTPError`][HTTPError], if there was a valid but non-200 HTTP response +- another error (e.g. a [`*url.Error`][urlError]) + +In case of a GraphQL error, the response-struct may be partly-populated (if one field failed but another was computed successfully). In other cases it will be blank, but it will always be initialized (never nil), even on error. + +[As]: https://pkg.go.dev/errors#As +[gqlerror]: https://pkg.go.dev/github.com/vektah/gqlparser/v2/gqlerror#List +[HTTPError]: https://pkg.go.dev/github.com/Khan/genqlient/graphql#HTTPError +[urlError]: https://pkg.go.dev/net/url#Error For example, you might do one of the following: ```go