Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminjkraft committed Nov 30, 2024
1 parent 892c8a0 commit fcdeb81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
13 changes: 12 additions & 1 deletion docs/client_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fcdeb81

Please sign in to comment.