Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# get 10 models sorted by created_at - oldest to newest.
# Note it shows models from all schemas, because no filtering is applied
query getItems {
models(
per_page: 10
) {
total_entries
results {
id
created_at
name: property(name: "name")
price: property_int(name: "price")
}
}
}
# get *items* filtered and sorted by created_at - newest to oldest
query getFilteredItems {
models(
per_page: 10,
filter: {
model_schema_name: { value: "item" },
properties: [
{
name: "category",
value: "jewellery/jewellery_sets"
},
{
name: "price",
range: { lt: "2000", gt: "1000" }
}
]
}
sort: {
created_at: { order: DESC }
}
) {
total_entries
results {
id
name: property(name: "name")
price: property_int(name: "price")
}
}
}
# Create item with some basic data
mutation createItem {
model_create(
model: {
model_schema_name: "item"
properties: [
{ name: "name", value: "item name" }
{ name: "description", value: "item description" }
{ name: "category", value: "jewellery/jewellery_sets" }
{ name: "price", value_int: 1337 }
]
}
){
id
name: property(name: "name")
description: property(name: "description")
price: property(name: "price")
category: property(name: "category")
}
}
# Verify that item has been created
query getCreatedItem {
models(
per_page: 10,
filter: {
id: { value: "6434" } # use ID returned by createItem mutation
}) {
results {
id
name: property(name: "name")
price: property_int(name: "price")
}
}
}
# Delete this item
mutation deleteItem {
model_delete(
id: 6434
) {
id
}
}
# Verify that item has been deleted
query getDeletedItem {
models(
per_page: 10,
filter: {
id: { value: "6434" } # use ID returned by createItem mutation
}) {
results {
id
name: property(name: "name")
price: property_int(name: "price")
}
}
}
# Delete all models - one time only, careful
mutation deleteAllItems {
models_delete_all(
model_schema_name: "item"
) {
count
}
}
# Verify that items are not returned by default
query getAllItems {
models(
per_page: 10
filter: {
model_schema_name: { value: "item" },
}
) {
results {
id
deleted_at
name: property(name: "name")
price: property_int(name: "price")
}
}
}
# Verify that items are in fact marked to be deleted in the next prune cycle
query getDeletedItems {
models(
per_page: 10
filter: {
model_schema_name: { value: "item" },
deleted_at: { exists: true }
}
) {
results {
id
deleted_at
name: property(name: "name")
price: property_int(name: "price")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment