A hook to interact with the Hermes API using template literal syntax. This provides a more intuitive API that closely mirrors the server-side query syntax, making queries easier to write and debug.
| Name | Type | Description | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
props | object | The props for the hook. Properties
|
- Since
- 5.1.0
The Hermes state and actions.
- Type:
- object
const { query, mutation, isLoading } = useHermesTemplate();
// Query with template literal
const fetchContacts = async () => {
const result = await query`{
contact(${ args( { limit: 20 } ) }) {
id,
firstName,
lastName
}
}`;
return result?.data?.data?.contact;
};
// Mutation with template literal
const createContact = async ( firstName, lastName ) => {
await mutation`{
insert_contact(objects: [${ { firstName, lastName } }]) {
returning { id, firstName, lastName }
}
}`;
};Methods
(inner) handleLoadingChange(loading)
Callback to update loading state when requests start/end.
| Name | Type | Description |
|---|---|---|
loading | boolean | Whether there are active requests. |
- Since
- 5.1.0
(inner) mutation(strings, …values) → {Promise.<object>}
Tagged template function for Hermes mutations. Use backticks to write mutations in GraphQL-like syntax.
| Name | Type | Attributes | Description |
|---|---|---|---|
strings | Array | The template literal strings. | |
values | * | <repeatable> | The interpolated values. |
- Since
- 5.1.0
The mutation response.
- Type:
- Promise.<object>
// Insert
await mutation`{
insert_contact(objects: [${ { firstName: 'John', lastName: 'Doe' } }]) {
returning { id, firstName, lastName }
}
}`;
// Update
await mutation`{
update_contact(id: ${ contactId }, firstName: ${ newName }) {
returning { id, firstName }
}
}`;
// Delete
await mutation`{
delete_contact(id: ${ contactId }) {}
}`;
// Connect
await mutation`{
connect_contact_company(objects: [${ { from: contactId, to: companyId } }]) {}
}`;(inner) query(strings, …values) → {Promise.<object>}
Tagged template function for Hermes queries. Use backticks to write queries in GraphQL-like syntax.
| Name | Type | Attributes | Description |
|---|---|---|---|
strings | Array | The template literal strings. | |
values | * | <repeatable> | The interpolated values. |
- Since
- 5.1.0
The query response.
- Type:
- Promise.<object>
const result = await query`{
contact(limit: ${ limit }, search: ${ searchTerm }) {
id,
firstName,
lastName,
email { address, isPrimary }
}
}`;