Tento Metaobject Query

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.

index.ts
schema.ts
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,
  },
}

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.

Include
Exclude
Both
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,
});

Filters

Tento supports all pecific filters what Shopify has, see here.
For metaobjects querying Tento supports all Shopify Metaobjects Query filters.

eq
not
gt
gte
lt
lte
raw
and
or
const result = await client.metaobjects.designer.list({
  query: {
    id: "1"
  },
});

Supported fields

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",
  },
});

Pagination

Tento supports Shopify pagination

first

Supported pagination options

optiondefaultdescription
first50requested 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

optiondefaultdescription
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

keysid, type, updated_at, display_name
reversetrue, false (false as default)
const result = await client.metaobjects.designer.list({
  sortKey: "id",
  reverse: true,
});