From 361896ba42901ecc8f3faa790737c5413babadf6 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Fri, 14 Jul 2023 22:40:26 +0100 Subject: [PATCH] Notes SDL codegen in docs --- docs/docs/typescript/generated-types.md | 33 ++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/docs/docs/typescript/generated-types.md b/docs/docs/typescript/generated-types.md index 76d33cb1b451..644cc7b39bd4 100644 --- a/docs/docs/typescript/generated-types.md +++ b/docs/docs/typescript/generated-types.md @@ -164,9 +164,40 @@ You can configure graphql-codegen in a number of different ways: `codegen.yml`, For completeness, [here's the docs](https://www.graphql-code-generator.com/docs/config-reference/config-field) on configuring GraphQL Code Generator. Currently, Redwood only supports the root level `config` option. +## Experimental SDL Code Generation + +There is also an experimental code generator based on [sdl-codegen](https://github.com/sdl-codegen/sdl-codegen) available. sdl-codegen is a fresh implementation of code generation for service files, built with Redwood in mind. It is currently in opt-in and can be enabled by setting the `experimentalSdlCodeGen` flag to `true` in your `redwood.toml` file: + +```toml title="redwood.toml" +[experimental] + useSDLCodeGenForGraphQLTypes = true +``` + +Running `yarn rw g types` will generate types for your resolvers on a per-file basis, this feature can be paired with the optional eslint auto-fix rule to have types automatically applied to your resolvers in TypeScript service files by editing your root `package.json` with: + +```diff title="package.json" + "eslintConfig": { + "extends": "@redwoodjs/eslint-config", + "root": true, + "parserOptions": { + "warnOnUnsupportedTypeScriptVersion": false + }, ++ "overrides": [ ++ { ++ "files": [ ++ "api/src/services/**/*.ts" ++ ], ++ "rules": { ++ "@redwoodjs/service-type-annotations": "error" ++ } ++ } + ] + }, +``` + :::tip Using VSCode? -As a part of type generation, the [VSCode GraphQL extension](https://marketplace.visualstudio.com/items?itemName=GraphQL.vscode-graphql) configures itself based on the merged schema Redwood generates in `.redwood/schema.graphql`. +As a part of type generation, the extension [GraphQL: Language Feature Support](https://marketplace.visualstudio.com/items?itemName=GraphQL.vscode-graphql) configures itself based on the merged schema Redwood generates in `.redwood/schema.graphql`. You can configure it further in `graphql.config.js` at the root of your project. :::