1 | |
2 |
|
3 | |
4 | * List Projects |
5 | * List the projects in the workspace, most recently updated first. Paginate with after = pageInfo.endCursor. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Linear, |
9 | include_archived: boolean = false, |
10 | first: number = 50, |
11 | after: string | undefined |
12 | ) { |
13 | const response = await fetch("https://api.linear.app/graphql", { |
14 | method: "POST", |
15 | headers: { |
16 | Authorization: auth.apiKey, |
17 | "Content-Type": "application/json", |
18 | Accept: "application/json", |
19 | }, |
20 | body: JSON.stringify({ |
21 | query: `query ($includeArchived: Boolean, $first: Int, $after: String) { projects(includeArchived: $includeArchived, first: $first, after: $after, orderBy: updatedAt) { nodes { id name description url progress startDate targetDate status { id name type } lead { id name } teams { nodes { id key } } } pageInfo { hasNextPage endCursor } } }`, |
22 | variables: { |
23 | includeArchived: include_archived, |
24 | first, |
25 | after: after || undefined, |
26 | }, |
27 | }), |
28 | }) |
29 |
|
30 | if (!response.ok) { |
31 | throw new Error(`${response.status} ${await response.text()}`) |
32 | } |
33 |
|
34 | const { data, errors } = await response.json() |
35 | if (errors) { |
36 | throw new Error(JSON.stringify(errors)) |
37 | } |
38 |
|
39 | return data.projects |
40 | } |
41 |
|