Skip to content

Commit

Permalink
Notes SDL codegen in docs (#8917)
Browse files Browse the repository at this point in the history
Got side-tracked into adding some light docs in the type generation page
  • Loading branch information
orta authored and jtoar committed Sep 16, 2023
1 parent 3e8bc4a commit c834781
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion docs/docs/typescript/generated-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

:::

0 comments on commit c834781

Please sign in to comment.