|
| 1 | +--- |
| 2 | +title: GraphQL API |
| 3 | +description: Reference for the read-only stack fields and objects on the GraphQL PullRequest type. |
| 4 | +--- |
| 5 | + |
| 6 | +The GraphQL API exposes a pull request's stack membership through two read-only fields on the `PullRequest` type, backed by a small set of stack objects. These fields are **read-only** — there are no stack mutations via GraphQL. To create or modify stacks use the [REST API](/gh-stack/reference/rest-api/). |
| 7 | + |
| 8 | +## Fields on `PullRequest` |
| 9 | + |
| 10 | +| Field | Type | Description | |
| 11 | +|-------|------|-------------| |
| 12 | +| `stack` | `PullRequestStack` | The stack this pull request belongs to, or `null` if it is not part of a stack. | |
| 13 | +| `stackEntry` | `PullRequestStackEntry` | This pull request's entry within its stack (including its position), or `null` if it is not part of a stack. | |
| 14 | + |
| 15 | +## Objects |
| 16 | + |
| 17 | +### `PullRequestStack` |
| 18 | + |
| 19 | +A stack of pull requests. |
| 20 | + |
| 21 | +| Field | Type | Description | |
| 22 | +|-------|------|-------------| |
| 23 | +| `id` | `ID!` | The Node ID of the `PullRequestStack` object. | |
| 24 | +| `number` | `Int!` | A number uniquely identifying the stack within its repository. | |
| 25 | +| `size` | `Int!` | The total number of pull requests in the stack. | |
| 26 | +| `baseRefName` | `String!` | The branch that the stack's pull requests target. | |
| 27 | +| `entries` | `PullRequestStackEntryConnection!` | The entries in the stack. | |
| 28 | + |
| 29 | +### `PullRequestStackEntry` |
| 30 | + |
| 31 | +A member of a `PullRequestStack`. |
| 32 | + |
| 33 | +| Field | Type | Description | |
| 34 | +|-------|------|-------------| |
| 35 | +| `id` | `ID!` | The Node ID of the `PullRequestStackEntry` object. | |
| 36 | +| `position` | `Int!` | This entry's position in the stack, where `1` is the closest to the base branch, `2` is stacked on top of `1`, and so on. | |
| 37 | +| `pullRequest` | `PullRequest` | The pull request that occupies this position in the stack. | |
| 38 | +| `stack` | `PullRequestStack` | The stack that this entry is a part of. | |
| 39 | + |
| 40 | +### `PullRequestStackEntryConnection` |
| 41 | + |
| 42 | +A paginated connection of stack entries. Follows the standard [GraphQL connection pattern](https://docs.github.com/en/graphql/guides/introduction-to-graphql#connection). |
| 43 | + |
| 44 | +| Field | Type | Description | |
| 45 | +|-------|------|-------------| |
| 46 | +| `edges` | `[PullRequestStackEntryEdge]` | A list of edges. | |
| 47 | +| `nodes` | `[PullRequestStackEntry]` | A list of the entries. | |
| 48 | +| `pageInfo` | `PageInfo!` | Information to aid in pagination. | |
| 49 | +| `totalCount` | `Int!` | The total number of entries in the connection. | |
| 50 | + |
| 51 | +### `PullRequestStackEntryEdge` |
| 52 | + |
| 53 | +An edge in a `PullRequestStackEntryConnection`. |
| 54 | + |
| 55 | +| Field | Type | Description | |
| 56 | +|-------|------|-------------| |
| 57 | +| `cursor` | `String!` | A cursor for use in pagination. | |
| 58 | +| `node` | `PullRequestStackEntry` | The item at the end of the edge. | |
| 59 | + |
| 60 | +## Example |
| 61 | + |
| 62 | +Read a pull request's stack, its position, and every pull request in the stack: |
| 63 | + |
| 64 | +```graphql |
| 65 | +{ |
| 66 | + repository(owner: "OWNER", name: "REPO") { |
| 67 | + pullRequest(number: 42) { |
| 68 | + number |
| 69 | + baseRefName |
| 70 | + stackEntry { |
| 71 | + position |
| 72 | + } |
| 73 | + stack { |
| 74 | + number |
| 75 | + size |
| 76 | + baseRefName |
| 77 | + entries(first: 20) { |
| 78 | + totalCount |
| 79 | + nodes { |
| 80 | + position |
| 81 | + pullRequest { |
| 82 | + number |
| 83 | + title |
| 84 | + state |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +The pull request's own `baseRefName` is the branch it directly targets (the PR below it in the stack), while `stack.baseRefName` is the branch the entire stack ultimately targets. These differ for every PR in the stack except the bottom one. |
0 commit comments