create-redmix-app 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +126 -0
- package/dist/create-redmix-app.js +637 -0
- package/package.json +57 -0
- package/templates/js/.editorconfig +10 -0
- package/templates/js/.env +15 -0
- package/templates/js/.env.defaults +19 -0
- package/templates/js/.env.example +4 -0
- package/templates/js/.redwood/README.md +44 -0
- package/templates/js/.vscode/extensions.json +14 -0
- package/templates/js/.vscode/launch.json +56 -0
- package/templates/js/.vscode/settings.json +11 -0
- package/templates/js/.vscode/tasks.json +29 -0
- package/templates/js/.yarnrc.yml +15 -0
- package/templates/js/README.md +122 -0
- package/templates/js/api/db/schema.prisma +24 -0
- package/templates/js/api/jest.config.js +8 -0
- package/templates/js/api/jsconfig.json +41 -0
- package/templates/js/api/package.json +9 -0
- package/templates/js/api/src/directives/requireAuth/requireAuth.js +22 -0
- package/templates/js/api/src/directives/requireAuth/requireAuth.test.js +18 -0
- package/templates/js/api/src/directives/skipAuth/skipAuth.js +16 -0
- package/templates/js/api/src/directives/skipAuth/skipAuth.test.js +10 -0
- package/templates/js/api/src/functions/graphql.js +19 -0
- package/templates/js/api/src/graphql/.keep +0 -0
- package/templates/js/api/src/lib/auth.js +32 -0
- package/templates/js/api/src/lib/db.js +26 -0
- package/templates/js/api/src/lib/logger.js +17 -0
- package/templates/js/api/src/services/.keep +0 -0
- package/templates/js/gitignore.template +24 -0
- package/templates/js/graphql.config.js +11 -0
- package/templates/js/jest.config.js +8 -0
- package/templates/js/package.json +28 -0
- package/templates/js/prettier.config.js +18 -0
- package/templates/js/redwood.toml +21 -0
- package/templates/js/scripts/.keep +0 -0
- package/templates/js/scripts/jsconfig.json +54 -0
- package/templates/js/scripts/seed.js +27 -0
- package/templates/js/web/jest.config.js +8 -0
- package/templates/js/web/jsconfig.json +53 -0
- package/templates/js/web/package.json +25 -0
- package/templates/js/web/public/README.md +43 -0
- package/templates/js/web/public/favicon.png +0 -0
- package/templates/js/web/public/robots.txt +2 -0
- package/templates/js/web/src/App.jsx +16 -0
- package/templates/js/web/src/Routes.jsx +20 -0
- package/templates/js/web/src/components/.keep +0 -0
- package/templates/js/web/src/entry.client.jsx +35 -0
- package/templates/js/web/src/index.css +0 -0
- package/templates/js/web/src/index.html +15 -0
- package/templates/js/web/src/layouts/.keep +0 -0
- package/templates/js/web/src/pages/FatalErrorPage/FatalErrorPage.jsx +58 -0
- package/templates/js/web/src/pages/NotFoundPage/NotFoundPage.jsx +45 -0
- package/templates/js/web/vite.config.js +15 -0
- package/templates/js/yarn.lock +17991 -0
- package/templates/ts/.editorconfig +10 -0
- package/templates/ts/.env +15 -0
- package/templates/ts/.env.defaults +19 -0
- package/templates/ts/.env.example +4 -0
- package/templates/ts/.redwood/README.md +44 -0
- package/templates/ts/.vscode/extensions.json +14 -0
- package/templates/ts/.vscode/launch.json +56 -0
- package/templates/ts/.vscode/settings.json +11 -0
- package/templates/ts/.vscode/tasks.json +29 -0
- package/templates/ts/.yarnrc.yml +15 -0
- package/templates/ts/README.md +122 -0
- package/templates/ts/api/db/schema.prisma +24 -0
- package/templates/ts/api/jest.config.js +8 -0
- package/templates/ts/api/package.json +9 -0
- package/templates/ts/api/src/directives/requireAuth/requireAuth.test.ts +18 -0
- package/templates/ts/api/src/directives/requireAuth/requireAuth.ts +25 -0
- package/templates/ts/api/src/directives/skipAuth/skipAuth.test.ts +10 -0
- package/templates/ts/api/src/directives/skipAuth/skipAuth.ts +16 -0
- package/templates/ts/api/src/functions/graphql.ts +19 -0
- package/templates/ts/api/src/graphql/.keep +0 -0
- package/templates/ts/api/src/lib/auth.ts +32 -0
- package/templates/ts/api/src/lib/db.ts +26 -0
- package/templates/ts/api/src/lib/logger.ts +17 -0
- package/templates/ts/api/src/services/.keep +0 -0
- package/templates/ts/api/tsconfig.json +26 -0
- package/templates/ts/gitignore.template +24 -0
- package/templates/ts/graphql.config.js +11 -0
- package/templates/ts/jest.config.js +8 -0
- package/templates/ts/package.json +28 -0
- package/templates/ts/prettier.config.js +18 -0
- package/templates/ts/redwood.toml +21 -0
- package/templates/ts/scripts/.keep +0 -0
- package/templates/ts/scripts/seed.ts +27 -0
- package/templates/ts/scripts/tsconfig.json +29 -0
- package/templates/ts/web/jest.config.js +8 -0
- package/templates/ts/web/package.json +25 -0
- package/templates/ts/web/public/README.md +43 -0
- package/templates/ts/web/public/favicon.png +0 -0
- package/templates/ts/web/public/robots.txt +2 -0
- package/templates/ts/web/src/App.tsx +22 -0
- package/templates/ts/web/src/Routes.tsx +20 -0
- package/templates/ts/web/src/components/.keep +0 -0
- package/templates/ts/web/src/entry.client.tsx +35 -0
- package/templates/ts/web/src/index.css +0 -0
- package/templates/ts/web/src/index.html +15 -0
- package/templates/ts/web/src/layouts/.keep +0 -0
- package/templates/ts/web/src/pages/FatalErrorPage/FatalErrorPage.tsx +57 -0
- package/templates/ts/web/src/pages/NotFoundPage/NotFoundPage.tsx +44 -0
- package/templates/ts/web/tsconfig.json +44 -0
- package/templates/ts/web/vite.config.ts +16 -0
- package/templates/ts/yarn.lock +17991 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
# THIS FILE SHOULD NOT BE CHECKED INTO YOUR VERSION CONTROL SYSTEM
|
2
|
+
#
|
3
|
+
# Environment variables set here will override those in .env.defaults.
|
4
|
+
# Any environment variables you need in production you will need to setup with
|
5
|
+
# your hosting provider. For example in Netlify you can add environment
|
6
|
+
# variables in Settings > Build & Deploy > environment
|
7
|
+
#
|
8
|
+
# DATABASE_URL=postgres://user:pass@postgreshost.com:5432/database_name
|
9
|
+
# TEST_DATABASE_URL=postgres://user:pass@postgreshost.com:5432/test_database_name
|
10
|
+
#
|
11
|
+
# Sets an app-specific secret used to sign and verify your own app's webhooks.
|
12
|
+
# For example if you schedule a cron job with a signed payload that later will
|
13
|
+
# then invoke your api-side webhook function you will use this secret to sign and the verify.
|
14
|
+
# Important: Please change this default to a strong password or other secret
|
15
|
+
# WEBHOOK_SECRET=THIS_IS_NOT_SECRET_PLEASE_CHANGE
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# These environment variables will be used by default if you do not create any
|
2
|
+
# yourself in .env. This file should be safe to check into your version control
|
3
|
+
# system. Any custom values should go in .env and .env should *not* be checked
|
4
|
+
# into version control.
|
5
|
+
|
6
|
+
# schema.prisma defaults
|
7
|
+
DATABASE_URL=file:./dev.db
|
8
|
+
|
9
|
+
# location of the test database for api service scenarios (defaults to ./.redwood/test.db if not set)
|
10
|
+
# TEST_DATABASE_URL=file:./.redwood/test.db
|
11
|
+
|
12
|
+
# disables Prisma CLI update notifier
|
13
|
+
PRISMA_HIDE_UPDATE_MESSAGE=true
|
14
|
+
|
15
|
+
# Option to override the current environment's default api-side log level
|
16
|
+
# See: https://redwoodjs.com/docs/logger for level options, defaults to "trace" otherwise.
|
17
|
+
# Most applications want "debug" or "info" during dev, "trace" when you have issues and "warn" in production.
|
18
|
+
# Ordered by how verbose they are: trace | debug | info | warn | error | silent
|
19
|
+
# LOG_LEVEL=debug
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# .redwood
|
2
|
+
|
3
|
+
## What is this directory?
|
4
|
+
|
5
|
+
Redwood uses this `.redwood` directory to store transitory data that aids in the smooth and convenient operation of your Redwood project.
|
6
|
+
|
7
|
+
## Do I need to do anything with this directory?
|
8
|
+
|
9
|
+
No. You shouldn't have to create, edit or delete anything in this directory in your day-to-day work with Redwood.
|
10
|
+
|
11
|
+
You don't need to commit any other contents of this directory to your version control system. It's ignored by default.
|
12
|
+
|
13
|
+
## What's in this directory?
|
14
|
+
|
15
|
+
### Files
|
16
|
+
|
17
|
+
| Name | Description |
|
18
|
+
| :---------------- | :----------------------------------------------------------------------------------------------------------------- |
|
19
|
+
| commandCache.json | This file contains mappings to assist the Redwood CLI in efficiently executing commands. |
|
20
|
+
| schema.graphql | This is the GraphQL schema which has been automatically generated from your Redwood project. |
|
21
|
+
| telemetry.txt | Contains a unique ID used for telemetry. This value is rotated every 24 hours to protect your project's anonymity. |
|
22
|
+
| test.db | The sqlite database used when running tests. |
|
23
|
+
|
24
|
+
### Directories
|
25
|
+
|
26
|
+
| Name | Description |
|
27
|
+
| :---------- | :----------------------------------------------------------------------------------------------------------------------------------------------- |
|
28
|
+
| locks | Stores temporary files that Redwood uses to keep track of the execution of async/background tasks between processes. |
|
29
|
+
| logs | Stores log files for background tasks such as update checking. |
|
30
|
+
| prebuild | Stores transpiled JavaScript that is generated as part of Redwood's build process. |
|
31
|
+
| telemetry | Stores the recent telemetry that the Redwood CLI has generated. You may inspect these files to see everything Redwood is anonymously collecting. |
|
32
|
+
| types | Stores the results of type generation. |
|
33
|
+
| updateCheck | Stores a file which contains the results of checking for Redwood updates. |
|
34
|
+
| studio | Used to store data for `rw studio` |
|
35
|
+
|
36
|
+
We try to keep this README up to date but you may, from time to time, find other files or directories in this `.redwood` directory that have not yet been documented here. This is likely nothing to worry about but feel free to let us know and we'll update this list.
|
37
|
+
|
38
|
+
### Telemetry
|
39
|
+
|
40
|
+
RedwoodJS collects completely anonymous telemetry data about general usage. For transparency, that data is viewable in the respective directories and files. To learn more and manage your project's settings, visit [telemetry.redwoodjs.com](https://telemetry.redwoodjs.com).
|
41
|
+
|
42
|
+
### Have any questions?
|
43
|
+
|
44
|
+
Feel free to reach out to us in the [RedwoodJS Community](https://community.redwoodjs.com/) forum if you have any questions.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"recommendations": [
|
3
|
+
"dbaeumer.vscode-eslint",
|
4
|
+
"eamodio.gitlens",
|
5
|
+
"ofhumanbondage.react-proptypes-intellisense",
|
6
|
+
"mgmcdermott.vscode-language-babel",
|
7
|
+
"wix.vscode-import-cost",
|
8
|
+
"pflannery.vscode-versionlens",
|
9
|
+
"editorconfig.editorconfig",
|
10
|
+
"prisma.prisma",
|
11
|
+
"graphql.vscode-graphql"
|
12
|
+
],
|
13
|
+
"unwantedRecommendations": []
|
14
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
{
|
2
|
+
"version": "0.3.0",
|
3
|
+
"configurations": [
|
4
|
+
{
|
5
|
+
"command": "yarn redwood dev --apiDebugPort 18911", // you can add --fwd='--open=false' to prevent the browser from opening
|
6
|
+
"name": "Run Dev Server",
|
7
|
+
"request": "launch",
|
8
|
+
"type": "node-terminal"
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"name": "Attach API debugger",
|
12
|
+
"port": 18911, // you can change this port, see https://redwoodjs.com/docs/project-configuration-dev-test-build#debugger-configuration
|
13
|
+
"request": "attach",
|
14
|
+
"skipFiles": [
|
15
|
+
"<node_internals>/**"
|
16
|
+
],
|
17
|
+
"type": "node",
|
18
|
+
"localRoot": "${workspaceFolder}/node_modules/@redmix/api-server/dist",
|
19
|
+
"remoteRoot": "${workspaceFolder}/node_modules/@redmix/api-server/dist",
|
20
|
+
"sourceMaps": true,
|
21
|
+
"restart": true,
|
22
|
+
"preLaunchTask": "WaitForDevServer",
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"name": "Launch Web debugger",
|
26
|
+
"type": "chrome",
|
27
|
+
"request": "launch",
|
28
|
+
"url": "http://localhost:8910",
|
29
|
+
"webRoot": "${workspaceRoot}/web/src",
|
30
|
+
"preLaunchTask": "WaitForDevServer",
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"command": "yarn redwood test api",
|
34
|
+
"name": "Test api",
|
35
|
+
"request": "launch",
|
36
|
+
"type": "node-terminal"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"command": "yarn redwood test web",
|
40
|
+
"name": "Test web",
|
41
|
+
"request": "launch",
|
42
|
+
"type": "node-terminal"
|
43
|
+
},
|
44
|
+
],
|
45
|
+
"compounds": [
|
46
|
+
{
|
47
|
+
"name": "Start Debug",
|
48
|
+
"configurations": [
|
49
|
+
"Run Dev Server",
|
50
|
+
"Attach API debugger",
|
51
|
+
"Launch Web debugger"
|
52
|
+
],
|
53
|
+
"stopAll": true
|
54
|
+
}
|
55
|
+
]
|
56
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"version": "2.0.0",
|
3
|
+
"tasks": [
|
4
|
+
{
|
5
|
+
"label": "WaitForDevServer",
|
6
|
+
"group": "none",
|
7
|
+
"type": "shell",
|
8
|
+
"command": "bash",
|
9
|
+
"args": [
|
10
|
+
"-c",
|
11
|
+
"while ! echo -n > /dev/tcp/localhost/18911; do sleep 1; done;"
|
12
|
+
],
|
13
|
+
"windows": {
|
14
|
+
"command": "powershell",
|
15
|
+
"args": [
|
16
|
+
"-NoProfile",
|
17
|
+
"-ExecutionPolicy", "Bypass",
|
18
|
+
"while (-not (Test-NetConnection -ComputerName localhost -Port 18911)) { Start-Sleep -Seconds 1 };"
|
19
|
+
]
|
20
|
+
},
|
21
|
+
"presentation": {
|
22
|
+
"reveal": "silent",
|
23
|
+
"revealProblems": "onProblem",
|
24
|
+
"panel": "shared",
|
25
|
+
"close": true
|
26
|
+
}
|
27
|
+
},
|
28
|
+
]
|
29
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Yarn's manifest file. You can configure yarn here.
|
2
|
+
# See https://yarnpkg.com/configuration/yarnrc.
|
3
|
+
|
4
|
+
# For `node_modules` (see `nodeLinker` below), this is almost always the preferred option.
|
5
|
+
compressionLevel: 0
|
6
|
+
|
7
|
+
enableGlobalCache: true
|
8
|
+
|
9
|
+
# Lets yarn use hardlinks inside `node_modules` to dedupe packages.
|
10
|
+
# For a more pnpm-like experience, consider `hardlinks-global` where hardlinks point to a global store.
|
11
|
+
nmMode: hardlinks-local
|
12
|
+
|
13
|
+
# How to install Node packages.
|
14
|
+
# Heads up: right now, Redwood expects this to be `node-modules`.
|
15
|
+
nodeLinker: node-modules
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# README
|
2
|
+
|
3
|
+
Welcome to [RedwoodJS](https://redwoodjs.com)!
|
4
|
+
|
5
|
+
> **Prerequisites**
|
6
|
+
>
|
7
|
+
> - Redwood requires [Node.js](https://nodejs.org/en/) (=20.x) and [Yarn](https://yarnpkg.com/)
|
8
|
+
> - Are you on Windows? For best results, follow our [Windows development setup](https://redwoodjs.com/docs/how-to/windows-development-setup) guide
|
9
|
+
|
10
|
+
Start by installing dependencies:
|
11
|
+
|
12
|
+
```
|
13
|
+
yarn install
|
14
|
+
```
|
15
|
+
|
16
|
+
Then start the development server:
|
17
|
+
|
18
|
+
```
|
19
|
+
yarn redwood dev
|
20
|
+
```
|
21
|
+
|
22
|
+
Your browser should automatically open to [http://localhost:8910](http://localhost:8910) where you'll see the Welcome Page, which links out to many great resources.
|
23
|
+
|
24
|
+
> **The Redwood CLI**
|
25
|
+
>
|
26
|
+
> Congratulations on running your first Redwood CLI command! From dev to deploy, the CLI is with you the whole way. And there's quite a few commands at your disposal:
|
27
|
+
>
|
28
|
+
> ```
|
29
|
+
> yarn redwood --help
|
30
|
+
> ```
|
31
|
+
>
|
32
|
+
> For all the details, see the [CLI reference](https://redwoodjs.com/docs/cli-commands).
|
33
|
+
|
34
|
+
## Prisma and the database
|
35
|
+
|
36
|
+
Redwood wouldn't be a full-stack framework without a database. It all starts with the schema. Open the [`schema.prisma`](api/db/schema.prisma) file in `api/db` and replace the `UserExample` model with the following `Post` model:
|
37
|
+
|
38
|
+
```prisma
|
39
|
+
model Post {
|
40
|
+
id Int @id @default(autoincrement())
|
41
|
+
title String
|
42
|
+
body String
|
43
|
+
createdAt DateTime @default(now())
|
44
|
+
}
|
45
|
+
```
|
46
|
+
|
47
|
+
Redwood uses [Prisma](https://www.prisma.io/), a next-gen Node.js and TypeScript ORM, to talk to the database. Prisma's schema offers a declarative way of defining your app's data models. And Prisma [Migrate](https://www.prisma.io/migrate) uses that schema to make database migrations hassle-free:
|
48
|
+
|
49
|
+
```
|
50
|
+
yarn rw prisma migrate dev
|
51
|
+
|
52
|
+
# ...
|
53
|
+
|
54
|
+
? Enter a name for the new migration: › create posts
|
55
|
+
```
|
56
|
+
|
57
|
+
> `rw` is short for `redwood`
|
58
|
+
|
59
|
+
You'll be prompted for the name of your migration. `create posts` will do.
|
60
|
+
|
61
|
+
Now let's generate everything we need to perform all the CRUD (Create, Retrieve, Update, Delete) actions on our `Post` model:
|
62
|
+
|
63
|
+
```
|
64
|
+
yarn redwood generate scaffold post
|
65
|
+
```
|
66
|
+
|
67
|
+
Navigate to [http://localhost:8910/posts/new](http://localhost:8910/posts/new), fill in the title and body, and click "Save".
|
68
|
+
|
69
|
+
Did we just create a post in the database? Yup! With `yarn rw generate scaffold <model>`, Redwood created all the pages, components, and services necessary to perform all CRUD actions on our posts table.
|
70
|
+
|
71
|
+
## Frontend first with Storybook
|
72
|
+
|
73
|
+
Don't know what your data models look like? That's more than ok—Redwood integrates Storybook so that you can work on design without worrying about data. Mockup, build, and verify your React components, even in complete isolation from the backend:
|
74
|
+
|
75
|
+
```
|
76
|
+
yarn rw storybook
|
77
|
+
```
|
78
|
+
|
79
|
+
Seeing "Couldn't find any stories"? That's because you need a `*.stories.{tsx,jsx}` file. The Redwood CLI makes getting one easy enough—try generating a [Cell](https://redwoodjs.com/docs/cells), Redwood's data-fetching abstraction:
|
80
|
+
|
81
|
+
```
|
82
|
+
yarn rw generate cell examplePosts
|
83
|
+
```
|
84
|
+
|
85
|
+
The Storybook server should hot reload and now you'll have four stories to work with. They'll probably look a little bland since there's no styling. See if the Redwood CLI's `setup ui` command has your favorite styling library:
|
86
|
+
|
87
|
+
```
|
88
|
+
yarn rw setup ui --help
|
89
|
+
```
|
90
|
+
|
91
|
+
## Testing with Jest
|
92
|
+
|
93
|
+
It'd be hard to scale from side project to startup without a few tests. Redwood fully integrates Jest with both the front- and back-ends, and makes it easy to keep your whole app covered by generating test files with all your components and services:
|
94
|
+
|
95
|
+
```
|
96
|
+
yarn rw test
|
97
|
+
```
|
98
|
+
|
99
|
+
To make the integration even more seamless, Redwood augments Jest with database [scenarios](https://redwoodjs.com/docs/testing#scenarios) and [GraphQL mocking](https://redwoodjs.com/docs/testing#mocking-graphql-calls).
|
100
|
+
|
101
|
+
## Ship it
|
102
|
+
|
103
|
+
Redwood is designed for both serverless deploy targets like Netlify and Vercel and serverful deploy targets like Render and AWS:
|
104
|
+
|
105
|
+
```
|
106
|
+
yarn rw setup deploy --help
|
107
|
+
```
|
108
|
+
|
109
|
+
Don't go live without auth! Lock down your app with Redwood's built-in, database-backed authentication system ([dbAuth](https://redwoodjs.com/docs/authentication#self-hosted-auth-installation-and-setup)), or integrate with nearly a dozen third-party auth providers:
|
110
|
+
|
111
|
+
```
|
112
|
+
yarn rw setup auth --help
|
113
|
+
```
|
114
|
+
|
115
|
+
## Next Steps
|
116
|
+
|
117
|
+
The best way to learn Redwood is by going through the comprehensive [tutorial](https://redwoodjs.com/docs/tutorial/foreword) and joining the community (via the [Discourse forum](https://community.redwoodjs.com) or the [Discord server](https://discord.gg/redwoodjs)).
|
118
|
+
|
119
|
+
## Quick Links
|
120
|
+
|
121
|
+
- Stay updated: read [Forum announcements](https://community.redwoodjs.com/c/announcements/5), follow us on [Twitter](https://twitter.com/redwoodjs), and subscribe to the [newsletter](https://redwoodjs.com/newsletter)
|
122
|
+
- [Learn how to contribute](https://redwoodjs.com/docs/contributing)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// Don't forget to tell Prisma about your edits to this file using
|
2
|
+
// `yarn rw prisma migrate dev` or `yarn rw prisma db push`.
|
3
|
+
// `migrate` is like committing while `push` is for prototyping.
|
4
|
+
// Read more about both here:
|
5
|
+
// https://www.prisma.io/docs/orm/prisma-migrate
|
6
|
+
|
7
|
+
datasource db {
|
8
|
+
provider = "sqlite"
|
9
|
+
url = env("DATABASE_URL")
|
10
|
+
}
|
11
|
+
|
12
|
+
generator client {
|
13
|
+
provider = "prisma-client-js"
|
14
|
+
binaryTargets = "native"
|
15
|
+
}
|
16
|
+
|
17
|
+
// Define your own datamodels here and run `yarn redwood prisma migrate dev`
|
18
|
+
// to create migrations for them and apply to your dev DB.
|
19
|
+
// TODO: Please remove the following example:
|
20
|
+
model UserExample {
|
21
|
+
id Int @id @default(autoincrement())
|
22
|
+
email String @unique
|
23
|
+
name String?
|
24
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { mockRedwoodDirective, getDirectiveName } from '@redmix/testing/api'
|
2
|
+
|
3
|
+
import requireAuth from './requireAuth'
|
4
|
+
|
5
|
+
describe('requireAuth directive', () => {
|
6
|
+
it('declares the directive sdl as schema, with the correct name', () => {
|
7
|
+
expect(requireAuth.schema).toBeTruthy()
|
8
|
+
expect(getDirectiveName(requireAuth.schema)).toBe('requireAuth')
|
9
|
+
})
|
10
|
+
|
11
|
+
it('requireAuth has stub implementation. Should not throw when current user', () => {
|
12
|
+
// If you want to set values in context, pass it through e.g.
|
13
|
+
// mockRedwoodDirective(requireAuth, { context: { currentUser: { id: 1, name: 'Lebron McGretzky' } }})
|
14
|
+
const mockExecution = mockRedwoodDirective(requireAuth, { context: {} })
|
15
|
+
|
16
|
+
expect(mockExecution).not.toThrowError()
|
17
|
+
})
|
18
|
+
})
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import gql from 'graphql-tag'
|
2
|
+
|
3
|
+
import type { ValidatorDirectiveFunc } from '@redmix/graphql-server'
|
4
|
+
import { createValidatorDirective } from '@redmix/graphql-server'
|
5
|
+
|
6
|
+
import { requireAuth as applicationRequireAuth } from 'src/lib/auth'
|
7
|
+
|
8
|
+
export const schema = gql`
|
9
|
+
"""
|
10
|
+
Use to check whether or not a user is authenticated and is associated
|
11
|
+
with an optional set of roles.
|
12
|
+
"""
|
13
|
+
directive @requireAuth(roles: [String]) on FIELD_DEFINITION
|
14
|
+
`
|
15
|
+
|
16
|
+
type RequireAuthValidate = ValidatorDirectiveFunc<{ roles?: string[] }>
|
17
|
+
|
18
|
+
const validate: RequireAuthValidate = ({ directiveArgs }) => {
|
19
|
+
const { roles } = directiveArgs
|
20
|
+
applicationRequireAuth({ roles })
|
21
|
+
}
|
22
|
+
|
23
|
+
const requireAuth = createValidatorDirective(schema, validate)
|
24
|
+
|
25
|
+
export default requireAuth
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { getDirectiveName } from '@redmix/testing/api'
|
2
|
+
|
3
|
+
import skipAuth from './skipAuth'
|
4
|
+
|
5
|
+
describe('skipAuth directive', () => {
|
6
|
+
it('declares the directive sdl as schema, with the correct name', () => {
|
7
|
+
expect(skipAuth.schema).toBeTruthy()
|
8
|
+
expect(getDirectiveName(skipAuth.schema)).toBe('skipAuth')
|
9
|
+
})
|
10
|
+
})
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import gql from 'graphql-tag'
|
2
|
+
|
3
|
+
import { createValidatorDirective } from '@redmix/graphql-server'
|
4
|
+
|
5
|
+
export const schema = gql`
|
6
|
+
"""
|
7
|
+
Use to skip authentication checks and allow public access.
|
8
|
+
"""
|
9
|
+
directive @skipAuth on FIELD_DEFINITION
|
10
|
+
`
|
11
|
+
|
12
|
+
const skipAuth = createValidatorDirective(schema, () => {
|
13
|
+
return
|
14
|
+
})
|
15
|
+
|
16
|
+
export default skipAuth
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { createGraphQLHandler } from '@redmix/graphql-server'
|
2
|
+
|
3
|
+
import directives from 'src/directives/**/*.{js,ts}'
|
4
|
+
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
|
5
|
+
import services from 'src/services/**/*.{js,ts}'
|
6
|
+
|
7
|
+
import { db } from 'src/lib/db'
|
8
|
+
import { logger } from 'src/lib/logger'
|
9
|
+
|
10
|
+
export const handler = createGraphQLHandler({
|
11
|
+
loggerConfig: { logger, options: {} },
|
12
|
+
directives,
|
13
|
+
sdls,
|
14
|
+
services,
|
15
|
+
onException: () => {
|
16
|
+
// Disconnect from your database with an unhandled exception.
|
17
|
+
db.$disconnect()
|
18
|
+
},
|
19
|
+
})
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* Once you are ready to add authentication to your application
|
3
|
+
* you'll build out requireAuth() with real functionality. For
|
4
|
+
* now we just return `true` so that the calls in services
|
5
|
+
* have something to check against, simulating a logged
|
6
|
+
* in user that is allowed to access that service.
|
7
|
+
*
|
8
|
+
* See https://redwoodjs.com/docs/authentication for more info.
|
9
|
+
*/
|
10
|
+
export const isAuthenticated = () => {
|
11
|
+
return true
|
12
|
+
}
|
13
|
+
|
14
|
+
export const hasRole = ({ roles }) => {
|
15
|
+
return roles !== undefined
|
16
|
+
}
|
17
|
+
|
18
|
+
// This is used by the redwood directive
|
19
|
+
// in ./api/src/directives/requireAuth
|
20
|
+
|
21
|
+
// Roles are passed in by the requireAuth directive if you have auth setup
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
23
|
+
export const requireAuth = ({ roles }) => {
|
24
|
+
return isAuthenticated()
|
25
|
+
}
|
26
|
+
|
27
|
+
export const getCurrentUser = async () => {
|
28
|
+
throw new Error(
|
29
|
+
'Auth is not set up yet. See https://redwoodjs.com/docs/authentication ' +
|
30
|
+
'to get started'
|
31
|
+
)
|
32
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
// See https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/constructor
|
2
|
+
// for options.
|
3
|
+
|
4
|
+
import { PrismaClient } from '@prisma/client'
|
5
|
+
|
6
|
+
import { emitLogLevels, handlePrismaLogging } from '@redmix/api/logger'
|
7
|
+
|
8
|
+
import { logger } from './logger'
|
9
|
+
|
10
|
+
const prismaClient = new PrismaClient({
|
11
|
+
log: emitLogLevels(['info', 'warn', 'error']),
|
12
|
+
})
|
13
|
+
|
14
|
+
handlePrismaLogging({
|
15
|
+
db: prismaClient,
|
16
|
+
logger,
|
17
|
+
logLevels: ['info', 'warn', 'error'],
|
18
|
+
})
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Global Prisma client extensions should be added here, as $extend
|
22
|
+
* returns a new instance.
|
23
|
+
* export const db = prismaClient.$extend(...)
|
24
|
+
* Add any .$on hooks before using $extend
|
25
|
+
*/
|
26
|
+
export const db = prismaClient
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { createLogger } from '@redmix/api/logger'
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Creates a logger with RedwoodLoggerOptions
|
5
|
+
*
|
6
|
+
* These extend and override default LoggerOptions,
|
7
|
+
* can define a destination like a file or other supported pino log transport stream,
|
8
|
+
* and sets whether or not to show the logger configuration settings (defaults to false)
|
9
|
+
*
|
10
|
+
* @param RedwoodLoggerOptions
|
11
|
+
*
|
12
|
+
* RedwoodLoggerOptions have
|
13
|
+
* @param {options} LoggerOptions - defines how to log, such as redaction and format
|
14
|
+
* @param {string | DestinationStream} destination - defines where to log, such as a transport stream or file
|
15
|
+
* @param {boolean} showConfig - whether to display logger configuration on initialization
|
16
|
+
*/
|
17
|
+
export const logger = createLogger({})
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"noEmit": true,
|
4
|
+
"allowJs": true,
|
5
|
+
"esModuleInterop": true,
|
6
|
+
"target": "ES2023",
|
7
|
+
"module": "Node16",
|
8
|
+
"moduleResolution": "Node16",
|
9
|
+
"skipLibCheck": false,
|
10
|
+
"rootDirs": ["./src", "../.redwood/types/mirror/api/src"],
|
11
|
+
"paths": {
|
12
|
+
"src/*": ["./src/*", "../.redwood/types/mirror/api/src/*"],
|
13
|
+
"types/*": ["./types/*", "../types/*"],
|
14
|
+
"@redmix/testing": ["../node_modules/@redmix/testing/api"]
|
15
|
+
},
|
16
|
+
"typeRoots": ["../node_modules/@types", "./node_modules/@types"],
|
17
|
+
"types": ["jest"],
|
18
|
+
"jsx": "react-jsx"
|
19
|
+
},
|
20
|
+
"include": [
|
21
|
+
"src",
|
22
|
+
"../.redwood/types/includes/all-*",
|
23
|
+
"../.redwood/types/includes/api-*",
|
24
|
+
"../types"
|
25
|
+
]
|
26
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
.idea
|
2
|
+
.DS_Store
|
3
|
+
.env*
|
4
|
+
!.env.example
|
5
|
+
!.env.defaults
|
6
|
+
.netlify
|
7
|
+
.redwood/*
|
8
|
+
!.redwood/README.md
|
9
|
+
dev.db*
|
10
|
+
dist
|
11
|
+
dist-babel
|
12
|
+
node_modules
|
13
|
+
yarn-error.log
|
14
|
+
web/public/mockServiceWorker.js
|
15
|
+
web/types/graphql.d.ts
|
16
|
+
api/types/graphql.d.ts
|
17
|
+
api/src/lib/generateGraphiQLHeader.*
|
18
|
+
.pnp.*
|
19
|
+
.yarn/*
|
20
|
+
!.yarn/patches
|
21
|
+
!.yarn/plugins
|
22
|
+
!.yarn/releases
|
23
|
+
!.yarn/sdks
|
24
|
+
!.yarn/versions
|
@@ -0,0 +1,11 @@
|
|
1
|
+
// This file is used by the VSCode GraphQL extension
|
2
|
+
|
3
|
+
const { getPaths } = require('@redmix/project-config')
|
4
|
+
|
5
|
+
/** @type {import('graphql-config').IGraphQLConfig} */
|
6
|
+
const config = {
|
7
|
+
schema: getPaths().generated.schema,
|
8
|
+
documents: './web/src/**/!(*.d).{ts,tsx,js,jsx}',
|
9
|
+
}
|
10
|
+
|
11
|
+
module.exports = config
|
@@ -0,0 +1,8 @@
|
|
1
|
+
// This the Redwood root jest config
|
2
|
+
// Each side, e.g. ./web/ and ./api/ has specific config that references this root
|
3
|
+
// More info at https://redwoodjs.com/docs/project-configuration-dev-test-build
|
4
|
+
|
5
|
+
module.exports = {
|
6
|
+
rootDir: '.',
|
7
|
+
projects: ['<rootDir>/{*,!(node_modules)/**/}/jest.config.js'],
|
8
|
+
}
|