diff --git a/.changeset/modern-zebras-invite.md b/.changeset/modern-zebras-invite.md
new file mode 100644
index 00000000..af459d95
--- /dev/null
+++ b/.changeset/modern-zebras-invite.md
@@ -0,0 +1,7 @@
+---
+'nx-mesh': minor
+---
+
+Add preset generator
+
+Create a new Nx workspace with GraphQL Mesh as the preset!
diff --git a/README.md b/README.md
index f98bab69..bb7afd12 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,7 @@
- [Features](#features)
- [Installing](#installing)
- [Peer Dependencies](#peer-dependencies)
+- [Preset](#preset)
- [Generators](#generators)
- [`application`](#application)
- [`sdk`](#sdk)
@@ -45,6 +46,7 @@
## Features
- Use GraphQL Mesh to combine multiple APIs into a single GraphQL API.
+- Create a new Nx workspace with a GraphQL Mesh preset.
- Generate a GraphQL Mesh API Gateway
- A standalone application for running GraphQL Mesh.
- Choose from multiple starter templates.
@@ -89,6 +91,18 @@ yarn add -D nx-mesh
+## Preset
+
+Create a new Nx workspace with a GraphQL Mesh SDK!
+
+```bash
+npx create-nx-workspace@latest myorg --preset=nx-mesh
+```
+
+See the [`sdk` generator](#sdk) for available options.
+
+
+
## Generators
### `application`
diff --git a/libs/nx-mesh/generators.json b/libs/nx-mesh/generators.json
index 7bfbb721..0c7016a2 100644
--- a/libs/nx-mesh/generators.json
+++ b/libs/nx-mesh/generators.json
@@ -21,6 +21,12 @@
"description": "Create a GraphQL Mesh SDK library for Nx",
"x-type": "library",
"aliases": ["library", "sdk-library"]
+ },
+ "preset": {
+ "factory": "./src/generators/preset/generator",
+ "schema": "./src/generators/preset/schema.json",
+ "description": "Create a GraphQL Mesh SDK in an empty workspace.",
+ "hidden": true
}
},
"schematics": {
diff --git a/libs/nx-mesh/src/generators/preset/index.ts b/libs/nx-mesh/src/generators/preset/index.ts
new file mode 100644
index 00000000..4592e52f
--- /dev/null
+++ b/libs/nx-mesh/src/generators/preset/index.ts
@@ -0,0 +1,9 @@
+import { convertNxGenerator } from '@nrwl/devkit';
+
+import { presetGenerator } from './preset';
+
+export const presetSchematic = convertNxGenerator(presetGenerator);
+
+export { presetGenerator } from './preset';
+
+export default presetGenerator;
diff --git a/libs/nx-mesh/src/generators/preset/preset.spec.ts b/libs/nx-mesh/src/generators/preset/preset.spec.ts
new file mode 100644
index 00000000..1b60ddd7
--- /dev/null
+++ b/libs/nx-mesh/src/generators/preset/preset.spec.ts
@@ -0,0 +1,34 @@
+import type { Tree } from '@nrwl/devkit';
+
+import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
+import { readProjectConfiguration } from '@nrwl/devkit';
+
+import { presetGenerator } from './preset';
+
+describe('generators/preset', () => {
+ let tree: Tree;
+
+ beforeEach(() => {
+ tree = createTreeWithEmptyWorkspace();
+
+ tree.write(
+ 'workspace.json',
+ JSON.stringify({
+ version: 2,
+ projects: {},
+ })
+ );
+ });
+
+ it('should create a workspace with the graphql-mesh sdk preset', async () => {
+ await presetGenerator(tree, {
+ name: 'hello-world',
+ compiler: 'tsc',
+ });
+
+ const config = readProjectConfiguration(tree, 'hello-world');
+
+ expect(config).toBeDefined();
+ expect(tree.exists('/libs/hello-world/.meshrc.yml')).toBe(true);
+ });
+});
diff --git a/libs/nx-mesh/src/generators/preset/preset.ts b/libs/nx-mesh/src/generators/preset/preset.ts
new file mode 100644
index 00000000..fdd3eba9
--- /dev/null
+++ b/libs/nx-mesh/src/generators/preset/preset.ts
@@ -0,0 +1,18 @@
+import type { Tree } from '@nrwl/devkit';
+
+import type { PresetGeneratorSchema } from './schema';
+
+import { convertNxGenerator } from '@nrwl/devkit';
+
+import { sdkGenerator } from '../sdk';
+
+export async function presetGenerator(
+ tree: Tree,
+ options: PresetGeneratorSchema
+) {
+ return await sdkGenerator(tree, options);
+}
+
+export const presetSchematic = convertNxGenerator(presetGenerator);
+
+export default presetGenerator;
diff --git a/libs/nx-mesh/src/generators/preset/schema.d.ts b/libs/nx-mesh/src/generators/preset/schema.d.ts
new file mode 100644
index 00000000..3c5f7556
--- /dev/null
+++ b/libs/nx-mesh/src/generators/preset/schema.d.ts
@@ -0,0 +1,3 @@
+import type { SdkGeneratorSchema } from '../sdk/schema';
+
+export type PresetGeneratorSchema = SdkGeneratorSchema;
diff --git a/libs/nx-mesh/src/generators/preset/schema.json b/libs/nx-mesh/src/generators/preset/schema.json
new file mode 100644
index 00000000..40161cf1
--- /dev/null
+++ b/libs/nx-mesh/src/generators/preset/schema.json
@@ -0,0 +1,155 @@
+{
+ "$schema": "http://json-schema.org/schema",
+ "cli": "nx",
+ "$id": "Preset",
+ "title": "Create a GraphQL Mesh SDK in an empty workspace.",
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string",
+ "description": "",
+ "$default": {
+ "$source": "argv",
+ "index": 0
+ },
+ "x-prompt": "What name would you like to use?"
+ },
+ "directory": {
+ "description": "The directory of the new sdk.",
+ "type": "string",
+ "alias": "d"
+ },
+ "meshConfig": {
+ "description": "The file extension to use for the Mesh config",
+ "type": "string",
+ "default": "yml",
+ "alias": "mc",
+ "x-prompt": {
+ "message": "Which config format would you like to use?",
+ "type": "list",
+ "items": [
+ { "value": "json", "label": "JSON" },
+ {
+ "value": "yml",
+ "label": "YAML"
+ },
+ {
+ "value": "js",
+ "label": "JavaScript"
+ },
+ {
+ "value": "cjs",
+ "label": "Common JS"
+ }
+ ]
+ }
+ },
+ "example": {
+ "description": "Which example project would you like to start with?",
+ "type": "string",
+ "default": "star-wars-api",
+ "x-prompt": {
+ "message": "Which example project would you like to start with?",
+ "type": "list",
+ "items": [
+ { "value": "country-info", "label": "Country Info (SOAP)" },
+ { "value": "fake-api", "label": "Fake API (JSON Schema)" },
+ { "value": "javascript-wiki", "label": "JavaScript Wiki (OpenAPI)" },
+ { "value": "movies", "label": "Movies (Neo4j)" },
+ { "value": "rfam", "label": "RFam (MySQL)" },
+ { "value": "stackexchange", "label": "StackExchange (OpenAPI)" },
+ { "value": "star-wars-api", "label": "Star Wars API (GraphQL)" },
+ { "value": "trippin", "label": "Trip Pin (odata)" }
+ ]
+ }
+ },
+ "codegen": {
+ "description": "Use `graphql-codegen` to generate custom files from the GraphQL Mesh schema.",
+ "type": "boolean",
+ "default": true
+ },
+ "simpleModuleName": {
+ "description": "Keep the module name simple (when using `--directory`).",
+ "type": "boolean",
+ "default": false
+ },
+ "linter": {
+ "description": "The tool to use for running lint checks.",
+ "type": "string",
+ "enum": ["eslint", "tslint"],
+ "default": "eslint"
+ },
+ "unitTestRunner": {
+ "type": "string",
+ "enum": ["jest", "none"],
+ "description": "Test runner to use for unit tests.",
+ "default": "jest"
+ },
+ "tags": {
+ "type": "string",
+ "description": "Add tags to the library (used for linting).",
+ "alias": "t"
+ },
+ "skipFormat": {
+ "description": "Skip formatting files.",
+ "type": "boolean",
+ "default": false
+ },
+ "skipTsConfig": {
+ "type": "boolean",
+ "default": false,
+ "description": "Do not update `tsconfig.base.json` for development experience."
+ },
+ "compiler": {
+ "type": "string",
+ "enum": ["tsc", "swc"],
+ "default": "tsc",
+ "description": "The compiler used by the build and test targets."
+ },
+ "importPath": {
+ "type": "string",
+ "description": "The library name used to import it, like `@myorg/my-awesome-lib`. Must be a valid npm name."
+ },
+ "rootDir": {
+ "type": "string",
+ "description": "Sets the `rootDir` for TypeScript compilation. When not defined, it uses the project's root property, or `srcRootForCompilationRoot` if it is defined."
+ },
+ "testEnvironment": {
+ "type": "string",
+ "enum": ["jsdom", "node"],
+ "description": "The test environment to use if `unitTestRunner` is set to `jest`.",
+ "default": "jsdom"
+ },
+ "babelJest": {
+ "type": "boolean",
+ "description": "Use `babel` instead of `ts-jest`.",
+ "default": false
+ },
+ "pascalCaseFiles": {
+ "type": "boolean",
+ "description": "Use pascal case file names.",
+ "alias": "P",
+ "default": false
+ },
+ "js": {
+ "type": "boolean",
+ "description": "Generate JavaScript files rather than TypeScript files.",
+ "default": false
+ },
+ "strict": {
+ "type": "boolean",
+ "description": "Whether to enable tsconfig strict mode or not.",
+ "default": false
+ },
+ "standaloneConfig": {
+ "description": "Split the project configuration into `/project.json` rather than including it inside `workspace.json`.",
+ "type": "boolean"
+ },
+ "setParserOptionsProject": {
+ "type": "boolean",
+ "description": "Whether or not to configure the ESLint `parserOptions.project`. We do not do this by default for lint performance reasons.",
+ "default": false
+ }
+ },
+ "required": ["name"]
+}
diff --git a/libs/nx-mesh/src/generators/sdk/index.ts b/libs/nx-mesh/src/generators/sdk/index.ts
new file mode 100644
index 00000000..10bd86a8
--- /dev/null
+++ b/libs/nx-mesh/src/generators/sdk/index.ts
@@ -0,0 +1,9 @@
+import { convertNxGenerator } from '@nrwl/devkit';
+
+import { sdkGenerator } from './sdk';
+
+export const sdkSchematic = convertNxGenerator(sdkGenerator);
+
+export { sdkGenerator } from './sdk';
+
+export default sdkGenerator;