Fetching & Modifying Data

Queries

Some models can be fetched from the Linear Client without any arguments:
1
const me = await linearClient.viewer;
2
const org = await linearClient.organization;
Copied!
Other models are exposed as connections, and return a list of nodes:
1
const issues = await linearClient.issues();
2
const firstIssue = issues.nodes[0];
Copied!
All required variables are passed as the first arguments:
1
const user = await linearClient.user("user-id");
2
const team = await linearClient.team("team-id");
Copied!
Any optional variables are passed into the last argument as an object:
1
const fiftyProjects = await linearClient.projects({ first: 50 });
2
const allComments = await linearClient.comments({ includeArchived: true });
Copied!
Most models expose operations to fetch other models:
1
const me = await linearClient.viewer;
2
const myIssues = await me.assignedIssues();
3
const myFirstIssue = myIssues.nodes[0];
4
const myFirstIssueComments = await myFirstIssue.comments();
5
const myFirstIssueFirstComment = myFirstIssueComments.nodes[0];
6
const myFirstIssueFirstCommentUser = await myFirstIssueFirstComment.user;
Copied!
NOTE: Parenthesis is required only if the operation takes an optional variables object.

Mutations

To create a model, call the Linear Client mutation and pass in the input object:
1
const teams = await linearClient.teams();
2
const team = teams.nodes[0];
3
if (team.id) {
4
await linearClient.issueCreate({ teamId: team.id, title: "My Created Issue" });
5
}
Copied!
To update a model, call the Linear Client mutation and pass in the required variables and input object:
1
const me = await linearClient.viewer;
2
if (me.id) {
3
await linearClient.userUpdate(me.id, { displayName: "Alice" });
4
}
Copied!
Or call the mutation from the model:
1
const me = await linearClient.viewer;
2
await me.update({ displayName: "Alice" });
Copied!
All mutations are exposed in the same way:
1
const projects = await linearClient.projects();
2
const project = projects.nodes[0];
3
if (project.id) {
4
await linearClient.projectArchive(project.id);
5
await project.archive();
6
}
Copied!
Mutations will often return a success boolean and the mutated entity:
1
const commentPayload = await linearClient.commentCreate({ issueId: "some-issue-id" });
2
if (commentPayload.success) {
3
return commentPayload.comment;
4
} else {
5
return new Error("Failed to create comment");
6
}
Copied!

Pagination

Connection models have helpers to fetch the next and previous pages of results:
1
const issues = await linearClient.issues({ after: "some-issue-cursor", first: 10 });
2
const nextIssues = await issues.fetchNext();
3
const prevIssues = await issues.fetchPrevious();
Copied!
Pagination info is exposed and can be passed to the query operations. This uses the Relay Connection spec:
1
const issues = await linearClient.issues();
2
const hasMoreIssues = issues.pageInfo.hasNextPage;
3
const issuesEndCursor = issues.pageInfo.endCursor;
4
const moreIssues = await linearClient.issues({ after: issuesEndCursor, first: 10 });
Copied!
Results can be ordered using the orderBy optional variable:
1
import { LinearDocument } from "@linear/sdk";
2
3
const issues = await linearClient.issues({ orderBy: LinearDocument.PaginationOrderBy.UpdatedAt });
Copied!
Last modified 4mo ago