API Documentation

druxt

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

addResourceContext : object

Parameters for the addResource mutation.

flushCollectionContext : object

Parameters for the flushCollection mutation.

flushResourceContext : object

Parameters for the flushResource 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.

ParamType
contextgetCollectionContext

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.

ParamType
contextgetResourceContext

Example

const resource = await this.$store.dispatch('druxt/getResource', {
  type: 'node--article',
  id,
  bypassCache: false
})

state : object

Vuex State object.

Read only: true
Properties

NameTypeDescription
collectionsDruxtClientCollectionsJSON:API resource collections store.
resourcesobjectJSON:API resources store.

addCollection

Adds a JSON:API collection to the Vuex state object.

Kind: mutation method of druxt

ParamType
contextaddCollectionContext

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

ParamType
contextaddResourceContext

Example

this.$store.commit('druxt/addResource', { resource })

flushCollection

Removes JSON:API collections from the Vuex state object.

Kind: mutation method of druxt

ParamType
contextflushCollectionContext

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

ParamType
contextflushResourceContext

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

ParamTypeDescription
collectionobjectA collection of JSON:API resources.
typestringThe JSON:API collection resource type.
hashstringAn 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

ParamTypeDescription
[prefix]string(Optional) The JSON:API endpoint prefix or langcode.
resourceobjectThe JSON:API resource.

Example

{
  prefix: 'en',
  resource: {
    jsonapi: {},
    data: {},
    links: {}
  },
}

flushCollectionContext : object

Parameters for the flushCollection mutation.

Kind: global typedef

ParamTypeDescription
typestringThe JSON:API collection resource type.
hashstringAn 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

ParamTypeDescription
[type]stringThe JSON:API Resource type.
[id]stringThe 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

ParamTypeDescription
typestringThe JSON:API collection resource type.
[query]DruxtClientQueryA 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

ParamTypeDescription
typestringThe JSON:API Resource type.
idstringThe Drupal resource UUID.
[query]DruxtClientQueryA 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)