> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trunk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Nx

> Instructions for enabling dynamic parallel queues powered by your Nx graph

Leveraging [parallel mode](https://docs.trunk.io/merge-queue/optimizations/parallel-queues) for Trunk Merge Queue is easy for Nx-enabled repos because Nx already knows the structure of your code and can automatically generate a dependency graph. Merge can use this information in parallel mode to create dynamic parallel queues enabling your pull requests to run through your Merge Queue faster.\
\
**How do we create parallel queues?**\
By understanding which Nx targets a pull request affects, we can build a real-time graph and detect intersection points and where distinct non-overlapping graphs exist. This information is essentially a list of unique target names, which can then be used in real time to understand along which targets pull requests might overlap.

**Calculating impacted targets in GitHub Actions**\
Trunk ships a [GitHub action](https://github.com/trunk-io/nx-action) that will generate the list of impacted targets for a pull request and post that information to the Trunk Merge Queue service.

```yaml theme={"system"}
name: Upload and Test Impacted Targets
on: pull_request

jobs:
  impacted_targets:
    name: Impacted Targets
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write # lets the action log in to Trunk with the run's GitHub credential
      # pull-requests: read # add in a private repository if you set the action's impact-all-filters-path input
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: compute impacted targets
        uses: trunk-io/nx-action@v1
        with:
          auth: github-actions
```

The above sample GitHub action code will calculate the impacted targets of your pull request and post that information to the trunk merge service. That data will be used to run your trunk merge queue in parallel mode.

`auth: github-actions` logs the job in to Trunk with the run's own GitHub credential through [`trunk-io/login`](https://github.com/trunk-io/login), so there's no Trunk secret to store, and the action uploads through the v2 API. On a public repository it also works on fork pull requests once an admin [allows them](https://docs.trunk.io/merge-queue/optimizations/parallel-queues/github-actions.md#allow-uploads-from-forks). On a private repository, fork pull requests can upload only if you leave out `auth` (below). The login runs only on Linux (x64 or arm64) and macOS (arm64) runners; elsewhere, use a stored token.

To use a stored token instead, leave out `auth` and `id-token: write`, and pass `trunk-token: ${{ secrets.TRUNK_API_TOKEN }}`. Set that secret to your organization API token, from the **Organization API token (v1)** section of [Settings → Developer → API Keys](https://app.trunk.io/settings/developer/api-tokens). This uploads through the v1 [`/setImpactedTargets`](https://docs.trunk.io/api/v1/set-impacted-targets-for-a-pull-request) endpoint, which will be deprecated soon; API keys don't work. On a fork pull request, which gets no secrets by default, this mode uploads with the workflow run's ID instead of the token. That works on private repositories too and needs no fork setting.
