API Documentation
druxt
Modules
- druxt
The DruxtStore Vuex module.
Provides a Vuex state object, mutations and actions for interacting with the DruxtClient.
Typedefs
- addCollectionContext :
object Parameters for the
addCollectionmutation.- addResourceContext :
object Parameters for the
addResourcemutation.- flushCollectionContext :
object Parameters for the
flushCollectionmutation.- flushResourceContext :
object Parameters for the
flushResourcemutation.- getCollectionContext :
object Parameters for the
getCollectionaction.- getResourceContext :
object Parameters for the
getResourceaction.- DruxtClientQuery :
string|object A correctly formatted JSON:API query string or object.
druxt
The DruxtStore Vuex module.
Provides a Vuex state object, mutations and actions for interacting with the DruxtClient.
- druxt
- action
- getCollection(context) ⇒
Array.<object> - getResource(context) ⇒
object
- getCollection(context) ⇒
- state :
object - mutation
- action
getCollection(context) ⇒ Array.<object>
Get collection of resources.
Vuex Action => Mutates state propertyundefined
Kind: action method of druxt
Returns: Array.<object> - Array of Drupal JSON:API resource data.
| Param | Type |
|---|---|
| context | getCollectionContext |
Example
// Load all currently published Articles.
const resources = await this.$store.dispatch('druxt/getCollection', {
type: 'node--article',
query: new DrupalJsonApiParams().addFilter('status', '1'),
bypassCache: false
})
getResource(context) ⇒ object
Get JSON:API Resource.
- Executes query against Drupal JSON:API.
- Caches result in the Vuex store.
- Returns cached result from Vuex store when available.
Vuex Action => Mutates state propertyresources
Kind: action method of druxt
Returns: object - The Drupal JSON:API resource.
| Param | Type |
|---|---|
| context | getResourceContext |
Example
const resource = await this.$store.dispatch('druxt/getResource', {
type: 'node--article',
id,
bypassCache: false
})
state : object
Vuex State object.
Read only: true
Properties
| Name | Type | Description |
|---|---|---|
| collections | DruxtClientCollections | JSON:API resource collections store. |
| resources | object | JSON:API resources store. |
addCollection
Adds a JSON:API collection to the Vuex state object.
Kind: mutation method of druxt
| Param | Type |
|---|---|
| context | addCollectionContext |
Example
this.$store.commit('druxt/addCollection', { collection, type, hash })
addResource
Adds a JSON:API resource to the Vuex state object.
Kind: mutation method of druxt
| Param | Type |
|---|---|
| context | addResourceContext |
Example
this.$store.commit('druxt/addResource', { resource })
flushCollection
Removes JSON:API collections from the Vuex state object.
Kind: mutation method of druxt
| Param | Type |
|---|---|
| context | flushCollectionContext |
Example
// Flush all collections.
this.$store.commit('druxt/flushCollection', {})
// Flush target collection.
this.$store.commit('druxt/flushCollection', { type, hash, prefix })
flushResource
Removes JSON:API resources from the Vuex state object.
Kind: mutation method of druxt
| Param | Type |
|---|---|
| context | flushResourceContext |
Example
// Flush all resources.
this.$store.commit('druxt/flushResource', {})
// Flush target resource.
this.$store.commit('druxt/flushResource', { id, type, prefix, hash })
addCollectionContext : object
Parameters for the addCollection mutation.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| collection | object | A collection of JSON:API resources. |
| type | string | The JSON:API collection resource type. |
| hash | string | An md5 hash of the query string. |
| [prefix] | string | (Optional) The JSON:API endpoint prefix or langcode. |
Example
{
collection: {
jsonapi: {},
data: [{}],
links: {}
},
type: 'node--page',
hash: '_default',
prefix: 'en'
}
addResourceContext : object
Parameters for the addResource mutation.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| [prefix] | string | (Optional) The JSON:API endpoint prefix or langcode. |
| resource | object | The JSON:API resource. |
Example
{
prefix: 'en',
resource: {
jsonapi: {},
data: {},
links: {}
},
}
flushCollectionContext : object
Parameters for the flushCollection mutation.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| type | string | The JSON:API collection resource type. |
| hash | string | An md5 hash of the query string. |
| [prefix] | string | (Optional) The JSON:API endpoint prefix or langcode. |
Example
{
type: 'node--page',
hash: '_default',
prefix: 'en'
}
flushResourceContext : object
Parameters for the flushResource mutation.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| [type] | string | The JSON:API Resource type. |
| [id] | string | The Drupal resource UUID. |
| [prefix] | string | (Optional) The JSON:API endpoint prefix or langcode. |
Example
{
type: 'node--page',
id: 'd8dfd355-7f2f-4fc3-a149-288e4e293bdd',
prefix: 'en'
}
getCollectionContext : object
Parameters for the getCollection action.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| type | string | The JSON:API collection resource type. |
| [query] | DruxtClientQuery | A correctly formatted JSON:API query string or object. |
| [prefix] | string | (Optional) The JSON:API endpoint prefix or langcode. |
| [bypassCache] | boolean | (Optional) Bypass the Vuex cached collection. |
Example
{
type: 'node--page',
query: new DrupalJsonApiParams().addFilter('status', '1'),
bypassCache: false
}
getResourceContext : object
Parameters for the getResource action.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| type | string | The JSON:API Resource type. |
| id | string | The Drupal resource UUID. |
| [query] | DruxtClientQuery | A correctly formatted JSON:API query string or object. |
| [prefix] | string | (Optional) The JSON:API endpoint prefix or langcode. |
| [bypassCache] | boolean | (Optional) Bypass the Vuex cached resource. |
Example
{
type: 'node--page',
id: 'd8dfd355-7f2f-4fc3-a149-288e4e293bdd',
prefix: 'en',
bypassCache: false
}
DruxtClientQuery : string | object
A correctly formatted JSON:API query string or object.
Kind: global typedef
See: https://www.npmjs.com/package/drupal-jsonapi-params
Example
page[limit]=5&page[offset]=5
Example
new DrupalJsonApiParams().addPageLimit(5)