Methods
addCurrentToMenuItem(item)
Add the current class and attributes to a menu item.
| Name | Type | Description |
|---|---|---|
item | HTMLElement | The menu item to add the current class and attributes to. |
- Since
- 4.0.2
buildArgsString(args, returnParensOnEmpty) → {string}
Build an arguments string from an object for use in Hermes query.
| Name | Type | Description |
|---|---|---|
args | object | The object to convert to a string. |
returnParensOnEmpty | boolean | Whether to return parentheses around the args string if it is empty. |
- Since
- 4.1.0
- Source
The arguments string.
- Type:
- string
buildCacheKey(prefix, paramKeys, params) → {string}
Build a cache key.
| Name | Type | Description |
|---|---|---|
prefix | string | The prefix for the cache key. |
paramKeys | Array | The keys of the parameters to build the cache key. |
params | object | The parameters to build the cache key. |
- Since
- 4.0.2
- Source
The cache key.
- Type:
- string
buildConnectObject(obj) → {object}
Build a connect or disconnect object for use in Hermes mutation.
| Name | Type | Description |
|---|---|---|
obj | object | | The object or array of objects to convert to a connect or disconnect object. |
- Since
- 4.1.0
The connect or disconnect object.
- Type:
- object
buildDeleteObject(obj) → {object}
Build a delete object for use in Hermes mutation.
| Name | Type | Description |
|---|---|---|
obj | object | The object to convert to a delete object. |
- Since
- 4.1.0
The delete object.
- Type:
- object
buildInsertObject(obj) → {object}
Build an insert object for use in Hermes mutation.
| Name | Type | Description |
|---|---|---|
obj | object | The object to convert to an insert object. |
- Since
- 4.1.0
The insert object.
- Type:
- object
buildMutationString(mutationObj, mutationType) → {string}
Build a mutation string from a mutation object and mutation type for use in Hermes mutation.
| Name | Type | Description |
|---|---|---|
mutationObj | object | The mutation object to convert to a string. |
mutationType | string | The type of mutation to build. Must be one of 'insert', 'update', 'delete', 'connect', or 'disconnect'. |
- Since
- 4.1.0
The mutation string.
- Type:
- string
// Example inserting single company object.
const insertMutationObj = {
company: {
objects: [ { name: 'My Business', address: '123 Main St' } ],
returning: {
id: true,
name: true,
address: true,
},
},
};
const insertMutationString = buildMutationString( insertMutationObj, 'insert' );
// insertMutationString = '{insert_company(objects: [{name: "My Business", address: "123 Main St"}]) {returning {id, name, address}}}';
// Example with single company updates.
const updateMutationObj = {
company: {
id: 1,
_args: {
name: 'My Business',
address: '123 Main St',
},
returning: {
id: true,
name: true,
address: true,
},
},
};
const updateMutationString = buildMutationString( updateMutationObj, 'update' );
// updateMutationString = '{update_company(id: 1, name: "My Business", address: "123 Main St") {returning {id, name, address}}}';
// Example deleting single company object.
const deleteMutationObj = {
company: {
id: 1,
},
};
const deleteMutationString = buildMutationString( deleteMutationObj, 'delete' );
// deleteMutationString = '{delete_company(id: 1) {}}';
// Example connecting single company and department objects.
const singleConnectMutationObj = {
company_department: {
from: 1,
to: 2,
},
};
const singleConnectMutationString = buildMutationString( singleConnectMutationObj, 'connect' );
// connectMutationString = '{connect_company_department(objects: [{from: 1, to: 2}]) {}}';
// Example connecting multiple company and department objects.
const multipleConnectMutationObj = {
company_department: [
{
from: 1,
to: 2,
},
{
from: 3,
to: 4,
},
],
};
const multipleConnectMutationString = buildMutationString( multipleConnectMutationObj, 'connect' );
// multipleConnectMutationString = '{connect_company_department(objects: [{from: 1, to: 2}, {from: 3, to: 4}]) {}}';
// Example disconnecting single company and department objects.
const singleDisconnectMutationObj = {
company_department: {
from: 1,
to: 2,
},
};
const disconnectMutationString = buildMutationString( singleDisconnectMutationObj, 'disconnect' );
// disconnectMutationString = '{disconnect_company_department(objects: [{from: 1, to: 2}]) {}}';
// Example disconnecting multiple company and department objects.
const multipleDisconnectMutationObj = {
company_department: [
{
from: 1,
to: 2,
},
{
from: 3,
to: 4,
},
],
};
const multipleDisconnectMutationString = buildMutationString( multipleDisconnectMutationObj, 'disconnect' );
// multipleDisconnectMutationString = '{disconnect_company_department(objects: [{from: 1, to: 2}, {from: 3, to: 4}]) {}}';buildQueryString(queryObj) → {string}
Build a query string from a query object for use in Hermes query.
| Name | Type | Description |
|---|---|---|
queryObj | object | The query object to convert to a string. |
- Since
- 4.0.5
The query string.
- Type:
- string
const queryObj = {
company: {
_alias: 'first_ten_companies',
_args: {
limit: 10,
},
id: true,
name: {
_alias: 'business_name',
},
address: true,
department: {
id: {
_alias: 'department_id',
},
name: true,
},
},
};
const queryString = buildQueryString( queryObj );
// queryString = '{first_ten_companies: company(limit: 10) {id, business_name: name, address, department {department_id: id, name}}}';
const arrayQueryObj = {
company: [
{
_args: {
limit: 2,
},
id: true,
},
{
_alias: 'pagination',
_args: {
limit: 1,
},
aggregate: true,
},
],
};
const arrayQueryString = buildQueryString( arrayQueryObj );
// arrayQueryString = '{company(limit: 2) {id}, pagination: company(limit: 1) {aggregate}}';
const transformQueryObj = {
company: {
companyLogo: {
_transform: {
_alias: 'companyLogoSrc',
_args: {
transformMakeThumb: 'medium',
},
},
},
},
};
const transformQueryString = buildQueryString( transformQueryObj );
// transformQueryString = '{company {companyLogoSrc: companyLogo(trahsformMakeThumb: "medium")}}';buildQueryStringPart(obj, key) → {string}
Build a query string part from a query object and key for use in Hermes query.
| Name | Type | Description |
|---|---|---|
obj | object | The query object to convert to a string. |
key | string | The key of the query object. |
- Since
- 4.1.0
If transform does not have
_aliasand_argskeys.- Type
- Error
The query string part.
- Type:
- string
buildQueryStringRecursive(obj) → {string}
Recursively build a query string from a query object for use in Hermes query.
| Name | Type | Description |
|---|---|---|
obj | object | | The query object or array to convert to a string. |
- Since
- 4.0.5
If an array of queries for the same key do not have aliases.
- Type
- Error
The query string.
- Type:
- string
buildUpdateObject(obj) → {object}
Build an update object for use in Hermes mutation.
| Name | Type | Description |
|---|---|---|
obj | object | The object to convert to an update object. |
- Since
- 4.1.0
The update object.
- Type:
- object
removeCurrentFromMenuItem(item)
Remove the current class and attributes from a menu item.
| Name | Type | Description |
|---|---|---|
item | HTMLElement | The menu item to remove the current class and attributes from. |
- Since
- 4.0.2
stringifyArg(arg) → {string}
Build a string representation of a variable for use in Hermes query.
| Name | Type | Description |
|---|---|---|
arg | * | The property to convert to a string. |
- Since
- 4.0.5
- Source
The string representation of the property.
- Type:
- string
useCache(initialState) → {object}
A hook to manage a cache.
| Name | Type | Description |
|---|---|---|
initialState | object | The initial state of the cache. |
- Since
- 4.0.2
- Source
The cache state and actions.
- Type:
- object
useId(defaultId) → {string}
Generates a unique ID if default ID is not provided.
| Name | Type | Description |
|---|---|---|
defaultId | string | The default ID. |
- Since
- 3.2.2
- Source
The ID.
- Type:
- string
validateAliases(arr, key) → {boolean}
Validates an array of objects to ensure three conditions related to _alias properties: 1. At least (array length - 1) objects must have an _alias key. 2. All _alias values must be unique. 3. None of the _alias values must match key.
| Name | Type | Description |
|---|---|---|
arr | Array | The array to validate. |
key | string | The key to avoid. |
- Source
Whether the array passes validation or not.
- Type:
- boolean