Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notes SDL codegen in docs #8917

Merged
merged 2 commits into from
Sep 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

:::