Skip to content

Commit

Permalink
feat(nx-plugin-graphql-mesh): add API Gateway generator (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
domjtalbot authored Aug 2, 2022
1 parent f71e97d commit 68e8380
Show file tree
Hide file tree
Showing 93 changed files with 2,523 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-hounds-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nx-plugin-graphql-mesh': major
---

Add `app` generator
41 changes: 21 additions & 20 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ jobs:
name: Setup
runs-on: ubuntu-latest
timeout-minutes: 10
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
node: [lts, latest]
node: [lts]
experimental: [false]
include:
- node: latest
experimental: true
env:
NX_CLOUD_ENV_NAME: node-${{ matrix.node }}
outputs:
Expand Down Expand Up @@ -103,24 +109,32 @@ jobs:
run: |
pnpm nx run-many --target=lint --all --parallel=3
- name: Affected Build
if: inputs.affected == 'true'
shell: bash
run: |
pnpm nx affected --target=build --parallel=3
- name: Build
if: inputs.affected != 'true'
shell: bash
run: |
pnpm nx run-many --target=build --all --parallel=3
nx:
runs-on: ubuntu-latest
needs: [setup]
if: needs.setup.outputs.hasAffected == 'true' || inputs.affected != 'true'
timeout-minutes: 10
continue-on-error: ${{ matrix.experimental }}
strategy:
max-parallel: 2
# max-parallel: 2
fail-fast: false
matrix:
node: [lts]
command:
[build, test, validate, e2e, e2e-start, e2e-serve, e2e-serve-dev]
command: [test, validate, e2e, e2e-start, e2e-serve, e2e-serve-dev]
experimental: [false]
include:
- node: latest
command: build
experimental: true
- node: latest
command: validate
experimental: true
Expand All @@ -136,7 +150,6 @@ jobs:
- node: latest
command: e2e-serve-dev
experimental: true

name: node-${{ matrix.node }} - ${{ matrix.command }}
env:
NX_CLOUD_ENV_NAME: node-${{ matrix.node }}
Expand All @@ -152,18 +165,6 @@ jobs:
ignore-cypress-cache: ${{ !startsWith(matrix.command, 'e2e') }}
node-version: ${{ matrix.node }}

- name: Affected Build
if: inputs.affected == 'true' && matrix.command == 'build'
shell: bash
run: |
pnpm nx affected --target=build --parallel=3
- name: Build
if: inputs.affected != 'true' && matrix.command == 'build'
shell: bash
run: |
pnpm nx run-many --target=build --all --parallel=3
- name: Affected Test
if: inputs.affected == 'true' && matrix.command == 'test'
shell: bash
Expand Down
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,62 @@

<br/>

## Generators

### `application`

Create a GraphQL Mesh API Gateway application for Nx.

```bash
nx generate @domjtalbot/nx-plugin-graphql-mesh:application my-api-gateway

# Shorthand
nx generate @domjtalbot/nx-plugin-graphql-mesh:app my-api-gateway
```

#### Example Output

```bash
> NX Generating @domjtalbot/nx-plugin-graphql-mesh:application

CREATE apps/my-api-gateway/.meshrc.yml
CREATE apps/my-api-gateway/tsconfig.app.json
CREATE apps/my-api-gateway/tsconfig.json
CREATE apps/my-api-gateway/project.json
UPDATE workspace.json
CREATE apps/my-api-gateway-e2e/cypress.json
CREATE apps/my-api-gateway-e2e/src/fixtures/example.json
CREATE apps/my-api-gateway-e2e/src/integration/app.spec.ts
CREATE apps/my-api-gateway-e2e/src/support/app.po.ts
CREATE apps/my-api-gateway-e2e/src/support/commands.ts
CREATE apps/my-api-gateway-e2e/src/support/index.ts
CREATE apps/my-api-gateway-e2e/tsconfig.json
CREATE apps/my-api-gateway-e2e/project.json
CREATE apps/my-api-gateway-e2e/.eslintrc.json
CREATE apps/my-api-gateway/jest.config.ts
CREATE apps/my-api-gateway/tsconfig.spec.json
CREATE apps/my-api-gateway/.eslintrc.json
```

#### Options

| Name | Alias | Type | Required | Default | Description |
| ----------------------------- | ----- | -------------------------- | -------- | --------- | --------------------------------------------------------------------------------------------------------------------------------- |
| **`name`** | - | `string` | `true` | - | What name would you like to use for the application? |
| **`directory`** | `d` | `string` | `false` | `apps/` | The directory of the new application. |
| **`meshConfig`** | `mc` | `cjs`, `js`, `json`, `yml` | `false` | `yml` | Which config format would you like to use? |
| **`linter`** | `-` | `eslint`, `tslint` | `false` | `eslint` | The tool to use for running lint checks |
| **`babelJest`** | `-` | `boolean` | `false` | `false` | Use `babel` instead of `ts-jest`? |
| **`skipFormat`** | `-` | `boolean` | `false` | `false` | Skip formatting files. |
| **`skipWorkspaceJson`** | `-` | `boolean` | `false` | `false` | Skip updating `workspace.json` with default options based on values provided to this app (e.g. `babel`). |
| **`unitTestRunner`** | `-` | `jest`, `none` | `false` | `jest` | Test runner to use for unit tests. |
| **`e2eTestRunner`** | `-` | `cypress`, `none` | `false` | `cypress` | Test runner to use for end to end (E2E) tests. |
| **`tags`** | `t` | `string` | `false` | - | Add tags to the application (used for linting). |
| **`setParserOptionsProject`** | `-` | `boolean` | `false` | `false` | Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons. |
| **`standaloneConfig`** | `-` | `boolean` | `false` | `false` | Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json` |

<br/>

## Executors

### `build`
Expand Down
10 changes: 10 additions & 0 deletions apps/api-gateway/javascript-wiki/cjs-config-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": ["plugin:cypress/recommended", "../../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
}
]
}
12 changes: 12 additions & 0 deletions apps/api-gateway/javascript-wiki/cjs-config-e2e/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"fileServerFolder": ".",
"fixturesFolder": "./src/fixtures",
"integrationFolder": "./src/integration",
"modifyObstructiveCode": false,
"supportFile": "./src/support/index.ts",
"pluginsFile": false,
"video": true,
"videosFolder": "../../../../dist/cypress/apps/api-gateway/javascript-wiki/cjs-config-e2e/videos",
"screenshotsFolder": "../../../../dist/cypress/apps/api-gateway/javascript-wiki/cjs-config-e2e/screenshots",
"chromeWebSecurity": false
}
30 changes: 30 additions & 0 deletions apps/api-gateway/javascript-wiki/cjs-config-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/api-gateway/javascript-wiki/cjs-config-e2e/src",
"projectType": "application",
"targets": {
"e2e": {
"executor": "@nrwl/cypress:cypress",
"options": {
"cypressConfig": "apps/api-gateway/javascript-wiki/cjs-config-e2e/cypress.json",
"devServerTarget": "api-gateway-javascript-wiki-cjs-config:serve"
},
"configurations": {
"production": {
"devServerTarget": "api-gateway-javascript-wiki-cjs-config:serve:production"
}
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"apps/api-gateway/javascript-wiki/cjs-config-e2e/**/*.{js,ts}"
]
}
}
},
"tags": [],
"implicitDependencies": ["api-gateway-javascript-wiki-cjs-config"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe('javascript-wiki-cjs-config', () => {
it('should start a mesh server', () => {
cy.request('/graphql/health').then((resp) => {
expect(resp.status).to.eq(200);
expect(resp.body).to.have.property('message', 'alive');
});
});

it('should still be running after 15 seconds', () => {
cy.wait(1000 * 15)
.request('/graphql/health')
.then((resp) => {
expect(resp.status).to.eq(200);
expect(resp.body).to.have.property('message', 'alive');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getGreeting = () => cy.get('h1');
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************

// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void;
}
}
//
// -- This is a parent command --
Cypress.Commands.add('login', (email, password) => {
console.log('Custom command example: Login', email, password);
});
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';
10 changes: 10 additions & 0 deletions apps/api-gateway/javascript-wiki/cjs-config-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../../../dist/out-tsc",
"allowJs": true,
"types": ["cypress", "node"]
},
"include": ["src/**/*.ts", "src/**/*.js"]
}
18 changes: 18 additions & 0 deletions apps/api-gateway/javascript-wiki/cjs-config/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../../../.eslintrc.json"],
"ignorePatterns": ["!**/*", ".mesh"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
16 changes: 16 additions & 0 deletions apps/api-gateway/javascript-wiki/cjs-config/.meshrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
sources: [
{
name: 'JavaScript Wiki',
handler: {
openapi: {
source:
'https://api.apis.guru/v2/specs/wikimedia.org/1.0.0/swagger.yaml',
},
},
},
],
serve: {
browser: false,
},
};
17 changes: 17 additions & 0 deletions apps/api-gateway/javascript-wiki/cjs-config/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable */
export default {
displayName: 'api-gateway-javascript-wiki-cjs-config',
preset: '../../../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory:
'../../../../coverage/apps/api-gateway/javascript-wiki/cjs-config',
};
Loading

0 comments on commit 68e8380

Please sign in to comment.