This base project implements expands on the Task Management example to demonstrate the use of custom string id
fields.
We use the standard Task
and People
lists but, in addition, both lists:
- Add
db: { idField: { kind: 'string' } }
to support custom string identifiers for database rows - Use a
resolveInput
hook that providesid
values forcreate
operations
In this case the id format is ${listKey}_${cuid2()}
(eg. TASK_knu49p0kr0m9p7q79goxgrnh
or PERSON_bpr7cdktsykgf486cmvqmfq1
) but any string format could be used.
If the resolveInput
was exclude, the id fields would fall back to using standard cuid
values – the Keystone default.
To run this project, clone the Keystone repository locally, run pnpm install
at the root of the repository then navigate to this directory and run:
pnpm dev
This will start Keystone’s Admin UI at localhost:3000, where you can add items to an empty database.
You can also access Keystone’s GraphQL Playground at localhost:3000/api/graphql to explore the GraphQL API, and run queries and mutations on your data.
Congratulations, you’re now up and running with Keystone! 🚀
This example includes sample data. To add it to your database:
- Ensure you’ve initialised your project with
pnpm dev
at least once. - Run
pnpm seed-data
. This will populate your database with sample content. - Run
pnpm dev
again to startup Admin UI with sample data in place.
You can play with this example online in a web browser using the free codesandbox.io service. To launch this example, open the URL https://githubbox.com/keystonejs/keystone/tree/main/examples/custom-id. You can also fork this sandbox to make your own changes.