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

Auto-generate GraphQL comments in SDL to support a self-documenting API #5824

Merged
merged 56 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
210dad8
Comments added to generated SDL
dthyresson Jun 25, 2022
e674b28
Comments added to redwood root schema
dthyresson Jun 25, 2022
f57cff2
Update test snapshots for sdl comments
dthyresson Jun 25, 2022
e5577cc
Better root schema descriptions
dthyresson Jun 25, 2022
db416ca
Rearrange functions
dthyresson Jun 25, 2022
3b58e65
Generate GraphQL comment from Prisma comment if present
dthyresson Jun 25, 2022
abc1f57
Support enum schema document comments
dthyresson Jun 25, 2022
e54c3a7
Updates sdl snaps
dthyresson Jun 25, 2022
6ca5bdf
Typo in shoe example
dthyresson Jun 25, 2022
95f748d
Updated snapshots
dthyresson Jun 25, 2022
b7afc27
Add comments to document test project
dthyresson Jun 25, 2022
a2caa26
how to auto-generate graphql comments and docs
dthyresson Jun 25, 2022
9ae35a6
Document @edno/docusaurus2-graphql-doc-generator graphql
dthyresson Jun 25, 2022
36acb7a
Typo fixes
dthyresson Jun 25, 2022
cb788cc
Field names as comments are redundant
dthyresson Jun 28, 2022
6cf4caa
Redo images
dthyresson Jun 28, 2022
9d3a5f3
Adds docs option to sdl and scaffold generators
dthyresson Jun 28, 2022
4cca875
Update docs/docs/graphql.md
dthyresson Jun 29, 2022
9e44931
Update docs/docs/graphql.md
dthyresson Jun 29, 2022
9eba126
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Jun 29, 2022
2d73723
Fixed comments in fields
dthyresson Jun 30, 2022
dbb2273
Updated docs
dthyresson Jun 30, 2022
ade267b
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Jun 30, 2022
e57bf71
Backtick fix
dthyresson Jun 30, 2022
aba530b
Update packages/cli/src/commands/generate/sdl/templates/sdl.js.template
dthyresson Jul 2, 2022
2d90d7b
Update docs/docs/graphql.md
dthyresson Jul 2, 2022
bcbaec1
Update docs/docs/graphql.md
dthyresson Jul 2, 2022
9efc323
Update docs/docs/graphql.md
dthyresson Jul 2, 2022
feadca4
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Jul 2, 2022
19a424f
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Jul 4, 2022
b99c22d
Adds docs option to sdl tests
dthyresson Jul 4, 2022
7784d33
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Jul 4, 2022
c255cec
Note to set --docs when generating comments
dthyresson Jul 5, 2022
c257784
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Jul 18, 2022
6ff66af
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Jul 25, 2022
b829550
Merge branch 'main' into dt-sdl-graphql-comments
jtoar Jul 29, 2022
074ecf7
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Aug 1, 2022
1c1ea88
PR feedback and update snapshots
dthyresson Aug 1, 2022
ea4c93d
Field level descriptions use single quotes
dthyresson Aug 1, 2022
961b2fc
Docs match quoting in graphql docs
dthyresson Aug 1, 2022
49bea40
Fixes broken typescript link in cells docs
dthyresson Aug 1, 2022
3884a2f
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Aug 1, 2022
acbf704
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Aug 1, 2022
374238c
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Aug 3, 2022
8042f1a
Update docs/docs/graphql.md
dthyresson Aug 4, 2022
62c05df
Update docs/docs/graphql.md
dthyresson Aug 4, 2022
bc84836
Update docs/docs/graphql.md
dthyresson Aug 4, 2022
84ca4c1
Update docs/docs/graphql.md
dthyresson Aug 4, 2022
1b01ff0
Update docs/docs/graphql.md
dthyresson Aug 4, 2022
f9b43ea
Update docs/docs/graphql.md
dthyresson Aug 4, 2022
a9c7b71
Update docs/docs/graphql.md
dthyresson Aug 4, 2022
44fdc3a
Rework intro, feedback, image sizing.
dthyresson Aug 4, 2022
084a0a9
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Aug 4, 2022
28f710e
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Aug 4, 2022
deb1ece
Next feedback round of edits.
dthyresson Aug 4, 2022
2cde232
Merge branch 'main' into dt-sdl-graphql-comments
dthyresson Aug 4, 2022
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
16 changes: 14 additions & 2 deletions __fixtures__/test-project/api/db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,40 @@ model UserExample {
name String?
}


/// A blog post.
model Post {
/// The unique identifier of a post.
id Int @id @default(autoincrement())
/// The title of a post.
title String
/// The content of a post.
body String
/// When the post was created.
createdAt DateTime @default(now())
}

model Contact {
/// The unique identifier of a contact.
id Int @id @default(autoincrement())
/// The name of the contact.
name String
/// The email of the contact.
email String
/// The message of the contact.
message String
/// When the contact was created.
createdAt DateTime @default(now())
}

/// A User.
model User {
/// The unique identifier of a user.
id Int @id @default(autoincrement())
/// The user's email address.
email String @unique
hashedPassword String
salt String
resetToken String?
resetTokenExpiresAt DateTime?
roles String?
}
}
29 changes: 16 additions & 13 deletions docs/docs/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -897,11 +897,13 @@ A scaffold quickly creates a CRUD for a model by generating the following files

The content of the generated components is different from what you'd get by running them individually.

| Arguments & Options | Description |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model` | Model to scaffold. You can also use `<path/model>` to nest files by type at the given path directory (or directories). For example, `redwood g scaffold admin/post` |
| `--force, -f` | Overwrite existing files |
| `--typescript, --ts` | Generate TypeScript files Enabled by default if we detect your project is TypeScript |
| Arguments & Options | Description |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model` | Model to scaffold. You can also use `<path/model>` to nest files by type at the given path directory (or directories). For example, `redwood g scaffold admin/post` |
| `--docs` | Use or set to `true` to generated comments in SDL to use in self-documentating your app's GraphQL API. See: [Self-Documenting GraphQL API](./graphql.md#self-documenting-graphql-api) [default:false] |
| `--force, -f` | Overwrite existing files |
| `--tailwind` | Generate TailwindCSS version of scaffold.css (automatically set to `true` if TailwindCSS config exists) |
| `--typescript, --ts` | Generate TypeScript files Enabled by default if we detect your project is TypeScript |

**Usage**

Expand Down Expand Up @@ -1043,13 +1045,14 @@ The sdl will inspect your `schema.prisma` and will do its best with relations. S
<!-- See limited generator support for relations
https://community.redwoodjs.com/t/prisma-beta-2-and-redwoodjs-limited-generator-support-for-relations-with-workarounds/361 -->

| Arguments & Options | Description |
| -------------------- | ------------------------------------------------------------------------------------ |
| `model` | Model to generate the sdl for |
| `--crud` | Set to `false`, or use `--no-crud`, if you do not want to generate mutations |
| `--force, -f` | Overwrite existing files |
| `--tests` | Generate service test and scenario [default: true] |
| `--typescript, --ts` | Generate TypeScript files Enabled by default if we detect your project is TypeScript |
| Arguments & Options | Description |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `model` | Model to generate the sdl for |
| `--crud` | Set to `false`, or use `--no-crud`, if you do not want to generate mutations |
| `--docs` | Use or set to `true` to generated comments in SDL to use in self-documentating your app's GraphQL API. See: [Self-Documenting GraphQL API](./graphql.md#self-documenting-graphql-api) [default: false] |
dthyresson marked this conversation as resolved.
Show resolved Hide resolved
| `--force, -f` | Overwrite existing files |
| `--tests` | Generate service test and scenario [default: true] |
| `--typescript, --ts` | Generate TypeScript files Enabled by default if we detect your project is TypeScript |

> **Note:** The generated sdl will include the `@requireAuth` directive by default to ensure queries and mutations are secure. If your app's queries and mutations are all public, you can set up a custom SDL generator template to apply `@skipAuth` (or a custom validator directive) to suit you application's needs.

Expand Down Expand Up @@ -1232,7 +1235,7 @@ Services are where Redwood puts its business logic. They can be used by your Gra
| `name` | Name of the service |
| `--force, -f` | Overwrite existing files |
| `--typescript, --ts` | Generate TypeScript files Enabled by default if we detect your project is TypeScript |
| `--tests` | Generate test and scenario files [default: true] |
| `--tests` | Generate test and scenario files [default: true] |


**Destroying**
Expand Down
Loading