Tento is designed to be a thin typed layer on top of Shopify GraphQL Client. We’ve designed in the best way to operate a Shopify from TypeScript
and it time to make it better.
Tento Metaobjects represents the Shopify Metaobject GraphQL with all features they have on the moment.
Relational queries are meant to provide you with a great developer experience for querying. You can opt-in to use it based on your needs.
import { tento } from "@drizzle-team/tento" ;
import * as schema from "./schema" ;
const client = tento ({ schema });
const result = await client . metaobjects . designer .list ();
const result = {
items : [
{
_id : "gid://shopify/Metaobject/1" ,
_handle : "designer-d" ,
_displayName : "Designer #D" ,
_updatedAt : "2024-11-19T12:37:37.000Z" ,
name : "Tento" ,
description : "Made by Drizzle team" ,
website : "https://drizzle.team/" ,
} ,
] ,
pageInfo : {
startCursor : "eyJs=" ,
endCursor : "eyJs=" ,
hasNextPage : false ,
hasPreviousPage : false ,
} ,
}
import { metaobject } from "@drizzle-team/tento" ;
export const designer = metaobject ({
name : "Designer" ,
type : "designer" ,
fieldDefinitions : (f) => ({
name : f .singleLineTextField ({
name : "Title" ,
required : true ,
validations : (v) => [ v .min ( 1 ) , v .max ( 50 )] ,
}) ,
description : f .multiLineTextField ({
name : "Description" ,
}) ,
website : f .url ({
name : "Website" ,
}) ,
}) ,
});
List
Tento represents Shopify Metaobjects query
const result = await client . metaobjects . designer .list ();
await client . metaobjects . designer .list ({
first : 50 ,
sortKey : "display_name" ,
query : {
updatedAt : {
$gt : "2024-01-01" ,
} ,
} ,
});
await client . metaobjects . designer .list ({
fields : {
_id : true ,
name : true ,
website : true ,
}
});
// result type
const result : {
items : {
name : string ;
description : string | null ;
website : string | null ;
_id : string ;
_handle : string ;
_displayName : string ;
_updatedAt : Date ;
}[];
pageInfo : {
startCursor : string ;
endCursor : string ;
hasNextPage : boolean ;
hasPreviousPage : boolean ;
};
}
Get
Tento represents Shopify Metaobject query
const result = await client . metaobjects . designer .get ( "gid://shopify/Metaobject/1" );
await client . metaobjects . designer .get ( "gid://shopify/Metaobject/1" , {
_id : true ,
name : true ,
website : true ,
});
// return type
const result : {
name : string ;
description : string | null ;
website : string | null ;
_id : string ;
_handle : string ;
_displayName : string ;
_updatedAt : Date ;
} | undefined
Partial fields select
fields
parameter lets you include or omit fields you want to get from Shopify, Tento performs partial selects on the query level,
no additional data is transferred from the Shopify.
const result = await client . metaobjects . designer .list ({
fields : {
_id : true ,
name : true ,
} ,
});
const result = await client . metaobjects . designer .get ( "gid://shopify/Metaobject/1" , {
_id : true ,
name : true ,
});
const result = await client . metaobjects . designer .list ({
fields : {
_id : false ,
_handle : false ,
_displayName : false ,
_updatedAt : false ,
description : false ,
} ,
});
const result = await client . metaobjects . designer .get ( "gid://shopify/Metaobject/1" , {
_id : false ,
_handle : false ,
_displayName : false ,
_updatedAt : false ,
description : false ,
});
When both true
and false
select options are present, all false
options are ingored.
const result = await client . metaobjects . designer .list ({
fields : {
_id : false ,
name : true ,
} ,
});
const result = await client . metaobjects . designer .get ( "gid://shopify/Metaobject/1" , {
_id : false ,
name : true ,
});
Filters
Tento supports all pecific filters what Shopify has, see here .
For metaobjects querying Tento supports all Shopify Metaobjects Query filters .
const result = await client . metaobjects . designer .list ({
query : {
id : "1"
} ,
});
const result = await client . metaobjects . designer .list ({
query : {
id : {
$not : "1"
}
} ,
});
const result = await client . metaobjects . designer .list ({
query : {
id : {
$gt : "1"
}
} ,
});
const result = await client . metaobjects . designer .list ({
query : {
id : {
$gte : "1"
}
} ,
});
const result = await client . metaobjects . designer .list ({
query : {
id : {
$lt : "1"
}
} ,
});
const result = await client . metaobjects . designer .list ({
query : {
id : {
$lte : "1"
}
} ,
});
const result = await client . metaobjects . designer .list ({
query : {
$raw : "id:1"
} ,
});
const result = await client . metaobjects . designer .list ({
query : [
{
id : "1"
} ,
{
id : {
$lte : "2" ,
} ,
} ,
] ,
});
const result = await client . metaobjects . designer .list ({
query : {
$or : [
{
id : "1" ,
} ,
{
id : {
$gt : "1" ,
} ,
} ,
] ,
} ,
});
All supported fields that can be used in filters:
const result = await client . metaobjects . designer .list ({
query : {
id : "1" ,
displayName : "Designer #1" ,
handle : "designer-handle" ,
updatedAt : "2024-01-01" ,
} ,
});
Tento supports Shopify pagination
first
Supported pagination options
option default description first
50 requested number of nodes
for each page. after
- cursor to retrieve nodes
after in the connection.
const result = await client . metaobjects . designer .list ({
first : 10 ,
after : "In0="
});
last
Supported pagination options
option default description last
- requested number of nodes
for each page. before
- cursor to retrieve nodes
after in the connection.
IMPORTANT
To provide last
option you must specify before
cursor to prevent exceptions.
const result = await client . metaobjects . designer .list ({
last : 10 ,
before : "In0="
});
Sort
Tento supports Shopify Metaobjects query sort keys
Supported sort keys
keys id
, type
, updated_at
, display_name
reverse
true
, false
(false
as default)
const result = await client . metaobjects . designer .list ({
sortKey : "id" ,
reverse : true ,
});