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 ();
{
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://www.google.com/" ,
} ,
] ,
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" ,
}) ,
}) ,
});
Querying
You need to provide all metaobject definitions
from your schema file upon tento()
initialization and then just use client.metaobjects
API.
import { tento } from "@drizzle-team/tento" ;
import * as schema from "./schema" ;
const client = tento ({ schema });
await client . metaobjects . designer .list ( ... );
import { metaobject , metafield } 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" ,
}) ,
}) ,
});
export const user = metaobject ({
name : "User" ,
type : "user" ,
fieldDefinitions : (f) => ({
name : f .singleLineTextField ({
name : "Name" ,
required : true ,
validations : (v) => [ v .min ( 3 ) , v .max ( 50 )] ,
}) ,
lastName : f .singleLineTextField ({
name : "Last name" ,
required : true ,
validations : (v) => [ v .min ( 3 ) , v .max ( 50 )] ,
}) ,
age : f .integer ({
name : "Age" ,
validations : (v) => [ v .min ( 18 )] ,
}) ,
}) ,
});
List
Tento represents Shopify Metaobjects query
const result = await client . metaobjects . designer .list ();
// 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" );
// 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.
Get including only with just _id
, name
:
const result = await client . metaobjects . designer .list ({
fields : {
_id : true ,
name : true ,
} ,
});
// result type
const result : {
items : {
_id : string ;
name : string ;
}[];
pageInfo : {
startCursor : string ;
endCursor : string ;
hasNextPage : boolean ;
hasPreviousPage : boolean ;
};
}
const result = await client . metaobjects . designer .get ( "gid://shopify/Metaobject/1" , {
_id : true ,
name : true ,
});
// result type
const result : {
_id : string ;
name : string ;
} | undefined
Get excluding _id
, _handle
, _displayName
, _updatedAt
, description
:
const result = await client . metaobjects . designer .list ({
fields : {
_id : false ,
_handle : false ,
_displayName : false ,
_updatedAt : false ,
description : false ,
} ,
});
// result type
const result : {
items : {
name : string ;
website : string | null ;
}[];
pageInfo : {
startCursor : string ;
endCursor : string ;
hasNextPage : boolean ;
hasPreviousPage : boolean ;
};
}
const result = await client . metaobjects . designer .get ( "gid://shopify/Metaobject/1" , {
_id : false ,
_handle : false ,
_displayName : false ,
_updatedAt : false ,
description : false ,
});
// result type
const result : {
name : string ;
website : string | null ;
} | undefined
Exclude and Include fields in the same query:
When both true
and false
select options are present, all false
options are ingored.
If you include the name
field and exclude the _id
field, _id
exclusion will be redundant, all fields apart from name
would be excluded anyways.
const result = await client . metaobjects . designer .list ({
fields : {
_id : false ,
name : true ,
} ,
});
// result type
const result : {
items : {
name : string ;
}[];
pageInfo : {
startCursor : string ;
endCursor : string ;
hasNextPage : boolean ;
hasPreviousPage : boolean ;
};
}
const result = await client . metaobjects . designer .get ( "gid://shopify/Metaobject/1" , {
_id : false ,
name : true ,
});
// result type
const result : {
name : string ;
} | undefined
Filters
Tento supports all pecific filters what Shopify has, see here .
Especially for metaobjects querying Tento supports all Shopify Metaobjects Query filters .
eq
Supported fields to filter
fields displayName
, handle
, id
, updatedAt
const result = await client . metaobjects . designer .list ({
query : {
displayName : "designer #1"
} ,
});
not
Supported fields to filter
fields displayName
, handle
, id
, updatedAt
const result = await client . metaobjects . designer .list ({
query : {
displayName : {
$not : "designer #1"
}
} ,
});
gt
Supported fields to filter
fields displayName
, handle
, id
, updatedAt
const result = await client . metaobjects . designer .list ({
query : {
id : {
$gt : "1"
}
} ,
});
gte
Supported fields to filter
fields displayName
, handle
, id
, updatedAt
const result = await client . metaobjects . designer .list ({
query : {
id : {
$gte : "1"
}
} ,
});
lt
Supported fields to filter
fields displayName
, handle
, id
, updatedAt
const result = await client . metaobjects . designer .list ({
query : {
id : {
$lt : "1"
}
} ,
});
lte
Supported fields to filter
fields displayName
, handle
, id
, updatedAt
const result = await client . metaobjects . designer .list ({
query : {
id : {
$lte : "1"
}
} ,
});
raw
const result = await client . metaobjects . designer .list ({
query : {
$raw : "id:1"
} ,
});
and
Supported fields to filter
fields displayName
, handle
, id
, updatedAt
const result = await client . metaobjects . designer .list ({
query : [
{
id : '1'
} ,
{
id : {
$lte : "2" ,
} ,
} ,
] ,
});
or
Supported fields to filter
fields displayName
, handle
, id
, updatedAt
const result = await client . metaobjects . designer .list ({
query : {
$or : [
{
id : "1" ,
} ,
{
id : {
$gt : "1" ,
} ,
} ,
] ,
} ,
});
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
const result = await client . metaobjects . designer .list ({
sortKey : 'id'
});
You can control sort direction using reverse
option. Default value is false
.
const result = await client . metaobjects . designer .list ({
sortKey : 'id' ,
reverse : true ,
});