You can import types directly from @octokit/graphql-schema to provide type safety when using @octokit/graphql. This allows you to cast the results of a GraphQL query to the specific shape defined by the GitHub schema.
import { graphql } from "@octokit/graphql";
import { Repository } from "@octokit/graphql-schema";
const { repository } = await graphql<{ repository: Repository }>(
`
{
repository(owner: "octokit", name: "graphql.js") {
issues(last: 3) {
edges {
node {
title
}
}
}
}
}
`,
{
headers: {
authorization: `token secret123`,
},
},
);