API Reference
The following sections work as a reference guide to all functionalities in OGM and in the Model class.
OGM
Function | Description | Example |
---|---|---|
|
Returns an |
|
|
Asynchronous method to initialize the OGM.
Internally, calls |
|
|
Returns a |
Type definition
Query return
Wrong query
|
|
Either writes to specified |
Writing to outFile
Writing with noWrite
|
assertIndexesAndConstraints
Asynchronous method to assert the existence of database constraints, that either resolves to void
in a successful scenario, or throws an error if the necessary constraints do not exist following its execution.
It takes an input
object as a parameter, being the supported fields the following examples.
Given the type definitions saved to the variable typeDefs
and a valid driver instance saved to the variable driver
:
type Book {
isbn: String! @unique
}
And the construction and initialization of an OGM
, using:
const ogm = new OGM({
typeDefs,
});
await ogm.init();
The following checks whether a unique node property constraint exists for label "Book" and property "isbn", and throws an error if it does not:
await ogm.assertIndexesAndConstraints();
The next example creates the constraint if it does not exist:
await ogm.assertIndexesAndConstraints({ options: { create: true } });
Input
Accepts the argument:
Name | Type | Description |
---|---|---|
|
|
Options for the execution of |
AssertConstraintsOptions
Name | Type | Description |
---|---|---|
|
|
Whether or not to create constraints if they do not yet exist. Disabled by default. |
Model
aggregate
This method can be used to aggregate nodes, and maps to the underlying schema Aggregate.
Arguments
Name | Type | Description |
---|---|---|
|
|
A JavaScript object representation of the GraphQL |
Example
Here is how you can write a query to find the longest User name:
const User = ogm.model("User");
const usersAggregate = await User.aggregate({
aggregate: {
name: {
longest: true
}
}
});
And this one is to find the longest User name where name starts with the letter "D":
const User = ogm.model("User");
const usersAggregate = await User.aggregate({
where: {
name_STARTS_WITH: "D"
},
aggregate: {
name: {
longest: true
}
}
});
create
This method can be used to update nodes, and maps to the underlying create
Mutation.
It returns a Promise
that resolves to the equivalent of the Mutation response for this operation.
Arguments
Name | Type | Description |
---|---|---|
|
|
JavaScript object representation of the GraphQL |
|
|
Selection set for the Mutation, see Selection Set for more information. |
|
|
The |
|
|
The |
|
|
The |
delete
This method can be used to delete nodes, and maps to the underlying Delete Mutation.
It returns a Promise
which resolves to a DeleteInfo
object:
Name | Type | Description |
---|---|---|
|
|
The number of nodes deleted. |
|
|
The number of relationships deleted. |
Arguments
Name | Type | Description |
---|---|---|
|
|
A JavaScript object representation of the GraphQL |
|
|
A JavaScript object representation of the GraphQL |
|
|
The |
|
|
The |
find
This method can be used to find nodes, and maps to the underlying schema Queries.
It returns a Promise
which resolves to an array of objects matching the type of the Model.
Arguments
Name | Type | Description |
---|---|---|
|
|
A JavaScript object representation of the GraphQL |
|
|
A JavaScript object representation of the GraphQL |
|
|
Selection set for the Mutation, see Selection Set for more information. |
|
|
The |
|
|
The |
|
|
The |
update
This method can be used to update nodes, and maps to the underlying update
mutation.
It returns a Promise
that resolves to the equivalent of the mutation response for this operation.
Arguments
Name | Type | Description |
---|---|---|
|
|
A JavaScript object representation of the GraphQL |
|
|
A JavaScript object representation of the GraphQL |
|
|
A JavaScript object representation of the GraphQL |
|
|
A JavaScript object representation of the GraphQL |
|
|
A JavaScript object representation of the GraphQL |
|
|
A JavaScript object representation of the GraphQL |
|
|
Selection set for the Mutation, see Selection set for more information. |
|
|
The |
|
|
The |
|
|
The |