query_records
Retrieve records from Gadget models by specifying the model name and GraphQL fields. Use introspect_model first to discover available fields for querying.
Instructions
Query records from any Gadget model. Specify the model name and a GraphQL field selection. Use introspect_model first to discover available fields.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | Yes | Model name in camelCase, e.g. shopifyOrder, label | |
| fields | Yes | GraphQL field selection, e.g. "id name email createdAt" | |
| filter | No | Gadget filter object, e.g. { "name": { "equals": "#59389" } } | |
| limit | No | Max records to return (default 10, max 50) |
Implementation Reference
- src/tools.ts:88-123 (handler)The handler logic for the 'query_records' tool, which constructs and executes a GraphQL query based on provided arguments.
case "query_records": { const { model, fields, filter, limit = 10 } = args as { model: string; fields: string; filter?: Record<string, unknown>; limit?: number; }; const first = Math.min(limit, 50); const filterArg = filter ? `, filter: $filter` : ""; const varsDef = filter ? `($filter: ${model.charAt(0).toUpperCase() + model.slice(1)}Filter, $first: Int)` : `($first: Int)`; const varsVal: Record<string, unknown> = { first }; if (filter) varsVal.filter = filter; const query = ` query QueryRecords${varsDef} { ${model}(first: $first${filterArg}) { edges { node { ${fields} } } pageInfo { hasNextPage } } } `; const data = await gql(query, varsVal); const connection = data[model]; const records = connection.edges.map((e: any) => e.node); return { content: [{ type: "text", text: JSON.stringify({ records, hasMore: connection.pageInfo.hasNextPage }, null, 2), }], }; } - src/tools.ts:184-204 (schema)The schema definition for 'query_records', including input parameters like model, fields, filter, and limit.
{ name: "query_records", description: "Query records from any Gadget model. Specify the model name and a GraphQL field selection. Use introspect_model first to discover available fields.", inputSchema: { type: "object", required: ["model", "fields"], properties: { model: { type: "string", description: "Model name in camelCase, e.g. shopifyOrder, label" }, fields: { type: "string", description: "GraphQL field selection, e.g. \"id name email createdAt\"", }, filter: { type: "object", description: "Gadget filter object, e.g. { \"name\": { \"equals\": \"#59389\" } }", }, limit: { type: "number", description: "Max records to return (default 10, max 50)" }, }, }, },