1.1.0-alpha-20221114084347 • Published 3 years ago

nx-mesh v1.1.0-alpha-20221114084347

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Nx Mesh. GraphQL Mesh for Nx

Contents

Features

  • Use GraphQL Mesh to combine multiple APIs into a single GraphQL API.
  • Generate a GraphQL Mesh API Gateway
    • A standalone application for running GraphQL Mesh.
  • Generate a GraphQL Mesh SDK
    • Supports deploying to Vercel as a NextJS route
  • Supports all GraphQL CLI commands (build, dev, start, validate)
  • Use SWC to compile a GraphQL Mesh SDK
  • Automatically use the first available port when running dev, start, or serve.
  • Supports E2E

Installing

Using npm:

npm install -D nx-mesh

Using pnpm:

pnpm add -D nx-mesh

Using yarn:

yarn add -D nx-mesh

Peer Dependencies

NameVersionRequiredAuto-installed by generators
nx>=14-
@graphql-mesh/cli>=0.71.0

Generators

application

Create a GraphQL Mesh API Gateway application for Nx.

nx generate nx-mesh:application my-api-gateway

# Alias
nx generate nx-mesh:app my-api-gateway

Example Output

>  NX  Generating nx-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

NameAliasTypeRequiredDefaultDescription
name-string-What name would you like to use for the application?
directorydstring--The directory of the new application.
meshConfigmccjs, js, json, yml-ymlWhich config format would you like to use?
babelJest-boolean-falseUse babel instead of ts-jest?
e2eTestRunner-cypress, none-cypressTest runner to use for end to end (E2E) tests.
linter-eslint, tslint-eslintThe tool to use for running lint checks
setParserOptionsProject-boolean-falseWhether or not to configure the ESLint parserOptions.project option. We do not do this by default for lint performance reasons.
skipFormat-boolean-falseSkip formatting files.
skipWorkspaceJson-boolean-falseSkip updating workspace.json with default options based on values provided to this app (e.g. babel).
standaloneConfig-boolean-falseSplit the project configuration into <projectRoot>/project.json rather than including it inside workspace.json
tagststring--Add tags to the application (used for linting).
unitTestRunner-jest, none-jestTest runner to use for unit tests.

sdk

Create a GraphQL Mesh SDK library for Nx.

nx generate nx-mesh:sdk my-mesh-sdk

# Alias
nx generate nx-mesh:sdk-library my-mesh-sdk
nx generate nx-mesh:library my-mesh-sdk

Example Output

TSC
>  NX  Generating nx-mesh:sdk

CREATE libs/my-mesh-sdk/README.md
CREATE libs/my-mesh-sdk/.babelrc
CREATE libs/my-mesh-sdk/package.json
CREATE libs/my-mesh-sdk/src/index.ts
CREATE libs/my-mesh-sdk/tsconfig.json
CREATE libs/my-mesh-sdk/tsconfig.lib.json
UPDATE tsconfig.base.json
CREATE libs/my-mesh-sdk/project.json
UPDATE workspace.json
CREATE libs/my-mesh-sdk/.eslintrc.json
CREATE libs/my-mesh-sdk/jest.config.ts
CREATE libs/my-mesh-sdk/tsconfig.spec.json
CREATE libs/my-mesh-sdk/.meshrc.yml
CREATE libs/my-mesh-sdk/src/lib/sdk.ts
UPDATE nx.json
SWC
>  NX  Generating nx-mesh:sdk

CREATE libs/my-mesh-sdk/README.md
CREATE libs/my-mesh-sdk/package.json
CREATE libs/my-mesh-sdk/src/index.ts
CREATE libs/my-mesh-sdk/tsconfig.json
CREATE libs/my-mesh-sdk/tsconfig.lib.json
UPDATE tsconfig.base.json
CREATE libs/my-mesh-sdk/project.json
UPDATE workspace.json
CREATE libs/my-mesh-sdk/.eslintrc.json
CREATE libs/my-mesh-sdk/jest.config.ts
CREATE libs/my-mesh-sdk/tsconfig.spec.json
CREATE libs/my-mesh-sdk/.lib.swcrc
CREATE libs/my-mesh-sdk/.meshrc.json
CREATE libs/my-mesh-sdk/src/lib/sdk.ts

Options

NameAliasTypeRequiredDefaultDescription
name-string-What name would you like to use?
directorydstring--The directory of the new sdk.
meshConfigmccjs, js, json, yml-ymlWhich config format would you like to use?
babelJest-boolean-falseUse babel instead of ts-jest.
compiler-tsc, swc-tscThe compiler used by the build and test targets.
importPath-string--The library name used to import it, like @myorg/my-awesome-lib. Must be a valid npm name.
js-boolean-falseGenerate JavaScript files rather than TypeScript files.
linter-eslint, tslint-eslintThe tool to use for running lint checks.?
pascalCaseFilespboolean-falseUse pascal case file names.
rootDir-string--Sets the rootDir for TypeScript compilation. When not defined, it uses the project's root property, or srcRootForCompilationRoot if it is defined.
setParserOptionsProject-boolean-falseWhether or not to configure the ESLint parserOptions.project option. We do not do this by default for lint performance reasons.
simpleModuleName-boolean-falseKeep the module name simple (when using --directory).
skipFormat-boolean-falseSkip formatting files.
skipTsConfig-boolean-falseDo not update tsconfig.base.json for development experience.
standaloneConfig-boolean-falseSplit the project configuration into <projectRoot>/project.json rather than including it inside workspace.json
strict-boolean-falseWhether to enable tsconfig strict mode or not.
tagststring--Add tags to the application (used for linting).
testEnvironment-jsdom, none-jsdomThe test environment to use if unitTestRunner is set to jest.
unitTestRunner-jest, none-jestTest runner to use for unit tests.

Executors

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.

"targets": {
  "build": {
    "executor": "nx-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

NameTypeRequiredDefaultDescription
assetsstring[]--List of static assets.
buildableProjectDepsInPackageJsonTypedependencies or peerDependencies-peerDependenciesWhen updateBuildableProjectDepsInPackageJson is true, this adds dependencies to either peerDependencies or dependencies.
debugboolean-falseDisplay debugging info by applying the DEBUG env variable.
dirstring-The path of the directory containing the GraphQL Mesh config.
fileTypejson, ts or js-tsThe filetype.
mainstring-The name of the main entry-point file.
outputPathstring-The output path of the generated files.
requirestring[]-[]Loads specific require.extensions before running the codegen and reading the configuration.
transformersstring[]--List of TypeScript Transformer Plugins.
tsConfigstring-The path to the Typescript configuration file.
updateBuildableProjectDepsInPackageJsonboolean-trueWhether 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.

"targets": {
  "build": {
    "executor": "nx-mesh:build-gateway",
    "options": {
      "dir": "apps/example-app",
      "outputPath": "dist/apps/example-app"
    },
  },
}

Options

NameTypeRequiredDefaultDescription
debugboolean-falseDisplay debugging info by applying the DEBUG env variable.
dirstring-The path of the directory containing the GraphQL Mesh config.
fileTypejson, ts or js-tsThe filetype.
requirestring[]-[]Loads specific require.extensions before running the codegen and reading the configuration.

build-swc

Builds artifacts for a GraphQL Mesh library.

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

"targets": {
  "build": {
    "executor": "nx-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

NameTypeRequiredDefaultDescription
assetsstring[]--List of static assets.
buildableProjectDepsInPackageJsonTypedependencies or peerDependencies-peerDependenciesWhen updateBuildableProjectDepsInPackageJson is true, this adds dependencies to either peerDependencies or dependencies.
debugboolean-falseDisplay debugging info by applying the DEBUG env variable.
dirstring-The path of the directory containing the GraphQL Mesh config.
fileTypejson, ts or js-tsThe filetype.
mainstring-The name of the main entry-point file.
outputPathstring-The output path of the generated files.
requirestring[]-[]Loads specific require.extensions before running the codegen and reading the configuration.
skipTypeCheckboolean-falseWhether to skip TypeScript type checking.
swcrcstring-.lib.swcrcThe path to the SWC configuration file.
transformersstring[]--List of TypeScript Transformer Plugins.
tsConfigstring-The path to the Typescript configuration file.
updateBuildableProjectDepsInPackageJsonboolean-trueWhether to update the buildable project dependencies in package.json.

dev

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

This is the equivalent of using graphql-mesh dev.

"targets": {
  "dev": {
    "executor": "nx-mesh:dev",
    "options": {
      "dir": "path/to/app/or/lib",
    },
  },
}

Options

NameTypeRequiredDefaultDescription
debugboolean-falseDisplay debugging info by applying the DEBUG env variable.
dirstring-The path of the directory containing the GraphQL Mesh config.
portobject--Port selection settings
port.autoboolean-trueUse the first available port
port.numbernumber-4200Define the preferred port to use when auto is set to false
port.rangeobject--The range of ports to select from.
port.range.fromnumber--The first port of the range. Must be in the range 1024...65535
port.range.tonumber--The last port of the range. Must be in the range 1024...65535 and must be greater than from.
port.fallbackauto, none-autoThe fallback strategy to use when the preferred port is unavailable.
port.hoststring-0.0.0.0The host to listen on (only used for port number lookup).
requirestring[]-[]Loads specific require.extensions before running the codegen and reading the configuration.

start

Serves a GraphQL server with a GraphQL interface based on your generated artifacts.

This is the equivalent of using graphql-mesh start.

"targets": {
  "start": {
    "executor": "nx-mesh:start",
    "options": {
      "dir": "path/to/app/or/lib",
    },
  },
}

Options

NameTypeRequiredDefaultDescription
debugboolean-falseDisplay debugging info by applying the DEBUG env variable.
dirstring-The path of the directory containing the GraphQL Mesh config.
portobject--Port selection settings
port.autoboolean-trueUse the first available port
port.numbernumber-4200Define the preferred port to use when auto is set to false
port.rangeobject--The range of ports to select from.
port.range.fromnumber--The first port of the range. Must be in the range 1024...65535
port.range.tonumber--The last port of the range. Must be in the range 1024...65535 and must be greater than from.
port.fallbackauto, none-autoThe fallback strategy to use when the preferred port is unavailable.
port.hoststring-0.0.0.0The host to listen on (only used for port number lookup).
requirestring[]-[]Loads specific require.extensions before running the codegen and reading the configuration.

serve

Serves a GraphQL server.

This combines dev & start via a dev option toggle.

"targets": {
  "serve": {
    "executor": "nx-mesh:serve",
    "options": {
      "dir": "path/to/app/or/lib",
      "dev": true,
    },
    "configuration": {
      "production": {
        "dev": false,
      }
    }
  },
}

Options

NameTypeRequiredDefaultDescription
debugboolean-falseDisplay debugging info by applying the DEBUG env variable.
devstring-falseRun the server in dev or production mode.
dirstring-The path of the directory containing the GraphQL Mesh config.
portobject--Port selection settings
port.autoboolean-trueUse the first available port
port.numbernumber-4200Define the preferred port to use when auto is set to false
port.rangeobject--The range of ports to select from.
port.range.fromnumber--The first port of the range. Must be in the range 1024...65535
port.range.tonumber--The last port of the range. Must be in the range 1024...65535 and must be greater than from.
port.fallbackauto, none-autoThe fallback strategy to use when the preferred port is unavailable.
port.hoststring-0.0.0.0The host to listen on (only used for port number lookup).
requirestring[]-[]Loads specific require.extensions before running the codegen and reading the configuration.

validate

Validates artifacts.

This is the equivalent of using graphql-mesh validate.

"targets": {
  "validate": {
    "executor": "nx-mesh:validate",
    "options": {
      "dir": "path/to/app/or/lib",
    },
  },
}

Options

NameTypeRequiredDefaultDescription
debugboolean-falseDisplay debugging info by applying the DEBUG env variable.
dirstring-The path of the directory containing the GraphQL Mesh config.
requirestring[]-[]Loads specific require.extensions before running the codegen and reading the configuration.

Examples

API Gateway

NameSource HandlerConfig
apps/api-gateway/javascript-wiki/cjs-configopenapicjs
apps/api-gateway/javascript-wiki/js-configopenapijs
apps/api-gateway/javascript-wiki/json-configopenapijson
apps/api-gateway/javascript-wiki/yml-configopenapiyml
apps/api-gateway/stackexchangeopenapiyml
apps/api-gateway/trippinodatayml
apps/api-gateway/country-infonew-openapiyml

SDK

NameSource HandlerFrameworkCompilerDeployed
apps/nextjs/stackexchangeopenapinextjstsc-
apps/nextjs/trippinodatanextjstscVercel
apps/nextjs/trippin-swcodatanextjsswcVercel
apps/nextjs/country-infonew-openapinextjstsc-

Credits

GraphQL Mesh is made by the awesome team at The Guild.

4.0.0

3 years ago

3.1.0

3 years ago

3.0.1

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.2.3

3 years ago

2.2.2

3 years ago

3.0.0

3 years ago

2.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago