Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
feat: add support for mesh build (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
domjtalbot authored Jul 12, 2022
1 parent be3fa82 commit 78e4d9c
Show file tree
Hide file tree
Showing 254 changed files with 5,934 additions and 1,414 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-carrots-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nx-plugin-graphql-mesh': major
---

Add `build`, `build-gateway` & `build-swc` executors
54 changes: 32 additions & 22 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
name: 'Build & Test'

on:
pull_request:
branches:
- main

workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false

workflow_call:
inputs:
affected:
Expand All @@ -25,37 +13,50 @@ on:
type: number
required: false
default: 3
outputs:
affectedApps:
description: 'The affected apps'
value: ${{ jobs.build-test.outputs.affectedApps }}
secrets:
NX__TRIPPIN__API_KEY:
description: 'The Trippin API Key'
required: true
NX__WEATHERBIT__API_KEY:
description: 'The Weatherbit API Key'
required: true
NX_CLOUD_TOKEN:
description: 'The NX Cloud API token'
required: true

concurrency:
group: build-test-${{ github.workflow }}-${{ github.ref }}

env:
NX__TRIPPIN__API_KEY: ${{ secrets.NX__TRIPPIN__API_KEY }}
NX__WEATHERBIT__API_KEY: ${{ secrets.NX__WEATHERBIT__API_KEY }}
NX_CLOUD_TOKEN: ${{ secrets.NX_CLOUD_TOKEN }}
NX_AFFECTED: ${{ inputs.affected == 'true' || true }}
NX_PARALLEL: ${{ inputs.parallel || 3 }}
NX_AFFECTED_COMMANDS: |
pnpm nx-cloud record -- npx nx workspace-lint
pnpm nx-cloud record -- npx nx format:check
pnpm nx affected --target=lint --parallel=${{ inputs.parallel || 3 }}
pnpm nx affected --target=test --parallel=${{ inputs.parallel || 3 }} --ci --code-coverage
pnpm nx affected --target=build --parallel=${{ inputs.parallel || 3 }}
pnpm nx affected --target=test --parallel=${{ inputs.parallel || 3 }} --ci --code-coverage
NX_COMMANDS: |
pnpm nx-cloud record -- npx nx workspace-lint
pnpm nx-cloud record -- npx nx format:check
pnpm nx run-many --target=lint --all --parallel=${{ inputs.parallel || 3 }}
pnpm nx run-many --target=test --all --parallel=${{ inputs.parallel || 3 }} --ci --code-coverage
pnpm nx run-many --target=build --all --parallel=${{ inputs.parallel || 3 }}
pnpm nx run-many --target=test --all --parallel=${{ inputs.parallel || 3 }} --ci --code-coverage
jobs:
build-test:
name: Build & Test
runs-on: ubuntu-latest
outputs:
affectedApps: ${{ steps.affected-apps.outputs.apps }}
steps:
# Enable tmate debugging of manually-triggered workflows
# if the input option was provided.
- name: Setup SSH debug session
uses: mxschmitt/action-tmate@8b4e4ac71822ed7e0ad5fb3d1c33483e9e8fb270 # tag=v3
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}

- name: Check out repository
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
with:
Expand All @@ -64,6 +65,11 @@ jobs:
- name: Setup
uses: ./.github/actions/setup

- name: Get Affected apps
id: affected-apps
run: |
echo ::set-output name=apps::$(pnpm nx affected:apps --plain)
# https://github.com/nrwl/ci/blob/main/.github/workflows/nx-cloud-main.yml#L165
- name: Create command utils
uses: actions/github-script@7a5c598405937d486b0331594b5da2b14db670da # tag=v6
Expand Down Expand Up @@ -125,15 +131,19 @@ jobs:
shell: bash

- name: Affected E2E
timeout-minutes: 5
if: ${{ env.NX_AFFECTED == 'true' }}
uses: cypress-io/github-action@be2de7b1fe1cdafb4a3c8da0a3746476ef636b65 # tag=v4.1.0
with:
install: false
command: pnpm nx affected --target=e2e --parallel=${{ env.NX_PARALLEL }}
command: |
pnpm nx affected --target=e2e --parallel=${{ env.NX_PARALLEL }}
- name: E2E
timeout-minutes: 5
if: ${{ env.NX_AFFECTED == 'false' }}
uses: cypress-io/github-action@be2de7b1fe1cdafb4a3c8da0a3746476ef636b65 # tag=v4.1.0
with:
install: false
command: pnpm nx run-many --target=e2e --all --parallel=${{ env.NX_PARALLEL }}
command: |
pnpm nx run-many --target=e2e --all --parallel=${{ env.NX_PARALLEL }}
79 changes: 79 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: 'Deploy'

on:
workflow_call:
inputs:
apps:
description: The apps to deploy
type: string
required: true
production:
description: Deploy production?
type: boolean
required: false
default: false
secrets:
VERCEL_ORG_ID:
description: 'The Vercel ORG ID'
required: true
NX__NEXTJS_TRIPPIN__VERCEL_PROJECT_ID:
description: 'The nextjs/trippin Vercel Project Id'
required: true
NX__NEXTJS_TRIPPIN_SWC__VERCEL_PROJECT_ID:
description: 'The nextjs/trippin-swc Vercel Project Id'
required: true
VERCEL_TOKEN:
description: 'The Vercel API token'
required: true

concurrency:
group: deploy-${{ github.workflow }}-${{ github.ref }}

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
with:
fetch-depth: 0

- name: Deploy env
id: deploy-env
shell: bash
run: |
name=Preview
if [ ${{ inputs.production }} = true ]; then
name=Production
fi
echo The env is $name
echo ::set-output name=name::$name
- name: Deploy to Vercel Action
if: contains(inputs.apps, 'nextjs-trippin')
uses: BetaHuhn/deploy-to-vercel-action@v1
with:
GITHUB_DEPLOYMENT_ENV: nextjs/trippin ${{ steps.deploy-env.outputs.name }}
GITHUB_DEPLOYMENT: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_LABELS: vercel
PRODUCTION: ${{ inputs.production }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.NX__NEXTJS_TRIPPIN__VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}

- name: Deploy to Vercel Action
if: contains(inputs.apps, 'nextjs-trippin-swc')
uses: BetaHuhn/deploy-to-vercel-action@v1
with:
GITHUB_DEPLOYMENT_ENV: nextjs/trippin-swc ${{ steps.deploy-env.outputs.name }}
GITHUB_DEPLOYMENT: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_LABELS: vercel
PRODUCTION: ${{ inputs.production }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.NX__NEXTJS_TRIPPIN_SWC__VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Pull Request'

on:
pull_request:
branches:
- main

concurrency:
group: pr-${{ github.workflow }}-${{ github.ref }}

jobs:
build-test:
uses: ./.github/workflows/build-test.yml
secrets: inherit

deploy:
needs: [build-test]
uses: ./.github/workflows/deploy.yml
with:
apps: ${{ needs.build-test.outputs.affectedApps }}
secrets: inherit
12 changes: 12 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ jobs:
uses: ./.github/workflows/build-test.yml
with:
affected: false
secrets: inherit

release:
needs: [build-test]
name: Release
runs-on: ubuntu-latest
outputs:
published: ${{ steps.changesets.outputs.published }}
steps:
# Enable tmate debugging of manually-triggered workflows
# if the input option was provided.
Expand Down Expand Up @@ -60,3 +63,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

deploy:
needs: [build-test, release]
if: needs.release.outputs.published == 'true'
uses: ./.github/workflows/deploy.yml
with:
apps: ${{ needs.build-test.outputs.affectedApps }}
production: true
secrets: inherit
124 changes: 123 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,108 @@

## Executors

### Dev
### `build`

Builds artifacts for a GraphQL Mesh library.

This is the equivalent of using `graphql-mesh dev`, but with extra steps for packaging the library.

```json
"targets": {
"build": {
"executor": "@domjtalbot/nx-plugin-graphql-mesh:build",
"options": {
"dir": "libs/example-lib",
"outputPath": "dist/libs/example-lib",
"tsConfig": "libs/example-lib/tsconfig.lib.json",
"main": "libs/example-lib/src/index.ts"
},
},
}
```

#### Options

| Name | Type | Required | Default | Description |
| --------------------------------------------- | ------------------------------------ | -------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| **`assets`** | `string[]` | `false` | - | List of static assets. |
| **`buildableProjectDepsInPackageJsonType`** | `dependencies` or `peerDependencies` | `false` | `peerDependencies` | When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`. |
| **`debug`** | `boolean` | `false` | `false` | Display debugging info by applying the `DEBUG` env variable. |
| **`dir`** | `string` | `true` | - | The path of the directory containing the GraphQL Mesh config. |
| **`fileType`** | `json`, `ts` or `js` | `false` | `ts` | The filetype. |
| **`main`** | `string` | `true` | - | The name of the main entry-point file. |
| **`outputPath`** | `string` | `true` | - | The output path of the generated files. |
| **`require`** | `string[]` | `false` | `[]` | Loads specific require.extensions before running the codegen and reading the configuration. |
| **`transformers`** | `string[]` | `false` | - | List of TypeScript Transformer Plugins. |
| **`tsConfig`** | `string` | `true` | - | The path to the Typescript configuration file. |
| **`updateBuildableProjectDepsInPackageJson`** | `boolean` | `false` | `true` | Whether to update the buildable project dependencies in `package.json`. |

### `build-gateway`

Builds artifacts for a GraphQL Mesh API Gateway app.

This is the equivalent of using `graphql-mesh build`, but with extra steps for compiling an app.

```json
"targets": {
"build": {
"executor": "@domjtalbot/nx-plugin-graphql-mesh:build-gateway",
"options": {
"dir": "apps/example-app",
"outputPath": "dist/apps/example-app"
},
},
}
```

#### Options

| Name | Type | Required | Default | Description |
| -------------- | -------------------- | -------- | ------- | ------------------------------------------------------------------------------------------- |
| **`debug`** | `boolean` | `false` | `false` | Display debugging info by applying the `DEBUG` env variable. |
| **`dir`** | `string` | `true` | - | The path of the directory containing the GraphQL Mesh config. |
| **`fileType`** | `json`, `ts` or `js` | `false` | `ts` | The filetype. |
| **`require`** | `string[]` | `false` | `[]` | Loads specific require.extensions before running the codegen and reading the configuration. |

### `build`

Builds artifacts for a GraphQL Mesh library.

This is the equivalent of using `graphql-mesh dev`, but with extra steps for packaging the library.

```json
"targets": {
"build": {
"executor": "@domjtalbot/nx-plugin-graphql-mesh:build-swc",
"options": {
"dir": "libs/example-lib",
"outputPath": "dist/libs/example-lib",
"tsConfig": "libs/example-lib/tsconfig.lib.json",
"main": "libs/example-lib/src/index.ts"
},
},
}
```

#### Options

| Name | Type | Required | Default | Description |
| --------------------------------------------- | ------------------------------------ | -------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| **`assets`** | `string[]` | `false` | - | List of static assets. |
| **`buildableProjectDepsInPackageJsonType`** | `dependencies` or `peerDependencies` | `false` | `peerDependencies` | When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`. |
| **`debug`** | `boolean` | `false` | `false` | Display debugging info by applying the `DEBUG` env variable. |
| **`dir`** | `string` | `true` | - | The path of the directory containing the GraphQL Mesh config. |
| **`fileType`** | `json`, `ts` or `js` | `false` | `ts` | The filetype. |
| **`main`** | `string` | `true` | - | The name of the main entry-point file. |
| **`outputPath`** | `string` | `true` | - | The output path of the generated files. |
| **`require`** | `string[]` | `false` | `[]` | Loads specific require.extensions before running the codegen and reading the configuration. |
| **`skipTypeCheck`** | `boolean` | `false` | `false` | Whether to skip TypeScript type checking. |
| **`swcrc`** | `string` | `false` | `.lib.swcrc` | The path to the SWC configuration file. |
| **`transformers`** | `string[]` | `false` | - | List of TypeScript Transformer Plugins. |
| **`tsConfig`** | `string` | `true` | - | The path to the Typescript configuration file. |
| **`updateBuildableProjectDepsInPackageJson`** | `boolean` | `false` | `true` | Whether to update the buildable project dependencies in `package.json`. |

### `dev`

Serves a GraphQL server with GraphQL interface by building artifacts on the fly.

Expand All @@ -53,6 +154,27 @@ This is the equifilent of using `graphql-mesh dev`.
| **`port`** | `number` | `false` | `4000` | The port number to run on. |
| **`require`** | `string[]` | `false` | `[]` | Loads specific require.extensions before running the codegen and reading the configuration. |

<br/>

## Examples

### API Gateway

| Name | Source Handler |
| ------------------------------------ | -------------- |
| **`apps/api-gateway/stackexchange`** | `openapi` |
| **`apps/api-gateway/trippin`** | `odata` |
| **`apps/api-gateway/weatherbit`** | `new-openapi` |

### SDK

| Name | Source Handler | Framework | Compiler | Deployed |
| ------------------------------- | -------------- | --------- | -------- | -------------------------------------------------------------------------- |
| **`apps/nextjs/stackexchange`** | `openapi` | `nextjs` | `tsc` | - |
| **`apps/nextjs/trippin`** | `odata` | `nextjs` | `tsc` | [Vercel](https://nx-plugin-graphql-mesh-trippin-domjtalbot.vercel.app) |
| **`apps/nextjs/trippin-swc`** | `odata` | `nextjs` | `swc` | [Vercel](https://nx-plugin-graphql-mesh-trippin-swc-domjtalbot.vercel.app) |
| **`apps/nextjs/weatherbit`** | `new-openapi` | `nextjs` | `tsc` | - |

<br/>
<br/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"extends": ["plugin:cypress/recommended", "../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
Expand Down
Loading

0 comments on commit 78e4d9c

Please sign in to comment.