convex-functions

Build validated Convex functions for queries, mutations, and actions with error handling.

Updated May 4, 2024
One-click install
npx skills add https://github.com/kcrlee/dots --skill convex-functions-kcrlee
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: convex-functions
Source: https://github.com/kcrlee/dots/tree/main/claude/.claude/skills/convex-functions
Command: npx skills add https://github.com/kcrlee/dots --skill convex-functions-kcrlee

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you implement Convex backend functions correctly, so you can avoid validation mistakes, runtime issues, and unsafe database or API usage.

Core Features & Use Cases

  • Queries, Mutations, and Actions: Choose the right function type for reactive reads, transactional writes, or external integrations.
  • HTTP Actions and Internal Functions: Build webhooks, API endpoints, and sensitive private workflows with proper separation of concerns.
  • Validation and Error Handling: Add argument and return validators, use ConvexError for user-facing failures, and keep code aligned with Convex best practices.
  • Use Case: Use this Skill when creating a production Convex feature such as a task manager, payment workflow, webhook handler, or scheduled notification pipeline.

Quick Start

Use this skill to draft a Convex function with the correct type, validators, runtime setup, and error handling for your specific backend task.

Frequently Asked Questions about convex-functions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add argument and return validators to Convex functions?

To add argument and return validators to Convex functions, define validation schemas at the function boundary using Convex's built-in validator types. This enforces runtime type checking for args and returns, preventing invalid database inputs and unsafe API usage in production.

When should I use Convex actions versus queries and mutations?

Use Convex actions versus queries and mutations based on execution model: queries handle reactive reads, mutations manage transactional database writes, and actions integrate external API calls or third-party services. Selecting the correct function type ensures safe runtime usage and proper separation of concerns.

How do I handle user-facing errors in Convex backend functions?

To handle user-facing errors in Convex backend functions, throw a ConvexError object within your mutation or action. This approach aligns with Convex best practices, safely communicating validation failures or runtime issues to the client without crashing the application.

Can I build webhook endpoints and API routes with Convex HTTP actions?

Yes, you can build webhook endpoints and API routes with Convex HTTP actions. HTTP actions provide proper separation of concerns for external integrations, allowing you to receive incoming webhooks and route API traffic independently from internal database queries and mutations.

What is the best way to separate database work from external API calls in Convex?

The best way to separate database work from external API calls in Convex is by isolating logic into distinct function types. Use mutations for transactional database operations and actions for external API requests, ensuring clear execution model selection and safe runtime usage.