Skip to content

Commit f697627

Browse files
authored
feat(types): expose GraphQlQueryResponseData type (#256)
1 parent 9ddc5b8 commit f697627

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
- [Pass query together with headers and variables](#pass-query-together-with-headers-and-variables)
1515
- [Use with GitHub Enterprise](#use-with-github-enterprise)
1616
- [Use custom `@octokit/request` instance](#use-custom-octokitrequest-instance)
17+
- [TypeScript](#typescript)
18+
- [Additional Types](#additional-types)
1719
- [Errors](#errors)
1820
- [Partial responses](#partial-responses)
1921
- [Writing tests](#writing-tests)
@@ -247,6 +249,18 @@ await myGraphql(`
247249
// requestCounter is now 2
248250
```
249251

252+
## TypeScript
253+
254+
`@octokit/graphql` is exposing proper types for its usage with TypeScript projects.
255+
256+
### Additional Types
257+
258+
Additionally, `GraphQlQueryResponseData` has been exposed to users:
259+
260+
```ts
261+
import type { GraphQlQueryResponseData } from "octokit/graphql";
262+
```
263+
250264
## Errors
251265

252266
In case of a GraphQL error, `error.message` is set to the first error from the response’s `errors` array. All errors can be accessed at `error.errors`. `error.request` has the request options such as query, variables and headers set for easier debugging.
@@ -269,14 +283,14 @@ try {
269283
} catch (error) {
270284
// server responds with
271285
// {
272-
// "data": null,
273-
// "errors": [{
274-
// "message": "Field 'bioHtml' doesn't exist on type 'User'",
275-
// "locations": [{
276-
// "line": 3,
277-
// "column": 5
278-
// }]
279-
// }]
286+
// "data": null,
287+
// "errors": [{
288+
// "message": "Field 'bioHtml' doesn't exist on type 'User'",
289+
// "locations": [{
290+
// "line": 3,
291+
// "column": 5
292+
// }]
293+
// }]
280294
// }
281295

282296
console.log("Request failed:", error.request); // { query, variables: {}, headers: { authorization: 'token secret123' } }

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const graphql = withDefaults(request, {
1313
url: "/graphql",
1414
});
1515

16+
export { GraphQlQueryResponseData } from "./types";
17+
1618
export function withCustomRequest(customRequest: typeof request) {
1719
return withDefaults(customRequest, {
1820
method: "POST",

0 commit comments

Comments
 (0)