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

Examples - in-lining data, fixing codesandbox #9286

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions .github/workflows/tests_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ jobs:
- name: Unit tests
run: DATABASE_URL=file:./test.db pnpm jest --ci --testPathIgnorePatterns=admin-ui-tests --testPathIgnorePatterns=api-tests --testPathIgnorePatterns=examples-smoke-tests --testPathIgnorePatterns=examples/testing

examples_snapshot_tests:
name: Examples Snapshot Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: ./.github/actions/ci-setup-examples

- name: Snapshot tests
run: pnpm run test:examples-snapshot-tests

graphql_api_tests_postgresql:
name: API Tests PostgreSQL
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
dist/
node_modules/
*.db
!example.db

# ts-gql
__generated__
Expand Down
19 changes: 19 additions & 0 deletions examples/usecase-todo/.codesandbox/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://codesandbox.io/schemas/tasks.json",
"setupTasks": [
{
"name": "Installing Dependencies",
"command": "pnpm install"
},
{
"name": "Start Dev Server",
"command": "pnpm dev"
}
],
"tasks": {
"start": {
"name": "Start Development",
"command": "pnpm dev"
}
}
}
4 changes: 4 additions & 0 deletions examples/usecase-todo/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Node.js",
"image": "mcr.microsoft.com/devcontainers/javascript-node:20"
}
13 changes: 7 additions & 6 deletions examples/usecase-todo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ To run this project, clone the Keystone repository locally, run `pnpm install` a
pnpm dev
```

This will start Keystone’s Admin UI at [localhost:3000](http://localhost:3000), where you can add items to an empty database.
This will start Keystone’s Admin UI at [localhost:3000](http://localhost:3000), where you will see Keystone with minimal sample data.

You can also access Keystone’s GraphQL Playground at [localhost:3000/api/graphql](http://localhost:3000/api/graphql) to explore the GraphQL API, and run [queries](https://keystonejs.com/docs/guides/filters) and [mutations](https://keystonejs.com/docs/graphql/overview#mutations) on your data.

Congratulations, you’re now up and running with Keystone! 🚀

### Optional: add sample data
### Sample data

This example includes sample data. To add it to your database:
This example includes sample data in `example.db` - deleting this file and restarting the dev server will leave you with an empty database.

1. Ensure you’ve initialised your project with `pnpm dev` at least once.
2. Run `pnpm seed-data`. This will populate your database with sample content.
3. Run `pnpm dev` again to startup Admin UI with sample data in place.
To re-seed the sample data:
1. Stop the server
2. Run `pnpm seed-data`
3. Restart the server with `pnpm dev`

## Try it out in CodeSandbox 🧪

Expand Down
Binary file added examples/usecase-todo/example.db
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/usecase-todo/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { config } from '@keystone-6/core'
import { lists } from './schema'
import type { TypeInfo } from '.keystone/types'

Check failure on line 3 in examples/usecase-todo/keystone.ts

View workflow job for this annotation

GitHub Actions / Linting

Cannot find module '.keystone/types' or its corresponding type declarations.

export default config<TypeInfo>({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
url: process.env.DATABASE_URL ?? 'file:./example.db',

// WARNING: this is only needed for our monorepo examples, dont do this
prismaClientPath: 'node_modules/myprisma',
Expand Down
9 changes: 5 additions & 4 deletions examples/usecase-todo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
"version": null,
"private": true,
"license": "MIT",
"packageManager": "[email protected]",
"scripts": {
"dev": "keystone dev",
"start": "keystone start",
"build": "keystone build",
"postinstall": "keystone postinstall",
kennedybaird marked this conversation as resolved.
Show resolved Hide resolved
"test:monorepo-snapshot-test": "keystone build --no-ui --frozen",
"seed-data": "tsx seed-data.ts"
},
"dependencies": {
"@keystone-6/core": "^6.2.0",
"@prisma/client": "5.17.0"
"@prisma/client": "*"
},
"devDependencies": {
"prisma": "5.17.0",
"tsx": "^4.0.0",
"prisma": "*",
kennedybaird marked this conversation as resolved.
Show resolved Hide resolved
"tsx": "^4.16.0",
"typescript": "^5.5.0"
}
}
7 changes: 0 additions & 7 deletions examples/usecase-todo/sandbox.config.json

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test:types": "tsc",
"test:debug": "node --inspect-brk ./node_modules/.bin/jest",
"test:admin-ui": "jest tests/admin-ui-tests",
"test:examples-snapshot-tests": "pnpm -F './examples/**' run test:monorepo-snapshot-test",
"build": "preconstruct build",
"prepare": "preconstruct dev"
},
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading