4.0.0 • Published 1 year ago

nx-mesh v4.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

nx–mesh — GraphQL Mesh support for Nx.

Contents

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.
  • Generate a GraphQL Mesh SDK
    • Supports deploying to Vercel as a NextJS route.
    • Choose from multiple starter templates.
  • Supports all GraphQL CLI commands (build, dev, start, validate)
  • Use SWC to compile a GraphQL Mesh SDK
  • Use graphql-codegen to build custom SDKs from GraphQL Mesh.
  • Automatically use the first available port when running dev, start, or serve.
  • Supports NX Cypress plugin

Installing

Using pnpm:

pnpm add -D nx-mesh
npm install -D nx-mesh
yarn add -D nx-mesh

Peer Dependencies

NameVersionRequiredAuto-installed by generators
nx>=15.7.1-
@graphql-mesh/cli>=0.71.0
@graphql-codgen/cli>=2.16.1

Preset

Create a new Nx workspace with a GraphQL Mesh SDK!

npx create-nx-workspace@latest myorg --preset=nx-mesh

See the sdk generator for available options.

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
>  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
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?
example-country-info, fake-api, javascript-wiki, movies, rfam, stackexchange, star-wars, trippin-star-warsWhich example project 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.
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
>  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
CREATE libs/my-mesh-sdk/codegen.ts
CREATE libs/my-mesh-sdk/src/lib/client.ts
UPDATE nx.json
>  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/.swcrc
CREATE libs/my-mesh-sdk/.meshrc.json
CREATE libs/my-mesh-sdk/src/lib/sdk.ts
CREATE libs/my-mesh-sdk/codegen.ts
CREATE libs/my-mesh-sdk/src/lib/client.ts
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?
example-javascriptWiki, stackexchange, trippin, countryInfo-javascript-wikiWhich example project would you like to use?
codegen-boolean-trueUse graphql-codegen to generate custom files from the GraphQL Mesh schema.
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"
    },
  },
}
NameTypeRequiredDefaultDescription
assetsstring[]--List of static assets.
buildableProjectDepsInPackageJsonTypedependencies or peerDependencies-peerDependenciesWhen updateBuildableProjectDepsInPackageJson is true, this adds dependencies to either peerDependencies or dependencies.
codegenobject--GraphQL Codegen settings
codegen.configstring-Path to GraphQL codegen YAML config file, defaults to codegen.yml on the current directory.
codegen.overwriteboolean-trueOverwrites existing files.
codegen.profileboolean-falseUse profiler to measure performance.
codegen.projectstring- | Name of a project in GraphQL Config.
codegen.requirestring[]-[]Loads specific require.extensions before running the codegen and reading the configuration.
codegen.silentboolean-falseSuppresses printing errors.
codegen.watchboolean-falseWatch for changes and execute generation automatically.
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.
watchboolean-falseRebuild upon file changes.

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"
    },
  },
}
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"
    },
  },
}
NameTypeRequiredDefaultDescription
assetsstring[]--List of static assets.
buildableProjectDepsInPackageJsonTypedependencies or peerDependencies-peerDependenciesWhen updateBuildableProjectDepsInPackageJson is true, this adds dependencies to either peerDependencies or dependencies.
codegenobject--GraphQL Codegen settings
codegen.configstring-Path to GraphQL codegen YAML config file, defaults to codegen.yml on the current directory.
codegen.overwriteboolean-trueOverwrites existing files.
codegen.profileboolean-falseUse profiler to measure performance.
codegen.projectstring- | Name of a project in GraphQL Config.
codegen.requirestring[]-[]Loads specific require.extensions before running the codegen and reading the configuration.
codegen.silentboolean-falseSuppresses printing errors.
codegen.watchboolean-falseWatch for changes and execute generation automatically.
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-.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.
watchboolean-falseRebuild upon file changes.

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",
    },
  },
}
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-localhostThe 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",
    },
  },
}
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-localhostThe 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,
      }
    }
  },
}
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-localhostThe 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",
    },
  },
}
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

NameTypeSource HandlerConfigNotes
country-infosdksoapcjs-
fake-apisdkjson-schemayml-
javascript-wikigatewayopenapijson-
javascript-wikisdkopenapiyml-
moviessdkneo4jyml-
nextjs with sdks---Deployed to Vercel
rfamsdkmysqlyml-
stackexchangesdkopenapijson-
star-warssdkgraphqlyml-
trippinsdkodatajsAPI Key documentation

Compatibility

nx-meshNx
^4.0.0^15.7.1
^3.0.0^15.4.0

Credits

This plugin wouldn't be possible without the projects from these great teams:

Please show them your support! ❤️

4.0.0

1 year ago

3.1.0

1 year ago

3.0.1

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.2.3

1 year ago

2.2.2

1 year ago

3.0.0

1 year ago

2.1.0

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago