The Linear GraphQL API can be queried directly by passing a raw GraphQL query to the LinearGraphQLClient:
constgraphQLClient=linearClient.client;constcycle=awaitgraphQLClient.rawRequest(` query cycle($id: String!) { cycle(id: $id) { id name completedAt } }`, { id:"cycle-id" });
Custom GraphQL Client
In order to use a custom GraphQL Client, the Linear SDK must be extended and provided with a request function:
import { LinearError, LinearFetch, LinearRequest, LinearSdk, parseLinearError, UserConnection } from"@linear/sdk";import { DocumentNode, GraphQLClient, print } from"graphql";import { CustomGraphqlClient } from"./graphql-client";/** Create a custom client configured with the Linear API base url and API key */constcustomGraphqlClient=newCustomGraphqlClient("https://api.linear.app/graphql", { headers: { Authorization: apiKey },});/** Create the custom request function */constcustomLinearRequest:LinearRequest= <Response,Variables>( document:DocumentNode, variables?:Variables) => {/** The request must take a GraphQL document and variables, then return a promise for the result */returncustomGraphqlClient.request<Data>(print(document), variables).catch(error => {/** Optionally catch and parse errors from the Linear API */throwparseLinearError(error); });};/** Extend the Linear SDK to provide a request function using the custom client */classCustomLinearClientextendsLinearSdk {publicconstructor() {super(customLinearRequest); }}/** Create an instance of the custom client */constcustomLinearClient=newCustomLinearClient();/** Use the custom client as if it were the Linear Client */asyncfunctiongetUsers():LinearFetch<UserConnection> {constusers=awaitcustomLinearClient.users();return users;}