$ show octokit/graphql.js
@octokit/graphql.js is a lightweight, purpose-built JavaScript library for making GraphQL queries to the GitHub API. It wraps the `@octokit/request` HTTP client to handle authentication, variables, error parsing, and GitHub Enterprise Server base URL normalization. The primary entry point is the `graphql` function, which accepts a query string and optional parameters (variables, headers, operation name) and returns a promise of the response data. It also exposes a `withCustomRequest` factory for injecting a custom request instance, a `GraphqlResponseError` class for structured error handling, and a `withDefaults` method for creating pre-configured instances. The library is fully typed with TypeScript, supports ESM and bundling, and follows the Octokit ecosystem conventions. It does not handle pagination or subscription – it is purely a thin GraphQL client for the GitHub API.
The LLM identified 3 files worth highlighting for reuse:
Defines `GraphqlResponseError`, a custom error class that encapsulates the request options, response headers, and the full GraphQL response data (including errors and partial data). It constructs a human-readable message from error details. This pattern is reusable in any API client that needs to preserve verbose error context and can be extracted independently.
Implements a `withDefaults` function that creates a new graphql client with pre-set defaults (e.g., authentication headers, base URL). It uses closure to merge new defaults with existing ones and returns an augmented function that also exposes `.defaults` and `.endpoint`. This is a clean implementation of the 'defaults-currying' pattern often used in API clients and could be adapted for similar function factories.
Core graphql request logic: parses the input (string query vs. options object), separates non-variable options (method, headers, url, etc.) from GraphQL variables, validates forbidden variable names, and handles GitHub Enterprise Server base URL conversion from `/api/v3` to `/api/graphql`. The variable extraction and GHES normalization logic are non-trivial and demonstrate good defensive programming.