From cd2f77c1d3d7375bf5356c864a3804a7afe4aa90 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 28 Mar 2023 12:42:23 +0200 Subject: [PATCH] Using new `cds-plugin` technique --- CHANGELOG.md | 1 + README.md | 24 +++++++----------------- cds-plugin.js | 5 +++++ 3 files changed, 13 insertions(+), 17 deletions(-) create mode 100644 cds-plugin.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 28dbf018..eecec379 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Supporting new `cds-plugin` technique for zero configuration - Support for filtering by `null` values ### Changed diff --git a/README.md b/README.md index cf23844e..b3563714 100644 --- a/README.md +++ b/README.md @@ -11,24 +11,14 @@ _**WARNING:** This package is in an early general availability state. This means ## Requirements and Setup -1. Add the GraphQL adapter to your project using `npm`: - ```js - npm add @cap-js/graphql - ``` - -2. Register the GraphQL adapter in your project's `package.json`: - ```jsonc - { - "cds": { - "protocols": { - "graphql": { "path": "/graphql", "impl": "@cap-js/graphql" } - } - } - } - ``` - > Note: This automatically enables the new [middlewares architecture](https://cap.cloud.sap/docs/node.js/middlewares) in Node.js. +1. Simply add the GraphQL adapter to your project using `npm`: + ```js + npm add @cap-js/graphql + ``` + +> This will automatically plugin to `@sap/cds` runtime, enabling the new [middlewares architecture](https://cap.cloud.sap/docs/node.js/middlewares) in Node.js, and register a GraphQL endpoint at `/graphql` serving all CRUD requests for the application services found in your model. -3. Run your server as usual, e.g. using `cds watch`. +2. Run your server as usual, e.g. using `cds watch`. > The runtime will automatically serve all services via GraphQL at the default configured endpoint. ## Limitations diff --git a/cds-plugin.js b/cds-plugin.js new file mode 100644 index 00000000..17ab8fdc --- /dev/null +++ b/cds-plugin.js @@ -0,0 +1,5 @@ +const cds = require('@sap/cds') +const protocols = cds.env.protocols ??= {} +if (!protocols.graphql) protocols.graphql = { + path: "/graphql", impl: "@cap-js/graphql" +}