# 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 addCollection mutation.

addResourceContext : object

Parameters for the addResource mutation.

getCollectionContext : object

Parameters for the getCollection action.

getResourceContext : object

Parameters for the getResource action.

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.


# 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'),
})
1
2
3
4
5

# 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 })
1

# 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 })
1

# 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, hash })
1

# 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.

Example

{
  collection: {
    jsonapi: {},
    data: [{}],
    links: {}
  },
  type: 'node--page',
  hash: '_default'
}
1
2
3
4
5
6
7
8
9

# addResourceContext : object

Parameters for the addResource mutation.

Kind: global typedef

Param Type Description
resource object The JSON:API resource.
hash string An md5 hash of the query string.

Example

{
  resource: {
    jsonapi: {},
    data: {},
    links: {}
  },
  hash: '_default'
}
1
2
3
4
5
6
7
8

# 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.

Example

{
  type: 'node--page',
  query: new DrupalJsonApiParams().addFilter('status', '1')
}
1
2
3
4

# 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.

Example

{
  type: 'node--page',
  id: 'd8dfd355-7f2f-4fc3-a149-288e4e293bdd'
}
1
2
3
4

# DruxtClientQuery : string | object

A correctly formatted JSON:API query string or object.

Kind: global typedef
See: https://www.npmjs.com/package/drupal-jsonapi-params (opens new window)
Example

page[limit]=5&page[offset]=5
1

Example

new DrupalJsonApiParams().addPageLimit(5)
1