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

Querying

You need to provide all metaobject definitions from your schema file upon tento() initialization and then just use client.metaobjects API.

index.ts
schema.ts
import { tento } from "@drizzle-team/tento";
import * as schema from "./schema";

const client = tento({ schema });

await client.metaobjects.designer.list(...);

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:

List query
Get query
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;
  };
}


Get excluding _id, _handle, _displayName, _updatedAt, description:

List query
Get query
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;
  };
}


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.

List query
Get query
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;
  };
}

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

fieldsdisplayName, handle, id, updatedAt
const result = await client.metaobjects.designer.list({
  query: {
   displayName: "designer #1"
  },
});

not

Supported fields to filter

fieldsdisplayName, handle, id, updatedAt
const result = await client.metaobjects.designer.list({
  query: {
   displayName: {
      $not: "designer #1"
    }
  },
});

gt

Supported fields to filter

fieldsdisplayName, handle, id, updatedAt
const result = await client.metaobjects.designer.list({
  query: {
    id: {
      $gt: "1"
    }
  },
});

gte

Supported fields to filter

fieldsdisplayName, handle, id, updatedAt
const result = await client.metaobjects.designer.list({
  query: {
    id: {
      $gte: "1"
    }
  },
});

lt

Supported fields to filter

fieldsdisplayName, handle, id, updatedAt
const result = await client.metaobjects.designer.list({
  query: {
    id: {
      $lt: "1"
    }
  },
});

lte

Supported fields to filter

fieldsdisplayName, 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

fieldsdisplayName, handle, id, updatedAt
const result = await client.metaobjects.designer.list({
  query: [
      {
        id: '1'
      },
      {
        id: {
          $lte: "2",
        },
      },
    ],
});

or

Supported fields to filter

fieldsdisplayName, handle, id, updatedAt
const result = await client.metaobjects.designer.list({
  query: {
    $or: [
      {
        id: "1",
      },
      {
        id: {
          $gt: "1",
        },
      },
    ],
  },
});

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