I created this script for personal use before peXed published his gridsome-source-directus. Because it has a slightly different approach I decided to publish this package anyway.
- Release 1.0.1
- Renamed addContentType to addCollection for compatibility. If you use a pre 0.7.* version of gridsome use 1.0.0
- Release 1.0.0
- Automaticaly converts table names to Pascal Case, this results in a cleaner schema. But all your queries will break after updating. Set
pascalTypestofalseif you do not want this. - Now also converts nested objects to camel case. This can also break your queries. Set
shallowCamelCasetotrueif you do not want this.
- Automaticaly converts table names to Pascal Case, this results in a cleaner schema. But all your queries will break after updating. Set
- Automatically gets all collections.
- Automatically adds references for files.
- Automatically adds references for relations.
- Optionally set up routes,
- Optionally make all field names camel case,
yarn add @pienter/gridsome-source-directusnpm install @pienter/gridsome-source-directus
Add the plugin to your gridsome.config.js file.
| Name | Required | Type | Default | Description |
|---|---|---|---|---|
| url | true | string | / | Directus API root url (see here for more info) |
| project | false | string | '_' |
Directus project prefix |
| token | false | string | '' |
Directus static token (see here for more info), use either token or email/password |
| false | string | '' |
Directus user email | |
| password | false | string | '' |
Directus user password |
| camelCase | false | boolean | true |
Transform field names to camel case |
| shallowCamelCase | false | boolean | false |
Do only a shalow transformation to camel case. Use this after updating this package |
| pascalTypes | false | boolean | true |
Converts table names to pascal case |
| routes | false | object | {} |
Add route option to content type, object where key is the collection and the value is the route (see here for more info) |
module.exports = {
plugins: [
{
use: '@pienter/gridsome-source-directus',
options: {
url: 'https://directus.api.url',
project: '_',
email: 'directus@user.something',
password: 'USERPASSWORD',
camelCase: false,
routes: {
posts: 'posts/:year/:slug',
},
},
},
],
};