Skip to content

Listing Printers

This example demonstrates how to query and paginate through available printers in the Helio Additive platform.

Create the following GraphQL query file, then run your language’s codegen tool to generate the types.

queries/Printers.graphql
query Printers($page: Int, $pageSize: Int) {
printers(page: $page, pageSize: $pageSize) {
pages
pageInfo {
hasPreviousPage
hasNextPage
}
objects {
... on Printer {
id
name
heatedBed
heatedChamber
nozzleDiameter
maxExtruderFlowRate
minExtruderFlowRate
maxHardwarePrintSpeed
minHardwarePrintSpeed
brand {
id
name
}
}
}
}
}

API Reference:

  1. Setup the client and configuration

    index.ts
    import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client";
    import { PrintersDocument } from "./queries/__generated/Printers.generated";
    // Load PAT from environment
    const PAT = process.env.PAT;
    if (!PAT) {
    throw new Error("PAT environment variable is required");
    }
    // Create Apollo Client
    const client = new ApolloClient({
    cache: new InMemoryCache(),
    link: new HttpLink({
    uri: "https://api.helioadditive.com/graphql",
    headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${PAT}`,
    },
    }),
    });
  2. Query and paginate through printers

    Fetch printers page by page until all printers have been retrieved.

    async function listPrinters() {
    let page = 1;
    const pageSize = 50;
    const allPrinters: Array<{ id: string; name: string; brand: string }> = [];
    // Paginate through all printers
    while (true) {
    const { data } = await client.query({
    query: PrintersDocument,
    variables: { page, pageSize },
    fetchPolicy: "no-cache",
    });
    // Collect printers from this page
    for (const printer of data?.printers?.objects ?? []) {
    if (printer.__typename === "Printer") {
    allPrinters.push({
    id: printer.id,
    name: printer.name,
    brand: printer.brand?.name ?? "Unknown",
    });
    console.log(`Printer: ${printer.name} (${printer.brand?.name})`);
    console.log(` - Heated Bed: ${printer.heatedBed}`);
    console.log(` - Heated Chamber: ${printer.heatedChamber}`);
    console.log(` - Nozzle Diameter: ${printer.nozzleDiameter}mm`);
    }
    }
    // Check if there are more pages
    if (!data?.printers?.pageInfo?.hasNextPage) {
    break;
    }
    page++;
    }
    return allPrinters;
    }
  3. Put it all together

    Run the function and display the results.

    // Example usage
    listPrinters()
    .then((printers) => {
    console.log(`\nTotal printers found: ${printers.length}`);
    })
    .catch(console.error);
  1. Create a .env.local file with your PAT:

    Terminal window
    PAT="your-personal-access-token"
  2. Run the example:

    Terminal window
    bun run index.ts